-
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.
Added tests to guard against RLP applying to HTTPRouteRule with diffe…
…rent method
- Loading branch information
1 parent
2540380
commit f106fe2
Showing
4 changed files
with
53 additions
and
40 deletions.
There are no files selected for viewing
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
36 changes: 0 additions & 36 deletions
36
testsuite/tests/kuadrant/limitador/test_route_rule_child.py
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
testsuite/tests/kuadrant/limitador/test_route_rule_invalid.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,46 @@ | ||
"""Tests that RLP for a HTTPRouteRule doesn't take effect if there isn't a exact matching HTTPRouteRule""" | ||
|
||
import pytest | ||
|
||
from testsuite.gateway import RouteMatch, PathMatch, MatchType, HTTPMethod | ||
from testsuite.policy.rate_limit_policy import Limit, RouteSelector | ||
|
||
|
||
@pytest.fixture(scope="module", params=["/anything/get", "/anything", "/get"]) | ||
def endpoint(request): | ||
"""Endpoints to apply a RLP to""" | ||
return request.param | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def route(route, backend): | ||
"""Add new rule to the route""" | ||
route.remove_all_rules() | ||
route.add_rule( | ||
backend, | ||
RouteMatch(path=PathMatch(value="/anything", type=MatchType.PATH_PREFIX), method=HTTPMethod.GET), | ||
) | ||
route.add_rule( | ||
backend, | ||
RouteMatch(path=PathMatch(value="/get", type=MatchType.PATH_PREFIX), method=HTTPMethod.GET), | ||
) | ||
return route | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(rate_limit, endpoint): | ||
"""Add limit to the policy""" | ||
selector = RouteSelector( | ||
RouteMatch(path=PathMatch(value=endpoint, type=MatchType.EXACT), method=HTTPMethod.GET) | ||
) | ||
rate_limit.add_limit("basic", [Limit(5, 10)], route_selectors=[selector]) | ||
return rate_limit | ||
|
||
|
||
def test_route_rule_invalid(client, endpoint): | ||
"""Tests that RLP for a HTTPRouteRule doesn't apply if there isn't an exact match""" | ||
responses = client.get_many(endpoint, 5) | ||
assert all( | ||
r.status_code == 200 for r in responses | ||
), f"Rate Limited resource unexpectedly rejected requests {responses}" | ||
assert client.get(endpoint).status_code == 200 |