summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-08-31 03:14:02 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2020-08-31 03:14:02 +0100
commitdf374057f7a42808d9482a8cac82111f24a104fa (patch)
treee3409b92c3aff18d661f6aba14b3e0d3766816af /test
parent70c2a4645efd62ad8219f5f7a992436d2930f6b7 (diff)
downloadunit-df374057f7a42808d9482a8cac82111f24a104fa.tar.gz
unit-df374057f7a42808d9482a8cac82111f24a104fa.tar.bz2
Tests: $host varaible test.
Also added few tests for $uri and minor style fixes.
Diffstat (limited to '')
-rw-r--r--test/test_variables.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/test/test_variables.py b/test/test_variables.py
index 805c5144..fb481be5 100644
--- a/test/test_variables.py
+++ b/test/test_variables.py
@@ -16,10 +16,11 @@ class TestVariables(TestApplicationProto):
"GET": [{"action": {"return": 201}}],
"POST": [{"action": {"return": 202}}],
"3": [{"action": {"return": 203}}],
- "4": [{"action": {"return": 204}}],
+ "4*": [{"action": {"return": 204}}],
"blahGET}": [{"action": {"return": 205}}],
"5GET": [{"action": {"return": 206}}],
"GETGET": [{"action": {"return": 207}}],
+ "localhost": [{"action": {"return": 208}}],
},
},
),
@@ -27,10 +28,7 @@ class TestVariables(TestApplicationProto):
)
def conf_routes(self, routes):
- self.assertIn(
- 'success',
- self.conf(routes, 'listeners/*:7080/pass')
- )
+ self.assertIn('success', self.conf(routes, 'listeners/*:7080/pass'))
def test_variables_method(self):
self.assertEqual(self.get()['status'], 201, 'method GET')
@@ -40,7 +38,26 @@ class TestVariables(TestApplicationProto):
self.conf_routes("\"routes$uri\"")
self.assertEqual(self.get(url='/3')['status'], 203, 'uri')
- self.assertEqual(self.get(url='/4')['status'], 204, 'uri 2')
+ self.assertEqual(self.get(url='/4*')['status'], 204, 'uri 2')
+ self.assertEqual(self.get(url='/4%2A')['status'], 204, 'uri 3')
+
+ def test_variables_host(self):
+ self.conf_routes("\"routes/$host\"")
+
+ def check_host(host, status=208):
+ self.assertEqual(
+ self.get(headers={'Host': host, 'Connection': 'close'})[
+ 'status'
+ ],
+ status,
+ )
+
+ check_host('localhost')
+ check_host('localhost.')
+ check_host('localhost:7080')
+ check_host('.localhost', 404)
+ check_host('www.localhost', 404)
+ check_host('localhost1', 404)
def test_variables_many(self):
self.conf_routes("\"routes$uri$method\"")
@@ -69,7 +86,7 @@ class TestVariables(TestApplicationProto):
self.assertEqual(self.post()['status'], 202)
self.conf_routes("\"routes${uri}\"")
- self.assertEqual(self.get(url='/4')['status'], 204)
+ self.assertEqual(self.get(url='/4*')['status'], 204)
self.conf_routes("\"routes/blah$method}\"")
self.assertEqual(self.get()['status'], 205)