diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2022-01-31 23:10:30 +0000 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2022-01-31 23:10:30 +0000 |
commit | e53ce40c5854d95722cdfc198626fcd5aecbe563 (patch) | |
tree | fe3be3f5d9685c29424e84f0f08b9459ea5de37b /test | |
parent | 485886d8f9a665e9c416a98dd00e5c836b6bf27c (diff) | |
download | unit-e53ce40c5854d95722cdfc198626fcd5aecbe563.tar.gz unit-e53ce40c5854d95722cdfc198626fcd5aecbe563.tar.bz2 |
Tests: removed TestApplicationTLS.get_server_certificate().
distutils.version is replaced by packaging.version. Also minor style fixes.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_asgi_application.py | 6 | ||||
-rw-r--r-- | test/test_asgi_lifespan.py | 6 | ||||
-rw-r--r-- | test/test_asgi_targets.py | 7 | ||||
-rw-r--r-- | test/test_asgi_websockets.py | 6 | ||||
-rw-r--r-- | test/test_client_ip.py | 28 | ||||
-rw-r--r-- | test/test_go_application.py | 1 | ||||
-rw-r--r-- | test/test_node_es_modules.py | 5 | ||||
-rw-r--r-- | test/test_perl_application.py | 10 | ||||
-rw-r--r-- | test/test_static.py | 3 | ||||
-rw-r--r-- | test/test_static_fallback.py | 5 | ||||
-rw-r--r-- | test/test_static_types.py | 5 | ||||
-rw-r--r-- | test/test_tls.py | 12 | ||||
-rw-r--r-- | test/test_variables.py | 12 | ||||
-rw-r--r-- | test/unit/applications/tls.py | 15 |
14 files changed, 61 insertions, 60 deletions
diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 021aa2b2..60fcffc1 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -1,14 +1,16 @@ import re import time -from distutils.version import LooseVersion import pytest +from packaging import version from unit.applications.lang.python import TestApplicationPython class TestASGIApplication(TestApplicationPython): prerequisites = { - 'modules': {'python': lambda v: LooseVersion(v) >= LooseVersion('3.5')} + 'modules': { + 'python': lambda v: version.parse(v) >= version.parse('3.5') + } } load_module = 'asgi' diff --git a/test/test_asgi_lifespan.py b/test/test_asgi_lifespan.py index dcdd107d..e295f7fa 100644 --- a/test/test_asgi_lifespan.py +++ b/test/test_asgi_lifespan.py @@ -1,14 +1,16 @@ import os -from distutils.version import LooseVersion from conftest import unit_stop +from packaging import version from unit.applications.lang.python import TestApplicationPython from unit.option import option class TestASGILifespan(TestApplicationPython): prerequisites = { - 'modules': {'python': lambda v: LooseVersion(v) >= LooseVersion('3.5')} + 'modules': { + 'python': lambda v: version.parse(v) >= version.parse('3.5') + } } load_module = 'asgi' diff --git a/test/test_asgi_targets.py b/test/test_asgi_targets.py index 73929783..c1e345ef 100644 --- a/test/test_asgi_targets.py +++ b/test/test_asgi_targets.py @@ -1,13 +1,14 @@ -from distutils.version import LooseVersion - import pytest +from packaging import version from unit.applications.lang.python import TestApplicationPython from unit.option import option class TestASGITargets(TestApplicationPython): prerequisites = { - 'modules': {'python': lambda v: LooseVersion(v) >= LooseVersion('3.5')} + 'modules': { + 'python': lambda v: version.parse(v) >= version.parse('3.5') + } } load_module = 'asgi' diff --git a/test/test_asgi_websockets.py b/test/test_asgi_websockets.py index bad54e22..feb99fbb 100644 --- a/test/test_asgi_websockets.py +++ b/test/test_asgi_websockets.py @@ -1,8 +1,8 @@ import struct import time -from distutils.version import LooseVersion import pytest +from packaging import version from unit.applications.lang.python import TestApplicationPython from unit.applications.websockets import TestApplicationWebsocket from unit.option import option @@ -10,7 +10,9 @@ from unit.option import option class TestASGIWebsockets(TestApplicationPython): prerequisites = { - 'modules': {'python': lambda v: LooseVersion(v) >= LooseVersion('3.5')} + 'modules': { + 'python': lambda v: version.parse(v) >= version.parse('3.5') + } } load_module = 'asgi' diff --git a/test/test_client_ip.py b/test/test_client_ip.py index 4b2b2fa1..53e52201 100644 --- a/test/test_client_ip.py +++ b/test/test_client_ip.py @@ -7,10 +7,14 @@ class TestClientIP(TestApplicationPython): def client_ip(self, options): assert 'success' in self.conf( { - "127.0.0.1:7081": - {"client_ip": options, "pass": "applications/client_ip"}, - "[::1]:7082": - {"client_ip": options, "pass": "applications/client_ip"}, + "127.0.0.1:7081": { + "client_ip": options, + "pass": "applications/client_ip", + }, + "[::1]:7082": { + "client_ip": options, + "pass": "applications/client_ip", + }, }, 'listeners', ), 'listeners configure' @@ -48,9 +52,7 @@ class TestClientIP(TestApplicationPython): ), 'ipv6 default 2' assert self.get_xff('1.1.1.1') == '1.1.1.1', 'replace' assert self.get_xff('blah') == '127.0.0.1', 'bad header 2' - assert ( - self.get_xff('1.1.1.1', 'ipv6') == '::1' - ), 'bad source ipv6 2' + assert self.get_xff('1.1.1.1', 'ipv6') == '::1', 'bad source ipv6 2' self.client_ip({'header': 'X-Forwarded-For', 'source': '!127.0.0.1'}) @@ -118,10 +120,18 @@ class TestClientIP(TestApplicationPython): def test_settings_client_ip_invalid(self): assert 'error' in self.conf( - {"http": {"client_ip": {'header': 'X-Forwarded-For', 'source': []}}}, + { + "http": { + "client_ip": {'header': 'X-Forwarded-For', 'source': []} + } + }, 'settings', ), 'empty array source' assert 'error' in self.conf( - {"http":{"client_ip": {'header': 'X-Forwarded-For', 'source': 'a'}}}, + { + "http": { + "client_ip": {'header': 'X-Forwarded-For', 'source': 'a'} + } + }, 'settings', ), 'empty source invalid' diff --git a/test/test_go_application.py b/test/test_go_application.py index 94da1aee..7c897b20 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -1,7 +1,6 @@ import re import pytest - from unit.applications.lang.go import TestApplicationGo diff --git a/test/test_node_es_modules.py b/test/test_node_es_modules.py index 12788fa4..8a9cb181 100644 --- a/test/test_node_es_modules.py +++ b/test/test_node_es_modules.py @@ -1,5 +1,4 @@ -from distutils.version import LooseVersion - +from packaging import version from unit.applications.lang.node import TestApplicationNode from unit.applications.websockets import TestApplicationWebsocket @@ -7,7 +6,7 @@ from unit.applications.websockets import TestApplicationWebsocket class TestNodeESModules(TestApplicationNode): prerequisites = { 'modules': { - 'node': lambda v: LooseVersion(v) >= LooseVersion("14.16.0") + 'node': lambda v: version.parse(v) >= version.parse('14.16.0') } } diff --git a/test/test_perl_application.py b/test/test_perl_application.py index 6803ff76..32d2b703 100644 --- a/test/test_perl_application.py +++ b/test/test_perl_application.py @@ -103,10 +103,7 @@ class TestPerlApplication(TestApplicationPerl): def test_perl_application_input_buffered_read(self): self.load('input_buffered_read') - assert ( - self.post(body='012345')['body'] == '012345' - ), 'buffered read #1' - + assert self.post(body='012345')['body'] == '012345', 'buffered read #1' assert ( self.post(body='9876543210')['body'] == '9876543210' ), 'buffered read #2' @@ -114,10 +111,7 @@ class TestPerlApplication(TestApplicationPerl): def test_perl_application_input_close(self): self.load('input_close') - assert ( - self.post(body='012345')['body'] == '012345' - ), 'input close #1' - + assert self.post(body='012345')['body'] == '012345', 'input close #1' assert ( self.post(body='9876543210')['body'] == '9876543210' ), 'input close #2' diff --git a/test/test_static.py b/test/test_static.py index 80f4c610..1d9c754a 100644 --- a/test/test_static.py +++ b/test/test_static.py @@ -3,7 +3,8 @@ import shutil import socket import pytest -from conftest import unit_run, unit_stop +from conftest import unit_run +from conftest import unit_stop from unit.applications.proto import TestApplicationProto from unit.option import option from unit.utils import waitforfiles diff --git a/test/test_static_fallback.py b/test/test_static_fallback.py index 71b268c8..1f1a1df7 100644 --- a/test/test_static_fallback.py +++ b/test/test_static_fallback.py @@ -82,7 +82,10 @@ class TestStaticFallback(TestApplicationProto): def test_static_fallback_share(self, temp_dir): self.action_update( - {"share": "/blah", "fallback": {"share": temp_dir + "/assets$uri"},} + { + "share": "/blah", + "fallback": {"share": temp_dir + "/assets$uri"}, + } ) resp = self.get() diff --git a/test/test_static_types.py b/test/test_static_types.py index 18564a21..0e86517b 100644 --- a/test/test_static_types.py +++ b/test/test_static_types.py @@ -85,7 +85,10 @@ class TestStaticTypes(TestApplicationProto): def test_static_types_regex(self, temp_dir): self.action_update( - {"share": temp_dir + "/assets$uri", "types": ["~text/(html|plain)"]} + { + "share": temp_dir + "/assets$uri", + "types": ["~text/(html|plain)"], + } ) assert self.get(url='/file.php')['status'] == 403, 'regex fail' self.check_body('/file.html', '.html') diff --git a/test/test_tls.py b/test/test_tls.py index 01336765..c4471f3f 100644 --- a/test/test_tls.py +++ b/test/test_tls.py @@ -175,11 +175,13 @@ basicConstraints = critical,CA:TRUE""" self.add_tls() - cert_old = self.get_server_certificate() + cert_old = ssl.get_server_certificate(('127.0.0.1', 7080)) self.certificate() - assert cert_old != self.get_server_certificate(), 'update certificate' + assert cert_old != ssl.get_server_certificate( + ('127.0.0.1', 7080) + ), 'update certificate' @pytest.mark.skip('not yet') def test_tls_certificate_key_incorrect(self): @@ -200,11 +202,13 @@ basicConstraints = critical,CA:TRUE""" self.add_tls() - cert_old = self.get_server_certificate() + cert_old = ssl.get_server_certificate(('127.0.0.1', 7080)) self.add_tls(cert='new') - assert cert_old != self.get_server_certificate(), 'change certificate' + assert cert_old != ssl.get_server_certificate( + ('127.0.0.1', 7080) + ), 'change certificate' def test_tls_certificate_key_rsa(self): self.load('empty') diff --git a/test/test_variables.py b/test/test_variables.py index d8547b7b..f110fb74 100644 --- a/test/test_variables.py +++ b/test/test_variables.py @@ -103,20 +103,16 @@ class TestVariables(TestApplicationProto): def test_variables_empty(self): def update_pass(prefix): assert 'success' in self.conf( - { - "listeners": { - "*:7080": {"pass": prefix + "/$method"}, - }, - }, + {"listeners": {"*:7080": {"pass": prefix + "/$method"}}}, ), 'variables empty' - update_pass("routes"); + update_pass("routes") assert self.get(url='/1')['status'] == 404 - update_pass("upstreams"); + update_pass("upstreams") assert self.get(url='/2')['status'] == 404 - update_pass("applications"); + update_pass("applications") assert self.get(url='/3')['status'] == 404 def test_variables_invalid(self): diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py index c7254235..93400328 100644 --- a/test/unit/applications/tls.py +++ b/test/unit/applications/tls.py @@ -52,21 +52,6 @@ class TestApplicationTLS(TestApplicationProto): def post_ssl(self, **kwargs): return self.post(wrapper=self.context.wrap_socket, **kwargs) - def get_server_certificate(self, addr=('127.0.0.1', 7080)): - - ssl_list = dir(ssl) - - if 'PROTOCOL_TLS' in ssl_list: - ssl_version = ssl.PROTOCOL_TLS - - elif 'PROTOCOL_TLSv1_2' in ssl_list: - ssl_version = ssl.PROTOCOL_TLSv1_2 - - else: - ssl_version = ssl.PROTOCOL_TLSv1_1 - - return ssl.get_server_certificate(addr, ssl_version=ssl_version) - def openssl_conf(self, rewrite=False, alt_names=[]): conf_path = option.temp_dir + '/openssl.conf' |