2017-03-15 02:11:21 +01:00
|
|
|
import pytest
|
2021-03-18 22:48:13 +01:00
|
|
|
from ssl import CertificateError
|
2024-05-04 23:52:57 +03:00
|
|
|
from requests import ConnectionError
|
2017-11-08 22:53:44 -05:00
|
|
|
from requests.exceptions import SSLError
|
2017-03-15 02:11:21 +01:00
|
|
|
|
2017-11-08 23:19:13 -05:00
|
|
|
|
2017-03-15 02:11:21 +01:00
|
|
|
@pytest.mark.parametrize("subdomain,should_redirect_to_https", [
|
|
|
|
(1, True),
|
|
|
|
(2, True),
|
|
|
|
(3, False),
|
|
|
|
])
|
|
|
|
def test_http_redirects_to_https(docker_compose, nginxproxy, subdomain, should_redirect_to_https):
|
2021-03-19 12:12:24 +01:00
|
|
|
r = nginxproxy.get(f"http://{subdomain}.web.nginx-proxy.tld/port")
|
2017-03-15 02:11:21 +01:00
|
|
|
if should_redirect_to_https:
|
2019-02-04 15:15:04 -05:00
|
|
|
assert len(r.history) > 0
|
2017-03-15 02:11:21 +01:00
|
|
|
assert r.history[0].is_redirect
|
2021-03-19 12:12:24 +01:00
|
|
|
assert r.history[0].headers.get("Location") == f"https://{subdomain}.web.nginx-proxy.tld/port"
|
|
|
|
assert f"answer from port 8{subdomain}\n" == r.text
|
2017-03-15 02:11:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("subdomain", [1, 2])
|
|
|
|
def test_https_get_served(docker_compose, nginxproxy, subdomain):
|
2021-03-19 12:12:24 +01:00
|
|
|
r = nginxproxy.get(f"https://{subdomain}.web.nginx-proxy.tld/port", allow_redirects=False)
|
2017-03-15 02:11:21 +01:00
|
|
|
assert r.status_code == 200
|
2021-03-19 12:12:24 +01:00
|
|
|
assert f"answer from port 8{subdomain}\n" == r.text
|
2017-03-15 02:11:21 +01:00
|
|
|
|
2021-08-02 18:09:34 +02:00
|
|
|
@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning')
|
2023-02-02 17:17:00 -05:00
|
|
|
def test_https_request_to_nohttps_vhost_goes_to_fallback_server(docker_compose, nginxproxy):
|
2017-11-08 23:19:13 -05:00
|
|
|
with pytest.raises( (CertificateError, SSLError) ) as excinfo:
|
2017-03-15 02:11:21 +01:00
|
|
|
nginxproxy.get("https://3.web.nginx-proxy.tld/port")
|
2023-12-12 19:24:14 +01:00
|
|
|
assert """certificate is not valid for '3.web.nginx-proxy.tld'""" in str(excinfo.value) or \
|
|
|
|
"""hostname '3.web.nginx-proxy.tld' doesn't match 'nginx-proxy.tld'""" in str(excinfo.value)
|
2017-03-15 02:11:21 +01:00
|
|
|
|
|
|
|
r = nginxproxy.get("https://3.web.nginx-proxy.tld/port", verify=False)
|
2023-02-02 17:17:00 -05:00
|
|
|
assert r.status_code == 503
|
2024-05-04 23:52:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("subdomain,acme_should_work", [
|
|
|
|
(1, True),
|
|
|
|
(2, True),
|
|
|
|
(3, False),
|
|
|
|
])
|
|
|
|
def test_acme_challenge_works(
|
|
|
|
docker_compose, nginxproxy, acme_challenge_path, subdomain, acme_should_work
|
|
|
|
):
|
|
|
|
if acme_should_work:
|
|
|
|
r = nginxproxy.get(
|
|
|
|
f"https://{subdomain}.web.nginx-proxy.tld/{acme_challenge_path}",
|
|
|
|
allow_redirects=False
|
|
|
|
)
|
|
|
|
assert r.status_code == 404
|
|
|
|
else:
|
|
|
|
with pytest.raises(ConnectionError):
|
|
|
|
nginxproxy.get(
|
|
|
|
f"https://{subdomain}.web.nginx-proxy.tld/{acme_challenge_path}",
|
|
|
|
allow_redirects=False
|
|
|
|
)
|