From 1329198655373e4b13971806a0ce3571af207a97 Mon Sep 17 00:00:00 2001 From: averevki Date: Wed, 12 Jul 2023 15:21:26 +0200 Subject: [PATCH] Refactor other tests due to the new response section structure --- .../test_response_condition.py | 14 +++----------- .../identity/rhsso/test_rhsso_context.py | 18 ++++++++---------- .../clusterwide/test_wildcard_collision.py | 5 +++-- .../authorino/operator/http/conftest.py | 11 ++++------- .../authorino/operator/sharding/conftest.py | 3 ++- .../kuadrant/authorino/wristband/conftest.py | 17 +---------------- 6 files changed, 21 insertions(+), 47 deletions(-) diff --git a/testsuite/tests/kuadrant/authorino/conditions/section_conditions/test_response_condition.py b/testsuite/tests/kuadrant/authorino/conditions/section_conditions/test_response_condition.py index 61f384b1..ee3e9ffe 100644 --- a/testsuite/tests/kuadrant/authorino/conditions/section_conditions/test_response_condition.py +++ b/testsuite/tests/kuadrant/authorino/conditions/section_conditions/test_response_condition.py @@ -1,23 +1,15 @@ """Test condition to skip the response section of AuthConfig""" import pytest -from testsuite.objects import Rule +from testsuite.objects import Property, Rule, Value from testsuite.utils import extract_response @pytest.fixture(scope="module") def authorization(authorization): """Add to the AuthConfig response, which will only trigger on POST requests""" - authorization.responses.add( - { - "name": "simple", - "json": { - "properties": [ - {"name": "data", "value": "response"}, - ] - }, - }, - when=[Rule("context.request.http.method", "eq", "POST")], + authorization.responses.json( + "simple", [Property("data", Value("response"))], when=[Rule("context.request.http.method", "eq", "POST")] ) return authorization diff --git a/testsuite/tests/kuadrant/authorino/identity/rhsso/test_rhsso_context.py b/testsuite/tests/kuadrant/authorino/identity/rhsso/test_rhsso_context.py index f1b2065f..6e16023c 100644 --- a/testsuite/tests/kuadrant/authorino/identity/rhsso/test_rhsso_context.py +++ b/testsuite/tests/kuadrant/authorino/identity/rhsso/test_rhsso_context.py @@ -4,20 +4,18 @@ import pytest +from testsuite.objects import Property, ValueFrom + @pytest.fixture(scope="module") def authorization(authorization): """Setup AuthConfig for test""" - authorization.responses.add( - { - "name": "auth-json", - "json": { - "properties": [ - {"name": "auth", "valueFrom": {"authJSON": "auth.identity"}}, - {"name": "context", "valueFrom": {"authJSON": "context.request.http.headers.authorization"}}, - ] - }, - } + authorization.responses.json( + "auth-json", + [ + Property("auth", ValueFrom("auth.identity")), + Property("context", ValueFrom("context.request.http.headers.authorization")), + ], ) return authorization diff --git a/testsuite/tests/kuadrant/authorino/operator/clusterwide/test_wildcard_collision.py b/testsuite/tests/kuadrant/authorino/operator/clusterwide/test_wildcard_collision.py index db274faa..28b462f7 100644 --- a/testsuite/tests/kuadrant/authorino/operator/clusterwide/test_wildcard_collision.py +++ b/testsuite/tests/kuadrant/authorino/operator/clusterwide/test_wildcard_collision.py @@ -4,6 +4,7 @@ import pytest +from testsuite.objects import Property, Value from testsuite.openshift.objects.auth_config import AuthConfig @@ -14,7 +15,7 @@ def authorization(authorino, blame, openshift, module_label, envoy, wildcard_dom auth = AuthConfig.create_instance( openshift, blame("ac"), None, hostnames=[wildcard_domain], labels={"testRun": module_label} ) - auth.responses.add({"name": "header", "json": {"properties": [{"name": "anything", "value": "one"}]}}) + auth.responses.json("header", [Property("anything", Value("one"))]) return auth @@ -25,7 +26,7 @@ def authorization2(authorino, blame, openshift2, module_label, envoy, wildcard_d auth = AuthConfig.create_instance( openshift2, blame("ac"), None, hostnames=[wildcard_domain], labels={"testRun": module_label} ) - auth.responses.add({"name": "header", "json": {"properties": [{"name": "anything", "value": "two"}]}}) + auth.responses.json("header", [Property("anything", Value("two"))]) return auth diff --git a/testsuite/tests/kuadrant/authorino/operator/http/conftest.py b/testsuite/tests/kuadrant/authorino/operator/http/conftest.py index 045f53c7..c73c37ec 100644 --- a/testsuite/tests/kuadrant/authorino/operator/http/conftest.py +++ b/testsuite/tests/kuadrant/authorino/operator/http/conftest.py @@ -1,7 +1,7 @@ """Conftest for all tests requiring custom deployment of Authorino""" import pytest -from testsuite.objects import Authorization +from testsuite.objects import Authorization, Property, Value from testsuite.httpx import HttpxBackoffClient @@ -11,12 +11,9 @@ def authorization(authorization, wildcard_domain, openshift, module_label) -> Au """In case of Authorino, AuthConfig used for authorization""" authorization.remove_all_hosts() authorization.add_host(wildcard_domain) - resp = { - "name": "another-json-returned-in-a-header", - "wrapperKey": "x-ext-auth-other-json", - "json": {"properties": [{"name": "propX", "value": "valueX"}]}, - } - authorization.responses.add(response=resp) + authorization.responses.json( + "another-json-returned-in-a-header", [Property("propX", Value("valueX"))], wrapper_key="x-ext-auth-other-json" + ) return authorization diff --git a/testsuite/tests/kuadrant/authorino/operator/sharding/conftest.py b/testsuite/tests/kuadrant/authorino/operator/sharding/conftest.py index f4d9d129..579704bc 100644 --- a/testsuite/tests/kuadrant/authorino/operator/sharding/conftest.py +++ b/testsuite/tests/kuadrant/authorino/operator/sharding/conftest.py @@ -1,6 +1,7 @@ """Conftest for authorino sharding tests""" import pytest +from testsuite.objects import Property, Value from testsuite.openshift.envoy import Envoy from testsuite.openshift.objects.auth_config import AuthConfig @@ -31,7 +32,7 @@ def _authorization(hostname=None, sharding_label=None): hostnames=[hostname], labels={"testRun": module_label, "sharding": sharding_label}, ) - auth.responses.add({"name": "header", "json": {"properties": [{"name": "anything", "value": sharding_label}]}}) + auth.responses.json("header", [Property("anything", Value(sharding_label))]) request.addfinalizer(auth.delete) auth.commit() return auth diff --git a/testsuite/tests/kuadrant/authorino/wristband/conftest.py b/testsuite/tests/kuadrant/authorino/wristband/conftest.py index 99699870..b963af13 100644 --- a/testsuite/tests/kuadrant/authorino/wristband/conftest.py +++ b/testsuite/tests/kuadrant/authorino/wristband/conftest.py @@ -63,22 +63,7 @@ def wristband_endpoint(openshift, authorino, authorization_name): @pytest.fixture(scope="module") def authorization(authorization, wristband_secret, wristband_endpoint) -> Authorization: """Add wristband response with the signing key to the AuthConfig""" - authorization.responses.add( - { - "name": "wristband", - "wrapper": "envoyDynamicMetadata", - "wristband": { - "issuer": wristband_endpoint, - "tokenDuration": 300, # default value - "signingKeyRefs": [ - { - "name": wristband_secret, - "algorithm": "RS256", - } - ], - }, - } - ) + authorization.responses.wristband("wristband", wristband_endpoint, wristband_secret, wrapper="envoyDynamicMetadata") return authorization