summaryrefslogtreecommitdiffhomepage
path: root/test/test_client_ip.py
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2022-06-20 13:58:04 +0800
committerZhidao HONG <z.hong@f5.com>2022-06-20 13:58:04 +0800
commit6da74019a03ca860b9867b3ca8a9195f402890ba (patch)
treef829db82bcaa5558adac1ccfe5eb0c99318d60f8 /test/test_client_ip.py
parent7e64971cbe6dcf249b586cc49bc4e7b163697d74 (diff)
downloadunit-6da74019a03ca860b9867b3ca8a9195f402890ba.tar.gz
unit-6da74019a03ca860b9867b3ca8a9195f402890ba.tar.bz2
Tests: reworked client IP tests.
Diffstat (limited to 'test/test_client_ip.py')
-rw-r--r--test/test_client_ip.py55
1 files changed, 38 insertions, 17 deletions
diff --git a/test/test_client_ip.py b/test/test_client_ip.py
index 53e52201..24436351 100644
--- a/test/test_client_ip.py
+++ b/test/test_client_ip.py
@@ -31,7 +31,7 @@ class TestClientIP(TestApplicationPython):
def setup_method(self):
self.load('client_ip')
- def test_settings_client_ip_single_ip(self):
+ def test_client_ip_single_ip(self):
self.client_ip(
{'header': 'X-Forwarded-For', 'source': '123.123.123.123'}
)
@@ -59,7 +59,7 @@ class TestClientIP(TestApplicationPython):
assert self.get_xff('1.1.1.1') == '127.0.0.1', 'bad source 3'
assert self.get_xff('1.1.1.1', 'ipv6') == '1.1.1.1', 'replace 2'
- def test_settings_client_ip_ipv4(self):
+ def test_client_ip_ipv4(self):
self.client_ip({'header': 'X-Forwarded-For', 'source': '127.0.0.1'})
assert (
@@ -72,7 +72,7 @@ class TestClientIP(TestApplicationPython):
self.get_xff(['8.8.8.8', '127.0.0.1, 10.0.1.1']) == '10.0.1.1'
), 'xff replace multi'
- def test_settings_client_ip_ipv6(self):
+ def test_client_ip_ipv6(self):
self.client_ip({'header': 'X-Forwarded-For', 'source': '::1'})
assert self.get_xff('1.1.1.1') == '127.0.0.1', 'bad source ipv4'
@@ -85,7 +85,7 @@ class TestClientIP(TestApplicationPython):
]:
assert self.get_xff(ip, 'ipv6') == ip, 'replace'
- def test_settings_client_ip_recursive(self):
+ def test_client_ip_recursive(self):
self.client_ip(
{
'header': 'X-Forwarded-For',
@@ -118,20 +118,41 @@ class TestClientIP(TestApplicationPython):
== '2001:db8:3c4d:15::1a2f:1a2b'
), 'xff chain ipv6'
- def test_settings_client_ip_invalid(self):
- assert 'error' in self.conf(
- {
- "http": {
- "client_ip": {'header': 'X-Forwarded-For', 'source': []}
- }
- },
- 'settings',
- ), 'empty array source'
+ def test_client_ip_case_insensitive(self):
+ self.client_ip({'header': 'x-forwarded-for', 'source': '127.0.0.1'})
+
+ assert self.get_xff('1.1.1.1') == '1.1.1.1', 'case insensitive'
+
+ def test_client_ip_empty_source(self):
+ self.client_ip({'header': 'X-Forwarded-For', 'source': []})
+
+ assert self.get_xff('1.1.1.1') == '127.0.0.1', 'empty source'
+
+ def test_client_ip_invalid(self):
assert 'error' in self.conf(
{
- "http": {
- "client_ip": {'header': 'X-Forwarded-For', 'source': 'a'}
+ "127.0.0.1:7081": {
+ "client_ip": {"source": '127.0.0.1'},
+ "pass": "applications/client_ip",
}
},
- 'settings',
- ), 'empty source invalid'
+ 'listeners',
+ ), 'invalid header'
+
+ def check_invalid_source(source):
+ assert 'error' in self.conf(
+ {
+ "127.0.0.1:7081": {
+ "client_ip": {
+ "header": "X-Forwarded-For",
+ "source": source,
+ },
+ "pass": "applications/client_ip",
+ }
+ },
+ 'listeners',
+ ), 'invalid source'
+
+ check_invalid_source(None)
+ check_invalid_source('a')
+ check_invalid_source(['a'])