Skip to content

Commit

Permalink
Refactor other tests due to the new response section structure
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Jul 25, 2023
1 parent ebe0022 commit cb3d31e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 47 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
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


@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", jsonPath="auth.identity"),
Property("context", jsonPath="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
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
11 changes: 4 additions & 7 deletions testsuite/tests/kuadrant/authorino/operator/http/conftest.py
Original file line number Diff line number Diff line change
@@ -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
from testsuite.httpx import HttpxBackoffClient


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


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


Expand Down

0 comments on commit cb3d31e

Please sign in to comment.