1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-12-24 03:26:31 +00:00

Modified tests to include dhparams

This commit is contained in:
Steve Kamerman 2017-03-07 14:04:44 -05:00
parent 0244b4e71e
commit 98b5828f83
30 changed files with 69 additions and 127 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
**/__pycache__/
**/.cache/
.idea/

View File

@ -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

View File

@ -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"]

View File

@ -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
}

View File

@ -1,5 +1,5 @@
web1:
image: web
image: web
expose:
- "81"
environment:
@ -8,7 +8,7 @@ web1:
web2:
image: web
expose:
expose:
- "82"
environment:
WEB_PORTS: 82
@ -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

View File

@ -4,11 +4,12 @@ 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
image: web
expose:
- "81"
environment:
WEB_PORTS: 81
VIRTUAL_HOST: web.nginx-proxy.local
VIRTUAL_HOST: web.nginx-proxy.local

View File

@ -2,11 +2,12 @@ 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
web1:
image: web
image: web
expose:
- "81"
environment:
@ -14,7 +15,7 @@ web1:
VIRTUAL_HOST: web1.nginx-proxy.local
web2:
image: web
image: web
expose:
- "82"
environment:
@ -22,9 +23,9 @@ web2:
VIRTUAL_HOST: web2.nginx-proxy.local
web3:
image: web
image: web
expose:
- "83"
environment:
WEB_PORTS: 83
VIRTUAL_HOST: web3.nginx-proxy.local
VIRTUAL_HOST: web3.nginx-proxy.local

View File

@ -4,10 +4,11 @@ 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:
image: web
image: web
expose:
- "81"
environment:
@ -15,9 +16,9 @@ services:
VIRTUAL_HOST: web1.nginx-proxy.local
web2:
image: web
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.local
VIRTUAL_HOST: web2.nginx-proxy.local

View File

@ -4,10 +4,11 @@ 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:
image: web
image: web
expose:
- "81"
environment:
@ -15,9 +16,9 @@ services:
VIRTUAL_HOST: web1.nginx-proxy.local
web2:
image: web
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.local
VIRTUAL_HOST: web2.nginx-proxy.local

View File

@ -4,10 +4,11 @@ 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:
image: web
image: web
expose:
- "81"
environment:
@ -15,9 +16,9 @@ services:
VIRTUAL_HOST: web1.nginx-proxy.local
web2:
image: web
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.local
VIRTUAL_HOST: web2.nginx-proxy.local

View File

@ -4,10 +4,11 @@ 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:
image: web
image: web
expose:
- "81"
environment:
@ -15,9 +16,9 @@ services:
VIRTUAL_HOST: web1.nginx-proxy.local
web2:
image: web
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.local
VIRTUAL_HOST: web2.nginx-proxy.local

View File

@ -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

View File

@ -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
@ -23,4 +24,4 @@ services:
- "80"
environment:
WEB_PORTS: 80
VIRTUAL_HOST: whoami.nginx.container.docker
VIRTUAL_HOST: whoami.nginx.container.docker

View File

@ -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")

View File

@ -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
@ -24,4 +25,4 @@ services:
VIRTUAL_HOST: whoami.nginx.container.docker
volumes:
nginx_conf: {}
nginx_conf: {}

View File

@ -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

View File

@ -10,4 +10,5 @@ web:
sut:
image: jwilder/nginx-proxy:test
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

View File

@ -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

View File

@ -1,5 +1,5 @@
web1:
image: web
image: web
expose:
- "81"
environment:
@ -8,7 +8,7 @@ web1:
web2:
image: web
expose:
expose:
- "82"
environment:
WEB_PORTS: 82
@ -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"

View File

@ -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

View File

@ -9,12 +9,13 @@ 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
web1:
image: web
image: web
expose:
- "81"
environment:
@ -24,11 +25,11 @@ services:
- net1
web2:
image: web
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.local
networks:
- net2
- net2

View File

@ -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

View File

@ -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

View File

@ -10,4 +10,5 @@ web:
sut:
image: jwilder/nginx-proxy:test
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

View File

@ -1,5 +1,5 @@
web1:
image: web
image: web
expose:
- "81"
environment:
@ -8,7 +8,7 @@ web1:
web2:
image: web
expose:
expose:
- "82"
environment:
WEB_PORTS: 82
@ -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

View File

@ -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

View File

@ -11,4 +11,5 @@ web:
sut:
image: jwilder/nginx-proxy:test
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

View File

@ -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

View File

@ -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

View File

@ -34,4 +34,5 @@ web4:
sut:
image: jwilder/nginx-proxy:test
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