-
Notifications
You must be signed in to change notification settings - Fork 15
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 gateway attached to AuthPolicy
- Loading branch information
Showing
7 changed files
with
91 additions
and
8 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
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
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 @@ | ||
"""TODO""" | ||
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): | ||
"""TODO""" | ||
request.addfinalizer(authorization.delete) | ||
authorization.commit() |
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
"""TODO""" | ||
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): | ||
"""TODO""" | ||
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): | ||
"""TODO""" | ||
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 nonexistent_hostname_client(gateway, exposer, blame): | ||
"""TODO""" | ||
hostname = exposer.expose_hostname(blame("nonexistent-hostname"), gateway) | ||
client = hostname.client() | ||
yield client | ||
client.close() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def sub_nonexistent_hostname_client(gateway, exposer, blame): | ||
"""TODO""" | ||
hostname = exposer.expose_hostname(blame("sub.nonexistent-hostname"), gateway) | ||
client = hostname.client() | ||
yield client | ||
client.close() | ||
|
||
|
||
def test_authpolicy_attached_to_gateway(client, gateway_httproute, gateway_authorization, nonexistent_hostname_client, sub_nonexistent_hostname_client): | ||
"""TODO""" | ||
response = client.get("/get") | ||
assert response.status_code == 200 | ||
|
||
response = nonexistent_hostname_client.get("/get") | ||
assert response.status_code == 500 | ||
|
||
gateway_authorization.commit() | ||
|
||
response = nonexistent_hostname_client.get("/get") | ||
assert response.status_code == 403 | ||
|
||
response = sub_nonexistent_hostname_client.get("/get") | ||
assert response.status_code == 403 |
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