mirror of
https://github.com/thib8956/nginx-proxy
synced 2024-11-21 11:26:31 +00:00
Modified tests to include dhparams
This commit is contained in:
parent
0244b4e71e
commit
98b5828f83
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
**/__pycache__/
|
||||
**/.cache/
|
||||
.idea/
|
||||
|
@ -15,6 +15,7 @@ if [[ -f $DHPARAM_FILE ]]; then
|
||||
CURRENT_HASH=$(md5sum $DHPARAM_FILE | cut -d" " -f1)
|
||||
if [[ $PREGEN_HASH != $CURRENT_HASH ]]; then
|
||||
# There is already a dhparam, and it's not the default
|
||||
echo "Custom dhparam.pem file found, generation skipped"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
FROM python:2.7
|
||||
FROM python:2.7-alpine
|
||||
|
||||
# Note: we're using alpine because it has openssl 1.0.2, which we need for testing
|
||||
RUN apk add --update bash openssl curl && rm -rf /var/cache/apk/*
|
||||
|
||||
COPY python-requirements.txt /requirements.txt
|
||||
RUN pip install -r /requirements.txt
|
||||
|
||||
WORKDIR /test
|
||||
ENTRYPOINT ["pytest"]
|
||||
|
@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
load test_helpers
|
||||
|
||||
function setup {
|
||||
# make sure to stop any web container before each test so we don't
|
||||
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
|
||||
stop_bats_containers web
|
||||
}
|
||||
|
||||
@test "[$TEST_FILE] test dhparam.pem is generated if missing" {
|
||||
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-1
|
||||
|
||||
# WHEN
|
||||
run docker_clean $SUT_CONTAINER \
|
||||
&& docker run -d \
|
||||
--label bats-type="nginx-proxy" \
|
||||
--name $SUT_CONTAINER \
|
||||
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||
-e DHPARAM_BITS=256 \
|
||||
$SUT_IMAGE \
|
||||
&& wait_for_nginxproxy_container_to_start $SUT_CONTAINER \
|
||||
&& docker logs $SUT_CONTAINER
|
||||
|
||||
DEFAULT_HASH=$(docker exec $SUT_CONTAINER md5sum /app/dhparam.pem.default | cut -d" " -f1)
|
||||
|
||||
assert_success
|
||||
docker_wait_for_log $SUT_CONTAINER 30 "Generating DH parameters"
|
||||
|
||||
# THEN
|
||||
docker_wait_for_log $SUT_CONTAINER 240 "dhparam generation complete, reloading nginx"
|
||||
|
||||
run docker exec $SUT_CONTAINER su -c "md5sum /etc/nginx/dhparam/dhparam.pem"
|
||||
|
||||
refute_output -p $DEFAULT_HASH
|
||||
}
|
||||
|
||||
@test "[$TEST_FILE] test dhparam.pem is generated if default one is present" {
|
||||
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-2
|
||||
|
||||
# Copy the default dhparams to a volume and mount it in to ensure it's regenerated
|
||||
TMP_DIR=/tmp/nginx-proxy-bats
|
||||
if [ ! -d $TMP_DIR ]; then
|
||||
mkdir $TMP_DIR
|
||||
fi
|
||||
|
||||
# If the previous test crashed, a dhparam is left that only root can delete, so we
|
||||
# delete it from within a container as root
|
||||
if [ -f $TMP_DIR/dhparam.pem ]; then
|
||||
docker run --rm -v $TMP_DIR:/opt busybox rm /opt/dhparam.pem
|
||||
fi
|
||||
|
||||
cp $DIR/../dhparam.pem.default $TMP_DIR/dhparam.pem
|
||||
|
||||
# WHEN
|
||||
run docker_clean $SUT_CONTAINER \
|
||||
&& docker run -d \
|
||||
--label bats-type="nginx-proxy" \
|
||||
--name $SUT_CONTAINER \
|
||||
-v /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||
-v $TMP_DIR:/etc/nginx/dhparam \
|
||||
-e DHPARAM_BITS=256 \
|
||||
$SUT_IMAGE \
|
||||
&& wait_for_nginxproxy_container_to_start $SUT_CONTAINER \
|
||||
&& docker logs $SUT_CONTAINER
|
||||
|
||||
# THEN
|
||||
assert_success
|
||||
docker_wait_for_log $SUT_CONTAINER 30 "Generating DH parameters"
|
||||
|
||||
docker exec $SUT_CONTAINER rm -rf /etc/nginx/dhparam/*
|
||||
}
|
||||
|
||||
@test "[$TEST_FILE] test dhparam.pem is not generated if custom one is present" {
|
||||
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-3
|
||||
|
||||
# WHEN
|
||||
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
assert_success
|
||||
docker_wait_for_log $SUT_CONTAINER 9 "Watching docker events"
|
||||
|
||||
sleep 3
|
||||
run docker logs $SUT_CONTAINER
|
||||
|
||||
# THEN
|
||||
refute_output -p "Generating DH parameters"
|
||||
}
|
||||
|
||||
@test "[$TEST_FILE] stop all bats containers" {
|
||||
stop_bats_containers
|
||||
}
|
@ -19,6 +19,6 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/f00.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
environment:
|
||||
DOCKER_HOST: unix:///f00.sock
|
||||
|
||||
|
@ -4,6 +4,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
||||
web:
|
||||
image: web
|
||||
|
@ -2,6 +2,7 @@ nginx-proxy:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/default_location:ro
|
||||
- ./my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/web3.nginx-proxy.local_location:ro
|
||||
|
||||
|
@ -4,6 +4,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./my_custom_proxy_settings.conf:/etc/nginx/proxy.conf:ro
|
||||
|
||||
web1:
|
||||
|
@ -4,6 +4,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/web1.nginx-proxy.local_location:ro
|
||||
|
||||
web1:
|
||||
|
@ -4,6 +4,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/web1.nginx-proxy.local:ro
|
||||
|
||||
web1:
|
||||
|
@ -4,6 +4,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./my_custom_proxy_settings.conf:/etc/nginx/conf.d/my_custom_proxy_settings.conf:ro
|
||||
|
||||
web1:
|
||||
|
@ -13,5 +13,6 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
environment:
|
||||
DEFAULT_HOST: web1.tld
|
||||
|
@ -6,6 +6,7 @@ services:
|
||||
container_name: nginx
|
||||
volumes:
|
||||
- /etc/nginx/conf.d
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
||||
dockergen:
|
||||
image: jwilder/docker-gen
|
||||
|
@ -2,12 +2,13 @@ import os
|
||||
import docker
|
||||
import logging
|
||||
import pytest
|
||||
|
||||
import re
|
||||
|
||||
def versiontuple(v):
|
||||
# Temporary hack to fix version parsing until PR#755 is pulled
|
||||
v = re.sub("[^\d\.]", "", v)
|
||||
return tuple(map(int, (v.split("."))))
|
||||
|
||||
|
||||
docker_version = docker.from_env().version()['Version']
|
||||
pytestmark = pytest.mark.skipif(versiontuple(docker_version) < versiontuple('1.13'),
|
||||
reason="Docker compose syntax v3 requires docker engine v1.13")
|
||||
|
@ -5,6 +5,7 @@ services:
|
||||
container_name: nginx
|
||||
volumes:
|
||||
- nginx_conf:/etc/nginx/conf.d
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
||||
dockergen:
|
||||
image: jwilder/docker-gen
|
||||
|
@ -2,3 +2,4 @@ nginxproxy:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -11,3 +11,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -13,3 +13,4 @@ sut:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./certs/web.nginx-proxy.tld.crt:/etc/nginx/certs/web.nginx-proxy.tld.crt:ro
|
||||
- ./certs/web.nginx-proxy.tld.key:/etc/nginx/certs/web.nginx-proxy.tld.key:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -19,5 +19,6 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
environment:
|
||||
ENABLE_IPV6: "true"
|
||||
|
@ -11,3 +11,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -9,6 +9,7 @@ services:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
networks:
|
||||
- net1
|
||||
- net2
|
||||
|
@ -12,3 +12,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -11,3 +11,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -11,3 +11,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -19,3 +19,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -12,4 +12,5 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./certs:/etc/nginx/certs:ro
|
||||
|
@ -12,3 +12,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
@ -12,4 +12,5 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./certs:/etc/nginx/certs:ro
|
||||
|
@ -10,4 +10,5 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./certs:/etc/nginx/certs:ro
|
||||
|
@ -35,3 +35,4 @@ sut:
|
||||
image: jwilder/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
Loading…
Reference in New Issue
Block a user