diff options
-rw-r--r-- | test/test_asgi_websockets.py | 4 | ||||
-rw-r--r-- | test/test_go_isolation.py | 8 | ||||
-rw-r--r-- | test/test_go_isolation_rootfs.py | 4 | ||||
-rw-r--r-- | test/test_java_application.py | 83 | ||||
-rw-r--r-- | test/test_java_websockets.py | 4 | ||||
-rw-r--r-- | test/test_node_websockets.py | 4 | ||||
-rw-r--r-- | test/test_python_isolation.py | 28 | ||||
-rw-r--r-- | test/test_python_isolation_chroot.py | 18 | ||||
-rw-r--r-- | test/test_status.py | 11 | ||||
-rw-r--r-- | test/test_tls.py | 4 | ||||
-rw-r--r-- | test/test_variables.py | 17 |
11 files changed, 90 insertions, 95 deletions
diff --git a/test/test_asgi_websockets.py b/test/test_asgi_websockets.py index e891b03e..e5b88206 100644 --- a/test/test_asgi_websockets.py +++ b/test/test_asgi_websockets.py @@ -34,10 +34,10 @@ class TestASGIWebsockets(TestApplicationPython): self.check_close(sock) def check_close(self, sock, code=1000, no_close=False, frame=None): - if frame == None: + if frame is None: frame = self.ws.frame_read(sock) - assert frame['fin'] == True, 'close fin' + assert frame['fin'], 'close fin' assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode' assert frame['code'] == code, 'close code' diff --git a/test/test_go_isolation.py b/test/test_go_isolation.py index 2f631692..8216a6fe 100644 --- a/test/test_go_isolation.py +++ b/test/test_go_isolation.py @@ -289,10 +289,10 @@ class TestGoIsolation(TestApplicationGo): obj = self.getjson(url='/?file=/go/app')['body'] - assert obj['FileExists'] == True, 'app relative to rootfs' + assert obj['FileExists'], 'app relative to rootfs' obj = self.getjson(url='/?file=/bin/sh')['body'] - assert obj['FileExists'] == False, 'file should not exists' + assert not obj['FileExists'], 'file should not exists' def test_go_isolation_rootfs_container_priv(self, is_su, temp_dir): if not is_su: @@ -310,10 +310,10 @@ class TestGoIsolation(TestApplicationGo): obj = self.getjson(url='/?file=/go/app')['body'] - assert obj['FileExists'] == True, 'app relative to rootfs' + assert obj['FileExists'], 'app relative to rootfs' obj = self.getjson(url='/?file=/bin/sh')['body'] - assert obj['FileExists'] == False, 'file should not exists' + assert not obj['FileExists'], 'file should not exists' def test_go_isolation_rootfs_automount_tmpfs(self, is_su, temp_dir): try: diff --git a/test/test_go_isolation_rootfs.py b/test/test_go_isolation_rootfs.py index b321bc3f..b4d73ec8 100644 --- a/test/test_go_isolation_rootfs.py +++ b/test/test_go_isolation_rootfs.py @@ -26,7 +26,7 @@ class TestGoIsolationRootfs(TestApplicationGo): obj = self.getjson(url='/?file=/go/app')['body'] - assert obj['FileExists'] == True, 'app relative to rootfs' + assert obj['FileExists'], 'app relative to rootfs' obj = self.getjson(url='/?file=/bin/sh')['body'] - assert obj['FileExists'] == False, 'file should not exists' + assert not obj['FileExists'], 'file should not exists' diff --git a/test/test_java_application.py b/test/test_java_application.py index 5e346ac9..82719dd7 100644 --- a/test/test_java_application.py +++ b/test/test_java_application.py @@ -374,7 +374,7 @@ class TestJavaApplication(TestApplicationJava): assert headers['X-Add-Utf8-Value'] == '????', 'add Utf8 header value' assert headers['X-Add-Utf8-Name-???'] == 'y', 'add Utf8 header name' assert headers['X-Add-Test'] == 'v1', 'add null header' - assert ('X-Set-Test1' in headers) == False, 'set null header' + assert 'X-Set-Test1' not in headers, 'set null header' assert headers['X-Set-Test2'] == '', 'set empty header' def test_java_application_content_type(self): @@ -440,10 +440,8 @@ class TestJavaApplication(TestApplicationJava): headers = self.get(url='/6')['headers'] - assert ('Content-Type' in headers) == False, '#6 no Content-Type header' - assert ( - 'X-Content-Type' in headers - ) == False, '#6 no response Content-Type' + assert 'Content-Type' not in headers, '#6 no Content-Type header' + assert 'X-Content-Type' not in headers, '#6 no response Content-Type' assert headers['X-Character-Encoding'] == 'utf-8', '#6 response charset' headers = self.get(url='/7')['headers'] @@ -477,7 +475,7 @@ class TestJavaApplication(TestApplicationJava): resp = self.get(url='/dir1/') - assert ('This is index.txt.' in resp['body']) == True, 'dir1 index body' + assert 'This is index.txt.' in resp['body'], 'dir1 index body' assert resp['headers']['X-TXT-Filter'] == '1', 'TXT Filter header' headers = self.get(url='/dir2/')['headers'] @@ -494,8 +492,8 @@ class TestJavaApplication(TestApplicationJava): headers = self.get(url='/dir4/')['headers'] assert ( - 'X-App-Servlet' in headers - ) == False, 'Static welcome file served first' + 'X-App-Servlet' not in headers + ), 'Static welcome file served first' headers = self.get(url='/dir5/')['headers'] @@ -617,14 +615,14 @@ class TestJavaApplication(TestApplicationJava): ), 'original request query' assert ( - 'Before forwarding' in resp['body'] - ) == False, 'discarded data added before forward() call' + 'Before forwarding' not in resp['body'] + ), 'discarded data added before forward() call' assert ( - 'X-After-Forwarding' in headers - ) == False, 'cannot add headers after forward() call' + 'X-After-Forwarding' not in headers + ), 'cannot add headers after forward() call' assert ( - 'After forwarding' in resp['body'] - ) == False, 'cannot add data after forward() call' + 'After forwarding' not in resp['body'] + ), 'cannot add data after forward() call' def test_java_application_named_dispatcher_forward(self): self.load('forward') @@ -668,14 +666,14 @@ class TestJavaApplication(TestApplicationJava): ), 'original request query' assert ( - 'Before forwarding' in resp['body'] - ) == False, 'discarded data added before forward() call' + 'Before forwarding' not in resp['body'] + ), 'discarded data added before forward() call' assert ( - 'X-After-Forwarding' in headers - ) == False, 'cannot add headers after forward() call' + 'X-After-Forwarding' not in headers + ), 'cannot add headers after forward() call' assert ( - 'After forwarding' in resp['body'] - ) == False, 'cannot add data after forward() call' + 'After forwarding' not in resp['body'] + ), 'cannot add data after forward() call' def test_java_application_request_uri_include(self): self.load('include') @@ -690,34 +688,32 @@ class TestJavaApplication(TestApplicationJava): assert headers['X-Include'] == '/data/test', 'including triggered' assert ( - 'X-INCLUDE-Id' in headers - ) == False, 'unable to add headers in include request' + 'X-INCLUDE-Id' not in headers + ), 'unable to add headers in include request' assert ( 'javax.servlet.include.request_uri: /data/test' in body - ) == True, 'include request uri' + ), 'include request uri' # assert ( # 'javax.servlet.include.context_path: ' in body # ) == True, 'include request context path' assert ( 'javax.servlet.include.servlet_path: /data' in body - ) == True, 'include request servlet path' + ), 'include request servlet path' assert ( 'javax.servlet.include.path_info: /test' in body - ) == True, 'include request path info' + ), 'include request path info' assert ( 'javax.servlet.include.query_string: null' in body - ) == True, 'include request query' + ), 'include request query' assert ( 'Before include' in body - ) == True, 'preserve data added before include() call' + ), 'preserve data added before include() call' assert ( headers['X-After-Include'] == 'you-should-see-this' ), 'add headers after include() call' - assert ( - 'After include' in body - ) == True, 'add data after include() call' + assert 'After include' in body, 'add data after include() call' def test_java_application_named_dispatcher_include(self): self.load('include') @@ -732,34 +728,32 @@ class TestJavaApplication(TestApplicationJava): assert headers['X-Include'] == 'data', 'including triggered' assert ( - 'X-INCLUDE-Id' in headers - ) == False, 'unable to add headers in include request' + 'X-INCLUDE-Id' not in headers + ), 'unable to add headers in include request' assert ( 'javax.servlet.include.request_uri: null' in body - ) == True, 'include request uri' + ), 'include request uri' # assert ( # 'javax.servlet.include.context_path: null' in body # ) == True, 'include request context path' assert ( 'javax.servlet.include.servlet_path: null' in body - ) == True, 'include request servlet path' + ), 'include request servlet path' assert ( 'javax.servlet.include.path_info: null' in body - ) == True, 'include request path info' + ), 'include request path info' assert ( 'javax.servlet.include.query_string: null' in body - ) == True, 'include request query' + ), 'include request query' assert ( 'Before include' in body - ) == True, 'preserve data added before include() call' + ), 'preserve data added before include() call' assert ( headers['X-After-Include'] == 'you-should-see-this' ), 'add headers after include() call' - assert ( - 'After include' in body - ) == True, 'add data after include() call' + assert 'After include' in body, 'add data after include() call' def test_java_application_path_translation(self): self.load('path_translation') @@ -772,9 +766,8 @@ class TestJavaApplication(TestApplicationJava): headers['X-Path-Translated'] == f"{headers['X-Real-Path']}{headers['X-Path-Info']}" ), 'translated path is the app root + path info' - assert ( - headers['X-Resource-Paths'].endswith('/WEB-INF/, /index.html]') - == True + assert headers['X-Resource-Paths'].endswith( + '/WEB-INF/, /index.html]' ), 'app root directory content' assert ( headers['X-Resource-As-Stream'] == 'null' @@ -789,9 +782,7 @@ class TestJavaApplication(TestApplicationJava): assert ( headers['X-Path-Translated'] == 'null' ), 'translated path is null because path info is null' - assert ( - headers['X-Real-Path'].endswith('/none') == True - ), 'read path is not null' + assert headers['X-Real-Path'].endswith('/none'), 'read path is not null' assert headers['X-Resource-Paths'] == 'null', 'no resource found' assert headers['X-Resource-As-Stream'] == 'null', 'no resource stream' diff --git a/test/test_java_websockets.py b/test/test_java_websockets.py index 85d7fec6..2f212aa4 100644 --- a/test/test_java_websockets.py +++ b/test/test_java_websockets.py @@ -28,10 +28,10 @@ class TestJavaWebsockets(TestApplicationJava): self.check_close(sock) def check_close(self, sock, code=1000, no_close=False, frame=None): - if frame == None: + if frame is None: frame = self.ws.frame_read(sock) - assert frame['fin'] == True, 'close fin' + assert frame['fin'], 'close fin' assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode' assert frame['code'] == code, 'close code' diff --git a/test/test_node_websockets.py b/test/test_node_websockets.py index 3c245596..8a32aa10 100644 --- a/test/test_node_websockets.py +++ b/test/test_node_websockets.py @@ -28,10 +28,10 @@ class TestNodeWebsockets(TestApplicationNode): self.check_close(sock) def check_close(self, sock, code=1000, no_close=False, frame=None): - if frame == None: + if frame is None: frame = self.ws.frame_read(sock) - assert frame['fin'] == True, 'close fin' + assert frame['fin'], 'close fin' assert frame['opcode'] == self.ws.OP_CLOSE, 'close opcode' assert frame['code'] == code, 'close code' diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index 35ca4a56..506d20b7 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -58,27 +58,25 @@ class TestPythonIsolation(TestApplicationPython): self.load('ns_inspect', isolation=isolation) - assert ( + assert not ( self.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] - == False ), 'temp_dir does not exists in rootfs' - assert ( - self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True - ), 'no /proc/self' + assert self.getjson(url='/?path=/proc/self')['body'][ + 'FileExists' + ], 'no /proc/self' - assert ( - self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False + assert not ( + self.getjson(url='/?path=/dev/pts')['body']['FileExists'] ), 'no /dev/pts' - assert ( + assert not ( self.getjson(url='/?path=/sys/kernel')['body']['FileExists'] - == False ), 'no /sys/kernel' ret = self.getjson(url='/?path=/app/python/ns_inspect') - assert ret['body']['FileExists'] == True, 'application exists in rootfs' + assert ret['body']['FileExists'], 'application exists in rootfs' def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir): if not is_su: @@ -113,17 +111,17 @@ class TestPythonIsolation(TestApplicationPython): self.load('ns_inspect', isolation=isolation) - assert ( - self.getjson(url='/?path=/proc/self')['body']['FileExists'] == False + assert not ( + self.getjson(url='/?path=/proc/self')['body']['FileExists'] ), 'no /proc/self' isolation['automount']['procfs'] = True self.load('ns_inspect', isolation=isolation) - assert ( - self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True - ), '/proc/self' + assert self.getjson(url='/?path=/proc/self')['body'][ + 'FileExists' + ], '/proc/self' def test_python_isolation_cgroup(self, is_su): if not is_su: diff --git a/test/test_python_isolation_chroot.py b/test/test_python_isolation_chroot.py index 349ec869..dd0dede0 100644 --- a/test/test_python_isolation_chroot.py +++ b/test/test_python_isolation_chroot.py @@ -15,24 +15,22 @@ class TestPythonIsolation(TestApplicationPython): self.load('ns_inspect', isolation=isolation) - assert ( + assert not ( self.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] - == False ), 'temp_dir does not exists in rootfs' - assert ( - self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True - ), 'no /proc/self' + assert self.getjson(url='/?path=/proc/self')['body'][ + 'FileExists' + ], 'no /proc/self' - assert ( - self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False + assert not ( + self.getjson(url='/?path=/dev/pts')['body']['FileExists'] ), 'no /dev/pts' - assert ( + assert not ( self.getjson(url='/?path=/sys/kernel')['body']['FileExists'] - == False ), 'no /sys/kernel' ret = self.getjson(url='/?path=/app/python/ns_inspect') - assert ret['body']['FileExists'] == True, 'application exists in rootfs' + assert ret['body']['FileExists'], 'application exists in rootfs' diff --git a/test/test_status.py b/test/test_status.py index 8a00002b..f8885dff 100644 --- a/test/test_status.py +++ b/test/test_status.py @@ -9,7 +9,7 @@ class TestStatus(TestApplicationPython): prerequisites = {'modules': {'python': 'any'}} def check_connections(self, accepted, active, idle, closed): - Status.get('/connections') == { + assert Status.get('/connections') == { 'accepted': accepted, 'active': active, 'idle': idle, @@ -112,7 +112,12 @@ Connection: close # idle - sock = self.http(b'', raw=True, no_recv=True) + (_, sock) = self.get( + headers={'Host': 'localhost', 'Connection': 'keep-alive'}, + start=True, + read_timeout=1, + ) + self.check_connections(2, 0, 1, 1) self.get(sock=sock) @@ -141,7 +146,7 @@ Connection: close assert apps == expert.sort() def check_application(name, running, starting, idle, active): - Status.get(f'/applications/{name}') == { + assert Status.get(f'/applications/{name}') == { 'processes': { 'running': running, 'starting': starting, diff --git a/test/test_tls.py b/test/test_tls.py index a4dc8ef5..52107d9a 100644 --- a/test/test_tls.py +++ b/test/test_tls.py @@ -331,7 +331,7 @@ basicConstraints = critical,CA:TRUE""" except ssl.SSLError: resp = None - assert resp == None, 'certificate chain incomplete chain' + assert resp is None, 'certificate chain incomplete chain' # intermediate @@ -571,7 +571,7 @@ basicConstraints = critical,CA:TRUE""" except: resp = None - assert resp == None, 'keepalive remove certificate' + assert resp is None, 'keepalive remove certificate' @pytest.mark.skip('not yet') def test_tls_certificates_remove_all(self): diff --git a/test/test_variables.py b/test/test_variables.py index 970ad7b0..f1d66b52 100644 --- a/test/test_variables.py +++ b/test/test_variables.py @@ -354,13 +354,16 @@ Connection: close reg = r'^1$' assert self.search_in_log(reg) is None - self.get( - headers={ - 'Host': 'localhost', - 'Cookie': 'foo_bar=1', - 'Connection': 'close', - }, - )['status'] == 200 + assert ( + self.get( + headers={ + 'Host': 'localhost', + 'Cookie': 'foo_bar=1', + 'Connection': 'close', + }, + )['status'] + == 200 + ) assert self.wait_for_record(reg) is not None check_no_cookie('fOo_bar=0') |