summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2022-07-19 17:34:32 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2022-07-19 17:34:32 +0100
commita1cda6455f5ab0b361d403bd7c183ebec92fb59a (patch)
treec70ba9920ac9c9e1d04b510ea064093f356ff0d5
parent3422e81ab6794b6f2a4a1fb237923bab11ae2b18 (diff)
downloadunit-a1cda6455f5ab0b361d403bd7c183ebec92fb59a.tar.gz
unit-a1cda6455f5ab0b361d403bd7c183ebec92fb59a.tar.bz2
Tests: added tests for more HTTP variables.
-rw-r--r--test/test_variables.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/test_variables.py b/test/test_variables.py
index 577408f6..ccd0839b 100644
--- a/test/test_variables.py
+++ b/test/test_variables.py
@@ -19,6 +19,10 @@ class TestVariables(TestApplicationProto):
"localhost": [{"action": {"return": 208}}],
"9?q#a": [{"action": {"return": 209}}],
"blah": [{"action": {"return": 210}}],
+ "127.0.0.1": [{"action": {"return": 211}}],
+ "::1": [{"action": {"return": 212}}],
+ "referer-value": [{"action": {"return": 213}}],
+ "MSIE": [{"action": {"return": 214}}],
},
},
), 'configure routes'
@@ -63,6 +67,53 @@ class TestVariables(TestApplicationProto):
check_host('www.localhost', 404)
check_host('localhost1', 404)
+ def test_variables_remote_addr(self):
+ self.conf_routes("\"routes/$remote_addr\"")
+ assert self.get()['status'] == 211
+
+ assert 'success' in self.conf(
+ {"[::1]:7080": {"pass": "routes/$remote_addr"}}, 'listeners'
+ )
+ assert self.get(sock_type='ipv6')['status'] == 212
+
+ def test_variables_header_referer(self):
+ self.conf_routes("\"routes/$header_referer\"")
+
+ def check_referer(referer, status=213):
+ assert (
+ self.get(
+ headers={
+ 'Host': 'localhost',
+ 'Connection': 'close',
+ 'Referer': referer,
+ }
+ )['status']
+ == status
+ )
+
+ check_referer('referer-value')
+ check_referer('', 404)
+ check_referer('no', 404)
+
+ def test_variables_header_user_agent(self):
+ self.conf_routes("\"routes/$header_user_agent\"")
+
+ def check_user_agent(user_agent, status=214):
+ assert (
+ self.get(
+ headers={
+ 'Host': 'localhost',
+ 'Connection': 'close',
+ 'User-Agent': user_agent,
+ }
+ )['status']
+ == status
+ )
+
+ check_user_agent('MSIE')
+ check_user_agent('', 404)
+ check_user_agent('no', 404)
+
def test_variables_many(self):
self.conf_routes("\"routes$uri$method\"")
assert self.get(url='/5')['status'] == 206, 'many'