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:
parent
ffa8553bac
commit
926b56766d
4 changed files with 16 additions and 52 deletions
13
nginx.tmpl
13
nginx.tmpl
|
@ -284,9 +284,18 @@ server {
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
{{ if (hasPrefix "www." $host) }}
|
{{ if (hasPrefix "www." $host) }}
|
||||||
return 301 https://{{ trimPrefix "www." $host }}$request_uri;
|
# Redirect www. to non-www.
|
||||||
{{ else }}
|
{{ $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;
|
return 301 https://$host$request_uri;
|
||||||
|
{{ else }}
|
||||||
|
return 301 https://$host:{{ $external_https_port }}$request_uri;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
# 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.
|
# docker-compose to work properly when run from within that container.
|
||||||
exec docker run --rm \
|
exec docker run --rm -it --name "nginx-proxy-pytest" \
|
||||||
-v ${DIR}:/${DIR} \
|
--volume "/var/run/docker.sock:/var/run/docker.sock" \
|
||||||
-w ${DIR} \
|
--volume "${DIR}:${DIR}" \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
--workdir "${DIR}" \
|
||||||
nginx-proxy-tester ${ARGS}
|
nginx-proxy-tester "${ARGS[@]}"
|
|
@ -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]
|
|
|
@ -22,6 +22,5 @@ sut:
|
||||||
image: nginxproxy/nginx-proxy:test
|
image: nginxproxy/nginx-proxy:test
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
- /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
|
- ./test_ssl/certs:/etc/nginx/certs:ro
|
||||||
|
|
Loading…
Reference in a new issue