diff --git a/test/conftest.py b/test/conftest.py
index 849520b..dc58041 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -1,6 +1,7 @@
import contextlib
import logging
import os
+import platform
import re
import shlex
import socket
@@ -9,12 +10,11 @@ import time
from typing import List
import backoff
-import docker
+import docker.errors
import pytest
import requests
-from _pytest._code.code import ReprExceptionInfo
-from packaging.version import Version
from docker.models.containers import Container
+from packaging.version import Version
from requests.packages.urllib3.util.connection import HAS_IPV6
logging.basicConfig(level=logging.INFO)
@@ -73,6 +73,17 @@ class requests_for_docker(object):
if os.path.isfile(CA_ROOT_CERTIFICATE):
self.session.verify = CA_ROOT_CERTIFICATE
+ @staticmethod
+ def __backoff_predicate(expected_status_codes=None):
+ if expected_status_codes is not None:
+ if isinstance(expected_status_codes, int):
+ expected_status_codes = [expected_status_codes]
+ return lambda r: r.status_code not in expected_status_codes
+ else:
+ return lambda r: r.status_code not in (200, 301)
+
+ __backed_off_exceptions = (requests.exceptions.SSLError, requests.exceptions.ConnectionError)
+
@staticmethod
def get_nginx_proxy_containers() -> List[Container]:
"""
@@ -99,17 +110,17 @@ class requests_for_docker(object):
nginx_proxy_containers = self.get_nginx_proxy_containers()
return container_ip(nginx_proxy_containers[0])
- def _backoff_predicate(expected_status_codes=None):
- if expected_status_codes is not None:
- return lambda r: r.status_code not in expected_status_codes
- else:
- return lambda r: r.status_code in (404, 502, 503)
-
def get(self, *args, **kwargs):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
- @backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_exception(backoff.constant, self.__backed_off_exceptions, interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ def _get(*args, **kwargs):
+ return self.session.get(*args, **kwargs)
+ return _get(*args, **kwargs)
+
+ def get_without_backoff(self, *args, **kwargs):
+ with ipv6(kwargs.pop('ipv6', False)):
def _get(*args, **kwargs):
return self.session.get(*args, **kwargs)
return _get(*args, **kwargs)
@@ -118,7 +129,7 @@ class requests_for_docker(object):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
@backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
def _post(*args, **kwargs):
return self.session.post(*args, **kwargs)
return _post(*args, **kwargs)
@@ -127,7 +138,7 @@ class requests_for_docker(object):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
@backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
def _put(*args, **kwargs):
return self.session.put(*args, **kwargs)
return _put(*args, **kwargs)
@@ -136,7 +147,7 @@ class requests_for_docker(object):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
@backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
def _head(*args, **kwargs):
return self.session.head(*args, **kwargs)
return _head(*args, **kwargs)
@@ -145,7 +156,7 @@ class requests_for_docker(object):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
@backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
def _delete(*args, **kwargs):
return self.session.delete(*args, **kwargs)
return _delete(*args, **kwargs)
@@ -154,7 +165,7 @@ class requests_for_docker(object):
_expected_status_code = kwargs.pop('expected_status_code', None)
with ipv6(kwargs.pop('ipv6', False)):
@backoff.on_exception(backoff.constant, requests.exceptions.SSLError, interval=.3, max_tries=30, jitter=None)
- @backoff.on_predicate(backoff.constant, self._backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
+ @backoff.on_predicate(backoff.constant, self.__backoff_predicate(_expected_status_code), interval=.3, max_tries=30, jitter=None)
def _options(*args, **kwargs):
return self.session.options(*args, **kwargs)
return _options(*args, **kwargs)
@@ -303,7 +314,11 @@ def monkey_patch_urllib_dns_resolver():
pytest.skip("This system does not support IPv6")
# custom DNS resolvers
- ip = nginx_proxy_single_container_dns_resolver(args[0])
+ ip = None
+ if platform.system() == "Darwin":
+ ip = "127.0.0.1"
+ if ip is None:
+ ip = nginx_proxy_single_container_dns_resolver(args[0])
if ip is None:
ip = nginx_proxy_separate_containers_dns_resolver(args[0])
if ip is None:
@@ -325,15 +340,6 @@ def restore_urllib_dns_resolver(getaddrinfo_func):
socket.getaddrinfo = getaddrinfo_func
-def remove_all_containers():
- for container in docker_client.containers.list(all=True):
- if PYTEST_RUNNING_IN_CONTAINER and container.name == test_container:
- continue # pytest is running within a Docker container, so we do not want to remove that particular container
- logging.info(f"removing container {container.name}")
- container.remove(v=True, force=True)
- docker_client.volumes.prune()
-
-
def get_nginx_conf_from_container(container):
"""
return the nginx /etc/nginx/conf.d/default.conf file content from a container
@@ -375,18 +381,26 @@ def wait_for_nginxproxy_to_be_ready():
or nginxproxy/nginx-proxy:test-dockergen is found, wait for its log to contain
substring "Watching docker events"
"""
- containers = docker_client.containers.list(filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
- if len(containers) > 1:
- logging.warning(f"Too many running nginxproxy/nginx-proxy:{IMAGE_TAG} containers")
- return
- elif len(containers) == 0:
- logging.warning(f"No running nginxproxy/nginx-proxy:{IMAGE_TAG} container")
- return
- container = containers[0]
- for line in container.logs(stream=True):
- if b"Generated '/etc/nginx/conf.d/default.conf'" in line:
- logging.debug("nginx-proxy ready")
+ timeout = time.time() + 10
+ while True:
+ containers = docker_client.containers.list(
+ filters={"status": "running", "ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"}
+ )
+ if len(containers) == 1:
break
+ if time.time() > timeout:
+ pytest.fail(f"Got {len(containers)} nginxproxy/nginx-proxy:{IMAGE_TAG} containers after 10s", pytrace=False)
+ time.sleep(1)
+
+ container = containers
+ conf_generated = False
+ while True:
+ for line in container[0].logs(stream=True, follow=True):
+ if b"Generated '/etc/nginx/conf.d/default.conf'" in line:
+ return
+ if time.time() > timeout:
+ pytest.fail(f"nginxproxy/nginx-proxy:{IMAGE_TAG} container not ready after 10s", pytrace=False)
+ time.sleep(1)
@pytest.fixture
@@ -484,6 +498,7 @@ def connect_to_all_networks():
class DockerComposer(contextlib.AbstractContextManager):
def __init__(self):
+ self._networks = None
self._docker_compose_file = None
self._project_name = None
@@ -504,11 +519,9 @@ class DockerComposer(contextlib.AbstractContextManager):
self._down()
if docker_compose_file is None:
return
- remove_all_containers()
docker_compose_up(project_name, docker_compose_file)
self._networks = connect_to_all_networks()
wait_for_nginxproxy_to_be_ready()
- time.sleep(3) # give time to containers to be ready
self._docker_compose_file = docker_compose_file
self._project_name = project_name
@@ -586,15 +599,14 @@ def acme_challenge_path():
# pytest hook to display additionnal stuff in test report
def pytest_runtest_logreport(report):
if report.failed:
- if isinstance(report.longrepr, ReprExceptionInfo):
- nginx_containers = docker_client.containers.list(all=True, filters={"label": "com.github.nginx-proxy.nginx-proxy.nginx"})
- for container in nginx_containers:
- report.longrepr.addsection('nginx container logs', container.logs())
+ nginx_containers = docker_client.containers.list(all=True, filters={"label": "com.github.nginx-proxy.nginx-proxy.nginx"})
+ for container in nginx_containers:
+ report.longrepr.addsection('nginx container logs', container.logs().decode())
- test_containers = docker_client.containers.list(all=True, filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
- for container in test_containers:
- report.longrepr.addsection('nginx-proxy logs', container.logs())
- report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container))
+ test_containers = docker_client.containers.list(all=True, filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
+ for container in test_containers:
+ report.longrepr.addsection('nginx-proxy logs', container.logs().decode())
+ report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container).decode())
# Py.test `incremental` marker, see http://stackoverflow.com/a/12579625/107049
diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt
index be22342..241e7f4 100644
--- a/test/requirements/python-requirements.txt
+++ b/test/requirements/python-requirements.txt
@@ -2,3 +2,4 @@ backoff==2.2.1
docker==7.1.0
pytest==8.3.4
requests==2.32.3
+packaging==24.2
\ No newline at end of file
diff --git a/test/stress_tests/test_unreachable_network/test_unreachable_net.py b/test/stress_tests/test_unreachable_network/test_unreachable_net.py
index 4c09da2..4808605 100644
--- a/test/stress_tests/test_unreachable_network/test_unreachable_net.py
+++ b/test/stress_tests/test_unreachable_network/test_unreachable_net.py
@@ -4,16 +4,6 @@ import pytest
import requests
-def test_default_nginx_welcome_page_should_not_be_served(docker_compose, nginxproxy):
- r = nginxproxy.get("http://whatever.nginx-proxy/", allow_redirects=False)
- assert "
Welcome to nginx!" not in r.text
-
-
-def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
- r = nginxproxy.get("http://unknown.nginx-proxy/", allow_redirects=False)
- assert r.status_code == 503
-
-
def test_http_web_a_is_forwarded(docker_compose, nginxproxy):
r = nginxproxy.get("http://webA.nginx-proxy/port", allow_redirects=False)
assert r.status_code == 200
@@ -21,12 +11,22 @@ def test_http_web_a_is_forwarded(docker_compose, nginxproxy):
def test_http_web_b_gets_an_error(docker_compose, nginxproxy):
- r = nginxproxy.get("http://webB.nginx-proxy/", allow_redirects=False)
+ r = nginxproxy.get("http://webB.nginx-proxy/", allow_redirects=False, expected_status_code=502)
assert "Welcome to nginx!" not in r.text
with pytest.raises(requests.exceptions.HTTPError):
r.raise_for_status()
+def test_default_nginx_welcome_page_should_not_be_served(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://whatever.nginx-proxy/", allow_redirects=False, expected_status_code=503)
+ assert "Welcome to nginx!" not in r.text
+
+
+def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://unknown.nginx-proxy/", allow_redirects=False, expected_status_code=503)
+ assert r.status_code == 503
+
+
def test_reverseproxy_survive_restart(docker_compose):
docker_compose.containers.get("reverseproxy").restart()
sleep(2) # give time for the container to initialize
diff --git a/test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py b/test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py
index acbc8fe..0d022bc 100644
--- a/test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py
+++ b/test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py
@@ -1,10 +1,8 @@
-import pytest
-
-
def test_redirect_acme_challenge_location_disabled(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web1.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=301
)
assert r.status_code == 301
@@ -18,7 +16,8 @@ def test_redirect_acme_challenge_location_enabled(docker_compose, nginxproxy, ac
def test_noredirect_acme_challenge_location_disabled(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web3.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=404
)
assert r.status_code == 404
diff --git a/test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py b/test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py
index fd06e84..35c373b 100644
--- a/test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py
+++ b/test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_redirect_acme_challenge_location_enabled(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web1.nginx-proxy.tld/{acme_challenge_path}",
@@ -11,7 +8,8 @@ def test_redirect_acme_challenge_location_enabled(docker_compose, nginxproxy, ac
def test_redirect_acme_challenge_location_disabled(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web2.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=301
)
assert r.status_code == 301
@@ -25,6 +23,7 @@ def test_noredirect_acme_challenge_location_enabled(docker_compose, nginxproxy,
def test_noredirect_acme_challenge_location_disabled(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web4.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=404
)
assert r.status_code == 404
diff --git a/test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py b/test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py
index d2051d0..c647553 100644
--- a/test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py
+++ b/test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_redirect_acme_challenge_location_legacy(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web1.nginx-proxy.tld/{acme_challenge_path}",
@@ -11,6 +8,7 @@ def test_redirect_acme_challenge_location_legacy(docker_compose, nginxproxy, acm
def test_noredirect_acme_challenge_location_legacy(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web2.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=404
)
assert r.status_code == 404
diff --git a/test/test_custom-error-page/test_custom-error-page.py b/test/test_custom-error-page/test_custom-error-page.py
index 32cb0b5..ebf97a8 100644
--- a/test/test_custom-error-page/test_custom-error-page.py
+++ b/test/test_custom-error-page/test_custom-error-page.py
@@ -1,8 +1,7 @@
-import pytest
import re
def test_custom_error_page(docker_compose, nginxproxy):
- r = nginxproxy.get("http://unknown.nginx-proxy.tld")
+ r = nginxproxy.get("http://unknown.nginx-proxy.tld", expected_status_code=503)
assert r.status_code == 503
assert re.search(r"Damn, there's some maintenance in progress.", r.text)
diff --git a/test/test_custom/test_defaults-location.py b/test/test_custom/test_defaults-location.py
index 5af359d..823f63a 100644
--- a/test/test_custom/test_defaults-location.py
+++ b/test/test_custom/test_defaults-location.py
@@ -1,10 +1,3 @@
-import pytest
-
-def test_custom_default_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
- assert "X-test" not in r.headers
-
def test_custom_default_conf_applies_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
@@ -19,10 +12,14 @@ def test_custom_default_conf_applies_to_web2(docker_compose, nginxproxy):
assert "X-test" in r.headers
assert "f00" == r.headers["X-test"]
-
def test_custom_default_conf_is_overriden_for_web3(docker_compose, nginxproxy):
r = nginxproxy.get("http://web3.nginx-proxy.example/port")
assert r.status_code == 200
assert r.text == "answer from port 83\n"
assert "X-test" in r.headers
assert "bar" == r.headers["X-test"]
+
+def test_custom_default_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
+ assert "X-test" not in r.headers
\ No newline at end of file
diff --git a/test/test_custom/test_defaults.py b/test/test_custom/test_defaults.py
index c9cb2df..26732cc 100644
--- a/test/test_custom/test_defaults.py
+++ b/test/test_custom/test_defaults.py
@@ -1,10 +1,3 @@
-import pytest
-
-def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
- assert "X-test" not in r.headers
-
def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
@@ -18,3 +11,8 @@ def test_custom_conf_applies_to_web2(docker_compose, nginxproxy):
assert r.text == "answer from port 82\n"
assert "X-test" in r.headers
assert "f00" == r.headers["X-test"]
+
+def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
+ assert "X-test" not in r.headers
\ No newline at end of file
diff --git a/test/test_custom/test_location-per-vhost.py b/test/test_custom/test_location-per-vhost.py
index 8218ed0..245a843 100644
--- a/test/test_custom/test_location-per-vhost.py
+++ b/test/test_custom/test_location-per-vhost.py
@@ -1,10 +1,3 @@
-import pytest
-
-def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
- assert "X-test" not in r.headers
-
def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
@@ -25,5 +18,10 @@ def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
assert r.text == "answer from port 82\n"
assert "X-test" not in r.headers
+def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
+ assert "X-test" not in r.headers
+
def test_custom_block_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
assert b"include /etc/nginx/vhost.d/web1.nginx-proxy.example_location;" in nginxproxy.get_conf()
\ No newline at end of file
diff --git a/test/test_custom/test_per-vhost.py b/test/test_custom/test_per-vhost.py
index 7394472..cd020a9 100644
--- a/test/test_custom/test_per-vhost.py
+++ b/test/test_custom/test_per-vhost.py
@@ -1,10 +1,3 @@
-import pytest
-
-def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
- assert "X-test" not in r.headers
-
def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
@@ -24,3 +17,8 @@ def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy):
assert r.status_code == 200
assert r.text == "answer from port 82\n"
assert "X-test" not in r.headers
+
+def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
+ assert "X-test" not in r.headers
\ No newline at end of file
diff --git a/test/test_custom/test_proxy-wide.py b/test/test_custom/test_proxy-wide.py
index c9cb2df..26732cc 100644
--- a/test/test_custom/test_proxy-wide.py
+++ b/test/test_custom/test_proxy-wide.py
@@ -1,10 +1,3 @@
-import pytest
-
-def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
- assert "X-test" not in r.headers
-
def test_custom_conf_applies_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
@@ -18,3 +11,8 @@ def test_custom_conf_applies_to_web2(docker_compose, nginxproxy):
assert r.text == "answer from port 82\n"
assert "X-test" in r.headers
assert "f00" == r.headers["X-test"]
+
+def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
+ assert "X-test" not in r.headers
\ No newline at end of file
diff --git a/test/test_debug_endpoint/test_global.py b/test/test_debug_endpoint/test_global.py
index aaa7b1f..96c4545 100644
--- a/test/test_debug_endpoint/test_global.py
+++ b/test/test_debug_endpoint/test_global.py
@@ -42,5 +42,5 @@ def test_debug_endpoint_hostname_replaced_by_warning_if_regexp(docker_compose, n
def test_debug_endpoint_is_disabled_per_container(docker_compose, nginxproxy):
- r = nginxproxy.get("http://disabled.debug.nginx-proxy.example/nginx-proxy-debug")
+ r = nginxproxy.get("http://disabled.debug.nginx-proxy.example/nginx-proxy-debug", expected_status_code=404)
assert r.status_code == 404
diff --git a/test/test_debug_endpoint/test_per_container.py b/test/test_debug_endpoint/test_per_container.py
index 16c680c..3eaa606 100644
--- a/test/test_debug_endpoint/test_per_container.py
+++ b/test/test_debug_endpoint/test_per_container.py
@@ -2,9 +2,9 @@ import json
import pytest
def test_debug_endpoint_is_disabled_globally(docker_compose, nginxproxy):
- r = nginxproxy.get("http://disabled1.debug.nginx-proxy.example/nginx-proxy-debug")
+ r = nginxproxy.get("http://disabled1.debug.nginx-proxy.example/nginx-proxy-debug", expected_status_code=404)
assert r.status_code == 404
- r = nginxproxy.get("http://disabled2.debug.nginx-proxy.example/nginx-proxy-debug")
+ r = nginxproxy.get("http://disabled2.debug.nginx-proxy.example/nginx-proxy-debug", expected_status_code=404)
assert r.status_code == 404
diff --git a/test/test_default-host.py b/test/test_default-host.py
index 90809a5..560baf7 100644
--- a/test/test_default-host.py
+++ b/test/test_default-host.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_fallback_on_default(docker_compose, nginxproxy):
r = nginxproxy.get("http://unknown.nginx-proxy.tld/port")
assert r.status_code == 200
diff --git a/test/test_docker_unix_socket.py b/test/test_docker_unix_socket.py
index b31da16..57fa004 100644
--- a/test/test_docker_unix_socket.py
+++ b/test/test_docker_unix_socket.py
@@ -1,15 +1,13 @@
-import pytest
-
-def test_unknown_virtual_host(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/port")
- assert r.status_code == 503
-
def test_forwards_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.tld/port")
- assert r.status_code == 200
+ assert r.status_code == 200
assert r.text == "answer from port 81\n"
def test_forwards_to_web2(docker_compose, nginxproxy):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port")
assert r.status_code == 200
- assert r.text == "answer from port 82\n"
+ assert r.text == "answer from port 82\n"
+
+def test_unknown_virtual_host(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/port", expected_status_code=503)
+ assert r.status_code == 503
diff --git a/test/test_enable_http_on_missing_cert.py b/test/test_enable_http_on_missing_cert.py
index cdedc8a..7f95541 100644
--- a/test/test_enable_http_on_missing_cert.py
+++ b/test/test_enable_http_on_missing_cert.py
@@ -1,18 +1,23 @@
-import pytest
-
-
-def test_nohttp_missing_cert_disabled(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nohttp-missing-cert-disabled.nginx-proxy.tld/", allow_redirects=False)
- assert r.status_code == 503
-
def test_nohttp_missing_cert_enabled(docker_compose, nginxproxy):
r = nginxproxy.get("http://nohttp-missing-cert-enabled.nginx-proxy.tld/", allow_redirects=False)
assert r.status_code == 200
-def test_redirect_missing_cert_disabled(docker_compose, nginxproxy):
- r = nginxproxy.get("http://redirect-missing-cert-disabled.nginx-proxy.tld/", allow_redirects=False)
- assert r.status_code == 301
+def test_nohttp_missing_cert_disabled(docker_compose, nginxproxy):
+ r = nginxproxy.get(
+ "http://nohttp-missing-cert-disabled.nginx-proxy.tld/",
+ allow_redirects=False,
+ expected_status_code=503
+ )
+ assert r.status_code == 503
def test_redirect_missing_cert_enabled(docker_compose, nginxproxy):
r = nginxproxy.get("http://redirect-missing-cert-enabled.nginx-proxy.tld/", allow_redirects=False)
assert r.status_code == 200
+
+def test_redirect_missing_cert_disabled(docker_compose, nginxproxy):
+ r = nginxproxy.get(
+ "http://redirect-missing-cert-disabled.nginx-proxy.tld/",
+ allow_redirects=False,
+ expected_status_code=301
+ )
+ assert r.status_code == 301
diff --git a/test/test_events.py b/test/test_events.py
index bd15575..4900f11 100644
--- a/test/test_events.py
+++ b/test/test_events.py
@@ -56,7 +56,7 @@ def web2(docker_compose):
pass
def test_nginx_proxy_behavior_when_alone(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
assert r.status_code == 503
@@ -67,18 +67,18 @@ def test_new_container_is_detected_vhost(web1, nginxproxy):
web1.remove(force=True)
sleep(2)
- r = nginxproxy.get("http://web1.nginx-proxy/port")
+ r = nginxproxy.get("http://web1.nginx-proxy/port", expected_status_code=503)
assert r.status_code == 503
def test_new_container_is_detected_vpath(web2, nginxproxy):
r = nginxproxy.get("http://nginx-proxy/web2/port")
assert r.status_code == 200
assert "answer from port 82\n" == r.text
- r = nginxproxy.get("http://nginx-proxy/port")
+ r = nginxproxy.get("http://nginx-proxy/port", expected_status_code=[404, 503])
assert r.status_code in [404, 503]
web2.remove(force=True)
sleep(2)
- r = nginxproxy.get("http://nginx-proxy/web2/port")
+ r = nginxproxy.get("http://nginx-proxy/web2/port", expected_status_code=503)
assert r.status_code == 503
diff --git a/test/test_fallback.py b/test/test_fallback.py
index 74dc29a..d6211e3 100644
--- a/test/test_fallback.py
+++ b/test/test_fallback.py
@@ -26,8 +26,11 @@ def get(docker_compose, nginxproxy, want_err_re):
interval=.3,
max_tries=30,
jitter=None)
- def _get(url):
- return nginxproxy.get(url, allow_redirects=False)
+ def _get(url, expected_status_code=None):
+ if expected_status_code is None:
+ return nginxproxy.get_without_backoff(url, allow_redirects=False)
+ else:
+ return nginxproxy.get(url, allow_redirects=False, expected_status_code=expected_status_code)
return _get
@@ -110,7 +113,7 @@ INTERNAL_ERR_RE = re.compile("TLSV1_UNRECOGNIZED_NAME")
])
def test_fallback(get, url, want_code, want_err_re):
if want_err_re is None:
- r = get(url)
+ r = get(url, want_code)
assert r.status_code == want_code
else:
with pytest.raises(requests.exceptions.SSLError, match=want_err_re):
diff --git a/test/test_headers/test_http.py b/test/test_headers/test_http.py
index b2b6147..f1ee9a9 100644
--- a/test/test_headers/test_http.py
+++ b/test/test_headers/test_http.py
@@ -101,7 +101,7 @@ def test_httpoxy_safe(docker_compose, nginxproxy):
)
def test_no_host_server_tokens_off(docker_compose, nginxproxy):
ip = nginxproxy.get_ip()
- r = nginxproxy.get(f"http://{ip}/headers")
+ r = nginxproxy.get(f"http://{ip}/headers", expected_status_code=503)
assert r.status_code == 503
assert r.headers["Server"] == "nginx"
diff --git a/test/test_headers/test_https.py b/test/test_headers/test_https.py
index d833c96..6566db0 100644
--- a/test/test_headers/test_https.py
+++ b/test/test_headers/test_https.py
@@ -102,7 +102,7 @@ def test_httpoxy_safe(docker_compose, nginxproxy):
@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning')
def test_no_host_server_tokens_off(docker_compose, nginxproxy):
ip = nginxproxy.get_ip()
- r = nginxproxy.get(f"https://{ip}/headers", verify=False)
+ r = nginxproxy.get(f"https://{ip}/headers", verify=False, expected_status_code=503)
assert r.status_code == 503
assert r.headers["Server"] == "nginx"
diff --git a/test/test_host-network-mode/test_host-network-mode.py b/test/test_host-network-mode/test_host-network-mode.py
index 0c21348..c80fbf0 100644
--- a/test/test_host-network-mode/test_host-network-mode.py
+++ b/test/test_host-network-mode/test_host-network-mode.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_forwards_to_bridge_network_container(docker_compose, nginxproxy):
r = nginxproxy.get("http://bridge-network.nginx-proxy.tld/port")
assert r.status_code == 200
diff --git a/test/test_host-network-mode/test_proxy-host-network-mode.py b/test/test_host-network-mode/test_proxy-host-network-mode.py
index 330334b..0c8bf65 100644
--- a/test/test_host-network-mode/test_proxy-host-network-mode.py
+++ b/test/test_host-network-mode/test_proxy-host-network-mode.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_forwards_to_host_network_container_1(docker_compose, nginxproxy):
r = nginxproxy.get("http://host-network-1.nginx-proxy.tld:8888/port")
assert r.status_code == 200
diff --git a/test/test_htpasswd/test_htpasswd_regex_virtual_host.py b/test/test_htpasswd/test_htpasswd_regex_virtual_host.py
index 1b169d0..099f13c 100644
--- a/test/test_htpasswd/test_htpasswd_regex_virtual_host.py
+++ b/test/test_htpasswd/test_htpasswd_regex_virtual_host.py
@@ -1,7 +1,5 @@
-import pytest
-
def test_htpasswd_regex_virtual_host_is_restricted(docker_compose, nginxproxy):
- r = nginxproxy.get("http://regex.htpasswd.nginx-proxy.example/port")
+ r = nginxproxy.get("http://regex.htpasswd.nginx-proxy.example/port", expected_status_code=401)
assert r.status_code == 401
assert "WWW-Authenticate" in r.headers
assert r.headers["WWW-Authenticate"] == 'Basic realm="Restricted access"'
diff --git a/test/test_htpasswd/test_htpasswd_virtual_host.py b/test/test_htpasswd/test_htpasswd_virtual_host.py
index aff3a62..3a006fe 100644
--- a/test/test_htpasswd/test_htpasswd_virtual_host.py
+++ b/test/test_htpasswd/test_htpasswd_virtual_host.py
@@ -1,7 +1,5 @@
-import pytest
-
def test_htpasswd_virtual_host_is_restricted(docker_compose, nginxproxy):
- r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/port")
+ r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/port", expected_status_code=401)
assert r.status_code == 401
assert "WWW-Authenticate" in r.headers
assert r.headers["WWW-Authenticate"] == 'Basic realm="Restricted htpasswd.nginx-proxy.tld"'
diff --git a/test/test_htpasswd/test_htpasswd_virtual_path.py b/test/test_htpasswd/test_htpasswd_virtual_path.py
index 262b314..d95077b 100644
--- a/test/test_htpasswd/test_htpasswd_virtual_path.py
+++ b/test/test_htpasswd/test_htpasswd_virtual_path.py
@@ -1,7 +1,5 @@
-import pytest
-
def test_htpasswd_virtual_path_is_restricted(docker_compose, nginxproxy):
- r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/foo/port")
+ r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/foo/port", expected_status_code=401)
assert r.status_code == 401
assert "WWW-Authenticate" in r.headers
assert r.headers["WWW-Authenticate"] == 'Basic realm="Restricted htpasswd.nginx-proxy.tld/foo/"'
diff --git a/test/test_http2/test_http2_global_disabled.py b/test/test_http2/test_http2_global_disabled.py
index 42e102d..c531375 100644
--- a/test/test_http2/test_http2_global_disabled.py
+++ b/test/test_http2/test_http2_global_disabled.py
@@ -1,4 +1,3 @@
-import pytest
import re
def test_http2_global_disabled_config(docker_compose, nginxproxy):
diff --git a/test/test_http3/test_http3_global_disabled.py b/test/test_http3/test_http3_global_disabled.py
index 508823e..f96a97a 100644
--- a/test/test_http3/test_http3_global_disabled.py
+++ b/test/test_http3/test_http3_global_disabled.py
@@ -1,4 +1,3 @@
-import pytest
import re
#Python Requests is not able to do native http3 requests.
diff --git a/test/test_http3/test_http3_global_enabled.py b/test/test_http3/test_http3_global_enabled.py
index c678ab6..8e198b6 100644
--- a/test/test_http3/test_http3_global_enabled.py
+++ b/test/test_http3/test_http3_global_enabled.py
@@ -1,4 +1,3 @@
-import pytest
import re
#Python Requests is not able to do native http3 requests.
diff --git a/test/test_http3/test_http3_vhost.py b/test/test_http3/test_http3_vhost.py
index 93a217c..a345dad 100644
--- a/test/test_http3/test_http3_vhost.py
+++ b/test/test_http3/test_http3_vhost.py
@@ -1,4 +1,3 @@
-import pytest
import re
#Python Requests is not able to do native http3 requests.
diff --git a/test/test_internal/test_internal-per-vhost.py b/test/test_internal/test_internal-per-vhost.py
index e64cc62..04649e2 100644
--- a/test/test_internal/test_internal-per-vhost.py
+++ b/test/test_internal/test_internal-per-vhost.py
@@ -1,5 +1,3 @@
-import pytest
-
def test_network_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
assert r.status_code == 200
diff --git a/test/test_internal/test_internal-per-vpath.py b/test/test_internal/test_internal-per-vpath.py
index def806c..f788fa5 100644
--- a/test/test_internal/test_internal-per-vpath.py
+++ b/test/test_internal/test_internal-per-vpath.py
@@ -1,5 +1,3 @@
-import pytest
-
def test_network_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://nginx-proxy.example/web1/port")
assert r.status_code == 200
diff --git a/test/test_ipv6/test_ipv6.py b/test/test_ipv6/test_ipv6.py
index 36bf653..7328e5b 100644
--- a/test/test_ipv6/test_ipv6.py
+++ b/test/test_ipv6/test_ipv6.py
@@ -1,25 +1,17 @@
-import pytest
-
-
-def test_unknown_virtual_host_ipv4(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/port")
- assert r.status_code == 503
-
-
def test_forwards_to_web1_ipv4(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.tld/port")
- assert r.status_code == 200
+ assert r.status_code == 200
assert r.text == "answer from port 81\n"
def test_forwards_to_web2_ipv4(docker_compose, nginxproxy):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port")
assert r.status_code == 200
- assert r.text == "answer from port 82\n"
+ assert r.text == "answer from port 82\n"
-def test_unknown_virtual_host_ipv6(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/port", ipv6=True)
+def test_unknown_virtual_host_ipv4(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/port", expected_status_code=503)
assert r.status_code == 503
@@ -33,3 +25,8 @@ def test_forwards_to_web2_ipv6(docker_compose, nginxproxy):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port", ipv6=True)
assert r.status_code == 200
assert r.text == "answer from port 82\n"
+
+
+def test_unknown_virtual_host_ipv6(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/port", ipv6=True, expected_status_code=503)
+ assert r.status_code == 503
\ No newline at end of file
diff --git a/test/test_ipv6/test_ipv6_prefer_ipv4_network.py b/test/test_ipv6/test_ipv6_prefer_ipv4_network.py
index 9a11fac..f11c797 100644
--- a/test/test_ipv6/test_ipv6_prefer_ipv4_network.py
+++ b/test/test_ipv6/test_ipv6_prefer_ipv4_network.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_forwards_to_ipv4_only_network(docker_compose, nginxproxy):
r = nginxproxy.get("http://ipv4only.nginx-proxy.tld/port")
assert r.status_code == 200
diff --git a/test/test_ipv6/test_ipv6_prefer_ipv6_network.py b/test/test_ipv6/test_ipv6_prefer_ipv6_network.py
index 09a8dde..3e1988d 100644
--- a/test/test_ipv6/test_ipv6_prefer_ipv6_network.py
+++ b/test/test_ipv6/test_ipv6_prefer_ipv6_network.py
@@ -1,6 +1,3 @@
-import pytest
-
-
def test_forwards_to_ipv4_only_network(docker_compose, nginxproxy):
r = nginxproxy.get("http://ipv4only.nginx-proxy.tld/port")
assert r.status_code == 200
diff --git a/test/test_loadbalancing.py b/test/test_loadbalancing.py
index 4b43aa5..d5f6d86 100644
--- a/test/test_loadbalancing.py
+++ b/test/test_loadbalancing.py
@@ -1,4 +1,3 @@
-import pytest
import re
def test_loadbalance_hash(docker_compose, nginxproxy):
diff --git a/test/test_location-override.py b/test/test_location-override.py
index cbccbd9..f37c609 100644
--- a/test/test_location-override.py
+++ b/test/test_location-override.py
@@ -1,39 +1,39 @@
def test_explicit_root_nohash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://explicit-root-nohash.nginx-proxy.test/port")
- assert r.status_code == 418
r = nginxproxy.get("http://explicit-root-nohash.nginx-proxy.test/foo/port")
assert r.status_code == 200
assert r.text == "answer from port 82\n"
+ r = nginxproxy.get("http://explicit-root-nohash.nginx-proxy.test/port", expected_status_code=418)
+ assert r.status_code == 418
def test_explicit_root_hash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://explicit-root-hash.nginx-proxy.test/port")
- assert r.status_code == 418
r = nginxproxy.get("http://explicit-root-hash.nginx-proxy.test/foo/port")
assert r.status_code == 200
assert r.text == "answer from port 82\n"
+ r = nginxproxy.get("http://explicit-root-hash.nginx-proxy.test/port", expected_status_code=418)
+ assert r.status_code == 418
def test_explicit_root_hash_and_nohash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://explicit-root-hash-and-nohash.nginx-proxy.test/port")
- assert r.status_code == 418
r = nginxproxy.get("http://explicit-root-hash-and-nohash.nginx-proxy.test/foo/port")
assert r.status_code == 200
assert r.text == "answer from port 82\n"
+ r = nginxproxy.get("http://explicit-root-hash-and-nohash.nginx-proxy.test/port", expected_status_code=418)
+ assert r.status_code == 418
def test_explicit_nonroot(docker_compose, nginxproxy):
r = nginxproxy.get("http://explicit-nonroot.nginx-proxy.test/port")
assert r.status_code == 200
assert r.text == "answer from port 81\n"
- r = nginxproxy.get("http://explicit-nonroot.nginx-proxy.test/foo/port")
+ r = nginxproxy.get("http://explicit-nonroot.nginx-proxy.test/foo/port", expected_status_code=418)
assert r.status_code == 418
def test_implicit_root_nohash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://implicit-root-nohash.nginx-proxy.test/port")
+ r = nginxproxy.get("http://implicit-root-nohash.nginx-proxy.test/port", expected_status_code=418)
assert r.status_code == 418
def test_implicit_root_hash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://implicit-root-hash.nginx-proxy.test/port")
+ r = nginxproxy.get("http://implicit-root-hash.nginx-proxy.test/port", expected_status_code=418)
assert r.status_code == 418
def test_implicit_root_hash_and_nohash(docker_compose, nginxproxy):
- r = nginxproxy.get("http://implicit-root-hash-and-nohash.nginx-proxy.test/port")
+ r = nginxproxy.get("http://implicit-root-hash-and-nohash.nginx-proxy.test/port", expected_status_code=418)
assert r.status_code == 418
diff --git a/test/test_logs/test_log_disabled.py b/test/test_logs/test_log_disabled.py
index cd8ab41..af8b9bb 100644
--- a/test/test_logs/test_log_disabled.py
+++ b/test/test_logs/test_log_disabled.py
@@ -1,6 +1,9 @@
+import time
+
import pytest
def test_log_disabled(docker_compose, nginxproxy):
+ time.sleep(3)
r = nginxproxy.get("http://nginx-proxy.test/port")
assert r.status_code == 200
assert r.text == "answer from port 81\n"
diff --git a/test/test_logs/test_log_format.py b/test/test_logs/test_log_format.py
index 5a0fdc8..940283f 100644
--- a/test/test_logs/test_log_format.py
+++ b/test/test_logs/test_log_format.py
@@ -1,6 +1,9 @@
+import time
+
import pytest
def test_log_format(docker_compose, nginxproxy):
+ time.sleep(3)
r = nginxproxy.get("http://nginx-proxy.test/port")
assert r.status_code == 200
assert r.text == "answer from port 81\n"
diff --git a/test/test_multiple-hosts.py b/test/test_multiple-hosts.py
index 76e7de6..e3b3468 100644
--- a/test/test_multiple-hosts.py
+++ b/test/test_multiple-hosts.py
@@ -1,10 +1,6 @@
import pytest
-def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
- r = nginxproxy.get("http://unknown.nginx-proxy.tld/port")
- assert r.status_code == 503
-
def test_webA_is_forwarded(docker_compose, nginxproxy):
r = nginxproxy.get("http://webA.nginx-proxy.tld/port")
assert r.status_code == 200
@@ -14,3 +10,7 @@ def test_webB_is_forwarded(docker_compose, nginxproxy):
r = nginxproxy.get("http://webB.nginx-proxy.tld/port")
assert r.status_code == 200
assert r.text == "answer from port 81\n"
+
+def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://unknown.nginx-proxy.tld/port", expected_status_code=503)
+ assert r.status_code == 503
diff --git a/test/test_multiple-networks.py b/test/test_multiple-networks.py
index 9d48cbe..96293e2 100644
--- a/test/test_multiple-networks.py
+++ b/test/test_multiple-networks.py
@@ -3,9 +3,6 @@ import re
import pytest
-def test_unknown_virtual_host(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/")
- assert r.status_code == 503
def test_forwards_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.example/port")
@@ -26,3 +23,7 @@ def test_multipath(docker_compose, nginxproxy):
web3_server_lines = [l for l in lines
if re.search(r'(?m)^\s*server\s+[^\s]*:83;\s*$', l)]
assert len(web3_server_lines) == 1
+
+def test_unknown_virtual_host(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/", expected_status_code=503)
+ assert r.status_code == 503
diff --git a/test/test_multiports/test_multiports-base-json.py b/test/test_multiports/test_multiports-base-json.py
index 7f1ef0f..4d328bd 100644
--- a/test/test_multiports/test_multiports-base-json.py
+++ b/test/test_multiports/test_multiports-base-json.py
@@ -5,7 +5,7 @@ def test_virtual_host_is_dropped_when_using_multiports(docker_compose, nginxprox
r = nginxproxy.get("http://notskipped.nginx-proxy.tld/port")
assert r.status_code == 200
assert "answer from port 81\n" in r.text
- r = nginxproxy.get("http://skipped.nginx-proxy.tld/")
+ r = nginxproxy.get("http://skipped.nginx-proxy.tld/", expected_status_code=503)
assert r.status_code == 503
diff --git a/test/test_multiports/test_multiports-base-yaml.py b/test/test_multiports/test_multiports-base-yaml.py
index 7f1ef0f..4d328bd 100644
--- a/test/test_multiports/test_multiports-base-yaml.py
+++ b/test/test_multiports/test_multiports-base-yaml.py
@@ -5,7 +5,7 @@ def test_virtual_host_is_dropped_when_using_multiports(docker_compose, nginxprox
r = nginxproxy.get("http://notskipped.nginx-proxy.tld/port")
assert r.status_code == 200
assert "answer from port 81\n" in r.text
- r = nginxproxy.get("http://skipped.nginx-proxy.tld/")
+ r = nginxproxy.get("http://skipped.nginx-proxy.tld/", expected_status_code=503)
assert r.status_code == 503
diff --git a/test/test_multiports/test_multiports-invalid-syntax.py b/test/test_multiports/test_multiports-invalid-syntax.py
index ed1c773..a21b74f 100644
--- a/test/test_multiports/test_multiports-invalid-syntax.py
+++ b/test/test_multiports/test_multiports-invalid-syntax.py
@@ -1,11 +1,14 @@
+import time
+
import pytest
import re
def test_virtual_hosts_with_syntax_error_should_not_be_reachable(docker_compose, nginxproxy):
- r = nginxproxy.get("http://test1.nginx-proxy.tld")
+ time.sleep(3)
+ r = nginxproxy.get("http://test1.nginx-proxy.tld", expected_status_code=503)
assert r.status_code == 503
- r = nginxproxy.get("http://test2.nginx-proxy.tld")
+ r = nginxproxy.get("http://test2.nginx-proxy.tld", expected_status_code=503)
assert r.status_code == 503
diff --git a/test/test_nominal.py b/test/test_nominal.py
index a3f9c87..90093dc 100644
--- a/test/test_nominal.py
+++ b/test/test_nominal.py
@@ -2,26 +2,26 @@ import pytest
from requests import ConnectionError
-def test_unknown_virtual_host(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy/port")
- assert r.status_code == 503
-
-
def test_forwards_to_web1(docker_compose, nginxproxy):
r = nginxproxy.get("http://web1.nginx-proxy.tld/port")
- assert r.status_code == 200
+ assert r.status_code == 200
assert r.text == "answer from port 81\n"
def test_forwards_to_web2(docker_compose, nginxproxy):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port")
assert r.status_code == 200
- assert r.text == "answer from port 82\n"
+ assert r.text == "answer from port 82\n"
+
+
+def test_unknown_virtual_host(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://nginx-proxy/port", expected_status_code=503)
+ assert r.status_code == 503
def test_ipv6_is_disabled_by_default(docker_compose, nginxproxy):
with pytest.raises(ConnectionError):
- nginxproxy.get("http://nginx-proxy/port", ipv6=True)
+ nginxproxy.get_without_backoff("http://nginx-proxy/port", ipv6=True)
def test_container_version_is_displayed(docker_compose, nginxproxy):
diff --git a/test/test_ports/test_ports.py b/test/test_ports/test_ports.py
index b8d9801..a3ac3fd 100644
--- a/test/test_ports/test_ports.py
+++ b/test/test_ports/test_ports.py
@@ -18,6 +18,6 @@ def test_answer_is_served_from_chosen_port(docker_compose, nginxproxy):
assert "answer from port 90\n" in r.text
def test_answer_is_served_from_chosen_port_even_if_unreachable(docker_compose, nginxproxy):
- r = nginxproxy.get("http://wrong-virtual-port.nginx-proxy.tld/port")
+ r = nginxproxy.get("http://wrong-virtual-port.nginx-proxy.tld/port", expected_status_code=502)
assert r.status_code == 502
assert re.search(r"\n\s+server \d+\.\d+\.\d+\.\d+:91;\n", nginxproxy.get_conf().decode('ASCII'))
diff --git a/test/test_server-down/test_server-down.py b/test/test_server-down/test_server-down.py
index 995cd7d..d94d4d6 100644
--- a/test/test_server-down/test_server-down.py
+++ b/test/test_server-down/test_server-down.py
@@ -1,7 +1,10 @@
+import time
+
import pytest
def test_web_has_server_down(docker_compose, nginxproxy):
+ time.sleep(3)
conf = nginxproxy.get_conf().decode('ASCII')
- r = nginxproxy.get("http://web.nginx-proxy.tld/port")
+ r = nginxproxy.get("http://web.nginx-proxy.tld/port", expected_status_code=(502, 503))
assert r.status_code in [502, 503]
assert conf.count("server 127.0.0.1 down;") == 1
diff --git a/test/test_ssl/test_hsts.py b/test/test_ssl/test_hsts.py
index 890c4ad..d4f5952 100644
--- a/test/test_ssl/test_hsts.py
+++ b/test/test_ssl/test_hsts.py
@@ -10,7 +10,7 @@ def test_web1_HSTS_default(docker_compose, nginxproxy):
# Regression test to ensure HSTS is enabled even when the upstream sends an error in response
# Issue #1073 https://github.com/nginx-proxy/nginx-proxy/pull/1073
def test_web1_HSTS_error(docker_compose, nginxproxy):
- r = nginxproxy.get("https://web1.nginx-proxy.tld/status/500", allow_redirects=False)
+ r = nginxproxy.get("https://web1.nginx-proxy.tld/status/500", allow_redirects=False, expected_status_code=500)
assert "Strict-Transport-Security" in r.headers
assert "max-age=31536000" == r.headers["Strict-Transport-Security"]
diff --git a/test/test_ssl/test_nohttp.py b/test/test_ssl/test_nohttp.py
index 032f60f..3d24ab2 100644
--- a/test/test_ssl/test_nohttp.py
+++ b/test/test_ssl/test_nohttp.py
@@ -2,18 +2,6 @@ import pytest
import requests
-def test_web2_http_is_connection_refused(docker_compose, nginxproxy):
- r = nginxproxy.get("http://web2.nginx-proxy.tld/", allow_redirects=False)
- assert r.status_code == 503
-
-
-def test_web2_http_is_connection_refused_for_acme_challenge(
- docker_compose, nginxproxy, acme_challenge_path
-):
- r = nginxproxy.get(f"http://web2.nginx-proxy.tld/{acme_challenge_path}", allow_redirects=False)
- assert r.status_code == 503
-
-
def test_web2_https_is_forwarded(docker_compose, nginxproxy):
r = nginxproxy.get("https://web2.nginx-proxy.tld/port", allow_redirects=False)
assert r.status_code == 200
@@ -24,3 +12,19 @@ def test_web2_HSTS_policy_is_active(docker_compose, nginxproxy):
r = nginxproxy.get("https://web2.nginx-proxy.tld/port", allow_redirects=False)
assert "answer from port 82\n" in r.text
assert "Strict-Transport-Security" in r.headers
+
+
+def test_web2_http_is_connection_refused(docker_compose, nginxproxy):
+ r = nginxproxy.get("http://web2.nginx-proxy.tld/", allow_redirects=False, expected_status_code=503)
+ assert r.status_code == 503
+
+
+def test_web2_http_is_connection_refused_for_acme_challenge(
+ docker_compose, nginxproxy, acme_challenge_path
+):
+ r = nginxproxy.get(
+ f"http://web2.nginx-proxy.tld/{acme_challenge_path}",
+ allow_redirects=False,
+ expected_status_code=503
+ )
+ assert r.status_code == 503
diff --git a/test/test_ssl/test_nohttps.py b/test/test_ssl/test_nohttps.py
index 23e8224..2daa1cb 100644
--- a/test/test_ssl/test_nohttps.py
+++ b/test/test_ssl/test_nohttps.py
@@ -15,6 +15,7 @@ def test_https_is_disabled(docker_compose, nginxproxy):
def test_http_acme_challenge_does_not_work(docker_compose, nginxproxy, acme_challenge_path):
r = nginxproxy.get(
f"http://web.nginx-proxy.tld/{acme_challenge_path}",
- allow_redirects=False
+ allow_redirects=False,
+ expected_status_code=404
)
assert r.status_code == 404
diff --git a/test/test_upstream-name/test_predictable-name.py b/test/test_upstream-name/test_predictable-name.py
index 7e19646..1a43472 100644
--- a/test/test_upstream-name/test_predictable-name.py
+++ b/test/test_upstream-name/test_predictable-name.py
@@ -1,7 +1,9 @@
import pytest
import re
+import time
def test_predictable_upstream_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
+ time.sleep(3)
conf = nginxproxy.get_conf().decode('ASCII')
assert re.search(r"upstream web\.nginx-proxy\.tld \{", conf)
diff --git a/test/test_upstream-name/test_sha1-name.py b/test/test_upstream-name/test_sha1-name.py
index 663ca28..de28d2d 100644
--- a/test/test_upstream-name/test_sha1-name.py
+++ b/test/test_upstream-name/test_sha1-name.py
@@ -1,8 +1,10 @@
import pytest
import re
+import time
def test_sha1_upstream_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
+ time.sleep(3)
conf = nginxproxy.get_conf().decode('ASCII')
assert re.search(r"upstream 3e837201a6255962094cd6d8f61e22b07d3cc8ed \{", conf)
diff --git a/test/test_virtual-path/test_custom_conf.py b/test/test_virtual-path/test_custom_conf.py
index eec149f..ef7e166 100644
--- a/test/test_virtual-path/test_custom_conf.py
+++ b/test/test_virtual-path/test_custom_conf.py
@@ -1,7 +1,7 @@
import pytest
def test_default_root_response(docker_compose, nginxproxy):
- r = nginxproxy.get("http://nginx-proxy.test/")
+ r = nginxproxy.get("http://nginx-proxy.test/", expected_status_code=418)
assert r.status_code == 418
@pytest.mark.parametrize("stub,header", [
@@ -21,7 +21,7 @@ def test_custom_applies(docker_compose, nginxproxy, stub, header):
("bar.nginx-proxy.test", 503),
])
def test_custom_does_not_apply(docker_compose, nginxproxy, stub, code):
- r = nginxproxy.get(f"http://{stub}/port")
+ r = nginxproxy.get(f"http://{stub}/port", expected_status_code=code)
assert r.status_code == code
assert "X-test" not in r.headers
diff --git a/test/test_virtual-path/test_default-root-none.py b/test/test_virtual-path/test_default-root-none.py
index 742d87b..f11d0b3 100644
--- a/test/test_virtual-path/test_default-root-none.py
+++ b/test/test_virtual-path/test_default-root-none.py
@@ -1,7 +1,9 @@
import re
+import time
def test_default_root_none(docker_compose, nginxproxy):
+ time.sleep(3)
conf = nginxproxy.get_conf().decode()
assert re.search(r"(?m)^\s*location\s+/path\s+\{", conf)
assert not re.search(r"(?m)^\s*location\s+/\s+\{", conf)
diff --git a/test/test_virtual-path/test_virtual_paths.py b/test/test_virtual-path/test_virtual_paths.py
index 8a8090c..934eb43 100644
--- a/test/test_virtual-path/test_virtual_paths.py
+++ b/test/test_virtual-path/test_virtual_paths.py
@@ -1,7 +1,6 @@
-from time import sleep
-
import pytest
from docker.errors import NotFound
+from time import sleep
@pytest.mark.parametrize("stub,expected_port", [
("nginx-proxy.test/web1", 81),
@@ -19,7 +18,7 @@ def test_valid_path(docker_compose, nginxproxy, stub, expected_port):
"bar.nginx-proxy.test",
])
def test_invalid_path(docker_compose, nginxproxy, stub):
- r = nginxproxy.get(f"http://{stub}/port")
+ r = nginxproxy.get(f"http://{stub}/port", expected_status_code=(404, 503))
assert r.status_code in [404, 503]
@pytest.fixture()
@@ -56,5 +55,5 @@ def test_container_hotplug(web4, nginxproxy):
assert r.text == f"answer from port 84\n"
web4.remove(force=True)
sleep(2)
- r = nginxproxy.get(f"http://nginx-proxy.test/web4/port")
+ r = nginxproxy.get(f"http://nginx-proxy.test/web4/port", expected_status_code=404)
assert r.status_code == 404
diff --git a/test/test_wildcard_host.py b/test/test_wildcard_host.py
index a5b6633..b1a05b4 100644
--- a/test/test_wildcard_host.py
+++ b/test/test_wildcard_host.py
@@ -28,5 +28,5 @@ def test_wildcard_prefix(docker_compose, nginxproxy, host, expected_port):
"web4.whatever.nginx-proxy.regexp-to-infinity-and-beyond"
])
def test_non_matching_host_is_503(docker_compose, nginxproxy, host):
- r = nginxproxy.get(f"http://{host}/port")
+ r = nginxproxy.get(f"http://{host}/port", expected_status_code=503)
assert r.status_code == 503, r.text