diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2019-04-15 16:08:53 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2019-04-15 16:08:53 +0300 |
commit | 704529e4b1c2cf79a359eb1823ab919434a65291 (patch) | |
tree | 106085f0b1df8e1551fb94f43bddc0a3f28205ab | |
parent | b3179538efa7256043fae6f7be41b72a9e7ab229 (diff) | |
download | unit-704529e4b1c2cf79a359eb1823ab919434a65291.tar.gz unit-704529e4b1c2cf79a359eb1823ab919434a65291.tar.bz2 |
Tests: more wildcard pattern tests for routing.
Diffstat (limited to '')
-rw-r--r-- | test/test_routing.py | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/test/test_routing.py b/test/test_routing.py index 63a7dc6c..1328f221 100644 --- a/test/test_routing.py +++ b/test/test_routing.py @@ -186,6 +186,124 @@ class TestRouting(TestApplicationProto): self.assertEqual(self.get()['status'], 200, 'method wildcard') + def test_routes_match_host_wildcard_invalid(self): + self.assertIn( + 'error', + self.conf( + [ + { + "match": {"method": "**"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'wildcard invalid', + ) + + self.assertIn( + 'error', + self.conf( + [ + { + "match": {"method": "blah**"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'wildcard invalid 2', + ) + + self.assertIn( + 'error', + self.conf( + [ + { + "match": {"host": "*blah*blah"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'wildcard invalid 3', + ) + + self.assertIn( + 'error', + self.conf( + [ + { + "match": {"host": "blah*blah*blah"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'wildcard invalid 4', + ) + + self.assertIn( + 'error', + self.conf( + [ + { + "match": {"host": "blah*blah*"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'wildcard invalid 5', + ) + + def test_routes_match_wildcard_middle(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"host": "ex*le"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'host wildcard middle configure', + ) + + self.assertEqual( + self.get(headers={'Host': 'example', 'Connection': 'close'})[ + 'status' + ], + 200, + 'host wildcard middle', + ) + + self.assertEqual( + self.get(headers={'Host': 'www.example', 'Connection': 'close'})[ + 'status' + ], + 404, + 'host wildcard middle 2', + ) + + self.assertEqual( + self.get(headers={'Host': 'example.com', 'Connection': 'close'})[ + 'status' + ], + 404, + 'host wildcard middle 3', + ) + + self.assertEqual( + self.get(headers={'Host': 'exampl', 'Connection': 'close'})[ + 'status' + ], + 404, + 'host wildcard middle 4', + ) + def test_routes_match_method_case_insensitive(self): self.assertIn( 'success', @@ -203,6 +321,192 @@ class TestRouting(TestApplicationProto): self.assertEqual(self.get()['status'], 200, 'method case insensitive') + def test_routes_match_wildcard_left_case_insensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"method": "*et"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard case insensitive configure', + ) + + self.assertEqual( + self.get()['status'], 200, 'match wildcard case insensitive' + ) + + def test_routes_match_wildcard_middle_case_insensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"method": "g*t"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard case insensitive configure', + ) + + self.assertEqual( + self.get()['status'], 200, 'match wildcard case insensitive' + ) + + def test_routes_match_wildcard_right_case_insensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"method": "get*"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard case insensitive configure', + ) + + self.assertEqual( + self.get()['status'], 200, 'match wildcard case insensitive' + ) + + def test_routes_match_wildcard_substring_case_insensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"method": "*et*"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard substring case insensitive configure', + ) + + self.assertEqual( + self.get()['status'], + 200, + 'match wildcard substring case insensitive', + ) + + def test_routes_match_wildcard_left_case_sensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"uri": "*blah"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard left case sensitive configure', + ) + + self.assertEqual( + self.get(url='/blah')['status'], + 200, + 'match wildcard left case sensitive /blah', + ) + + self.assertEqual( + self.get(url='/BLAH')['status'], + 404, + 'match wildcard left case sensitive /BLAH', + ) + + def test_routes_match_wildcard_middle_case_sensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"uri": "/b*h"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard middle case sensitive configure', + ) + + self.assertEqual( + self.get(url='/blah')['status'], + 200, + 'match wildcard middle case sensitive /blah', + ) + + self.assertEqual( + self.get(url='/BLAH')['status'], + 404, + 'match wildcard middle case sensitive /BLAH', + ) + + def test_routes_match_wildcard_right_case_sensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"uri": "/bla*"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard right case sensitive configure', + ) + + self.assertEqual( + self.get(url='/blah')['status'], + 200, + 'match wildcard right case sensitive /blah', + ) + + self.assertEqual( + self.get(url='/BLAH')['status'], + 404, + 'match wildcard right case sensitive /BLAH', + ) + + def test_routes_match_wildcard_substring_case_sensitive(self): + self.assertIn( + 'success', + self.conf( + [ + { + "match": {"uri": "*bla*"}, + "action": {"pass": "applications/empty"}, + } + ], + 'routes', + ), + 'match wildcard substring case sensitive configure', + ) + + self.assertEqual( + self.get(url='/blah')['status'], + 200, + 'match wildcard substring case sensitive /blah', + ) + + self.assertEqual( + self.get(url='/BLAH')['status'], + 404, + 'match wildcard substring case sensitive /BLAH', + ) + def test_routes_absent(self): self.conf( { |