|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## Test for standalone certificates. |
| 4 | + |
| 5 | +if [[ -z $TRAVIS_CI ]]; 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 | +# Create the $domains array from comma separated domains in TEST_DOMAINS. |
| 12 | +IFS=',' read -r -a domains <<< "$TEST_DOMAINS" |
| 13 | + |
| 14 | +# Cleanup function with EXIT trap |
| 15 | +function cleanup { |
| 16 | + # Cleanup the files created by this run of the test to avoid foiling following test(s). |
| 17 | + docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*' |
| 18 | + # Stop the LE container |
| 19 | + docker stop "$le_container_name" > /dev/null |
| 20 | +} |
| 21 | +trap cleanup EXIT |
| 22 | + |
| 23 | +# Create letsencrypt_user_data with a single domain cert |
| 24 | +cat > ${TRAVIS_BUILD_DIR}/test/tests/certs_standalone/letsencrypt_user_data <<EOF |
| 25 | +LETSENCRYPT_STANDALONE_CERTS=('single') |
| 26 | +LETSENCRYPT_single_HOST=('${domains[0]}') |
| 27 | +EOF |
| 28 | + |
| 29 | +run_le_container ${1:?} "$le_container_name" \ |
| 30 | + "--volume ${TRAVIS_BUILD_DIR}/test/tests/certs_standalone/letsencrypt_user_data:/app/letsencrypt_user_data" |
| 31 | + |
| 32 | +# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt |
| 33 | +# then grab the certificate in text form ... |
| 34 | +wait_for_symlink "${domains[0]}" "$le_container_name" |
| 35 | +created_cert="$(docker exec "$le_container_name" \ |
| 36 | + openssl x509 -in /etc/nginx/certs/${domains[0]}/cert.pem -text -noout)" |
| 37 | + |
| 38 | +# Check if the domain is on the certificate. |
| 39 | +if grep -q "${domains[0]}" <<< "$created_cert"; then |
| 40 | + echo "Domain ${domains[0]} is on certificate." |
| 41 | +else |
| 42 | + echo "Domain ${domains[0]} did not appear on certificate." |
| 43 | +fi |
| 44 | + |
| 45 | +docker exec "$le_container_name" bash -c "[[ -f /etc/nginx/conf.d/standalone-cert-${domains[0]}.conf ]]" \ |
| 46 | + && echo "Standalone configuration for ${domains[0]} wasn't correctly removed." |
| 47 | + |
| 48 | +# Add another (SAN) certificate to letsencrypt_user_data |
| 49 | +cat > ${TRAVIS_BUILD_DIR}/test/tests/certs_standalone/letsencrypt_user_data <<EOF |
| 50 | +LETSENCRYPT_STANDALONE_CERTS=('single' 'san') |
| 51 | +LETSENCRYPT_single_HOST=('${domains[0]}') |
| 52 | +LETSENCRYPT_san_HOST=('${domains[1]}' '${domains[2]}') |
| 53 | +EOF |
| 54 | + |
| 55 | +# Manually trigger the service loop |
| 56 | +docker exec "$le_container_name" /app/signal_le_service > /dev/null |
| 57 | + |
| 58 | +# Wait for a symlink at /etc/nginx/certs/${domains[1]}.crt |
| 59 | +# then grab the certificate in text form ... |
| 60 | +wait_for_symlink "${domains[1]}" "$le_container_name" |
| 61 | +created_cert="$(docker exec "$le_container_name" \ |
| 62 | + openssl x509 -in /etc/nginx/certs/${domains[1]}/cert.pem -text -noout)" |
| 63 | + |
| 64 | +for domain in "${domains[1]}" "${domains[2]}"; do |
| 65 | + # Check if the domain is on the certificate. |
| 66 | + if grep -q "$domain" <<< "$created_cert"; then |
| 67 | + echo "Domain $domain is on certificate." |
| 68 | + else |
| 69 | + echo "Domain $domain did not appear on certificate." |
| 70 | + fi |
| 71 | +done |
| 72 | + |
| 73 | +docker exec "$le_container_name" bash -c "[[ ! -f /etc/nginx/conf.d/standalone-cert-${domains[1]}.conf ]]" \ |
| 74 | + || echo "Standalone configuration for ${domains[1]} wasn't correctly removed." |
0 commit comments