From 30299e69bcafb80ce8d30c6406dd7fe64549c012 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Sat, 7 Dec 2024 20:15:44 +0100 Subject: [PATCH] tests: certificate selection --- test/test_ssl/test_cert_selection.py | 25 ++++++++++++++++++++ test/test_ssl/test_cert_selection.yml | 33 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/test_ssl/test_cert_selection.py create mode 100644 test/test_ssl/test_cert_selection.yml diff --git a/test/test_ssl/test_cert_selection.py b/test/test_ssl/test_cert_selection.py new file mode 100644 index 0000000..23c3790 --- /dev/null +++ b/test/test_ssl/test_cert_selection.py @@ -0,0 +1,25 @@ +import json +import pytest + + +@pytest.mark.parametrize("host,expected_cert_ok,expected_cert", [ + ("nginx-proxy.tld", True, "nginx-proxy.tld"), + ("web1.nginx-proxy.tld", True, "nginx-proxy.tld"), + ("sub.web1.nginx-proxy.tld", False, ""), + ("web2.nginx-proxy.tld", True, "web2.nginx-proxy.tld"), +]) +def test_certificate_selection( + docker_compose, + nginxproxy, + host: str, + expected_cert_ok: bool, + expected_cert: str, +): + r = nginxproxy.get(f"http://{host}/nginx-proxy-debug") + assert r.status_code == 200 + try: + jsonResponse = json.loads(r.text) + except ValueError as err: + pytest.fail("Failed to parse debug endpoint response as JSON:: %s" % err, pytrace=False) + assert jsonResponse["vhost"]["cert_ok"] == expected_cert_ok + assert jsonResponse["vhost"]["cert"] == expected_cert diff --git a/test/test_ssl/test_cert_selection.yml b/test/test_ssl/test_cert_selection.yml new file mode 100644 index 0000000..34e0b64 --- /dev/null +++ b/test/test_ssl/test_cert_selection.yml @@ -0,0 +1,33 @@ +services: + base: + image: web + environment: + WEB_PORTS: "80" + VIRTUAL_HOST: "nginx-proxy.tld" + + web1: + image: web + environment: + WEB_PORTS: "80" + VIRTUAL_HOST: "web1.nginx-proxy.tld" + + sub-web1: + image: web + environment: + WEB_PORTS: "80" + VIRTUAL_HOST: "sub.web1.nginx-proxy.tld" + + web2: + image: web + environment: + WEB_PORTS: "80" + VIRTUAL_HOST: "web2.nginx-proxy.tld" + + sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs:ro + - ./acme_root:/usr/share/nginx/html:ro + environment: + DEBUG_ENDPOINT: "true"