Skip to content

Commit 6f3691d

Browse files
committed
tests: add test case for default renew
1 parent b9ffe8c commit 6f3691d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

test/config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ globalTests+=(
1717
permissions_custom
1818
symlinks
1919
acme_hooks
20+
certs_default_renew
2021
)
2122

2223
# The ocsp_must_staple test does not work with Pebble
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

test/tests/certs_default_renew/run.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
## Test for the DEFAULT_RENEW function.
4+
5+
if [[ -z $GITHUB_ACTIONS ]]; then
6+
le_container_name="$(basename "${0%/*}")_$(date "+%Y-%m-%d_%H.%M.%S")"
7+
else
8+
le_container_name="$(basename "${0%/*}")"
9+
fi
10+
11+
default_renew=170
12+
run_le_container "${1:?}" "$le_container_name" \
13+
--cli-args "--env DEFAULT_RENEW=$default_renew"
14+
15+
# Create the $domains array from comma separated domains in TEST_DOMAINS.
16+
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
17+
18+
# Cleanup function with EXIT trap
19+
function cleanup {
20+
# Remove the Nginx container silently.
21+
docker rm --force "${domains[0]}" &> /dev/null
22+
# Cleanup the files created by this run of the test to avoid foiling following test(s).
23+
docker exec "$le_container_name" /app/cleanup_test_artifacts
24+
# Stop the LE container
25+
docker stop "$le_container_name" > /dev/null
26+
}
27+
trap cleanup EXIT
28+
29+
container_email="contact@${domains[0]}"
30+
31+
# Run a nginx container for ${domains[0]} with LETSENCRYPT_EMAIL set.
32+
run_nginx_container --hosts "${domains[0]}" \
33+
--cli-args "--env LETSENCRYPT_EMAIL=${container_email}"
34+
35+
# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
36+
wait_for_symlink "${domains[0]}" "$le_container_name"
37+
38+
acme_cert_create_time_key="Le_CertCreateTime="
39+
acme_renewal_days_key="Le_RenewalDays="
40+
acme_next_renew_time_key="Le_NextRenewTime="
41+
42+
# Check if the default command is deliverd properly in /etc/acme.sh
43+
if docker exec "$le_container_name" [[ ! -d "/etc/acme.sh/$container_email" ]]; then
44+
echo "The /etc/acme.sh/$container_email folder does not exist."
45+
elif docker exec "$le_container_name" [[ ! -d "/etc/acme.sh/$container_email/${domains[0]}" ]]; then
46+
echo "The /etc/acme.sh/$container_email/${domains[0]} folder does not exist."
47+
elif docker exec "$le_container_name" [[ ! -f "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf" ]]; then
48+
echo "The /etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf file does not exist."
49+
fi
50+
51+
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\')"
52+
expected_renewal_days="${acme_renewal_days_key}'$default_renew'"
53+
expected_next_renew_time="${acme_next_renew_time_key}'$(($cert_create_time + $default_renew * 24 * 60 * 60 - 86400))'"
54+
actual_renewal_days="$(docker exec "$le_container_name" grep "$acme_renewal_days_key" "/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf")"
55+
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")"
56+
57+
if [[ "$expected_renewal_days" != "$actual_renewal_days" ]]; then
58+
echo "Renewal days is not correct"
59+
fi
60+
if [[ "$expected_next_renew_time" != "$actual_next_renew_time" ]]; then
61+
echo "Next renewal time is not correct"
62+
fi

0 commit comments

Comments
 (0)