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 Dec 6, 2023
1 parent fc8f2c8 commit 91d3b35
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Empty file.
34 changes: 34 additions & 0 deletions testsuite/tests/kuadrant/gateway/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""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", autouse=True)
def gateway_wait_for_ready(gateway):
"""Waits for gateway to be ready"""
gateway.wait_for_ready()


@pytest.fixture(scope="module")
def authorization(gateway_wait_for_ready, gateway, 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, 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 91d3b35

Please sign in to comment.