Skip to content

Commit

Permalink
Refactor response tests due to the new section structure
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Aug 2, 2023
1 parent 9bd8c00 commit 32486ee
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from testsuite.objects import Property, Value
from testsuite.openshift.objects.auth_config import AuthConfig


Expand All @@ -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


Expand All @@ -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


Expand Down
10 changes: 4 additions & 6 deletions testsuite/tests/kuadrant/authorino/operator/http/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Conftest for all tests requiring custom deployment of Authorino"""
import pytest

from testsuite.objects import Property, Value
from testsuite.httpx import HttpxBackoffClient
from testsuite.openshift.objects.auth_config import AuthConfig

Expand All @@ -11,12 +12,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


Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions testsuite/tests/kuadrant/authorino/wristband/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,7 @@ def wristband_endpoint(openshift, authorino, authorization_name):
@pytest.fixture(scope="module")
def authorization(authorization, wristband_secret, wristband_endpoint) -> AuthConfig:
"""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


Expand Down

0 comments on commit 32486ee

Please sign in to comment.