Skip to content

Commit edb84c8

Browse files
committed
refactor: remove xfails and incorporate review comments
Signed-off-by: Silvia Tarabova <starabov@redhat.com>
1 parent 25a4747 commit edb84c8

7 files changed

Lines changed: 30 additions & 64 deletions

File tree

testsuite/tests/singlecluster/extensions/pipeline_policy/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
from openshift_client import OpenShiftPythonException
6+
57
from testsuite.kubernetes import Selector
68
from testsuite.kubernetes.deployment import Deployment
79
from testsuite.kubernetes.service import Service, ServicePort
@@ -13,7 +15,7 @@ def check_pipeline_policy_crd(cluster, skip_or_fail):
1315
"""Skip all PipelinePolicy tests if the CRD is not installed on the cluster."""
1416
try:
1517
cluster.do_action("get", "crd/pipelinepolicies.extensions.kuadrant.io")
16-
except Exception: # pylint: disable=broad-except
18+
except OpenShiftPythonException:
1719
skip_or_fail("PipelinePolicy CRD is not installed on the cluster")
1820

1921

@@ -57,7 +59,6 @@ def threat_assessment_service(request, cluster, blame, module_label, testconfig)
5759
@pytest.fixture(scope="module", autouse=True)
5860
def commit(request, pipeline_policy):
5961
"""Commit and wait for PipelinePolicy to be ready."""
60-
for component in [pipeline_policy]:
61-
request.addfinalizer(component.delete)
62-
component.commit()
63-
component.wait_for_ready()
62+
request.addfinalizer(pipeline_policy.delete)
63+
pipeline_policy.commit()
64+
pipeline_policy.wait_for_ready()

testsuite/tests/singlecluster/extensions/pipeline_policy/interactions/test_pipeline_policy_auth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ def test_auth_and_pipeline_unauthorized(client):
3636
assert response.headers.get("x-pipeline-policy") is None
3737

3838

39-
@pytest.mark.issue("https://github.com/Kuadrant/wasm-shim/issues/371")
40-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/wasm-shim/issues/371")
4139
def test_auth_and_pipeline_blocked_path(client, auth):
4240
"""Authenticated request to blocked path is denied by PipelinePolicy deny action."""
4341
response = client.get("/blocked", auth=auth)

testsuite/tests/singlecluster/extensions/pipeline_policy/test_pipeline_policy_composition.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def test_fail_before_deny(request, cluster, blame, route, client, threat_assessm
4949
assert response.status_code == 500
5050

5151

52-
@pytest.mark.issue("https://github.com/Kuadrant/wasm-shim/issues/371")
53-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/wasm-shim/issues/371")
5452
def test_deny_after_grpc_call(request, cluster, blame, route, client, threat_assessment_service):
5553
"""Deny action after gRPC call works when the deny predicate matches."""
5654
svc_url = (
@@ -100,8 +98,6 @@ def test_deny_based_on_grpc_var(request, cluster, blame, route, client, threat_a
10098
assert response.status_code == 200
10199

102100

103-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2018")
104-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2018")
105101
def test_deny_with_dynamic_body(request, cluster, blame, route, client, threat_assessment_service):
106102
"""Deny action with CEL expression in withBody interpolates gRPC response variable."""
107103
svc_url = (

testsuite/tests/singlecluster/extensions/pipeline_policy/test_pipeline_policy_deny.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,13 @@ def test_deny_custom_headers(client):
9292
assert response.headers.get("x-deny-reason") == "blocked"
9393

9494

95-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2018")
96-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2018")
9795
def test_deny_custom_body(client):
9896
"""Deny with withBody as CEL expression returns custom body text."""
9997
response = client.get("/custom-body")
10098
assert response.status_code == 403
10199
assert response.text == "Access denied"
102100

103101

104-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2018")
105-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2018")
106102
def test_deny_all_response_fields(client):
107103
"""Deny with withStatus, withHeaders, and withBody as CEL expression returns all fields."""
108104
response = client.get("/custom-all")
@@ -123,8 +119,6 @@ def test_response_deny_no_override(client):
123119
assert response.status_code == 200
124120

125121

126-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2018")
127-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2018")
128122
def test_response_deny_with_headers_and_body(client):
129123
"""Response deny with all fields as CEL expressions replaces the backend response."""
130124
response = client.get("/get", headers={"x-resp-deny": "true"})

testsuite/tests/singlecluster/extensions/pipeline_policy/test_pipeline_policy_isolation.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,27 @@ def pipeline_policy(pipeline_policy):
8080
return pipeline_policy
8181

8282

83-
def test_policy_affects_targeted_route(client):
84-
"""Route with PipelinePolicy gets the response header."""
83+
def test_policy_does_not_affect_other_route(client, client2):
84+
"""Route without PipelinePolicy on the same gateway does not get the response header."""
85+
time.sleep(EXTENSION_POLICY_PROPAGATION_WAIT)
86+
8587
response = client.get("/get")
8688
assert response.status_code == 200
8789
assert response.headers.get("x-pipeline-policy") == "active"
8890

89-
90-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2023")
91-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2023")
92-
def test_policy_does_not_affect_other_route(client2):
93-
"""Route without PipelinePolicy on the same gateway does not get the response header."""
94-
time.sleep(EXTENSION_POLICY_PROPAGATION_WAIT)
9591
response = client2.get("/get")
9692
assert response.status_code == 200
9793
assert response.headers.get("x-pipeline-policy") is None
9894

9995

100-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2023")
101-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2023")
102-
def test_policy_does_not_affect_other_gateway(client3):
96+
def test_policy_does_not_affect_other_gateway(client, client3):
10397
"""Route on a different gateway does not get the response header."""
10498
time.sleep(EXTENSION_POLICY_PROPAGATION_WAIT)
99+
100+
response = client.get("/get")
101+
assert response.status_code == 200
102+
assert response.headers.get("x-pipeline-policy") == "active"
103+
105104
response = client3.get("/get")
106105
assert response.status_code == 200
107106
assert response.headers.get("x-pipeline-policy") is None

testsuite/tests/singlecluster/extensions/pipeline_policy/test_pipeline_policy_lifecycle.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Tests for PipelinePolicy lifecycle: update and delete."""
22

3+
import time
4+
35
import pytest
46

57
from testsuite.kuadrant.extensions.pipeline_policy import PipelinePolicy
8+
from testsuite.utils.constants import EXTENSION_POLICY_PROPAGATION_WAIT
69

710
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.extensions]
811

@@ -35,8 +38,6 @@ def test_update_policy(request, cluster, blame, route, client):
3538
assert response.headers.get("x-update-new") == "true"
3639

3740

38-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2009")
39-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2009")
4041
@pytest.mark.flaky(reruns=0)
4142
def test_delete_policy(request, cluster, blame, route, client):
4243
"""After deleting the PipelinePolicy, the CR is removed and the actions stop being enforced."""
@@ -51,7 +52,8 @@ def test_delete_policy(request, cluster, blame, route, client):
5152
assert response.headers.get("x-delete-test") == "active"
5253

5354
policy.delete()
54-
assert policy.wait_until(lambda obj: not obj.exists(), timelimit=30), "PipelinePolicy was not deleted"
55+
assert not policy.committed, "PipelinePolicy was not deleted"
56+
time.sleep(EXTENSION_POLICY_PROPAGATION_WAIT)
5557

5658
response = client.get("/get")
5759
assert response.status_code == 200

testsuite/tests/singlecluster/extensions/pipeline_policy/test_pipeline_policy_validation.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ def commit():
1414
"""No module-level policy; each test creates its own with bad configuration."""
1515

1616

17-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2022")
18-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2022")
19-
def test_invalid_target_ref(request, cluster, blame):
20-
"""PipelinePolicy targeting a non-existent HTTPRoute does not reach Enforced state."""
17+
@pytest.mark.parametrize("kind", ["HTTPRoute", "Gateway"])
18+
def test_invalid_target_ref(request, cluster, blame, kind):
19+
"""PipelinePolicy targeting a non-existent resource does not reach Accepted state."""
20+
target_name = "does-not-exist"
2121
target = CustomReference(
2222
group="gateway.networking.k8s.io",
23-
kind="HTTPRoute",
24-
name="does-not-exist",
23+
kind=kind,
24+
name=target_name,
2525
)
2626
policy = PipelinePolicy.create_instance(cluster, blame("bad-target"), target)
2727
policy.on_http_request.add_deny(predicate='request.url_path == "/blocked"', with_status=403)
@@ -30,34 +30,11 @@ def test_invalid_target_ref(request, cluster, blame):
3030
policy.commit()
3131

3232
assert policy.wait_until(
33-
has_condition("Accepted", "False", "TargetNotFound"),
33+
has_condition("Accepted", "False", message=f"targetRef {kind} {cluster.project}/{target_name} not found"),
3434
timelimit=30,
35-
), f"Policy did not report TargetNotFound, status: {policy.refresh().model.status.conditions}"
35+
), f"Policy did not report target not found, status: {policy.refresh().model.status.conditions}"
3636

3737

38-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2022")
39-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2022")
40-
def test_invalid_gateway_target_ref(request, cluster, blame):
41-
"""PipelinePolicy targeting a non-existent Gateway does not reach Enforced state."""
42-
target = CustomReference(
43-
group="gateway.networking.k8s.io",
44-
kind="Gateway",
45-
name="does-not-exist",
46-
)
47-
policy = PipelinePolicy.create_instance(cluster, blame("bad-gw"), target)
48-
policy.on_http_request.add_deny(predicate='request.url_path == "/blocked"', with_status=403)
49-
50-
request.addfinalizer(policy.delete)
51-
policy.commit()
52-
53-
assert policy.wait_until(
54-
has_condition("Accepted", "False", "TargetNotFound"),
55-
timelimit=30,
56-
), f"Policy did not report TargetNotFound, status: {policy.refresh().model.status.conditions}"
57-
58-
59-
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/2015")
60-
@pytest.mark.xfail(reason="https://github.com/Kuadrant/kuadrant-operator/issues/2015")
6138
def test_top_level_fail_action(request, cluster, blame, route):
6239
"""PipelinePolicy with a top-level fail action (not inside gRPC onReply) should not be accepted."""
6340
policy = PipelinePolicy.create_instance(cluster, blame("top-fail"), route)
@@ -66,9 +43,8 @@ def test_top_level_fail_action(request, cluster, blame, route):
6643
request.addfinalizer(policy.delete)
6744
policy.commit()
6845

69-
# TODO: add expected message assertion once the validation is implemented
7046
assert policy.wait_until(
71-
has_condition("Accepted", "False"),
47+
has_condition("Accepted", "False", message="fail action must reference a gRPC response variable"),
7248
timelimit=30,
7349
), f"Policy with top-level fail was accepted, status: {policy.refresh().model.status.conditions}"
7450

0 commit comments

Comments
 (0)