Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for changing parentRef field in policies (AuthPolicy and RateLimitPolicy) #622

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

emmaaroche
Copy link

Test for changing parentRef field in policies (AuthPolicy and RateLimitPolicy)

@emmaaroche emmaaroche requested a review from averevki January 21, 2025 14:32
@emmaaroche emmaaroche force-pushed the test-change-parentref branch 2 times, most recently from db28248 to 4dbcc75 Compare January 21, 2025 14:57
@emmaaroche emmaaroche force-pushed the test-change-parentref branch from 4dbcc75 to 5edc14b Compare January 27, 2025 15:20
Comment on lines +12 to +13


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add pytestmark please so these tests are properly collected by pytest when run from the command line. See other tests in the testsuite for the reference. Here should be kuadrant_only and dnspolicy marks

P.S. custom mark definitions are stored in our pyproject.toml

Comment on lines +35 to +38
if kuadrant:
route = HTTPRoute.create_instance(gateway_b.cluster, blame("route-b"), gateway_b, {"app": module_label})
else:
route = EnvoyVirtualRoute.create_instance(gateway_b.cluster, blame("route-b"), gateway_b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add the pytest marks above, you will be dealing only with the kuadrant and httproute case here. So no if else will be needed

route = HTTPRoute.create_instance(gateway_b.cluster, blame("route-b"), gateway_b, {"app": module_label})
else:
route = EnvoyVirtualRoute.create_instance(gateway_b.cluster, blame("route-b"), gateway_b)
route.add_hostname(wildcard_domain2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard hostname is defined inside the gateway and it is better to write the exact hostname in the according httproute, same as first gateway and httproute are done. You can find similar setup inside the singlecluster/authorino/operator/clusterwide/conftest.py. There is also a second client fixture that can help you in this test

response = client.get("/get", auth=auth)
assert response.status_code == 200

rate_limit_policy.wait_for_ready()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly you should wait for the policy to become ready right after you commit it to the server. Or you did some changes in it and waiting for this policy reconciliation

Comment on lines +60 to +63
initial_target_ref = rate_limit_policy.model["spec"]["targetRef"]["name"]
assert (
initial_target_ref == gateway.model.metadata.name
), f"Initial targetRef mismatch: expected {gateway.model.metadata.name}, got {initial_target_ref}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is a bit unnecessary. We expect that the server will have what we have commited there

Comment on lines +90 to +93
authorization.model["spec"]["targetRef"] = gateway.reference
authorization.apply()
authorization.wait_for_ready()
authorization.refresh()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup should be done inside the fixtures. If higher conftests set wrong targetRef then feel free to overwrite it here

Comment on lines +76 to +79
updated_target_ref = rate_limit_policy.model["spec"]["targetRef"]["name"]
assert (
updated_target_ref == gateway_b.model.metadata.name
), f"Updated targetRef mismatch: expected {gateway_b.model.metadata.name}, got {updated_target_ref}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, we expect it to be there

rate_limit_policy.wait_for_ready()
rate_limit_policy.refresh()

rate_limit_policy.model["spec"]["targetRef"]["name"] = gateway_b.model.metadata.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Openshift python library allows both dictionary and dot notations to access object values. Consider using only the dot notation for consistency. Here and everywhere else

Comment on lines +116 to +117
response = client.get("/get", auth=auth)
assert response.status_code == 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work even without auth, because you're using the same client that points to the hostname from the first httproute. You will need second client fixture that will point on the new route

Comment on lines +65 to +66
response = client.get("/get", auth=auth)
assert response.status_code == 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check if ratelimit policy is correctly applied to the first gateway in the test beginning and is limiting the requests. get_many client method should help with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants