From ed432ab7271d96a1f938a8fadec5416b70923ac7 Mon Sep 17 00:00:00 2001 From: phala Date: Fri, 6 Jan 2023 12:49:58 +0100 Subject: [PATCH] Add host manipulation to AuthPolicy --- .../objects/auth_config/auth_policy.py | 27 ++++++++++++++++--- .../openshift/objects/gateway_api/__init__.py | 13 ++++++++- .../authorino/multiple_hosts/conftest.py | 6 ----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/testsuite/openshift/objects/auth_config/auth_policy.py b/testsuite/openshift/objects/auth_config/auth_policy.py index 9e23eb5a..546ae58a 100644 --- a/testsuite/openshift/objects/auth_config/auth_policy.py +++ b/testsuite/openshift/objects/auth_config/auth_policy.py @@ -3,12 +3,24 @@ from testsuite.openshift.client import OpenShiftClient from testsuite.openshift.objects.auth_config import AuthConfig -from testsuite.openshift.objects.gateway_api import Referencable +from testsuite.openshift.objects.gateway_api import HTTPRoute class AuthPolicy(AuthConfig): """AuthPolicy object, it serves as Kuadrants AuthConfig""" + def __init__(self, dict_to_model=None, string_to_model=None, context=None, route: HTTPRoute = None): + super().__init__(dict_to_model, string_to_model, context) + self._route = route + + @property + def route(self) -> HTTPRoute: + """Returns route to which the Policy is bound, won't work with objects fetched from Openshift""" + if not self._route: + # TODO: Fetch route from Openshift directly + raise ValueError("This instance doesnt have a Route specified!!") + return self._route + @property def auth_section(self): return self.model.spec.setdefault("authScheme", {}) @@ -19,7 +31,7 @@ def create_instance( # type: ignore cls, openshift: OpenShiftClient, name, - route: Referencable, + route: HTTPRoute, labels: Dict[str, str] = None, hostnames: List[str] = None, ): @@ -39,4 +51,13 @@ def create_instance( # type: ignore if labels is not None: model["metadata"]["labels"] = labels - return cls(model, context=openshift.context) + return cls(model, context=openshift.context, route=route) + + def add_host(self, hostname): + return self.route.add_hostname(hostname) + + def remove_host(self, hostname): + return self.route.remove_hostname(hostname) + + def remove_all_hosts(self): + return self.route.remove_all_hostnames() diff --git a/testsuite/openshift/objects/gateway_api/__init__.py b/testsuite/openshift/objects/gateway_api/__init__.py index d66a5d00..288284e3 100644 --- a/testsuite/openshift/objects/gateway_api/__init__.py +++ b/testsuite/openshift/objects/gateway_api/__init__.py @@ -74,7 +74,18 @@ def reference(self): @modify def add_hostname(self, hostname): """Adds hostname to the Route""" - self.model.spec.hostnames.append(hostname) + if hostname not in self.model.spec.hostnames: + self.model.spec.hostnames.append(hostname) + + @modify + def remove_hostname(self, hostname): + """Adds hostname to the Route""" + self.model.spec.hostnames.remove(hostname) + + @modify + def remove_all_hostnames(self): + """Adds hostname to the Route""" + self.model.spec.hostnames = [] # pylint: disable=too-many-instance-attributes diff --git a/testsuite/tests/kuadrant/authorino/multiple_hosts/conftest.py b/testsuite/tests/kuadrant/authorino/multiple_hosts/conftest.py index 953bf08c..37822fe8 100644 --- a/testsuite/tests/kuadrant/authorino/multiple_hosts/conftest.py +++ b/testsuite/tests/kuadrant/authorino/multiple_hosts/conftest.py @@ -4,12 +4,6 @@ from testsuite.httpx import HttpxBackoffClient -@pytest.fixture(scope="module") -def run_on_kuadrant(): - """Handling of hosts needs to be rewritten""" - return False - - @pytest.fixture(scope="module") def hostname(envoy): """Original hostname"""