summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAxel Duch <axel.duch@nginx.com>2019-07-24 13:47:35 +0300
committerAxel Duch <axel.duch@nginx.com>2019-07-24 13:47:35 +0300
commit7785c96c1aea16dee0ec17403fda01b4f5ba41b3 (patch)
tree9abd736f0cfbfd6bea13685b1849ca4565dd1ce8 /test
parentb1165d2edc99daf8eef0e092e4ed6dcee9bce252 (diff)
downloadunit-7785c96c1aea16dee0ec17403fda01b4f5ba41b3.tar.gz
unit-7785c96c1aea16dee0ec17403fda01b4f5ba41b3.tar.bz2
Added routing based on request scheme.
Scheme matches exact string “http” or “https”.
Diffstat (limited to 'test')
-rw-r--r--test/test_routing.py94
-rw-r--r--test/test_routing_tls.py58
2 files changed, 152 insertions, 0 deletions
diff --git a/test/test_routing.py b/test/test_routing.py
index 40d9f786..6073877d 100644
--- a/test/test_routing.py
+++ b/test/test_routing.py
@@ -2641,5 +2641,99 @@ class TestRouting(TestApplicationProto):
'match cookies array 10',
)
+ def test_routes_match_scheme(self):
+ self.assertIn(
+ 'success',
+ self.route(
+ {
+ "match": {"scheme": "http"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'match scheme http configure',
+ )
+ self.assertIn(
+ 'success',
+ self.route(
+ {
+ "match": {"scheme": "https"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'match scheme https configure',
+ )
+ self.assertIn(
+ 'success',
+ self.route(
+ {
+ "match": {"scheme": "HtTp"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'match scheme http case insensitive configure',
+ )
+ self.assertIn(
+ 'success',
+ self.route(
+ {
+ "match": {"scheme": "HtTpS"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'match scheme https case insensitive configure',
+ )
+
+ def test_routes_match_scheme_invalid(self):
+ self.assertIn(
+ 'error',
+ self.route(
+ {
+ "match": {"scheme": ["http"]},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'scheme invalid type no arrays allowed',
+ )
+ self.assertIn(
+ 'error',
+ self.route(
+ {
+ "match": {"scheme": "ftp"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'scheme invalid protocol 1',
+ )
+ self.assertIn(
+ 'error',
+ self.route(
+ {
+ "match": {"scheme": "ws"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'scheme invalid protocol 2',
+ )
+ self.assertIn(
+ 'error',
+ self.route(
+ {
+ "match": {"scheme": "*"},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'scheme invalid no wildcard allowed',
+ )
+ self.assertIn(
+ 'error',
+ self.route(
+ {
+ "match": {"scheme": ""},
+ "action": {"pass": "applications/empty"},
+ }
+ ),
+ 'scheme invalid empty',
+ )
+
if __name__ == '__main__':
TestRouting.main()
diff --git a/test/test_routing_tls.py b/test/test_routing_tls.py
new file mode 100644
index 00000000..433a303e
--- /dev/null
+++ b/test/test_routing_tls.py
@@ -0,0 +1,58 @@
+from unit.applications.tls import TestApplicationTLS
+
+
+class TestRoutingTLS(TestApplicationTLS):
+ prerequisites = ['python', 'openssl']
+
+ def test_routes_match_scheme(self):
+ self.certificate()
+
+ self.assertIn(
+ 'success',
+ self.conf(
+ {
+ "listeners": {
+ "*:7080": {"pass": "routes"},
+ "*:7081": {
+ "pass": "routes",
+ "tls": {"certificate": 'default'},
+ },
+ },
+ "routes": [
+ {
+ "match": {"scheme": "http"},
+ "action": {"pass": "applications/empty"},
+ },
+ {
+ "match": {"scheme": "https"},
+ "action": {"pass": "applications/204_no_content"},
+ },
+ ],
+ "applications": {
+ "empty": {
+ "type": "python",
+ "processes": {"spare": 0},
+ "path": self.current_dir + "/python/empty",
+ "module": "wsgi",
+ },
+ "204_no_content": {
+ "type": "python",
+ "processes": {"spare": 0},
+ "path": self.current_dir
+ + "/python/204_no_content",
+ "module": "wsgi",
+ },
+ },
+ }
+ ),
+ 'scheme configure',
+ )
+
+ self.assertEqual(self.get()['status'], 200, 'scheme http')
+ self.assertEqual(
+ self.get_ssl(port=7081)['status'], 204, 'scheme https'
+ )
+
+
+if __name__ == '__main__':
+ TestRoutingTLS.main()