From 573e1b8c2ade12f8dad8466434c07ebd9c9fbd59 Mon Sep 17 00:00:00 2001 From: averevki Date: Wed, 11 Sep 2024 13:23:08 +0200 Subject: [PATCH] Add dnspolicy deletion test Signed-off-by: averevki --- testsuite/gateway/gateway_api/hostname.py | 2 +- .../gateway/dnspolicy/__init__.py | 0 .../dnspolicy/test_dnspolicy_removal.py | 43 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/singlecluster/gateway/dnspolicy/__init__.py create mode 100644 testsuite/tests/singlecluster/gateway/dnspolicy/test_dnspolicy_removal.py diff --git a/testsuite/gateway/gateway_api/hostname.py b/testsuite/gateway/gateway_api/hostname.py index d688aa30..b6bd9460 100644 --- a/testsuite/gateway/gateway_api/hostname.py +++ b/testsuite/gateway/gateway_api/hostname.py @@ -27,7 +27,7 @@ def __init__(self, hostname, tls_cert_getter: Callable[[], Certificate | bool] = def client(self, **kwargs) -> KuadrantClient: protocol = "http" - if self.tls_cert_getter is not None: + if self.tls_cert_getter is not None and self.tls_cert_getter() is not None: protocol = "https" kwargs.setdefault("verify", self.tls_cert_getter()) return KuadrantClient(base_url=f"{protocol}://{self.hostname}", **kwargs) diff --git a/testsuite/tests/singlecluster/gateway/dnspolicy/__init__.py b/testsuite/tests/singlecluster/gateway/dnspolicy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/tests/singlecluster/gateway/dnspolicy/test_dnspolicy_removal.py b/testsuite/tests/singlecluster/gateway/dnspolicy/test_dnspolicy_removal.py new file mode 100644 index 00000000..02ae49c7 --- /dev/null +++ b/testsuite/tests/singlecluster/gateway/dnspolicy/test_dnspolicy_removal.py @@ -0,0 +1,43 @@ +"""Test that Gateway will behave properly after attached DNSPolicy is deleted""" + +import pytest + +from testsuite.gateway.gateway_api.gateway import KuadrantGateway + +pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy] + + +@pytest.fixture(scope="module") +def gateway(request, cluster, blame, wildcard_domain, module_label): + """Create gateway without TLS enabled""" + gw = KuadrantGateway.create_instance(cluster, blame("gw"), wildcard_domain, {"app": module_label}, tls=False) + request.addfinalizer(gw.delete) + gw.commit() + gw.wait_for_ready() + return gw + + +@pytest.fixture(scope="module", autouse=True) +def commit(request, route, dns_policy): # pylint: disable=unused-argument + """Commits dnspolicy""" + request.addfinalizer(dns_policy.delete) + dns_policy.commit() + dns_policy.wait_for_ready() + + +def test_dnspolicy_removal(gateway, dns_policy, client): + """ + Test that Gateway will behave properly after attached DNSPolicy is deleted + - Verify that Gateway is affected by DNSPolicy and requests are successful + - Delete attached DNSPolicy + - Verify that Gateway is no longer affected by DNSPolicy and requests are failing + """ + assert gateway.refresh().is_affected_by(dns_policy) + response = client.get("/get") + assert response.status_code == 200 + + dns_policy.delete() + + assert not gateway.refresh().is_affected_by(dns_policy) + response = client.get("/get") + assert response.has_dns_error()