1
- """Test basic enforcement of the rules inside the 'overrides' block of the RateLimitPolicy assigned to a Gateway"""
1
+ """Test enforcement of the rules inside the 'overrides' block of the RateLimitPolicy assigned to a Gateway/HTTPRoute """
2
2
3
3
import pytest
4
4
5
5
from testsuite .kuadrant .policy .rate_limit import Limit , RateLimitPolicy
6
6
7
7
pytestmark = [pytest .mark .kuadrant_only , pytest .mark .limitador ]
8
8
9
- GATEWAY_LIMIT = Limit (3 , "5s" )
9
+ OVERRIDE_LIMIT = Limit (3 , "5s" )
10
10
ROUTE_LIMIT = Limit (2 , "5s" )
11
11
12
12
@@ -16,33 +16,34 @@ def authorization():
16
16
return None
17
17
18
18
19
- @pytest .fixture (scope = "module " )
20
- def rate_limit_gw (request , cluster , blame , module_label , gateway ):
21
- """Add a RateLimitPolicy to the Gateway with an overrides block to override the Route-level policy ."""
22
- rate_limit_gateway = RateLimitPolicy .create_instance (
23
- cluster , blame ("limit-gateway " ), gateway , labels = {"testRun" : module_label }
19
+ @pytest .fixture (scope = "function " )
20
+ def rate_limit_route (request , cluster , blame , module_label , route ):
21
+ """Add a RateLimitPolicy to the HTTPRoute with a basic limit to be overriden ."""
22
+ rate_limit_route = RateLimitPolicy .create_instance (
23
+ cluster , blame ("limit-route " ), route , labels = {"testRun" : module_label }
24
24
)
25
- rate_limit_gateway . overrides . add_limit ("basic" , [GATEWAY_LIMIT ])
26
- request .addfinalizer (rate_limit_gateway .delete )
27
- rate_limit_gateway .commit ()
28
- rate_limit_gateway . wait_for_ready ()
29
- return rate_limit_gateway
25
+ rate_limit_route . add_limit ("basic" , [ROUTE_LIMIT ])
26
+ request .addfinalizer (rate_limit_route .delete )
27
+ rate_limit_route .commit ()
28
+ rate_limit_route . wait_for_accepted ()
29
+ return rate_limit_route
30
30
31
31
32
32
@pytest .fixture (scope = "module" )
33
33
def rate_limit (rate_limit ):
34
- """Add basic requests limit to RateLimitPolicy"""
35
- rate_limit .add_limit ("basic " , [ROUTE_LIMIT ])
34
+ """Add an override to RateLimitPolicy"""
35
+ rate_limit .overrides . add_limit ("override-limit " , [OVERRIDE_LIMIT ])
36
36
return rate_limit
37
37
38
38
39
- def test_basic_rate_limit (rate_limit , rate_limit_gw , route , client ):
40
- """Test if rules inside overrides block of Gateway's RateLimitPolicy are inherited by the HTTPRoute
41
- and enforced like any other normal rule"""
39
+ @pytest .mark .parametrize ("rate_limit" , ["route" , "gateway" ], indirect = True )
40
+ def test_basic_rate_limit (rate_limit , rate_limit_route , route , client ):
41
+ """Test if rules inside overrides block of Gateway/HTTPRoute RateLimitPolicy are inherited by the HTTPRoute
42
+ and override the rate limit targeting the route."""
42
43
route .refresh ()
43
44
assert route .is_affected_by (rate_limit )
44
- rate_limit_gw . wait_for_full_enforced ( )
45
+ assert route . is_affected_by ( rate_limit_route )
45
46
46
- responses = client .get_many ("/get" , GATEWAY_LIMIT .limit )
47
+ responses = client .get_many ("/get" , OVERRIDE_LIMIT .limit )
47
48
responses .assert_all (status_code = 200 )
48
49
assert client .get ("/get" ).status_code == 429 # assert that RateLimitPolicy is enforced
0 commit comments