1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-05-12 18:46:06 +02:00
nginx-proxy/test/test_ssl/test_dhparam_generation.py

45 lines
1.7 KiB
Python
Raw Normal View History

2017-03-08 02:37:12 +01:00
import backoff
2017-03-07 20:04:37 +01:00
import docker
docker_client = docker.from_env()
2017-03-08 02:37:12 +01:00
###############################################################################
#
# Tests helpers
#
###############################################################################
2017-03-07 20:04:37 +01:00
2017-03-08 02:37:12 +01:00
@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.
2017-03-07 20:04:37 +01:00
2017-03-08 02:37:12 +01:00
: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")
2017-03-07 20:04:37 +01:00
docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False)
assert bytes(expected_log_line, encoding="utf8") in docker_logs
2017-03-07 20:04:37 +01:00
2017-03-08 02:37:12 +01:00
###############################################################################
#
# Tests
#
###############################################################################
2017-03-07 20:04:37 +01:00
2017-03-08 02:37:12 +01:00
def test_dhparam_is_generated_if_missing(docker_compose):
sut_container = docker_client.containers.get("nginxproxy")
assert sut_container.status == "running"
2017-03-07 20:04:37 +01:00
assert_log_contains("Generating DSA parameters")
2017-03-08 02:37:12 +01:00
assert_log_contains("dhparam generation complete, reloading nginx")
2017-03-07 20:04:37 +01:00
# Make sure the dhparam in use is not the default, pre-generated one
default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").output.split()
generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split()
2017-03-07 20:04:37 +01:00
assert default_checksum[0] != generated_checksum[0]