1
0
docker-letsencrypt-nginx-pr.../test/tests/test-functions.sh

78 lines
2.2 KiB
Bash
Raw Normal View History

2017-11-24 23:51:31 +01:00
#!/bin/bash
set -e
# Get the first domain of a comma separated list.
function get_base_domain {
awk -F ',' '{print $1}' <(echo ${1:?}) | tr -d ' '
}
export -f get_base_domain
# Run a letsencrypt-nginx-proxy-companion container
function run_le_container {
local image="${1:?}"
local name="${2:?}"
docker run -d \
--name "$name" \
--volumes-from $NGINX_CONTAINER_NAME \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--env "DEBUG=true" \
--env "ACME_CA_URI=http://${BOULDER_IP}:4000/directory" \
2017-12-29 00:28:15 +01:00
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.test_suite \
2017-11-24 23:51:31 +01:00
"$image" > /dev/null && echo "Started letsencrypt container for test ${name%%_2*}"
}
export -f run_le_container
2018-03-18 18:50:47 +01:00
# Wait for the /etc/nginx/certs/$1.crt symlink to exist inside container $2
function wait_for_symlink {
2017-11-24 23:51:31 +01:00
local domain="${1:?}"
local name="${2:?}"
local i=0
2018-03-18 18:50:47 +01:00
local target
until docker exec "$name" [ -L "/etc/nginx/certs/$domain.crt" ]; do
2017-11-24 23:51:31 +01:00
if [ $i -gt 180 ]; then
2018-03-18 18:50:47 +01:00
echo "Symlink for $domain certificate was not generated under three minutes, timing out."
2017-11-24 23:51:31 +01:00
return 1
fi
i=$((i + 2))
sleep 2
done
2018-03-18 18:50:47 +01:00
target="$(docker exec "$name" readlink "/etc/nginx/certs/$domain.crt")"
echo "Symlink to $domain certificate has been generated."
echo "The link is pointing to the file $target"
2017-11-24 23:51:31 +01:00
}
2018-03-18 18:50:47 +01:00
export -f wait_for_symlink
# Wait for the /etc/nginx/certs/$1.crt file to be removed inside container $2
function wait_for_symlink_rm {
local domain="${1:?}"
local name="${2:?}"
local i=0
until docker exec "$name" [ ! -f "/etc/nginx/certs/$domain.crt" ]; do
if [ $i -gt 120 ]; then
echo "Certificate symlink for $domain was not removed under two minutes, timing out."
return 1
fi
i=$((i + 2))
sleep 2
done
echo "Symlink to $domain certificate has been removed."
}
export -f wait_for_symlink_rm
2017-11-24 23:51:31 +01:00
# Wait for a successful https connection to domain $1
function wait_for_conn {
local domain="${1:?}"
local i=0
until curl -k https://"$domain" > /dev/null 2>&1; do
if [ $i -gt 120 ]; then
echo "Could not connect to $domain using https under two minutes, timing out."
return 1
fi
i=$((i + 2))
sleep 2
done
echo "Connection to $domain using https was successful."
}
export -f wait_for_conn