Skip to content

Commit

Permalink
Test suite refactoring
Browse files Browse the repository at this point in the history
As much as possible, output to stdout on error condition only
in order to reduce the need for expected-std-out.txt
  • Loading branch information
buchdag committed Nov 27, 2020
1 parent f8a24a6 commit 92cf9ff
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 353 deletions.
2 changes: 1 addition & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ while true; do
shift
case "$flag" in
## Next line was modified by jrcs/docker-letsencrypt-nginx-proxy-companion
--dry-run|-d) dryRun=1 ;;
--dry-run|-d) dryRun=1 && export DRY_RUN=1 ;;
--help|-h|'-?') usage && exit 0 ;;
--test|-t) argTests["$1"]=1 && shift ;;
--config|-c) configs+=("$(readlink -f "$1")") && shift ;;
Expand Down
11 changes: 0 additions & 11 deletions test/tests/acme_accounts/expected-std-out.txt

This file was deleted.

33 changes: 14 additions & 19 deletions test/tests/acme_accounts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
function cleanup {
# Remove any remaining Nginx container(s) silently.
for domain in "${domains[@]}"; do
docker rm --force "$domain" > /dev/null 2>&1
docker rm --force "$domain" &> /dev/null
done
# Cleanup the files created by this run of the test to avoid foiling following test(s).
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf* && rm -rf /etc/acme.sh/default/le?.wtf*'
Expand All @@ -26,12 +26,7 @@ function cleanup {
trap cleanup EXIT

# Run an nginx container for ${domains[0]}.
docker run --rm -d \
--name "${domains[0]}" \
-e "VIRTUAL_HOST=${domains[0]}" \
-e "LETSENCRYPT_HOST=${domains[0]}" \
--network boulder_bluenet \
nginx:alpine > /dev/null && echo "Started test web server for ${domains[0]}"
run_nginx_container "${domains[0]}"

# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
wait_for_symlink "${domains[0]}" "$le_container_name"
Expand All @@ -48,21 +43,16 @@ elif [[ "$(docker exec "$le_container_name" jq .contact "$json_file")" != '[]' ]
fi

# Stop the nginx and companion containers silently.
docker stop "${domains[0]}" > /dev/null 2>&1
docker stop "$le_container_name" > /dev/null 2>&1
docker stop "${domains[0]}" &> /dev/null
docker stop "$le_container_name" &> /dev/null

# Run the companion container with the DEFAULT_EMAIL env var set.
default_email="contact@${domains[1]}"
le_container_name="${le_container_name}_default"
run_le_container "${1:?}" "$le_container_name" "--env DEFAULT_EMAIL=${default_email}"

# Run an nginx container for ${domains[1]} without LETSENCRYPT_EMAIL set.
docker run --rm -d \
--name "${domains[1]}" \
-e "VIRTUAL_HOST=${domains[1]}" \
-e "LETSENCRYPT_HOST=${domains[1]}" \
--network boulder_bluenet \
nginx:alpine > /dev/null && echo "Started test web server for ${domains[1]}"
run_nginx_container "${domains[1]}"

# Wait for a symlink at /etc/nginx/certs/${domains[1]}.crt
wait_for_symlink "${domains[1]}" "$le_container_name"
Expand All @@ -80,13 +70,18 @@ fi

# Run an nginx container for ${domains[2]} with LETSENCRYPT_EMAIL set.
container_email="contact@${domains[2]}"
docker run --rm -d \
if ! docker run --rm -d \
--name "${domains[2]}" \
-e "VIRTUAL_HOST=${domains[2]}" \
-e "LETSENCRYPT_HOST=${domains[2]}" \
-e "LETSENCRYPT_EMAIL=${container_email}" \
--network boulder_bluenet \
nginx:alpine > /dev/null && echo "Started test web server for ${domains[2]}"
nginx:alpine > /dev/null ; \
then
echo "Failed to start test web server for ${domains[2]}"
elif [[ "${DRY_RUN:-}" == 1 ]]; then
echo "Started test web server for ${domains[2]}"
fi

# Wait for a symlink at /etc/nginx/certs/${domains[2]}.crt
wait_for_symlink "${domains[2]}" "$le_container_name"
Expand All @@ -103,5 +98,5 @@ elif [[ "$(docker exec "$le_container_name" jq -r '.contact|.[0]' "$json_file")"
fi

# Stop the nginx containers silently.
docker stop "${domains[1]}" > /dev/null 2>&1
docker stop "${domains[2]}" > /dev/null 2>&1
docker stop "${domains[1]}" &> /dev/null
docker stop "${domains[2]}" &> /dev/null
49 changes: 0 additions & 49 deletions test/tests/certs_san/expected-std-out.txt

This file was deleted.

23 changes: 9 additions & 14 deletions test/tests/certs_san/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function cleanup {
# Remove any remaining Nginx container(s) silently.
i=1
for hosts in "${letsencrypt_hosts[@]}"; do
docker rm --force "test$i" > /dev/null 2>&1
docker rm --force "test$i" &> /dev/null
i=$(( i + 1 ))
done
# Cleanup the files created by this run of the test to avoid foiling following test(s).
Expand Down Expand Up @@ -46,16 +46,11 @@ for hosts in "${letsencrypt_hosts[@]}"; do
container="test$i"

# Run an Nginx container passing one of the comma separated list as LETSENCRYPT_HOST env var.
docker run --rm -d \
--name "$container" \
-e "VIRTUAL_HOST=${TEST_DOMAINS}" \
-e "LETSENCRYPT_HOST=${hosts}" \
--network boulder_bluenet \
nginx:alpine > /dev/null && echo "Started test web server for $hosts"
run_nginx_container "$hosts" "$container"

# Wait for a symlink at /etc/nginx/certs/$base_domain.crt
# then grab the certificate in text form ...
wait_for_symlink "$base_domain" "$le_container_name"
wait_for_symlink "$base_domain" "$le_container_name" "./${base_domain}/fullchain.pem"
created_cert="$(docker exec "$le_container_name" \
openssl x509 -in "/etc/nginx/certs/${base_domain}/cert.pem" -text -noout)"
# ... as well as the certificate fingerprint.
Expand All @@ -66,10 +61,10 @@ for hosts in "${letsencrypt_hosts[@]}"; do
## For all the domains in the $domains array ...

# Check if the domain is on the certificate.
if grep -q "$domain" <<< "$created_cert"; then
echo "$domain is on certificate."
else
if ! grep -q "$domain" <<< "$created_cert"; then
echo "$domain did not appear on certificate."
elif [[ "${DRY_RUN:-}" == 1 ]]; then
echo "$domain is on certificate."
fi

# Wait for a connection to https://domain then grab the served certificate in text form.
Expand All @@ -88,12 +83,12 @@ for hosts in "${letsencrypt_hosts[@]}"; do
| openssl x509 -text -noout \
| sed 's/ = /=/g' )"
diff -u <(echo "${created_cert// = /=}") <(echo "$served_cert")
else
echo "The correct certificate for $domain was served by Nginx."
elif [[ "${DRY_RUN:-}" == 1 ]]; then
echo "The correct certificate for $domain was served by Nginx."
fi
done

docker stop "$container" > /dev/null 2>&1
docker stop "$container" &> /dev/null
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf* && rm -rf /etc/acme.sh/default/le?.wtf*'
i=$(( i + 1 ))

Expand Down
19 changes: 0 additions & 19 deletions test/tests/certs_single/expected-std-out.txt

This file was deleted.

19 changes: 7 additions & 12 deletions test/tests/certs_single/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
function cleanup {
# Remove any remaining Nginx container(s) silently.
for domain in "${domains[@]}"; do
docker rm --force "$domain" > /dev/null 2>&1
docker rm --force "$domain" &> /dev/null
done
# Cleanup the files created by this run of the test to avoid foiling following test(s).
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf* && rm -rf /etc/acme.sh/default/le?.wtf*'
Expand All @@ -28,30 +28,25 @@ trap cleanup EXIT
# Run a separate nginx container for each domain in the $domains array.
# Start all the containers in a row so that docker-gen debounce timers fire only once.
for domain in "${domains[@]}"; do
docker run --rm -d \
--name "$domain" \
-e "VIRTUAL_HOST=${domain}" \
-e "LETSENCRYPT_HOST=${domain}" \
--network boulder_bluenet \
nginx:alpine > /dev/null && echo "Started test web server for $domain"
run_nginx_container "$domain"
done

for domain in "${domains[@]}"; do

# Wait for a symlink at /etc/nginx/certs/$domain.crt
# then grab the certificate in text form from the file ...
wait_for_symlink "$domain" "$le_container_name"
wait_for_symlink "$domain" "$le_container_name" "./${domain}/fullchain.pem"
created_cert="$(docker exec "$le_container_name" \
openssl x509 -in "/etc/nginx/certs/${domain}/cert.pem" -text -noout)"
# ... as well as the certificate fingerprint.
created_cert_fingerprint="$(docker exec "$le_container_name" \
openssl x509 -in "/etc/nginx/certs/${domain}/cert.pem" -fingerprint -noout)"

# Check if the domain is on the certificate.
if grep -q "$domain" <<< "$created_cert"; then
echo "Domain $domain is on certificate."
else
if ! grep -q "$domain" <<< "$created_cert"; then
echo "Domain $domain isn't on certificate."
elif [[ "${DRY_RUN:-}" == 1 ]]; then
echo "Domain $domain is on certificate."
fi

# Wait for a connection to https://domain then grab the served certificate fingerprint.
Expand All @@ -69,7 +64,7 @@ for domain in "${domains[@]}"; do
| openssl x509 -text -noout \
| sed 's/ = /=/g' )"
diff -u <(echo "${created_cert// = /=}") <(echo "$served_cert")
else
elif [[ "${DRY_RUN:-}" == 1 ]]; then
echo "The correct certificate for $domain was served by Nginx."
fi

Expand Down
67 changes: 0 additions & 67 deletions test/tests/certs_single_domain/expected-std-out.txt

This file was deleted.

Loading

0 comments on commit 92cf9ff

Please sign in to comment.