-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for authpolicy attached directly to gateway
- Loading branch information
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Conftest for gateway tests""" | ||
import pytest | ||
|
||
|
||
@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", autouse=True) | ||
def commit(request, authorization): | ||
"""Only commit authorization component""" | ||
request.addfinalizer(authorization.delete) | ||
authorization.commit() |
60 changes: 60 additions & 0 deletions
60
testsuite/tests/kuadrant/gateway/test_authpolicy_to_gateway.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Test for AuthPolicy attached directly to gateway""" | ||
from time import sleep | ||
import pytest | ||
|
||
from testsuite.openshift.objects.auth_config.auth_policy import AuthPolicy | ||
from testsuite.openshift.objects.gateway_api.route import HTTPRoute | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def gateway_httproute(request, gateway, wildcard_domain, module_label, blame): | ||
"""HTTPRoute with wildcard domain""" | ||
route = HTTPRoute.create_instance(gateway.openshift, blame("gw-route"), gateway, {"app": module_label}) | ||
route.add_hostname(wildcard_domain) | ||
route.set_path_match("/") | ||
|
||
request.addfinalizer(route.delete) | ||
route.commit() | ||
return route | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def gateway_authorization(request, gateway, authorization_name, openshift, module_label): | ||
"""AuthPolicy attached straight to gateway""" | ||
auth_policy = AuthPolicy.create_instance( | ||
openshift, f"gw-{authorization_name}", gateway, labels={"testRun": module_label} | ||
) | ||
auth_policy.authorization.add_opa_policy("deny-all", "allow { false }") | ||
request.addfinalizer(auth_policy.delete) | ||
return auth_policy | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def client_to_deny(gateway, exposer, blame): | ||
"""Hostname that should be denied by AuthPolicy attached directly to gateway""" | ||
hostname = exposer.expose_hostname(blame("not-accepted-hostname"), gateway) | ||
client = hostname.client() | ||
yield client | ||
client.close() | ||
|
||
|
||
def test_authpolicy_attached_to_gateway(gateway_httproute, gateway_authorization, client, client_to_deny): | ||
# pylint: disable=unused-argument | ||
""" | ||
Test if AuthPolicy denying all requests sent to the undefined domains: | ||
- send request to the hostname defined | ||
- send request to the undefined domain without AuthPolicy attached to gateway | ||
- commit deny-all AuthPolicy attached to gateway | ||
- send request to the undefined domain with deny-all AuthPolicy attached to gateway | ||
""" | ||
response = client.get("/get") | ||
assert response.status_code == 200 | ||
|
||
response = client_to_deny.get("/get") | ||
assert response.status_code == 500 | ||
|
||
gateway_authorization.commit() | ||
sleep(5) | ||
|
||
response = client_to_deny.get("/get") | ||
assert response.status_code == 403 |