Fix tests after merge with upstream

* Don't mount dh params as read only because that lets container fail in startup
* Use pytest.sh from upstream to ensure correct container name
* Remove renamed dh param test
* Fix www redirect in case of wildcard host
This commit is contained in:
Robin Windey 2022-02-20 15:03:17 +01:00
parent ffa8553bac
commit 926b56766d
No known key found for this signature in database
GPG key ID: 35D381829B5DF829
4 changed files with 16 additions and 52 deletions

View file

@ -284,9 +284,18 @@ server {
location / {
{{ if (hasPrefix "www." $host) }}
return 301 https://{{ trimPrefix "www." $host }}$request_uri;
{{ else }}
# Redirect www. to non-www.
{{ $trimmedHost := trimPrefix "www." $host }}
{{ if eq $external_https_port "443" }}
return 301 https://{{ $trimmedHost }}$request_uri;
{{ else }}
return 301 https://{{ $trimmedHost }}:{{ $external_https_port }}$request_uri;
{{ end }}
{{ end }}
{{ if eq $external_https_port "443" }}
return 301 https://$host$request_uri;
{{ else }}
return 301 https://$host:{{ $external_https_port }}$request_uri;
{{ end }}
}
}

View file

@ -18,8 +18,8 @@ docker build -t nginx-proxy-tester -f "${DIR}/requirements/Dockerfile-nginx-prox
# run the nginx-proxy-tester container setting the correct value for the working dir in order for
# docker-compose to work properly when run from within that container.
exec docker run --rm \
-v ${DIR}:/${DIR} \
-w ${DIR} \
-v /var/run/docker.sock:/var/run/docker.sock \
nginx-proxy-tester ${ARGS}
exec docker run --rm -it --name "nginx-proxy-pytest" \
--volume "/var/run/docker.sock:/var/run/docker.sock" \
--volume "${DIR}:${DIR}" \
--workdir "${DIR}" \
nginx-proxy-tester "${ARGS[@]}"

View file

@ -1,44 +0,0 @@
import backoff
import docker
docker_client = docker.from_env()
###############################################################################
#
# Tests helpers
#
###############################################################################
@backoff.on_exception(backoff.constant, AssertionError, interval=2, max_tries=15, jitter=None)
def assert_log_contains(expected_log_line):
"""
Check that the nginx-proxy container log contains a given string.
The backoff decorator will retry the check 15 times with a 2 seconds delay.
:param expected_log_line: string to search for
:return: None
:raises: AssertError if the expected string is not found in the log
"""
sut_container = docker_client.containers.get("nginxproxy")
docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False)
assert expected_log_line in docker_logs
###############################################################################
#
# Tests
#
###############################################################################
def test_dhparam_is_generated_if_missing(docker_compose):
sut_container = docker_client.containers.get("nginxproxy")
assert sut_container.status == "running"
assert_log_contains("A pre-generated dhparam.pem will be used for now")
assert_log_contains("dhparam generation complete, reloading nginx")
# Make sure the dhparam in use is not the default, pre-generated one
default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").split()
generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").split()
assert default_checksum[0] != generated_checksum[0]

View file

@ -22,6 +22,5 @@ sut:
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
- ./test_ssl/certs:/etc/nginx/certs:ro