1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-11-22 20:06:30 +00:00
nginx-proxy/test/test_ssl/test_dhparam_generation.py

45 lines
1.6 KiB
Python
Raw Normal View History

2017-03-08 01:37:12 +00:00
import backoff
2017-03-07 19:04:37 +00:00
import docker
docker_client = docker.from_env()
2017-03-08 01:37:12 +00:00
###############################################################################
#
# Tests helpers
#
###############################################################################
2017-03-07 19:04:37 +00:00
2017-03-08 01:37:12 +00: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 19:04:37 +00:00
2017-03-08 01:37:12 +00: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 19:04:37 +00:00
docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False)
2017-03-08 01:37:12 +00:00
assert expected_log_line in docker_logs
2017-03-07 19:04:37 +00:00
2017-03-08 01:37:12 +00:00
###############################################################################
#
# Tests
#
###############################################################################
2017-03-07 19:04:37 +00:00
2017-03-08 01:37:12 +00: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 19:04:37 +00:00
2017-03-08 01:37:12 +00:00
assert_log_contains("Generating DH parameters")
assert_log_contains("dhparam generation complete, reloading nginx")
2017-03-07 19:04:37 +00: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").split()
generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").split()
assert default_checksum[0] != generated_checksum[0]