From b93071f958a1d8c3abbf784866b16b9b5e73433b Mon Sep 17 00:00:00 2001 From: averevki Date: Wed, 19 Feb 2025 12:02:01 +0100 Subject: [PATCH] Add pytest smoke target Signed-off-by: averevki --- Makefile | 3 ++ pyproject.toml | 1 + .../identity/auth/test_auth_identity.py | 25 +++++++--------- .../test_authpolicy_attached_gateway.py | 21 ++++++++++++++ .../tests/singlecluster/gateway/test_basic.py | 29 ++++++++++--------- .../tests/singlecluster/gateway/test_dns.py | 24 --------------- .../limitador/test_basic_limit.py | 2 +- 7 files changed, 52 insertions(+), 53 deletions(-) create mode 100644 testsuite/tests/singlecluster/gateway/test_authpolicy_attached_gateway.py delete mode 100644 testsuite/tests/singlecluster/gateway/test_dns.py diff --git a/Makefile b/Makefile index 366e863c..28923b48 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,9 @@ testsuite/%: FORCE poetry-no-dev test: ## Run all non mgc tests test pytest tests: kuadrant +smoke: poetry-no-dev + $(PYTEST) -n6 -m 'smoke' --dist loadfile --enforce $(flags) testsuite/tests + authorino: ## Run only authorino related tests authorino: poetry-no-dev $(PYTEST) -n4 -m 'authorino and not multicluster' --dist loadfile --enforce $(flags) testsuite/tests/singlecluster diff --git a/pyproject.toml b/pyproject.toml index 4a4487b7..04391907 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ markers = [ "limitador: Test is using Limitador features", "tlspolicy: Test is using TLSPolicy", "dnspolicy: Test is using DNSPolicy", + "smoke: Build verification test", "disruptive: Test is disruptive", "multicluster: Test is specifc to Multicluster deployment", ] diff --git a/testsuite/tests/singlecluster/authorino/identity/auth/test_auth_identity.py b/testsuite/tests/singlecluster/authorino/identity/auth/test_auth_identity.py index 5b89e7da..ca73d759 100644 --- a/testsuite/tests/singlecluster/authorino/identity/auth/test_auth_identity.py +++ b/testsuite/tests/singlecluster/authorino/identity/auth/test_auth_identity.py @@ -16,7 +16,6 @@ def authorization(authorization, oidc_provider): return authorization -@pytest.fixture(scope="module", params=("keycloak", "auth0")) def oidc_provider(request) -> OIDCProvider: """Fixture which enables switching out OIDC providers for individual modules""" return request.getfixturevalue(request.param) @@ -31,25 +30,21 @@ def wrong_auth(oidc_provider, auth0, keycloak): return HttpxOidcClientAuth(token) -def test_correct_auth(client, auth): - """Tests correct auth""" +@pytest.mark.parametrize( + "oidc_provider", + [pytest.param("keycloak", marks=[pytest.mark.smoke]), pytest.param("auth0")], + indirect=True, +) +def test_auth_identity(client, auth, wrong_auth): + """Tests endpoint protection with auth identity""" + response = client.get("/get") + assert response.status_code == 401 + response = client.get("/get", auth=auth) assert response.status_code == 200 - -def test_wrong_auth(wrong_auth, client): - """Tests request with wrong token""" response = client.get("/get", auth=wrong_auth) assert response.status_code == 401 - -def test_no_auth(client): - """Tests request without any auth""" - response = client.get("/get") - assert response.status_code == 401 - - -def test_invalid_auth(client): - """Tests request with invalid token""" response = client.get("/get", headers={"Authorization": "Bearer xyz"}) assert response.status_code == 401 diff --git a/testsuite/tests/singlecluster/gateway/test_authpolicy_attached_gateway.py b/testsuite/tests/singlecluster/gateway/test_authpolicy_attached_gateway.py new file mode 100644 index 00000000..bb6ff122 --- /dev/null +++ b/testsuite/tests/singlecluster/gateway/test_authpolicy_attached_gateway.py @@ -0,0 +1,21 @@ +"""Test for AuthPolicy attached directly to gateway""" + +import pytest + +pytestmark = [pytest.mark.kuadrant_only] + + +@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_authpolicy_attached_gateway(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 diff --git a/testsuite/tests/singlecluster/gateway/test_basic.py b/testsuite/tests/singlecluster/gateway/test_basic.py index cf988035..020fb6b3 100644 --- a/testsuite/tests/singlecluster/gateway/test_basic.py +++ b/testsuite/tests/singlecluster/gateway/test_basic.py @@ -1,21 +1,24 @@ -"""Test for AuthPolicy attached directly to gateway""" +""" +This module contains the most basic happy path test for both DNSPolicy and TLSPolicy +""" import pytest -pytestmark = [pytest.mark.kuadrant_only] +pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy, pytest.mark.tlspolicy, pytest.mark.smoke] -@pytest.fixture(scope="module") -def rate_limit(): - """Basic gateway test doesn't utilize RateLimitPolicy component""" - return None +def test_gateway_readiness(gateway): + """Tests whether the Gateway was successfully placed by having its IP address assigned""" + assert gateway.is_ready() -@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 +def test_gateway_basic_dns_tls(client, auth): + """ + Tests whether the backend, exposed using the HTTPRoute and Gateway, was exposed correctly, + having a tls secured endpoint with a hostname managed by Kuadrant + """ - response = client.get("/get") - assert response.status_code == 401 + result = client.get("/get", auth=auth) + assert not result.has_dns_error() + assert not result.has_cert_verify_error() + assert result.status_code == 200 diff --git a/testsuite/tests/singlecluster/gateway/test_dns.py b/testsuite/tests/singlecluster/gateway/test_dns.py deleted file mode 100644 index c5a5b2b9..00000000 --- a/testsuite/tests/singlecluster/gateway/test_dns.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This module contains the most basic happy path test for both DNSPolicy and TLSPolicy -""" - -import pytest - -pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy, pytest.mark.tlspolicy] - - -def test_gateway_readiness(gateway): - """Tests whether the Gateway was successfully placed by having its IP address assigned""" - assert gateway.is_ready() - - -def test_smoke(client, auth): - """ - Tests whether the backend, exposed using the HTTPRoute and Gateway, was exposed correctly, - having a tls secured endpoint with a hostname managed by Kuadrant - """ - - result = client.get("/get", auth=auth) - assert not result.has_dns_error() - assert not result.has_cert_verify_error() - assert result.status_code == 200 diff --git a/testsuite/tests/singlecluster/limitador/test_basic_limit.py b/testsuite/tests/singlecluster/limitador/test_basic_limit.py index c1473865..4818238b 100644 --- a/testsuite/tests/singlecluster/limitador/test_basic_limit.py +++ b/testsuite/tests/singlecluster/limitador/test_basic_limit.py @@ -12,7 +12,7 @@ @pytest.fixture( scope="module", params=[ - pytest.param(Limit(2, "15s"), id="2 requests every 15 sec"), + pytest.param(Limit(2, "15s"), id="2 requests every 15 sec", marks=[pytest.mark.smoke]), pytest.param(Limit(5, "10s"), id="5 requests every 10 sec"), pytest.param(Limit(3, "5s"), id="3 request every 5 sec"), ],