Skip to content

Commit

Permalink
tests: add test case for default renew
Browse files Browse the repository at this point in the history
  • Loading branch information
chinkung committed Jul 22, 2022
1 parent b9ffe8c commit 6f3691d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ globalTests+=(
permissions_custom
symlinks
acme_hooks
certs_default_renew
)

# The ocsp_must_staple test does not work with Pebble
Expand Down
1 change: 1 addition & 0 deletions test/tests/certs_default_renew/expected-std-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

62 changes: 62 additions & 0 deletions test/tests/certs_default_renew/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

## Test for the DEFAULT_RENEW function.

if [[ -z $GITHUB_ACTIONS ]]; then
le_container_name="$(basename "${0%/*}")_$(date "+%Y-%m-%d_%H.%M.%S")"
else
le_container_name="$(basename "${0%/*}")"
fi

default_renew=170
run_le_container "${1:?}" "$le_container_name" \
--cli-args "--env DEFAULT_RENEW=$default_renew"

# Create the $domains array from comma separated domains in TEST_DOMAINS.
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"

# Cleanup function with EXIT trap
function cleanup {
# Remove the Nginx container silently.
docker rm --force "${domains[0]}" &> /dev/null
# Cleanup the files created by this run of the test to avoid foiling following test(s).
docker exec "$le_container_name" /app/cleanup_test_artifacts
# Stop the LE container
docker stop "$le_container_name" > /dev/null
}
trap cleanup EXIT

container_email="contact@${domains[0]}"

# Run a nginx container for ${domains[0]} with LETSENCRYPT_EMAIL set.
run_nginx_container --hosts "${domains[0]}" \
--cli-args "--env LETSENCRYPT_EMAIL=${container_email}"

# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
wait_for_symlink "${domains[0]}" "$le_container_name"

acme_cert_create_time_key="Le_CertCreateTime="
acme_renewal_days_key="Le_RenewalDays="
acme_next_renew_time_key="Le_NextRenewTime="

# Check if the default command is deliverd properly in /etc/acme.sh
if docker exec "$le_container_name" [[ ! -d "/etc/acme.sh/$container_email" ]]; then
echo "The /etc/acme.sh/$container_email folder does not exist."
elif docker exec "$le_container_name" [[ ! -d "/etc/acme.sh/$container_email/${domains[0]}" ]]; then
echo "The /etc/acme.sh/$container_email/${domains[0]} folder does not exist."
elif docker exec "$le_container_name" [[ ! -f "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf" ]]; then
echo "The /etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf file does not exist."
fi

cert_create_time="$(docker exec "$le_container_name" grep "$acme_cert_create_time_key" "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf" | cut -f2 -d\')"
expected_renewal_days="${acme_renewal_days_key}'$default_renew'"
expected_next_renew_time="${acme_next_renew_time_key}'$(($cert_create_time + $default_renew * 24 * 60 * 60 - 86400))'"
actual_renewal_days="$(docker exec "$le_container_name" grep "$acme_renewal_days_key" "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf")"
actual_next_renew_time="$(docker exec "$le_container_name" grep "$acme_next_renew_time_key" "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf")"

if [[ "$expected_renewal_days" != "$actual_renewal_days" ]]; then
echo "Renewal days is not correct"
fi
if [[ "$expected_next_renew_time" != "$actual_next_renew_time" ]]; then
echo "Next renewal time is not correct"
fi

0 comments on commit 6f3691d

Please sign in to comment.