Skip to content

Commit

Permalink
Add smoke test for authpolicy attached directly to gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Jan 2, 2024
1 parent fc8f2c8 commit 91b8477
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
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


@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

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

0 comments on commit 91b8477

Please sign in to comment.