Skip to content

Commit 8e86700

Browse files
committed
Add tests for changing targetRef field in policies
Signed-off-by: emmaaroche <[email protected]>
1 parent 7d040d4 commit 8e86700

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

testsuite/tests/singlecluster/gateway/reconciliation/change_targetref/conftest.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from testsuite.gateway import GatewayRoute, GatewayListener, Hostname, Exposer
7+
from testsuite.gateway import GatewayRoute, Hostname, Exposer, GatewayListener
88
from testsuite.gateway.gateway_api.gateway import KuadrantGateway
99
from testsuite.gateway.gateway_api.hostname import DNSPolicyExposer
1010
from testsuite.gateway.gateway_api.route import HTTPRoute
@@ -81,6 +81,15 @@ def client2(route2, hostname2): # pylint: disable=unused-argument
8181
client.close()
8282

8383

84+
@pytest.fixture(scope="module")
85+
def authorization():
86+
"""
87+
Override the authorization fixture to prevent the creation of an AuthPolicy.
88+
This ensures no authentication is enforced during the test
89+
"""
90+
return None
91+
92+
8493
@pytest.fixture(scope="module")
8594
def dns_policy2(blame, gateway2, module_label, dns_provider_secret, request):
8695
"""DNSPolicy fixture for Gateway 2"""

testsuite/tests/singlecluster/gateway/reconciliation/change_targetref/test_update_authpolicy_target_ref.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
import pytest
66

7+
from testsuite.kuadrant.policy.authorization.auth_policy import AuthPolicy
8+
79
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy]
810

911

12+
@pytest.fixture(scope="module")
13+
def authorization(oidc_provider, gateway, cluster, blame, module_label, route): # pylint: disable=unused-argument
14+
"""Overwrite the authorization fixture and attach it to the gateway"""
15+
policy = AuthPolicy.create_instance(cluster, blame("authz"), gateway, labels={"testRun": module_label})
16+
policy.identity.add_oidc("default", oidc_provider.well_known["issuer"])
17+
return policy
18+
19+
1020
def test_update_auth_policy_target_ref(
1121
gateway2, authorization, client, client2, auth, dns_policy, dns_policy2, change_target_ref
1222
): # pylint: disable=unused-argument
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
Test for changing targetRef field in DNSPolicy & TLSPolicy
3+
"""
4+
5+
import pytest
6+
7+
from testsuite.gateway import TLSGatewayListener
8+
from testsuite.gateway.gateway_api.gateway import KuadrantGateway
9+
10+
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy, pytest.mark.tlspolicy]
11+
12+
13+
@pytest.fixture(scope="module")
14+
def gateway(request, cluster, blame, wildcard_domain, module_label):
15+
"""Create Gateway 1 with TLSGatewayListener"""
16+
gateway_name = blame("gw")
17+
gw = KuadrantGateway.create_instance(
18+
cluster,
19+
gateway_name,
20+
{"app": module_label},
21+
)
22+
gw.add_listener(TLSGatewayListener(hostname=wildcard_domain, gateway_name=gateway_name))
23+
request.addfinalizer(gw.delete)
24+
gw.commit()
25+
gw.wait_for_ready()
26+
return gw
27+
28+
29+
@pytest.fixture(scope="module")
30+
def gateway2(request, cluster, blame, wildcard_domain2, module_label):
31+
"""Create Gateway 2 with TLSGatewayListener"""
32+
gateway_name = blame("gw2")
33+
gw = KuadrantGateway.create_instance(
34+
cluster,
35+
gateway_name,
36+
{"app": module_label},
37+
)
38+
gw.add_listener(TLSGatewayListener(hostname=wildcard_domain2, gateway_name=gateway_name))
39+
request.addfinalizer(gw.delete)
40+
gw.commit()
41+
gw.wait_for_ready()
42+
return gw
43+
44+
45+
def test_update_policies_target_ref(
46+
route2, tls_policy, gateway, gateway2, client, dns_policy, change_target_ref, hostname2
47+
): # pylint: disable=unused-argument
48+
"""Test updating the targetRef of both TLSPolicy and DNSPolicy from Gateway 1 to Gateway 2"""
49+
assert gateway.wait_until(lambda obj: obj.is_affected_by(tls_policy))
50+
assert gateway.wait_until(lambda obj: obj.is_affected_by(dns_policy))
51+
assert gateway2.wait_until(lambda obj: not obj.is_affected_by(tls_policy))
52+
assert gateway2.wait_until(lambda obj: not obj.is_affected_by(dns_policy))
53+
54+
response = client.get("/get")
55+
assert not response.has_cert_verify_error()
56+
assert not response.has_dns_error()
57+
assert response.status_code == 200
58+
59+
change_target_ref(tls_policy, gateway2)
60+
change_target_ref(dns_policy, gateway2)
61+
62+
assert gateway.wait_until(lambda obj: not obj.is_affected_by(tls_policy))
63+
assert gateway.wait_until(lambda obj: not obj.is_affected_by(dns_policy))
64+
assert gateway2.wait_until(lambda obj: obj.is_affected_by(tls_policy))
65+
assert gateway2.wait_until(lambda obj: obj.is_affected_by(dns_policy))
66+
67+
client2 = hostname2.client()
68+
69+
response = client2.get("/get")
70+
assert not response.has_cert_verify_error()
71+
assert not response.has_dns_error()
72+
assert response.status_code == 200
73+
74+
client2.close()

testsuite/tests/singlecluster/gateway/reconciliation/change_targetref/test_update_ratelimitpolicy_target_ref.py

-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy]
1010

1111

12-
@pytest.fixture(scope="module")
13-
def authorization():
14-
"""
15-
Override the authorization fixture to prevent the creation of an AuthPolicy.
16-
This ensures no authentication is enforced during the test
17-
"""
18-
return None
19-
20-
2112
@pytest.fixture(scope="module")
2213
def rate_limit(cluster, blame, module_label, gateway, route): # pylint: disable=unused-argument
2314
"""RateLimitPolicy for testing"""

0 commit comments

Comments
 (0)