summaryrefslogtreecommitdiffhomepage
path: root/test/test_routing.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_routing.py')
-rw-r--r--test/test_routing.py110
1 files changed, 108 insertions, 2 deletions
diff --git a/test/test_routing.py b/test/test_routing.py
index eb7b2fd8..950923d6 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -288,14 +288,62 @@ class TestRouting(TestApplicationProto):
)
def test_routes_route_pass_absent(self):
- self.skip_alerts.append(r'failed to apply new conf')
-
self.assertIn(
'error',
self.conf([{"match": {"method": "GET"}, "action": {}}], 'routes'),
'route pass absent configure',
)
+ def test_routes_action_unique(self):
+ self.assertIn(
+ 'success',
+ self.conf(
+ {
+ "listeners": {
+ "*:7080": {"pass": "routes"},
+ "*:7081": {"pass": "applications/app"},
+ },
+ "routes": [{"action": {"proxy": "http://127.0.0.1:7081"}}],
+ "applications": {
+ "app": {
+ "type": "python",
+ "processes": {"spare": 0},
+ "path": "/app",
+ "module": "wsgi",
+ }
+ },
+ }
+ ),
+ )
+
+ self.assertIn(
+ 'error',
+ self.conf(
+ {"proxy": "http://127.0.0.1:7081", "share": self.testdir},
+ 'routes/0/action',
+ ),
+ 'proxy share',
+ )
+ self.assertIn(
+ 'error',
+ self.conf(
+ {
+ "proxy": "http://127.0.0.1:7081",
+ "pass": "applications/app",
+ },
+ 'routes/0/action',
+ ),
+ 'proxy pass',
+ )
+ self.assertIn(
+ 'error',
+ self.conf(
+ {"share": self.testdir, "pass": "applications/app"},
+ 'routes/0/action',
+ ),
+ 'share pass',
+ )
+
def test_routes_rules_two(self):
self.assertIn(
'success',
@@ -1364,6 +1412,13 @@ class TestRouting(TestApplicationProto):
sock, port = sock_port()
sock2, port2 = sock_port()
+ self.route_match({"source": ["*:" + str(port), "!127.0.0.1"]})
+ self.assertEqual(self.get(sock=sock)['status'], 404, 'negative 3')
+ self.assertEqual(self.get(sock=sock2)['status'], 404, 'negative 4')
+
+ sock, port = sock_port()
+ sock2, port2 = sock_port()
+
self.route_match(
{"source": "127.0.0.1:" + str(port) + "-" + str(port)}
)
@@ -1678,6 +1733,7 @@ class TestRouting(TestApplicationProto):
self.route_match_invalid({"source": "127"})
self.route_match_invalid({"source": "256.0.0.1"})
self.route_match_invalid({"source": "127.0.0."})
+ self.route_match_invalid({"source": " 127.0.0.1"})
self.route_match_invalid({"source": "127.0.0.1:"})
self.route_match_invalid({"source": "127.0.0.1/"})
self.route_match_invalid({"source": "11.0.0.0/33"})
@@ -1690,6 +1746,7 @@ class TestRouting(TestApplicationProto):
self.route_match_invalid({"source": "2001::/129"})
self.route_match_invalid({"source": "::FFFFF"})
self.route_match_invalid({"source": "[::1]:"})
+ self.route_match_invalid({"source": "[:::]:7080"})
self.route_match_invalid({"source": "*:"})
self.route_match_invalid({"source": "*:1-a"})
self.route_match_invalid({"source": "*:65536"})
@@ -1716,6 +1773,55 @@ class TestRouting(TestApplicationProto):
self.assertEqual(self.get()['status'], 404, 'dest neg')
self.assertEqual(self.get(port=7081)['status'], 200, 'dest neg 2')
+ self.route_match({"destination": ['!*:7080', '!*:7081']})
+ self.assertEqual(self.get()['status'], 404, 'dest neg 3')
+ self.assertEqual(self.get(port=7081)['status'], 404, 'dest neg 4')
+
+ self.route_match({"destination": ['!*:7081', '!*:7082']})
+ self.assertEqual(self.get()['status'], 200, 'dest neg 5')
+
+ self.route_match({"destination": ['*:7080', '!*:7080']})
+ self.assertEqual(self.get()['status'], 404, 'dest neg 6')
+
+ self.route_match(
+ {"destination": ['127.0.0.1:7080', '*:7081', '!*:7080']}
+ )
+ self.assertEqual(self.get()['status'], 404, 'dest neg 7')
+ self.assertEqual(self.get(port=7081)['status'], 200, 'dest neg 8')
+
+ self.route_match({"destination": ['!*:7081', '!*:7082', '*:7083']})
+ self.assertEqual(self.get()['status'], 404, 'dest neg 9')
+
+ self.route_match(
+ {"destination": ['*:7081', '!127.0.0.1:7080', '*:7080']}
+ )
+ self.assertEqual(self.get()['status'], 404, 'dest neg 10')
+ self.assertEqual(self.get(port=7081)['status'], 200, 'dest neg 11')
+
+ self.assertIn(
+ 'success',
+ self.conf_delete('routes/0/match/destination/0'),
+ 'remove destination rule',
+ )
+ self.assertEqual(self.get()['status'], 404, 'dest neg 12')
+ self.assertEqual(self.get(port=7081)['status'], 404, 'dest neg 13')
+
+ self.assertIn(
+ 'success',
+ self.conf_delete('routes/0/match/destination/0'),
+ 'remove destination rule 2',
+ )
+ self.assertEqual(self.get()['status'], 200, 'dest neg 14')
+ self.assertEqual(self.get(port=7081)['status'], 404, 'dest neg 15')
+
+ self.assertIn(
+ 'success',
+ self.conf_post("\"!127.0.0.1\"", 'routes/0/match/destination'),
+ 'add destination rule',
+ )
+ self.assertEqual(self.get()['status'], 404, 'dest neg 16')
+ self.assertEqual(self.get(port=7081)['status'], 404, 'dest neg 17')
+
def test_routes_match_destination_proxy(self):
self.assertIn(
'success',