Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for gateway attached to AuthPolicy #295

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testsuite/policy/authorization/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_instance(
cls,
openshift: OpenShiftClient,
name,
route,
target,
labels: Dict[str, str] = None,
):
"""Creates base instance"""
Expand All @@ -52,7 +52,7 @@ def create_instance(
"spec": {"hosts": []},
}
obj = cls(model, context=openshift.context)
route.add_auth_config(obj)
target.add_auth_config(obj)
return obj

@modify
Expand Down
8 changes: 4 additions & 4 deletions testsuite/policy/authorization/auth_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ class AuthPolicy(AuthConfig):
def auth_section(self):
return self.model.spec.setdefault("rules", {})
pehala marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=unused-argument
@classmethod
def create_instance( # type: ignore
def create_instance(
cls,
openshift: OpenShiftClient,
name,
route: Referencable,
target: Referencable,
labels: Dict[str, str] = None,
):
"""Creates base instance"""
Expand All @@ -33,7 +32,8 @@ def create_instance( # type: ignore
"kind": "AuthPolicy",
"metadata": {"name": name, "namespace": openshift.project, "labels": labels},
"spec": {
"targetRef": route.reference,
"targetRef": target.reference,
"rules": {},
},
}

Expand Down
Empty file.
37 changes: 37 additions & 0 deletions testsuite/tests/kuadrant/gateway/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Conftest for gateway tests"""
import pytest

from testsuite.httpx.auth import HttpxOidcClientAuth
from testsuite.policy.authorization.auth_policy import AuthPolicy


averevki marked this conversation as resolved.
Show resolved Hide resolved
@pytest.fixture(scope="module")
def kuadrant(kuadrant):
"""Skip if not running on Kuadrant"""
if not kuadrant:
pytest.skip("Gateway tests are only for Kuadrant")
return kuadrant


@pytest.fixture(scope="module")
def gateway_ready(gateway):
"""Returns ready gateway"""
gateway.wait_for_ready()
return gateway


@pytest.fixture(scope="module")
def authorization(gateway_ready, route, oidc_provider, authorization_name, openshift, module_label):
# pylint: disable=unused-argument
"""Create AuthPolicy attached to gateway"""
authorization = AuthPolicy.create_instance(
openshift, authorization_name, gateway_ready, labels={"testRun": module_label}
)
authorization.identity.add_oidc("rhsso", oidc_provider.well_known["issuer"])
return authorization


@pytest.fixture(scope="module")
def auth(oidc_provider):
"""Returns RHSSO authentication object for HTTPX"""
return HttpxOidcClientAuth(oidc_provider.get_token, "authorization")
18 changes: 18 additions & 0 deletions testsuite/tests/kuadrant/gateway/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test for AuthPolicy attached directly to gateway"""
import pytest


@pytest.fixture(scope="module")
def rate_limit():
"""Basic gateway test doesn't utilize RateLimitPolicy component"""
return None


@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/pull/287")
def test_smoke(client, auth):
"""Test if AuthPolicy attached directly to gateway works"""
response = client.get("/get", auth=auth)
assert response.status_code == 200
averevki marked this conversation as resolved.
Show resolved Hide resolved

response = client.get("/get")
assert response.status_code == 401