Skip to content

Commit

Permalink
Fix dinosaur tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Smolar <[email protected]>
  • Loading branch information
Jakub Smolar committed Nov 13, 2024
1 parent e4b703c commit 4da66e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
7 changes: 2 additions & 5 deletions testsuite/kuadrant/policy/authorization/auth_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
from testsuite.utils import asdict
from .auth_config import AuthConfig
from .sections import ResponseSection
from .. import Policy
from .. import Policy, CelPredicate
from . import Pattern

if TYPE_CHECKING:
from . import Rule


class AuthPolicy(Policy, AuthConfig):
"""AuthPolicy object, it serves as Kuadrants AuthConfig"""
Expand Down Expand Up @@ -44,7 +41,7 @@ def create_instance(
return cls(model, context=cluster.context)

@modify
def add_rule(self, when: list["Rule"]):
def add_rule(self, when: list[CelPredicate]):
"""Add rule for the skip of entire AuthPolicy"""
self.model.spec.setdefault("when", [])
self.model.spec["when"].extend([asdict(x) for x in when])
Expand Down
21 changes: 12 additions & 9 deletions testsuite/tests/singlecluster/authorino/dinosaur/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from openshift_client import OpenShiftPythonException

from testsuite.httpx.auth import HttpxOidcClientAuth
from testsuite.kuadrant.policy import CelPredicate
from testsuite.oidc.keycloak import Keycloak
from testsuite.utils import ContentType
from testsuite.kuadrant.policy.authorization import Pattern, PatternRef, Value, ValueFrom, DenyResponse
Expand Down Expand Up @@ -100,21 +101,18 @@ def _resource_info(org_id, owner):
@pytest.fixture(scope="module")
def authorization(authorization, keycloak, terms_and_conditions, cluster_info, admin_rhsso, resource_info):
"""Creates complex Authorization Config."""
path_fourth_element = 'context.request.http.path.@extract:{"sep":"/","pos":4}'
path_third_element = 'context.request.http.path.@extract:{"sep":"/","pos":3}'
path_fourth_element = 'request.path.@extract:{"sep":"/","pos":4}'
authorization.add_patterns(
{
"api-route": [Pattern("context.request.http.path", "matches", "^/anything/dinosaurs_mgmt/.+")],
"v1-route": [Pattern(path_third_element, "eq", "v1")],
"dinosaurs-route": [Pattern(path_fourth_element, "eq", "dinosaurs")],
"dinosaur-resource-route": [Pattern("context.request.http.path", "matches", "/dinosaurs/[^/]+$")],
"dinosaur-resource-route": [Pattern("request.path", "matches", "/dinosaurs/[^/]+$")],
"create-dinosaur-route": [
Pattern("context.request.http.path", "matches", "/dinosaurs/?$"),
Pattern("context.request.http.method", "eq", "POST"),
Pattern("request.path", "matches", "/dinosaurs/?$"),
Pattern("request.method", "eq", "POST"),
],
"metrics-federate-route": [
Pattern(path_fourth_element, "eq", "dinosaurs"),
Pattern("context.request.http.path", "matches", "/metrics/federate$"),
Pattern("request.path", "matches", "/metrics/federate$"),
],
"service-accounts-route": [Pattern(path_fourth_element, "eq", "service_accounts")],
"supported-instance-types-route": [Pattern(path_fourth_element, "eq", "instance_types")],
Expand All @@ -129,7 +127,12 @@ def authorization(authorization, keycloak, terms_and_conditions, cluster_info, a
"require-org-id": [Pattern("auth.identity.org_id", "neq", "")],
}
)
authorization.add_rule([PatternRef("api-route"), PatternRef("v1-route")])
authorization.add_rule(
[
CelPredicate("request.path.matches('^/anything/dinosaurs_mgmt/.+')"),
CelPredicate("request.path.split('/')[3] == 'v1'"),
]
)

authorization.identity.clear_all()
authorization.identity.add_oidc(
Expand Down

0 comments on commit 4da66e8

Please sign in to comment.