2016-04-20 18:20:08 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
load test_helpers
|
|
|
|
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
|
|
|
|
|
|
|
|
function setup {
|
2016-04-20 18:33:21 +02:00
|
|
|
# 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
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "[$TEST_FILE] start a nginx-proxy container" {
|
2016-04-20 18:33:21 +02:00
|
|
|
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro -v $(pwd)/lib/ssl:/etc/nginx/certs:ro
|
|
|
|
assert_success
|
|
|
|
docker_wait_for_log $SUT_CONTAINER 9 "Watching docker events"
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "[$TEST_FILE] test SSL for VIRTUAL_HOST=*.nginx-proxy.bats" {
|
2016-04-20 18:33:21 +02:00
|
|
|
# WHEN
|
|
|
|
prepare_web_container bats-ssl-hosts-1 "80 443" \
|
|
|
|
-e VIRTUAL_HOST=*.nginx-proxy.bats \
|
|
|
|
-e CERT_NAME=nginx-proxy.bats
|
|
|
|
dockergen_wait_for_event $SUT_CONTAINER start bats-ssl-hosts-1
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
# THEN
|
|
|
|
assert_301 test.nginx-proxy.bats
|
|
|
|
assert_200_https test.nginx-proxy.bats
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "[$TEST_FILE] test HTTPS_METHOD=nohttp" {
|
2016-04-20 18:33:21 +02:00
|
|
|
# WHEN
|
|
|
|
prepare_web_container bats-ssl-hosts-2 "80 443" \
|
|
|
|
-e VIRTUAL_HOST=*.nginx-proxy.bats \
|
|
|
|
-e CERT_NAME=nginx-proxy.bats \
|
|
|
|
-e HTTPS_METHOD=nohttp
|
|
|
|
dockergen_wait_for_event $SUT_CONTAINER start bats-ssl-hosts-2
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
# THEN
|
|
|
|
assert_503 test.nginx-proxy.bats
|
|
|
|
assert_200_https test.nginx-proxy.bats
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "[$TEST_FILE] test HTTPS_METHOD=noredirect" {
|
2016-04-20 18:33:21 +02:00
|
|
|
# WHEN
|
|
|
|
prepare_web_container bats-ssl-hosts-3 "80 443" \
|
|
|
|
-e VIRTUAL_HOST=*.nginx-proxy.bats \
|
|
|
|
-e CERT_NAME=nginx-proxy.bats \
|
|
|
|
-e HTTPS_METHOD=noredirect
|
|
|
|
dockergen_wait_for_event $SUT_CONTAINER start bats-ssl-hosts-3
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
# THEN
|
|
|
|
assert_200 test.nginx-proxy.bats
|
|
|
|
assert_200_https test.nginx-proxy.bats
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "[$TEST_FILE] stop all bats containers" {
|
2016-04-20 18:33:21 +02:00
|
|
|
stop_bats_containers
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_200 {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 200 OK\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_503 {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_301 {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 301 Moved Permanently\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_200_https {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container_https $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 200 OK\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_503_https {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container_https $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
|
|
|
|
# $1 Host HTTP header to use when querying nginx-proxy
|
|
|
|
function assert_301_https {
|
2016-04-20 18:33:21 +02:00
|
|
|
local -r host=$1
|
2016-04-20 18:20:08 +02:00
|
|
|
|
2016-04-20 18:33:21 +02:00
|
|
|
run curl_container_https $SUT_CONTAINER / --head --header "Host: $host"
|
|
|
|
assert_output -l 0 $'HTTP/1.1 301 Moved Permanently\r'
|
2016-04-20 18:20:08 +02:00
|
|
|
}
|