summaryrefslogtreecommitdiffhomepage
path: root/test/test_routing.py
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2021-11-05 22:56:34 +0800
committerZhidao HONG <z.hong@f5.com>2021-11-05 22:56:34 +0800
commitaee908bcbd6ae160ab8e470ea6a373148649968b (patch)
tree99baed6d733282fd4cb537478c9ebf7a4ed194a8 /test/test_routing.py
parent1260add0f5cacd5849640f7ee335f3ace97ade2c (diff)
downloadunit-aee908bcbd6ae160ab8e470ea6a373148649968b.tar.gz
unit-aee908bcbd6ae160ab8e470ea6a373148649968b.tar.bz2
Router: matching query string support.
The "query" option matches decoded arguments, including plus ('+') to space (' '). Like "uri", it can be a string or an array of strings.
Diffstat (limited to 'test/test_routing.py')
-rw-r--r--test/test_routing.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/test_routing.py b/test/test_routing.py
index 7c3b56f8..c031d768 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -1320,6 +1320,50 @@ class TestRouting(TestApplicationProto):
self.route_match_invalid({"arguments": {"%%1F": ""}})
self.route_match_invalid({"arguments": {"%7%F": ""}})
+ def test_routes_match_query(self):
+ self.route_match({"query": "!"})
+ assert self.get(url='/')['status'] == 404
+ assert self.get(url='/?')['status'] == 404
+ assert self.get(url='/?foo')['status'] == 200
+ assert self.get(url='/?foo=')['status'] == 200
+ assert self.get(url='/?foo=baz')['status'] == 200
+
+ self.route_match({"query": "foo=%26"})
+ assert self.get(url='/?foo=&')['status'] == 200
+
+ self.route_match({"query": "a=b&c=d"})
+ assert self.get(url='/?a=b&c=d')['status'] == 200
+
+ self.route_match({"query": "a=b%26c%3Dd"})
+ assert self.get(url='/?a=b%26c%3Dd')['status'] == 200
+ assert self.get(url='/?a=b&c=d')['status'] == 200
+
+ self.route_match({"query": "a=b%26c%3Dd+e"})
+ assert self.get(url='/?a=b&c=d e')['status'] == 200
+
+ def test_routes_match_query_array(self):
+ self.route_match({
+ "query": ["foo", "bar"]
+ })
+
+ assert self.get()['status'] == 404, 'arr'
+ assert self.get(url='/?foo')['status'] == 200, 'arr 1'
+ assert self.get(url='/?bar')['status'] == 200, 'arr 2'
+
+ assert 'success' in self.conf_delete(
+ 'routes/0/match/query/1'
+ ), 'match query array configure 2'
+
+ assert self.get(url='/?bar')['status'] == 404, 'arr 2'
+
+ def test_routes_match_query_invalid(self):
+ self.route_match_invalid({"query": [1]})
+ self.route_match_invalid({"query": "%"})
+ self.route_match_invalid({"query": "%1G"})
+ self.route_match_invalid({"query": "%0"})
+ self.route_match_invalid({"query": "%%1F"})
+ self.route_match_invalid({"query": ["foo", "%3D", "%%1F"]})
+
def test_routes_match_cookies(self):
self.route_match({"cookies": {"foO": "bar"}})