diff options
| author | oxpa <iippolitov@gmail.com> | 2024-09-17 14:21:10 +0100 |
|---|---|---|
| committer | oxpa <iippolitov@gmail.com> | 2024-09-17 14:21:10 +0100 |
| commit | 2417826d8bebf921ee1be102ef8ce702f0683d66 (patch) | |
| tree | 76d29a1705415ed7368870826dbb2f04942ee794 /test/test_routing.py | |
| parent | 0e79d961bb1ea68674961da1703ffedb1ddf6e43 (diff) | |
| parent | 24ed91f40634372d99f67f0e4e3c2ac0abde81bd (diff) | |
| download | unit-2417826d8bebf921ee1be102ef8ce702f0683d66.tar.gz unit-2417826d8bebf921ee1be102ef8ce702f0683d66.tar.bz2 | |
Merge tag '1.33.0' into packaging.
Unit 1.33.0 release.
Diffstat (limited to 'test/test_routing.py')
| -rw-r--r-- | test/test_routing.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/test_routing.py b/test/test_routing.py index 0b6eced2..170f627e 100644 --- a/test/test_routing.py +++ b/test/test_routing.py @@ -2009,3 +2009,75 @@ def test_routes_match_destination_proxy(): ), 'proxy configure' assert client.get()['status'] == 200, 'proxy' + + +def set_if(condition): + assert 'success' in client.conf(f'"{condition}"', 'routes/0/match/if') + + +def test_routes_match_if(): + + def try_if(condition, status): + set_if(condition) + assert client.get(url=f'/{condition}')['status'] == status + + assert 'success' in client.conf( + { + "listeners": {"*:8080": {"pass": "routes"}}, + "routes": [ + { + "match": {"method": "GET"}, + "action": {"return": 200}, + } + ], + "applications": {}, + } + ), 'routing configure' + + # const + + try_if('', 404) + try_if('0', 404) + try_if('false', 404) + try_if('undefined', 404) + try_if('!', 200) + try_if('!null', 200) + try_if('1', 200) + + # variable + + set_if('$arg_foo') + assert client.get(url='/bar?bar')['status'] == 404 + assert client.get(url='/foo_empty?foo')['status'] == 404 + assert client.get(url='/foo?foo=1')['status'] == 200 + + set_if('!$arg_foo') + assert client.get(url='/bar?bar')['status'] == 200 + assert client.get(url='/foo_empty?foo')['status'] == 200 + assert client.get(url='/foo?foo=1')['status'] == 404 + +def test_routes_match_if_njs(require): + require({'modules': {'njs': 'any'}}) + + assert 'success' in client.conf( + { + "listeners": {"*:8080": {"pass": "routes"}}, + "routes": [ + { + "match": {"method": "GET"}, + "action": {"return": 200}, + } + ], + "applications": {}, + } + ) + + set_if('`${args.foo == \'1\'}`') + assert client.get(url='/foo_1?foo=1')['status'] == 200 + assert client.get(url='/foo_2?foo=2')['status'] == 404 + + set_if('!`${args.foo == \'1\'}`') + assert client.get(url='/foo_1?foo=1')['status'] == 404 + assert client.get(url='/foo_2?foo=2')['status'] == 200 + + assert 'error' in client.conf('$arg_', 'routes/0/match/if') |
