diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2022-08-08 10:32:24 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2022-08-08 10:32:24 +0100 |
commit | e5d835e1593389b1490def9ec9c031156e2a74a4 (patch) | |
tree | fd3d057e99d958d6eb648d9c7b676428e6d3d38b /test/test_client_ip.py | |
parent | 418bc208d08dbc4a0a3511e503c946ab6ac71c39 (diff) | |
download | unit-e5d835e1593389b1490def9ec9c031156e2a74a4.tar.gz unit-e5d835e1593389b1490def9ec9c031156e2a74a4.tar.bz2 |
Tests: added tests with UNIX sockets in "source".
Diffstat (limited to 'test/test_client_ip.py')
-rw-r--r-- | test/test_client_ip.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/test/test_client_ip.py b/test/test_client_ip.py index 24436351..50aa6afc 100644 --- a/test/test_client_ip.py +++ b/test/test_client_ip.py @@ -1,4 +1,5 @@ from unit.applications.lang.python import TestApplicationPython +from unit.option import option class TestClientIP(TestApplicationPython): @@ -15,15 +16,27 @@ class TestClientIP(TestApplicationPython): "client_ip": options, "pass": "applications/client_ip", }, + "unix:" + + option.temp_dir + + "/sock": { + "client_ip": options, + "pass": "applications/client_ip", + }, }, 'listeners', ), 'listeners configure' def get_xff(self, xff, sock_type='ipv4'): - port = 7081 if sock_type == 'ipv4' else 7082 + address = { + 'ipv4': ('127.0.0.1', 7081), + 'ipv6': ('::1', 7082), + 'unix': (option.temp_dir + '/sock', None), + } + (addr, port) = address[sock_type] return self.get( sock_type=sock_type, + addr=addr, port=port, headers={'Connection': 'close', 'X-Forwarded-For': xff}, )['body'] @@ -85,6 +98,18 @@ class TestClientIP(TestApplicationPython): ]: assert self.get_xff(ip, 'ipv6') == ip, 'replace' + def test_client_ip_unix(self, temp_dir): + self.client_ip({'header': 'X-Forwarded-For', 'source': 'unix'}) + + assert self.get_xff('1.1.1.1') == '127.0.0.1', 'bad source ipv4' + assert self.get_xff('1.1.1.1', 'ipv6') == '::1', 'bad source ipv6' + + for ip in [ + '1.1.1.1', + '::11.22.33.44', + ]: + assert self.get_xff(ip, 'unix') == ip, 'replace' + def test_client_ip_recursive(self): self.client_ip( { |