Tests: style.

This commit is contained in:
Andrei Zeliankou
2022-04-11 21:05:14 +01:00
parent aeed86c682
commit 0f72534660
36 changed files with 285 additions and 337 deletions

View File

@@ -159,9 +159,7 @@ def pytest_generate_tests(metafunc):
type + ' ' + available_versions[0] type + ' ' + available_versions[0]
) )
elif callable(prereq_version): elif callable(prereq_version):
generate_tests( generate_tests(list(filter(prereq_version, available_versions)))
list(filter(prereq_version, available_versions))
)
else: else:
raise ValueError( raise ValueError(
@@ -320,9 +318,7 @@ def run(request):
public_dir(path) public_dir(path)
if os.path.isfile(path) or stat.S_ISSOCK( if os.path.isfile(path) or stat.S_ISSOCK(os.stat(path).st_mode):
os.stat(path).st_mode
):
os.remove(path) os.remove(path)
else: else:
for attempt in range(10): for attempt in range(10):
@@ -520,7 +516,7 @@ def _clear_conf(sock, *, log=None):
try: try:
certs = json.loads( certs = json.loads(
http.get(url='/certificates', sock_type='unix', addr=sock,)['body'] http.get(url='/certificates', sock_type='unix', addr=sock)['body']
).keys() ).keys()
except json.JSONDecodeError: except json.JSONDecodeError:
@@ -528,7 +524,9 @@ def _clear_conf(sock, *, log=None):
for cert in certs: for cert in certs:
resp = http.delete( resp = http.delete(
url='/certificates/' + cert, sock_type='unix', addr=sock, url='/certificates/' + cert,
sock_type='unix',
addr=sock,
)['body'] )['body']
assert 'success' in resp, 'remove certificate' assert 'success' in resp, 'remove certificate'
@@ -554,9 +552,7 @@ def _check_fds(*, log=None):
) )
ps['fds'] += fds_diff ps['fds'] += fds_diff
assert ( assert fds_diff <= option.fds_threshold, 'descriptors leak main process'
fds_diff <= option.fds_threshold
), 'descriptors leak main process'
else: else:
ps['fds'] = _count_fds(unit_instance['pid']) ps['fds'] = _count_fds(unit_instance['pid'])
@@ -588,7 +584,8 @@ def _count_fds(pid):
try: try:
out = subprocess.check_output( out = subprocess.check_output(
['procstat', '-f', pid], stderr=subprocess.STDOUT, ['procstat', '-f', pid],
stderr=subprocess.STDOUT,
).decode() ).decode()
return len(out.splitlines()) return len(out.splitlines())
@@ -597,7 +594,8 @@ def _count_fds(pid):
try: try:
out = subprocess.check_output( out = subprocess.check_output(
['lsof', '-n', '-p', pid], stderr=subprocess.STDOUT, ['lsof', '-n', '-p', pid],
stderr=subprocess.STDOUT,
).decode() ).decode()
return len(out.splitlines()) return len(out.splitlines())

View File

@@ -1,8 +1,10 @@
async def application(scope, receive, send): async def application(scope, receive, send):
assert scope['type'] == 'http' assert scope['type'] == 'http'
await send({ await send(
'type': 'http.response.start', {
'status': 204, 'type': 'http.response.start',
'headers': [], 'status': 204,
}) 'headers': [],
}
)

View File

@@ -164,7 +164,7 @@ class TestASGIWebsockets(TestApplicationPython):
self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False) self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
self.ws.frame_write( self.ws.frame_write(
sock, self.ws.OP_CONT, 'fragment2', length=2 ** 64 - 1 sock, self.ws.OP_CONT, 'fragment2', length=2**64 - 1
) )
self.check_close(sock, 1009) # 1009 - CLOSE_TOO_LARGE self.check_close(sock, 1009) # 1009 - CLOSE_TOO_LARGE
@@ -942,9 +942,7 @@ class TestASGIWebsockets(TestApplicationPython):
frame = self.ws.frame_read(sock) frame = self.ws.frame_read(sock)
if frame['opcode'] == self.ws.OP_TEXT: if frame['opcode'] == self.ws.OP_TEXT:
self.check_frame( self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
frame, True, self.ws.OP_TEXT, 'fragment1fragment2'
)
frame = None frame = None
self.check_close(sock, 1002, frame=frame) self.check_close(sock, 1002, frame=frame)
@@ -1189,7 +1187,7 @@ class TestASGIWebsockets(TestApplicationPython):
_, sock, _ = self.ws.upgrade() _, sock, _ = self.ws.upgrade()
self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2 ** 10) self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2**10)
self.ws.frame_write(sock, self.ws.OP_TEXT, payload) self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close()) self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
@@ -1351,62 +1349,62 @@ class TestASGIWebsockets(TestApplicationPython):
def check_message(opcode, f_size): def check_message(opcode, f_size):
if opcode == self.ws.OP_TEXT: if opcode == self.ws.OP_TEXT:
payload = '*' * 4 * 2 ** 20 payload = '*' * 4 * 2**20
else: else:
payload = b'*' * 4 * 2 ** 20 payload = b'*' * 4 * 2**20
self.ws.message(sock, opcode, payload, fragmention_size=f_size) self.ws.message(sock, opcode, payload, fragmention_size=f_size)
frame = self.ws.frame_read(sock, read_timeout=5) frame = self.ws.frame_read(sock, read_timeout=5)
self.check_frame(frame, True, opcode, payload) self.check_frame(frame, True, opcode, payload)
check_payload(op_text, 64 * 2 ** 10) # 9_1_1 check_payload(op_text, 64 * 2**10) # 9_1_1
check_payload(op_text, 256 * 2 ** 10) # 9_1_2 check_payload(op_text, 256 * 2**10) # 9_1_2
check_payload(op_text, 2 ** 20) # 9_1_3 check_payload(op_text, 2**20) # 9_1_3
check_payload(op_text, 4 * 2 ** 20) # 9_1_4 check_payload(op_text, 4 * 2**20) # 9_1_4
check_payload(op_text, 8 * 2 ** 20) # 9_1_5 check_payload(op_text, 8 * 2**20) # 9_1_5
check_payload(op_text, 16 * 2 ** 20) # 9_1_6 check_payload(op_text, 16 * 2**20) # 9_1_6
check_payload(op_binary, 64 * 2 ** 10) # 9_2_1 check_payload(op_binary, 64 * 2**10) # 9_2_1
check_payload(op_binary, 256 * 2 ** 10) # 9_2_2 check_payload(op_binary, 256 * 2**10) # 9_2_2
check_payload(op_binary, 2 ** 20) # 9_2_3 check_payload(op_binary, 2**20) # 9_2_3
check_payload(op_binary, 4 * 2 ** 20) # 9_2_4 check_payload(op_binary, 4 * 2**20) # 9_2_4
check_payload(op_binary, 8 * 2 ** 20) # 9_2_5 check_payload(op_binary, 8 * 2**20) # 9_2_5
check_payload(op_binary, 16 * 2 ** 20) # 9_2_6 check_payload(op_binary, 16 * 2**20) # 9_2_6
if option.system != 'Darwin' and option.system != 'FreeBSD': if option.system != 'Darwin' and option.system != 'FreeBSD':
check_message(op_text, 64) # 9_3_1 check_message(op_text, 64) # 9_3_1
check_message(op_text, 256) # 9_3_2 check_message(op_text, 256) # 9_3_2
check_message(op_text, 2 ** 10) # 9_3_3 check_message(op_text, 2**10) # 9_3_3
check_message(op_text, 4 * 2 ** 10) # 9_3_4 check_message(op_text, 4 * 2**10) # 9_3_4
check_message(op_text, 16 * 2 ** 10) # 9_3_5 check_message(op_text, 16 * 2**10) # 9_3_5
check_message(op_text, 64 * 2 ** 10) # 9_3_6 check_message(op_text, 64 * 2**10) # 9_3_6
check_message(op_text, 256 * 2 ** 10) # 9_3_7 check_message(op_text, 256 * 2**10) # 9_3_7
check_message(op_text, 2 ** 20) # 9_3_8 check_message(op_text, 2**20) # 9_3_8
check_message(op_text, 4 * 2 ** 20) # 9_3_9 check_message(op_text, 4 * 2**20) # 9_3_9
check_message(op_binary, 64) # 9_4_1 check_message(op_binary, 64) # 9_4_1
check_message(op_binary, 256) # 9_4_2 check_message(op_binary, 256) # 9_4_2
check_message(op_binary, 2 ** 10) # 9_4_3 check_message(op_binary, 2**10) # 9_4_3
check_message(op_binary, 4 * 2 ** 10) # 9_4_4 check_message(op_binary, 4 * 2**10) # 9_4_4
check_message(op_binary, 16 * 2 ** 10) # 9_4_5 check_message(op_binary, 16 * 2**10) # 9_4_5
check_message(op_binary, 64 * 2 ** 10) # 9_4_6 check_message(op_binary, 64 * 2**10) # 9_4_6
check_message(op_binary, 256 * 2 ** 10) # 9_4_7 check_message(op_binary, 256 * 2**10) # 9_4_7
check_message(op_binary, 2 ** 20) # 9_4_8 check_message(op_binary, 2**20) # 9_4_8
check_message(op_binary, 4 * 2 ** 20) # 9_4_9 check_message(op_binary, 4 * 2**20) # 9_4_9
check_payload(op_text, 2 ** 20, chopsize=64) # 9_5_1 check_payload(op_text, 2**20, chopsize=64) # 9_5_1
check_payload(op_text, 2 ** 20, chopsize=128) # 9_5_2 check_payload(op_text, 2**20, chopsize=128) # 9_5_2
check_payload(op_text, 2 ** 20, chopsize=256) # 9_5_3 check_payload(op_text, 2**20, chopsize=256) # 9_5_3
check_payload(op_text, 2 ** 20, chopsize=512) # 9_5_4 check_payload(op_text, 2**20, chopsize=512) # 9_5_4
check_payload(op_text, 2 ** 20, chopsize=1024) # 9_5_5 check_payload(op_text, 2**20, chopsize=1024) # 9_5_5
check_payload(op_text, 2 ** 20, chopsize=2048) # 9_5_6 check_payload(op_text, 2**20, chopsize=2048) # 9_5_6
check_payload(op_binary, 2 ** 20, chopsize=64) # 9_6_1 check_payload(op_binary, 2**20, chopsize=64) # 9_6_1
check_payload(op_binary, 2 ** 20, chopsize=128) # 9_6_2 check_payload(op_binary, 2**20, chopsize=128) # 9_6_2
check_payload(op_binary, 2 ** 20, chopsize=256) # 9_6_3 check_payload(op_binary, 2**20, chopsize=256) # 9_6_3
check_payload(op_binary, 2 ** 20, chopsize=512) # 9_6_4 check_payload(op_binary, 2**20, chopsize=512) # 9_6_4
check_payload(op_binary, 2 ** 20, chopsize=1024) # 9_6_5 check_payload(op_binary, 2**20, chopsize=1024) # 9_6_5
check_payload(op_binary, 2 ** 20, chopsize=2048) # 9_6_6 check_payload(op_binary, 2**20, chopsize=2048) # 9_6_6
self.close_connection(sock) self.close_connection(sock)

View File

@@ -157,9 +157,7 @@ class TestGoApplication(TestApplicationGo):
'applications/command_line_arguments/arguments', 'applications/command_line_arguments/arguments',
) )
assert ( assert self.get()['body'] == arg1 + ',' + arg2 + ',' + arg3, 'arguments'
self.get()['body'] == arg1 + ',' + arg2 + ',' + arg3
), 'arguments'
def test_go_application_command_line_arguments_change(self): def test_go_application_command_line_arguments_change(self):
self.load('command_line_arguments') self.load('command_line_arguments')
@@ -176,6 +174,4 @@ class TestGoApplication(TestApplicationGo):
assert 'success' in self.conf('[]', args_path) assert 'success' in self.conf('[]', args_path)
assert ( assert self.get()['headers']['Content-Length'] == '0', 'arguments empty'
self.get()['headers']['Content-Length'] == '0'
), 'arguments empty'

View File

@@ -167,9 +167,7 @@ class TestGoIsolation(TestApplicationGo):
user='nobody', user='nobody',
isolation={ isolation={
'namespaces': {'credential': True}, 'namespaces': {'credential': True},
'uidmap': [ 'uidmap': [{'container': 0, 'host': 0, 'size': nobody_uid + 1}],
{'container': 0, 'host': 0, 'size': nobody_uid + 1}
],
}, },
) )

View File

@@ -213,7 +213,7 @@ Connection: close
self.post( self.post(
headers={ headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Length': str(2 ** 64), 'Content-Length': str(2**64),
'Connection': 'close', 'Connection': 'close',
}, },
body='X' * 1000, body='X' * 1000,
@@ -325,9 +325,7 @@ Connection: close
def test_http_header_host_port_empty(self): def test_http_header_host_port_empty(self):
self.load('host') self.load('host')
resp = self.get( resp = self.get(headers={'Host': 'exmaple.com:', 'Connection': 'close'})
headers={'Host': 'exmaple.com:', 'Connection': 'close'}
)
assert resp['status'] == 200, 'Host port empty status' assert resp['status'] == 200, 'Host port empty status'
assert ( assert (
@@ -376,9 +374,7 @@ Connection: close
def test_http_header_host_trailing_period_2(self): def test_http_header_host_trailing_period_2(self):
self.load('host') self.load('host')
resp = self.get( resp = self.get(headers={'Host': 'EXAMPLE.COM.', 'Connection': 'close'})
headers={'Host': 'EXAMPLE.COM.', 'Connection': 'close'}
)
assert resp['status'] == 200, 'Host trailing period 2 status' assert resp['status'] == 200, 'Host trailing period 2 status'
assert ( assert (
@@ -453,14 +449,16 @@ Connection: close
assert 'CUSTOM' not in resp['headers']['All-Headers'] assert 'CUSTOM' not in resp['headers']['All-Headers']
assert 'success' in self.conf( assert 'success' in self.conf(
{'http': {'discard_unsafe_fields': False}}, 'settings', {'http': {'discard_unsafe_fields': False}},
'settings',
) )
resp = check_status("!#$%&'*+.^`|~Custom_Header") resp = check_status("!#$%&'*+.^`|~Custom_Header")
assert 'CUSTOM' in resp['headers']['All-Headers'] assert 'CUSTOM' in resp['headers']['All-Headers']
assert 'success' in self.conf( assert 'success' in self.conf(
{'http': {'discard_unsafe_fields': True}}, 'settings', {'http': {'discard_unsafe_fields': True}},
'settings',
) )
resp = check_status("!Custom-Header") resp = check_status("!Custom-Header")

View File

@@ -173,9 +173,7 @@ class TestJavaApplication(TestApplicationJava):
} }
) )
assert ( assert resp['headers']['X-Session-Id'] == session_id, 'session active 2'
resp['headers']['X-Session-Id'] == session_id
), 'session active 2'
time.sleep(2) time.sleep(2)
@@ -187,9 +185,7 @@ class TestJavaApplication(TestApplicationJava):
} }
) )
assert ( assert resp['headers']['X-Session-Id'] == session_id, 'session active 3'
resp['headers']['X-Session-Id'] == session_id
), 'session active 3'
def test_java_application_session_inactive(self): def test_java_application_session_inactive(self):
self.load('session_inactive') self.load('session_inactive')
@@ -213,9 +209,7 @@ class TestJavaApplication(TestApplicationJava):
} }
) )
assert ( assert resp['headers']['X-Session-Id'] != session_id, 'session inactive'
resp['headers']['X-Session-Id'] != session_id
), 'session inactive'
def test_java_application_session_invalidate(self): def test_java_application_session_invalidate(self):
self.load('session_invalidate') self.load('session_invalidate')
@@ -391,9 +385,7 @@ class TestJavaApplication(TestApplicationJava):
assert ( assert (
headers['X-Content-Type'] == 'text/plain;charset=utf-8' headers['X-Content-Type'] == 'text/plain;charset=utf-8'
), '#1 response Content-Type' ), '#1 response Content-Type'
assert ( assert headers['X-Character-Encoding'] == 'utf-8', '#1 response charset'
headers['X-Character-Encoding'] == 'utf-8'
), '#1 response charset'
headers = self.get(url='/2')['headers'] headers = self.get(url='/2')['headers']
@@ -445,15 +437,11 @@ class TestJavaApplication(TestApplicationJava):
headers = self.get(url='/6')['headers'] headers = self.get(url='/6')['headers']
assert ( assert ('Content-Type' in headers) == False, '#6 no Content-Type header'
'Content-Type' in headers
) == False, '#6 no Content-Type header'
assert ( assert (
'X-Content-Type' in headers 'X-Content-Type' in headers
) == False, '#6 no response Content-Type' ) == False, '#6 no response Content-Type'
assert ( assert headers['X-Character-Encoding'] == 'utf-8', '#6 response charset'
headers['X-Character-Encoding'] == 'utf-8'
), '#6 response charset'
headers = self.get(url='/7')['headers'] headers = self.get(url='/7')['headers']
@@ -463,9 +451,7 @@ class TestJavaApplication(TestApplicationJava):
assert ( assert (
headers['X-Content-Type'] == 'text/plain;charset=utf-8' headers['X-Content-Type'] == 'text/plain;charset=utf-8'
), '#7 response Content-Type' ), '#7 response Content-Type'
assert ( assert headers['X-Character-Encoding'] == 'utf-8', '#7 response charset'
headers['X-Character-Encoding'] == 'utf-8'
), '#7 response charset'
headers = self.get(url='/8')['headers'] headers = self.get(url='/8')['headers']
@@ -475,9 +461,7 @@ class TestJavaApplication(TestApplicationJava):
assert ( assert (
headers['X-Content-Type'] == 'text/html;charset=utf-8' headers['X-Content-Type'] == 'text/html;charset=utf-8'
), '#8 response Content-Type' ), '#8 response Content-Type'
assert ( assert headers['X-Character-Encoding'] == 'utf-8', '#8 response charset'
headers['X-Character-Encoding'] == 'utf-8'
), '#8 response charset'
def test_java_application_welcome_files(self): def test_java_application_welcome_files(self):
self.load('welcome_files') self.load('welcome_files')
@@ -490,9 +474,7 @@ class TestJavaApplication(TestApplicationJava):
resp = self.get(url='/dir1/') resp = self.get(url='/dir1/')
assert ( assert ('This is index.txt.' in resp['body']) == True, 'dir1 index body'
'This is index.txt.' in resp['body']
) == True, 'dir1 index body'
assert resp['headers']['X-TXT-Filter'] == '1', 'TXT Filter header' assert resp['headers']['X-TXT-Filter'] == '1', 'TXT Filter header'
headers = self.get(url='/dir2/')['headers'] headers = self.get(url='/dir2/')['headers']
@@ -655,9 +637,7 @@ class TestJavaApplication(TestApplicationJava):
assert ( assert (
headers['X-FORWARD-Id'] == 'data' headers['X-FORWARD-Id'] == 'data'
), 'forward request servlet mapping' ), 'forward request servlet mapping'
assert ( assert headers['X-FORWARD-Request-URI'] == '/fwd', 'forward request uri'
headers['X-FORWARD-Request-URI'] == '/fwd'
), 'forward request uri'
assert ( assert (
headers['X-FORWARD-Servlet-Path'] == '/fwd' headers['X-FORWARD-Servlet-Path'] == '/fwd'
), 'forward request servlet path' ), 'forward request servlet path'
@@ -1003,9 +983,7 @@ class TestJavaApplication(TestApplicationJava):
) )
assert resp['status'] == 200, 'multipart status' assert resp['status'] == 200, 'multipart status'
assert re.search( assert re.search(r'sample\.txt created', resp['body']), 'multipart body'
r'sample\.txt created', resp['body']
), 'multipart body'
assert ( assert (
self.search_in_log( self.search_in_log(
r'^Data from sample file$', name=reldst + '/sample.txt' r'^Data from sample file$', name=reldst + '/sample.txt'

View File

@@ -11,7 +11,7 @@ class TestJavaIsolationRootfs(TestApplicationJava):
def setup_method(self, is_su): def setup_method(self, is_su):
if not is_su: if not is_su:
return pytest.skip('require root')
os.makedirs(option.temp_dir + '/jars') os.makedirs(option.temp_dir + '/jars')
os.makedirs(option.temp_dir + '/tmp') os.makedirs(option.temp_dir + '/tmp')
@@ -61,7 +61,8 @@ class TestJavaIsolationRootfs(TestApplicationJava):
self.load('empty_war', isolation=isolation) self.load('empty_war', isolation=isolation)
assert 'success' in self.conf( assert 'success' in self.conf(
'"/"', '/config/applications/empty_war/working_directory', '"/"',
'/config/applications/empty_war/working_directory',
) )
assert 'success' in self.conf( assert 'success' in self.conf(

View File

@@ -869,9 +869,7 @@ class TestJavaWebsockets(TestApplicationJava):
frame = self.ws.frame_read(sock) frame = self.ws.frame_read(sock)
if frame['opcode'] == self.ws.OP_TEXT: if frame['opcode'] == self.ws.OP_TEXT:
self.check_frame( self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
frame, True, self.ws.OP_TEXT, 'fragment1fragment2'
)
frame = None frame = None
self.check_close(sock, 1002, frame=frame) self.check_close(sock, 1002, frame=frame)
@@ -1116,7 +1114,7 @@ class TestJavaWebsockets(TestApplicationJava):
_, sock, _ = self.ws.upgrade() _, sock, _ = self.ws.upgrade()
self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2 ** 10) self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2**10)
self.ws.frame_write(sock, self.ws.OP_TEXT, payload) self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close()) self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
@@ -1278,62 +1276,62 @@ class TestJavaWebsockets(TestApplicationJava):
def check_message(opcode, f_size): def check_message(opcode, f_size):
if opcode == self.ws.OP_TEXT: if opcode == self.ws.OP_TEXT:
payload = '*' * 4 * 2 ** 20 payload = '*' * 4 * 2**20
else: else:
payload = b'*' * 4 * 2 ** 20 payload = b'*' * 4 * 2**20
self.ws.message(sock, opcode, payload, fragmention_size=f_size) self.ws.message(sock, opcode, payload, fragmention_size=f_size)
frame = self.ws.frame_read(sock, read_timeout=5) frame = self.ws.frame_read(sock, read_timeout=5)
self.check_frame(frame, True, opcode, payload) self.check_frame(frame, True, opcode, payload)
check_payload(op_text, 64 * 2 ** 10) # 9_1_1 check_payload(op_text, 64 * 2**10) # 9_1_1
check_payload(op_text, 256 * 2 ** 10) # 9_1_2 check_payload(op_text, 256 * 2**10) # 9_1_2
check_payload(op_text, 2 ** 20) # 9_1_3 check_payload(op_text, 2**20) # 9_1_3
check_payload(op_text, 4 * 2 ** 20) # 9_1_4 check_payload(op_text, 4 * 2**20) # 9_1_4
check_payload(op_text, 8 * 2 ** 20) # 9_1_5 check_payload(op_text, 8 * 2**20) # 9_1_5
check_payload(op_text, 16 * 2 ** 20) # 9_1_6 check_payload(op_text, 16 * 2**20) # 9_1_6
check_payload(op_binary, 64 * 2 ** 10) # 9_2_1 check_payload(op_binary, 64 * 2**10) # 9_2_1
check_payload(op_binary, 256 * 2 ** 10) # 9_2_2 check_payload(op_binary, 256 * 2**10) # 9_2_2
check_payload(op_binary, 2 ** 20) # 9_2_3 check_payload(op_binary, 2**20) # 9_2_3
check_payload(op_binary, 4 * 2 ** 20) # 9_2_4 check_payload(op_binary, 4 * 2**20) # 9_2_4
check_payload(op_binary, 8 * 2 ** 20) # 9_2_5 check_payload(op_binary, 8 * 2**20) # 9_2_5
check_payload(op_binary, 16 * 2 ** 20) # 9_2_6 check_payload(op_binary, 16 * 2**20) # 9_2_6
if option.system != 'Darwin' and option.system != 'FreeBSD': if option.system != 'Darwin' and option.system != 'FreeBSD':
check_message(op_text, 64) # 9_3_1 check_message(op_text, 64) # 9_3_1
check_message(op_text, 256) # 9_3_2 check_message(op_text, 256) # 9_3_2
check_message(op_text, 2 ** 10) # 9_3_3 check_message(op_text, 2**10) # 9_3_3
check_message(op_text, 4 * 2 ** 10) # 9_3_4 check_message(op_text, 4 * 2**10) # 9_3_4
check_message(op_text, 16 * 2 ** 10) # 9_3_5 check_message(op_text, 16 * 2**10) # 9_3_5
check_message(op_text, 64 * 2 ** 10) # 9_3_6 check_message(op_text, 64 * 2**10) # 9_3_6
check_message(op_text, 256 * 2 ** 10) # 9_3_7 check_message(op_text, 256 * 2**10) # 9_3_7
check_message(op_text, 2 ** 20) # 9_3_8 check_message(op_text, 2**20) # 9_3_8
check_message(op_text, 4 * 2 ** 20) # 9_3_9 check_message(op_text, 4 * 2**20) # 9_3_9
check_message(op_binary, 64) # 9_4_1 check_message(op_binary, 64) # 9_4_1
check_message(op_binary, 256) # 9_4_2 check_message(op_binary, 256) # 9_4_2
check_message(op_binary, 2 ** 10) # 9_4_3 check_message(op_binary, 2**10) # 9_4_3
check_message(op_binary, 4 * 2 ** 10) # 9_4_4 check_message(op_binary, 4 * 2**10) # 9_4_4
check_message(op_binary, 16 * 2 ** 10) # 9_4_5 check_message(op_binary, 16 * 2**10) # 9_4_5
check_message(op_binary, 64 * 2 ** 10) # 9_4_6 check_message(op_binary, 64 * 2**10) # 9_4_6
check_message(op_binary, 256 * 2 ** 10) # 9_4_7 check_message(op_binary, 256 * 2**10) # 9_4_7
check_message(op_binary, 2 ** 20) # 9_4_8 check_message(op_binary, 2**20) # 9_4_8
check_message(op_binary, 4 * 2 ** 20) # 9_4_9 check_message(op_binary, 4 * 2**20) # 9_4_9
check_payload(op_text, 2 ** 20, chopsize=64) # 9_5_1 check_payload(op_text, 2**20, chopsize=64) # 9_5_1
check_payload(op_text, 2 ** 20, chopsize=128) # 9_5_2 check_payload(op_text, 2**20, chopsize=128) # 9_5_2
check_payload(op_text, 2 ** 20, chopsize=256) # 9_5_3 check_payload(op_text, 2**20, chopsize=256) # 9_5_3
check_payload(op_text, 2 ** 20, chopsize=512) # 9_5_4 check_payload(op_text, 2**20, chopsize=512) # 9_5_4
check_payload(op_text, 2 ** 20, chopsize=1024) # 9_5_5 check_payload(op_text, 2**20, chopsize=1024) # 9_5_5
check_payload(op_text, 2 ** 20, chopsize=2048) # 9_5_6 check_payload(op_text, 2**20, chopsize=2048) # 9_5_6
check_payload(op_binary, 2 ** 20, chopsize=64) # 9_6_1 check_payload(op_binary, 2**20, chopsize=64) # 9_6_1
check_payload(op_binary, 2 ** 20, chopsize=128) # 9_6_2 check_payload(op_binary, 2**20, chopsize=128) # 9_6_2
check_payload(op_binary, 2 ** 20, chopsize=256) # 9_6_3 check_payload(op_binary, 2**20, chopsize=256) # 9_6_3
check_payload(op_binary, 2 ** 20, chopsize=512) # 9_6_4 check_payload(op_binary, 2**20, chopsize=512) # 9_6_4
check_payload(op_binary, 2 ** 20, chopsize=1024) # 9_6_5 check_payload(op_binary, 2**20, chopsize=1024) # 9_6_5
check_payload(op_binary, 2 ** 20, chopsize=2048) # 9_6_6 check_payload(op_binary, 2**20, chopsize=2048) # 9_6_6
self.close_connection(sock) self.close_connection(sock)

View File

@@ -218,9 +218,7 @@ class TestNodeApplication(TestApplicationNode):
def test_node_application_status_message(self): def test_node_application_status_message(self):
self.load('status_message') self.load('status_message')
assert re.search( assert re.search(r'200 blah', self.get(raw_resp=True)), 'status message'
r'200 blah', self.get(raw_resp=True)
), 'status message'
def test_node_application_get_header_type(self): def test_node_application_get_header_type(self):
self.load('get_header_type') self.load('get_header_type')

View File

@@ -888,9 +888,7 @@ class TestNodeWebsockets(TestApplicationNode):
frame = self.ws.frame_read(sock) frame = self.ws.frame_read(sock)
if frame['opcode'] == self.ws.OP_TEXT: if frame['opcode'] == self.ws.OP_TEXT:
self.check_frame( self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
frame, True, self.ws.OP_TEXT, 'fragment1fragment2'
)
frame = None frame = None
self.check_close(sock, 1002, frame=frame) self.check_close(sock, 1002, frame=frame)
@@ -1135,7 +1133,7 @@ class TestNodeWebsockets(TestApplicationNode):
_, sock, _ = self.ws.upgrade() _, sock, _ = self.ws.upgrade()
self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2 ** 10) self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2**10)
self.ws.frame_write(sock, self.ws.OP_TEXT, payload) self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close()) self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
@@ -1297,62 +1295,62 @@ class TestNodeWebsockets(TestApplicationNode):
def check_message(opcode, f_size): def check_message(opcode, f_size):
if opcode == self.ws.OP_TEXT: if opcode == self.ws.OP_TEXT:
payload = '*' * 4 * 2 ** 20 payload = '*' * 4 * 2**20
else: else:
payload = b'*' * 4 * 2 ** 20 payload = b'*' * 4 * 2**20
self.ws.message(sock, opcode, payload, fragmention_size=f_size) self.ws.message(sock, opcode, payload, fragmention_size=f_size)
frame = self.ws.frame_read(sock, read_timeout=5) frame = self.ws.frame_read(sock, read_timeout=5)
self.check_frame(frame, True, opcode, payload) self.check_frame(frame, True, opcode, payload)
check_payload(op_text, 64 * 2 ** 10) # 9_1_1 check_payload(op_text, 64 * 2**10) # 9_1_1
check_payload(op_text, 256 * 2 ** 10) # 9_1_2 check_payload(op_text, 256 * 2**10) # 9_1_2
check_payload(op_text, 2 ** 20) # 9_1_3 check_payload(op_text, 2**20) # 9_1_3
check_payload(op_text, 4 * 2 ** 20) # 9_1_4 check_payload(op_text, 4 * 2**20) # 9_1_4
check_payload(op_text, 8 * 2 ** 20) # 9_1_5 check_payload(op_text, 8 * 2**20) # 9_1_5
check_payload(op_text, 16 * 2 ** 20) # 9_1_6 check_payload(op_text, 16 * 2**20) # 9_1_6
check_payload(op_binary, 64 * 2 ** 10) # 9_2_1 check_payload(op_binary, 64 * 2**10) # 9_2_1
check_payload(op_binary, 256 * 2 ** 10) # 9_2_2 check_payload(op_binary, 256 * 2**10) # 9_2_2
check_payload(op_binary, 2 ** 20) # 9_2_3 check_payload(op_binary, 2**20) # 9_2_3
check_payload(op_binary, 4 * 2 ** 20) # 9_2_4 check_payload(op_binary, 4 * 2**20) # 9_2_4
check_payload(op_binary, 8 * 2 ** 20) # 9_2_5 check_payload(op_binary, 8 * 2**20) # 9_2_5
check_payload(op_binary, 16 * 2 ** 20) # 9_2_6 check_payload(op_binary, 16 * 2**20) # 9_2_6
if option.system != 'Darwin' and option.system != 'FreeBSD': if option.system != 'Darwin' and option.system != 'FreeBSD':
check_message(op_text, 64) # 9_3_1 check_message(op_text, 64) # 9_3_1
check_message(op_text, 256) # 9_3_2 check_message(op_text, 256) # 9_3_2
check_message(op_text, 2 ** 10) # 9_3_3 check_message(op_text, 2**10) # 9_3_3
check_message(op_text, 4 * 2 ** 10) # 9_3_4 check_message(op_text, 4 * 2**10) # 9_3_4
check_message(op_text, 16 * 2 ** 10) # 9_3_5 check_message(op_text, 16 * 2**10) # 9_3_5
check_message(op_text, 64 * 2 ** 10) # 9_3_6 check_message(op_text, 64 * 2**10) # 9_3_6
check_message(op_text, 256 * 2 ** 10) # 9_3_7 check_message(op_text, 256 * 2**10) # 9_3_7
check_message(op_text, 2 ** 20) # 9_3_8 check_message(op_text, 2**20) # 9_3_8
check_message(op_text, 4 * 2 ** 20) # 9_3_9 check_message(op_text, 4 * 2**20) # 9_3_9
check_message(op_binary, 64) # 9_4_1 check_message(op_binary, 64) # 9_4_1
check_message(op_binary, 256) # 9_4_2 check_message(op_binary, 256) # 9_4_2
check_message(op_binary, 2 ** 10) # 9_4_3 check_message(op_binary, 2**10) # 9_4_3
check_message(op_binary, 4 * 2 ** 10) # 9_4_4 check_message(op_binary, 4 * 2**10) # 9_4_4
check_message(op_binary, 16 * 2 ** 10) # 9_4_5 check_message(op_binary, 16 * 2**10) # 9_4_5
check_message(op_binary, 64 * 2 ** 10) # 9_4_6 check_message(op_binary, 64 * 2**10) # 9_4_6
check_message(op_binary, 256 * 2 ** 10) # 9_4_7 check_message(op_binary, 256 * 2**10) # 9_4_7
check_message(op_binary, 2 ** 20) # 9_4_8 check_message(op_binary, 2**20) # 9_4_8
check_message(op_binary, 4 * 2 ** 20) # 9_4_9 check_message(op_binary, 4 * 2**20) # 9_4_9
check_payload(op_text, 2 ** 20, chopsize=64) # 9_5_1 check_payload(op_text, 2**20, chopsize=64) # 9_5_1
check_payload(op_text, 2 ** 20, chopsize=128) # 9_5_2 check_payload(op_text, 2**20, chopsize=128) # 9_5_2
check_payload(op_text, 2 ** 20, chopsize=256) # 9_5_3 check_payload(op_text, 2**20, chopsize=256) # 9_5_3
check_payload(op_text, 2 ** 20, chopsize=512) # 9_5_4 check_payload(op_text, 2**20, chopsize=512) # 9_5_4
check_payload(op_text, 2 ** 20, chopsize=1024) # 9_5_5 check_payload(op_text, 2**20, chopsize=1024) # 9_5_5
check_payload(op_text, 2 ** 20, chopsize=2048) # 9_5_6 check_payload(op_text, 2**20, chopsize=2048) # 9_5_6
check_payload(op_binary, 2 ** 20, chopsize=64) # 9_6_1 check_payload(op_binary, 2**20, chopsize=64) # 9_6_1
check_payload(op_binary, 2 ** 20, chopsize=128) # 9_6_2 check_payload(op_binary, 2**20, chopsize=128) # 9_6_2
check_payload(op_binary, 2 ** 20, chopsize=256) # 9_6_3 check_payload(op_binary, 2**20, chopsize=256) # 9_6_3
check_payload(op_binary, 2 ** 20, chopsize=512) # 9_6_4 check_payload(op_binary, 2**20, chopsize=512) # 9_6_4
check_payload(op_binary, 2 ** 20, chopsize=1024) # 9_6_5 check_payload(op_binary, 2**20, chopsize=1024) # 9_6_5
check_payload(op_binary, 2 ** 20, chopsize=2048) # 9_6_6 check_payload(op_binary, 2**20, chopsize=2048) # 9_6_6
self.close_connection(sock) self.close_connection(sock)

View File

@@ -134,8 +134,7 @@ class TestPerlApplication(TestApplicationPerl):
assert self.get()['body'] == '1', 'errors result' assert self.get()['body'] == '1', 'errors result'
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application') is not None
is not None
), 'errors print' ), 'errors print'
def test_perl_application_header_equal_names(self): def test_perl_application_header_equal_names(self):

View File

@@ -419,9 +419,7 @@ opcache.preload_user = %(user)s
body = self.get()['body'] body = self.get()['body']
assert not re.search( assert not re.search(r'time: \d+', body), 'disable_functions comma time'
r'time: \d+', body
), 'disable_functions comma time'
assert not re.search( assert not re.search(
r'exec: \/\w+', body r'exec: \/\w+', body
), 'disable_functions comma exec' ), 'disable_functions comma exec'
@@ -498,9 +496,7 @@ opcache.preload_user = %(user)s
body = self.get()['body'] body = self.get()['body']
assert not re.search( assert not re.search(r'time: \d+', body), 'disable_functions space time'
r'time: \d+', body
), 'disable_functions space time'
assert not re.search( assert not re.search(
r'exec: \/\w+', body r'exec: \/\w+', body
), 'disable_functions space exec' ), 'disable_functions space exec'
@@ -671,7 +667,8 @@ opcache.preload_user = %(user)s
assert resp['body'] == script_cwd, 'default cwd' assert resp['body'] == script_cwd, 'default cwd'
assert 'success' in self.conf( assert 'success' in self.conf(
'"' + option.test_dir + '"', 'applications/cwd/working_directory', '"' + option.test_dir + '"',
'applications/cwd/working_directory',
) )
resp = self.get() resp = self.get()

View File

@@ -75,8 +75,7 @@ Content-Length: 10
"type": self.get_application_type(), "type": self.get_application_type(),
"processes": {"spare": 0}, "processes": {"spare": 0},
"path": option.test_dir + "/python/mirror", "path": option.test_dir + "/python/mirror",
"working_directory": option.test_dir "working_directory": option.test_dir + "/python/mirror",
+ "/python/mirror",
"module": "wsgi", "module": "wsgi",
}, },
"custom_header": { "custom_header": {
@@ -126,8 +125,7 @@ Content-Length: 10
"type": self.get_application_type(), "type": self.get_application_type(),
"processes": {"spare": 0}, "processes": {"spare": 0},
"path": option.test_dir + "/python/mirror", "path": option.test_dir + "/python/mirror",
"working_directory": option.test_dir "working_directory": option.test_dir + "/python/mirror",
+ "/python/mirror",
"module": "wsgi", "module": "wsgi",
} }
}, },
@@ -502,8 +500,7 @@ Content-Length: 10
"type": self.get_application_type(), "type": self.get_application_type(),
"processes": {"spare": 0}, "processes": {"spare": 0},
"path": option.test_dir + "/python/mirror", "path": option.test_dir + "/python/mirror",
"working_directory": option.test_dir "working_directory": option.test_dir + "/python/mirror",
+ "/python/mirror",
"module": "wsgi", "module": "wsgi",
}, },
}, },

View File

@@ -90,12 +90,13 @@ class TestProxyChunked(TestApplicationPython):
assert 'success' in self.conf( assert 'success' in self.conf(
{ {
"listeners": {"*:7080": {"pass": "routes"},}, "listeners": {
"*:7080": {"pass": "routes"},
},
"routes": [ "routes": [
{ {
"action": { "action": {
"proxy": "http://127.0.0.1:" "proxy": "http://127.0.0.1:" + str(self.SERVER_PORT)
+ str(self.SERVER_PORT)
} }
} }
], ],
@@ -166,9 +167,7 @@ class TestProxyChunked(TestApplicationPython):
assert ( assert (
self.get_http10( self.get_http10(
body=self.chunks( body=self.chunks([('1', hex(i % 16)[2:]) for i in range(4096)]),
[('1', hex(i % 16)[2:]) for i in range(4096)]
),
)['body'] )['body']
== part * 256 == part * 256
) )
@@ -210,8 +209,7 @@ class TestProxyChunked(TestApplicationPython):
assert resp['body'][-5:] != '0\r\n\r\n', 'no zero chunk' assert resp['body'][-5:] != '0\r\n\r\n', 'no zero chunk'
assert ( assert (
self.get_http10(body='\r\n\r\n80000000\r\nA X 100')['status'] self.get_http10(body='\r\n\r\n80000000\r\nA X 100')['status'] == 200
== 200
) )
assert ( assert (
self.get_http10(body='\r\n\r\n10000000000000000\r\nA X 100')[ self.get_http10(body='\r\n\r\n10000000000000000\r\nA X 100')[

View File

@@ -735,9 +735,7 @@ last line: 987654321
'nobody uid user=nobody group=%s' % group 'nobody uid user=nobody group=%s' % group
) )
assert obj['GID'] == group_id, ( assert obj['GID'] == group_id, 'nobody gid user=nobody group=%s' % group
'nobody gid user=nobody group=%s' % group
)
self.load('user_group', group=group) self.load('user_group', group=group)

View File

@@ -56,9 +56,7 @@ class TestPythonIsolation(TestApplicationPython):
ret = self.getjson(url='/?path=/app/python/ns_inspect') ret = self.getjson(url='/?path=/app/python/ns_inspect')
assert ( assert ret['body']['FileExists'] == True, 'application exists in rootfs'
ret['body']['FileExists'] == True
), 'application exists in rootfs'
def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir): def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir):
if not is_su: if not is_su:
@@ -93,8 +91,7 @@ class TestPythonIsolation(TestApplicationPython):
self.load('ns_inspect', isolation=isolation) self.load('ns_inspect', isolation=isolation)
assert ( assert (
self.getjson(url='/?path=/proc/self')['body']['FileExists'] self.getjson(url='/?path=/proc/self')['body']['FileExists'] == False
== False
), 'no /proc/self' ), 'no /proc/self'
isolation['automount']['procfs'] = True isolation['automount']['procfs'] = True

View File

@@ -35,6 +35,4 @@ class TestPythonIsolation(TestApplicationPython):
ret = self.getjson(url='/?path=/app/python/ns_inspect') ret = self.getjson(url='/?path=/app/python/ns_inspect')
assert ( assert ret['body']['FileExists'] == True, 'application exists in rootfs'
ret['body']['FileExists'] == True
), 'application exists in rootfs'

View File

@@ -82,8 +82,7 @@ class TestRespawn(TestApplicationPython):
skip_alert(r'process %s exited on signal 9' % pid) skip_alert(r'process %s exited on signal 9' % pid)
assert ( assert (
self.wait_for_process(self.PATTERN_CONTROLLER, unit_pid) self.wait_for_process(self.PATTERN_CONTROLLER, unit_pid) is not None
is not None
) )
assert self.get()['status'] == 200 assert self.get()['status'] == 200

View File

@@ -12,7 +12,10 @@ class TestRouting(TestApplicationPython):
{ {
"listeners": {"*:7080": {"pass": "routes"}}, "listeners": {"*:7080": {"pass": "routes"}},
"routes": [ "routes": [
{"match": {"method": "GET"}, "action": {"return": 200},} {
"match": {"method": "GET"},
"action": {"return": 200},
}
], ],
"applications": {}, "applications": {},
} }
@@ -490,11 +493,15 @@ class TestRouting(TestApplicationPython):
'routes/0/action', 'routes/0/action',
), 'proxy share' ), 'proxy share'
assert 'error' in self.conf( assert 'error' in self.conf(
{"proxy": "http://127.0.0.1:7081", "pass": "applications/app",}, {
"proxy": "http://127.0.0.1:7081",
"pass": "applications/app",
},
'routes/0/action', 'routes/0/action',
), 'proxy pass' ), 'proxy pass'
assert 'error' in self.conf( assert 'error' in self.conf(
{"share": temp_dir, "pass": "applications/app"}, 'routes/0/action', {"share": temp_dir, "pass": "applications/app"},
'routes/0/action',
), 'share pass' ), 'share pass'
def test_routes_rules_two(self): def test_routes_rules_two(self):
@@ -693,7 +700,8 @@ class TestRouting(TestApplicationPython):
assert self.post()['status'] == 404, 'routes edit POST' assert self.post()['status'] == 404, 'routes edit POST'
assert 'success' in self.conf_post( assert 'success' in self.conf_post(
{"match": {"method": "POST"}, "action": {"return": 200}}, 'routes', {"match": {"method": "POST"}, "action": {"return": 200}},
'routes',
), 'routes edit configure 2' ), 'routes edit configure 2'
assert 'GET' == self.conf_get( assert 'GET' == self.conf_get(
'routes/0/match/method' 'routes/0/match/method'
@@ -733,7 +741,8 @@ class TestRouting(TestApplicationPython):
assert self.post()['status'] == 404, 'routes edit POST 5' assert self.post()['status'] == 404, 'routes edit POST 5'
assert 'success' in self.conf_post( assert 'success' in self.conf_post(
{"match": {"method": "POST"}, "action": {"return": 200}}, 'routes', {"match": {"method": "POST"}, "action": {"return": 200}},
'routes',
), 'routes edit configure 6' ), 'routes edit configure 6'
assert self.get()['status'] == 404, 'routes edit GET 6' assert self.get()['status'] == 404, 'routes edit GET 6'
@@ -1042,9 +1051,7 @@ class TestRouting(TestApplicationPython):
def check_headers(hds): def check_headers(hds):
hds = dict({"Host": "localhost", "Connection": "close"}, **hds) hds = dict({"Host": "localhost", "Connection": "close"}, **hds)
assert ( assert self.get(headers=hds)['status'] == 200, 'headers array match'
self.get(headers=hds)['status'] == 200
), 'headers array match'
def check_headers_404(hds): def check_headers_404(hds):
hds = dict({"Host": "localhost", "Connection": "close"}, **hds) hds = dict({"Host": "localhost", "Connection": "close"}, **hds)
@@ -1262,9 +1269,7 @@ class TestRouting(TestApplicationPython):
self.get(url='/?foo=bar&blah=test')['status'] == 200 self.get(url='/?foo=bar&blah=test')['status'] == 200
), 'multiple 2' ), 'multiple 2'
assert self.get(url='/?foo=bar&blah')['status'] == 404, 'multiple 3' assert self.get(url='/?foo=bar&blah')['status'] == 404, 'multiple 3'
assert ( assert self.get(url='/?foo=bar&blah=tes')['status'] == 404, 'multiple 4'
self.get(url='/?foo=bar&blah=tes')['status'] == 404
), 'multiple 4'
assert ( assert (
self.get(url='/?foo=b%61r&bl%61h=t%65st')['status'] == 200 self.get(url='/?foo=b%61r&bl%61h=t%65st')['status'] == 200
), 'multiple 5' ), 'multiple 5'
@@ -1494,9 +1499,7 @@ class TestRouting(TestApplicationPython):
sock, port = sock_port() sock, port = sock_port()
sock2, port2 = sock_port() sock2, port2 = sock_port()
self.route_match( self.route_match({"source": "127.0.0.1:" + str(port) + "-" + str(port)})
{"source": "127.0.0.1:" + str(port) + "-" + str(port)}
)
assert self.get(sock=sock)['status'] == 200, 'range single' assert self.get(sock=sock)['status'] == 200, 'range single'
assert self.get(sock=sock2)['status'] == 404, 'range single 2' assert self.get(sock=sock2)['status'] == 404, 'range single 2'
@@ -1544,7 +1547,10 @@ class TestRouting(TestApplicationPython):
def test_routes_source_addr(self): def test_routes_source_addr(self):
assert 'success' in self.conf( assert 'success' in self.conf(
{"*:7080": {"pass": "routes"}, "[::1]:7081": {"pass": "routes"},}, {
"*:7080": {"pass": "routes"},
"[::1]:7081": {"pass": "routes"},
},
'listeners', 'listeners',
), 'source listeners configure' ), 'source listeners configure'
@@ -1650,7 +1656,10 @@ class TestRouting(TestApplicationPython):
def test_routes_source_cidr(self): def test_routes_source_cidr(self):
assert 'success' in self.conf( assert 'success' in self.conf(
{"*:7080": {"pass": "routes"}, "[::1]:7081": {"pass": "routes"},}, {
"*:7080": {"pass": "routes"},
"[::1]:7081": {"pass": "routes"},
},
'listeners', 'listeners',
), 'source listeners configure' ), 'source listeners configure'

View File

@@ -175,8 +175,7 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application') is not None
is not None
), 'errors puts' ), 'errors puts'
def test_ruby_application_errors_puts_int(self): def test_ruby_application_errors_puts_int(self):
@@ -194,8 +193,7 @@ class TestRubyApplication(TestApplicationRuby):
self.get() self.get()
assert ( assert (
self.wait_for_record(r'\[error\].+Error in application') self.wait_for_record(r'\[error\].+Error in application') is not None
is not None
), 'errors write' ), 'errors write'
def test_ruby_application_errors_write_to_s_custom(self): def test_ruby_application_errors_write_to_s_custom(self):
@@ -229,7 +227,8 @@ class TestRubyApplication(TestApplicationRuby):
try: try:
locales = ( locales = (
subprocess.check_output( subprocess.check_output(
['locale', '-a'], stderr=subprocess.STDOUT, ['locale', '-a'],
stderr=subprocess.STDOUT,
) )
.decode() .decode()
.split('\n') .split('\n')

View File

@@ -81,7 +81,10 @@ class TestRubyHooks(TestApplicationRuby):
threads = 1 threads = 1
self.load( self.load(
'hooks', processes=processes, threads=threads, hooks='multiple.rb', 'hooks',
processes=processes,
threads=threads,
hooks='multiple.rb',
) )
hooked = self._wait_cookie('worker_boot.*', processes) hooked = self._wait_cookie('worker_boot.*', processes)

View File

@@ -34,11 +34,13 @@ class TestRubyIsolation(TestApplicationRuby):
self.load('status_int', isolation=isolation) self.load('status_int', isolation=isolation)
assert 'success' in self.conf( assert 'success' in self.conf(
'"/ruby/status_int/config.ru"', 'applications/status_int/script', '"/ruby/status_int/config.ru"',
'applications/status_int/script',
) )
assert 'success' in self.conf( assert 'success' in self.conf(
'"/ruby/status_int"', 'applications/status_int/working_directory', '"/ruby/status_int"',
'applications/status_int/working_directory',
) )
assert self.get()['status'] == 200, 'status int' assert self.get()['status'] == 200, 'status int'

View File

@@ -207,9 +207,7 @@ Connection: close
{"unix:" + addr: {'application': 'body_generate'}}, 'listeners' {"unix:" + addr: {'application': 'body_generate'}}, 'listeners'
) )
assert 'success' in self.conf( assert 'success' in self.conf({'http': {'send_timeout': 1}}, 'settings')
{'http': {'send_timeout': 1}}, 'settings'
)
data = req(addr, data_len) data = req(addr, data_len)
assert re.search(r'200 OK', data), 'send timeout status' assert re.search(r'200 OK', data), 'send timeout status'
@@ -237,14 +235,10 @@ Connection: close
assert self.get()['status'] == 200, 'init' assert self.get()['status'] == 200, 'init'
assert 'success' in self.conf( assert 'success' in self.conf({'http': {'idle_timeout': 2}}, 'settings')
{'http': {'idle_timeout': 2}}, 'settings'
)
assert req()['status'] == 408, 'status idle timeout' assert req()['status'] == 408, 'status idle timeout'
assert 'success' in self.conf( assert 'success' in self.conf({'http': {'idle_timeout': 7}}, 'settings')
{'http': {'idle_timeout': 7}}, 'settings'
)
assert req()['status'] == 200, 'status idle timeout 2' assert req()['status'] == 200, 'status idle timeout 2'
def test_settings_idle_timeout_2(self): def test_settings_idle_timeout_2(self):
@@ -259,14 +253,10 @@ Connection: close
assert self.get()['status'] == 200, 'init' assert self.get()['status'] == 200, 'init'
assert 'success' in self.conf( assert 'success' in self.conf({'http': {'idle_timeout': 1}}, 'settings')
{'http': {'idle_timeout': 1}}, 'settings'
)
assert req()['status'] == 408, 'status idle timeout' assert req()['status'] == 408, 'status idle timeout'
assert 'success' in self.conf( assert 'success' in self.conf({'http': {'idle_timeout': 7}}, 'settings')
{'http': {'idle_timeout': 7}}, 'settings'
)
assert req()['status'] == 200, 'status idle timeout 2' assert req()['status'] == 200, 'status idle timeout 2'
def test_settings_max_body_size(self): def test_settings_max_body_size(self):

View File

@@ -133,7 +133,8 @@ class TestStatic(TestApplicationProto):
def test_static_space_in_name(self, temp_dir): def test_static_space_in_name(self, temp_dir):
os.rename( os.rename(
temp_dir + '/assets/dir/file', temp_dir + '/assets/dir/fi le', temp_dir + '/assets/dir/file',
temp_dir + '/assets/dir/fi le',
) )
assert waitforfiles(temp_dir + '/assets/dir/fi le') assert waitforfiles(temp_dir + '/assets/dir/fi le')
assert self.get(url='/dir/fi le')['body'] == 'blah', 'file name' assert self.get(url='/dir/fi le')['body'] == 'blah', 'file name'
@@ -154,9 +155,7 @@ class TestStatic(TestApplicationProto):
assert ( assert (
self.get(url='/ di r %2Ffi le')['body'] == 'blah' self.get(url='/ di r %2Ffi le')['body'] == 'blah'
), 'slash encoded' ), 'slash encoded'
assert ( assert self.get(url='/ di r /fi%20le')['body'] == 'blah', 'file encoded'
self.get(url='/ di r /fi%20le')['body'] == 'blah'
), 'file encoded'
assert ( assert (
self.get(url='/%20di%20r%20%2Ffi%20le')['body'] == 'blah' self.get(url='/%20di%20r%20%2Ffi%20le')['body'] == 'blah'
), 'encoded' ), 'encoded'
@@ -195,7 +194,8 @@ class TestStatic(TestApplicationProto):
), 'file name 2' ), 'file name 2'
os.rename( os.rename(
temp_dir + '/assets/ di r ', temp_dir + '/assets/ди ректория', temp_dir + '/assets/ di r ',
temp_dir + '/assets/ди ректория',
) )
assert waitforfiles(temp_dir + '/assets/ди ректория/фа йл') assert waitforfiles(temp_dir + '/assets/ди ректория/фа йл')
assert ( assert (
@@ -266,13 +266,14 @@ class TestStatic(TestApplicationProto):
self.get(url='/')['headers']['Content-Type'] == 'text/plain' self.get(url='/')['headers']['Content-Type'] == 'text/plain'
), 'mime_types index default' ), 'mime_types index default'
assert ( assert (
self.get(url='/dir/file')['headers']['Content-Type'] self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
== 'text/plain'
), 'mime_types file in dir' ), 'mime_types file in dir'
def test_static_mime_types_partial_match(self): def test_static_mime_types_partial_match(self):
assert 'success' in self.conf( assert 'success' in self.conf(
{"text/x-blah": ["ile", "fil", "f", "e", ".file"],}, {
"text/x-blah": ["ile", "fil", "f", "e", ".file"],
},
'settings/http/static/mime_types', 'settings/http/static/mime_types',
), 'configure mime_types' ), 'configure mime_types'
assert 'Content-Type' not in self.get(url='/dir/file'), 'partial match' assert 'Content-Type' not in self.get(url='/dir/file'), 'partial match'
@@ -313,16 +314,14 @@ class TestStatic(TestApplicationProto):
'"file"', 'settings/http/static/mime_types/text%2Fplain' '"file"', 'settings/http/static/mime_types/text%2Fplain'
), 'mime_types add array element' ), 'mime_types add array element'
assert ( assert (
self.get(url='/dir/file')['headers']['Content-Type'] self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
== 'text/plain'
), 'mime_types reverted' ), 'mime_types reverted'
assert 'success' in self.conf( assert 'success' in self.conf(
'"file"', 'settings/http/static/mime_types/text%2Fplain' '"file"', 'settings/http/static/mime_types/text%2Fplain'
), 'configure mime_types update' ), 'configure mime_types update'
assert ( assert (
self.get(url='/dir/file')['headers']['Content-Type'] self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
== 'text/plain'
), 'mime_types updated' ), 'mime_types updated'
assert ( assert (
'Content-Type' not in self.get(url='/log.log')['headers'] 'Content-Type' not in self.get(url='/log.log')['headers']
@@ -346,7 +345,10 @@ class TestStatic(TestApplicationProto):
'settings/http/static/mime_types', 'settings/http/static/mime_types',
), 'mime_types same extensions array' ), 'mime_types same extensions array'
assert 'error' in self.conf( assert 'error' in self.conf(
{"text/x-code": [".h", ".c", "readme"], "text/plain": "README",}, {
"text/x-code": [".h", ".c", "readme"],
"text/plain": "README",
},
'settings/http/static/mime_types', 'settings/http/static/mime_types',
), 'mime_types same extensions case insensitive' ), 'mime_types same extensions case insensitive'

View File

@@ -26,13 +26,14 @@ class TestStaticChroot(TestApplicationProto):
def update_action(self, share, chroot): def update_action(self, share, chroot):
return self.conf( return self.conf(
{"share": share, "chroot": chroot}, 'routes/0/action', {"share": share, "chroot": chroot},
'routes/0/action',
) )
def get_custom(self, uri, host): def get_custom(self, uri, host):
return self.get( return self.get(url=uri, headers={'Host': host, 'Connection': 'close'})[
url=uri, headers={'Host': host, 'Connection': 'close'} 'status'
)['status'] ]
def test_static_chroot(self, temp_dir): def test_static_chroot(self, temp_dir):
assert self.get(url='/dir/file')['status'] == 200, 'default chroot' assert self.get(url='/dir/file')['status'] == 200, 'default chroot'
@@ -101,7 +102,8 @@ class TestStaticChroot(TestApplicationProto):
), 'chroot empty absolute' ), 'chroot empty absolute'
assert 'success' in self.conf( assert 'success' in self.conf(
{"share": ".$uri", "chroot": ""}, 'routes/0/action', {"share": ".$uri", "chroot": ""},
'routes/0/action',
), 'configure chroot empty relative' ), 'configure chroot empty relative'
assert ( assert (
@@ -120,13 +122,15 @@ class TestStaticChroot(TestApplicationProto):
assert self.get(url='/dir/file')['status'] == 403, 'relative chroot' assert self.get(url='/dir/file')['status'] == 403, 'relative chroot'
assert 'success' in self.conf( assert 'success' in self.conf(
{"share": ".$uri"}, 'routes/0/action', {"share": ".$uri"},
'routes/0/action',
), 'configure relative share' ), 'configure relative share'
assert self.get(url=self.test_path)['status'] == 200, 'relative share' assert self.get(url=self.test_path)['status'] == 200, 'relative share'
assert 'success' in self.conf( assert 'success' in self.conf(
{"share": ".$uri", "chroot": "."}, 'routes/0/action', {"share": ".$uri", "chroot": "."},
'routes/0/action',
), 'configure relative' ), 'configure relative'
assert self.get(url=self.test_path)['status'] == 200, 'relative' assert self.get(url=self.test_path)['status'] == 200, 'relative'
@@ -208,13 +212,16 @@ class TestStaticChroot(TestApplicationProto):
def test_static_chroot_invalid(self, temp_dir): def test_static_chroot_invalid(self, temp_dir):
assert 'error' in self.conf( assert 'error' in self.conf(
{"share": temp_dir, "chroot": True}, 'routes/0/action', {"share": temp_dir, "chroot": True},
'routes/0/action',
), 'configure chroot error' ), 'configure chroot error'
assert 'error' in self.conf( assert 'error' in self.conf(
{"share": temp_dir, "symlinks": "True"}, 'routes/0/action', {"share": temp_dir, "symlinks": "True"},
'routes/0/action',
), 'configure symlink error' ), 'configure symlink error'
assert 'error' in self.conf( assert 'error' in self.conf(
{"share": temp_dir, "mount": "True"}, 'routes/0/action', {"share": temp_dir, "mount": "True"},
'routes/0/action',
), 'configure mount error' ), 'configure mount error'
assert 'error' in self.update_action( assert 'error' in self.update_action(

View File

@@ -41,9 +41,7 @@ class TestStaticMount(TestApplicationProto):
self._load_conf( self._load_conf(
{ {
"listeners": {"*:7080": {"pass": "routes"}}, "listeners": {"*:7080": {"pass": "routes"}},
"routes": [ "routes": [{"action": {"share": temp_dir + "/assets/dir$uri"}}],
{"action": {"share": temp_dir + "/assets/dir$uri"}}
],
} }
) )

View File

@@ -358,9 +358,7 @@ basicConstraints = critical,CA:TRUE"""
self.add_tls(cert='int') self.add_tls(cert='int')
assert ( assert self.get_ssl()['status'] == 200, 'certificate chain intermediate'
self.get_ssl()['status'] == 200
), 'certificate chain intermediate'
# intermediate server # intermediate server

View File

@@ -178,7 +178,8 @@ basicConstraints = critical,CA:TRUE"""
self.add_tls(["localhost.com", "example.com"]) self.add_tls(["localhost.com", "example.com"])
resp, sock = self.get_ssl( resp, sock = self.get_ssl(
headers={'Content-Length': '0', 'Connection': 'close'}, start=True, headers={'Content-Length': '0', 'Connection': 'close'},
start=True,
) )
assert resp['status'] == 200 assert resp['status'] == 200
assert ( assert (
@@ -272,9 +273,7 @@ basicConstraints = critical,CA:TRUE"""
) )
assert resp['status'] == 200 assert resp['status'] == 200
assert ( assert sock.getpeercert()['subjectAltName'][0][1] == 'alt.localhost.com'
sock.getpeercert()['subjectAltName'][0][1] == 'alt.localhost.com'
)
def test_tls_sni_invalid(self): def test_tls_sni_invalid(self):
self.config_bundles({"localhost": {"subj": "subj1", "alt_names": ''}}) self.config_bundles({"localhost": {"subj": "subj1", "alt_names": ''}})

View File

@@ -17,9 +17,7 @@ class TestTLSTicket(TestApplicationTLS):
prerequisites = {'modules': {'openssl': 'any'}} prerequisites = {'modules': {'openssl': 'any'}}
ticket = 'U1oDTh11mMxODuw12gS0EXX1E/PkZG13cJNQ6m5+6BGlfPTjNlIEw7PSVU3X1gTE' ticket = 'U1oDTh11mMxODuw12gS0EXX1E/PkZG13cJNQ6m5+6BGlfPTjNlIEw7PSVU3X1gTE'
ticket2 = ( ticket2 = '5AV0DSYIYbZWZQB7fCnTHZmMxtotb/aXjam+n2XS79lTvX3Tq9xGqpC8XKNEF2lt'
'5AV0DSYIYbZWZQB7fCnTHZmMxtotb/aXjam+n2XS79lTvX3Tq9xGqpC8XKNEF2lt'
)
ticket80 = '6Pfil8lv/k8zf8MndPpfXaO5EAV6dhME6zs6CfUyq2yziynQwSywtKQMqHGnJ2HR\ ticket80 = '6Pfil8lv/k8zf8MndPpfXaO5EAV6dhME6zs6CfUyq2yziynQwSywtKQMqHGnJ2HR\
49TZXi/Y4/8RSIO7QPsU51/HLR1gWIMhVM2m9yh93Bw=' 49TZXi/Y4/8RSIO7QPsU51/HLR1gWIMhVM2m9yh93Bw='
@@ -182,7 +180,8 @@ class TestTLSTicket(TestApplicationTLS):
def test_tls_ticket_invalid(self): def test_tls_ticket_invalid(self):
def check_tickets(tickets): def check_tickets(tickets):
assert 'error' in self.conf( assert 'error' in self.conf(
{"tickets": tickets}, 'listeners/*:7080/tls/session', {"tickets": tickets},
'listeners/*:7080/tls/session',
) )
check_tickets({}) check_tickets({})

View File

@@ -342,7 +342,8 @@ Connection: close
assert self.get()['body'] == '' assert self.get()['body'] == ''
assert 'success' in self.conf( assert 'success' in self.conf(
{"127.0.0.1:7083": {"weight": 2}}, 'upstreams/one/servers', {"127.0.0.1:7083": {"weight": 2}},
'upstreams/one/servers',
), 'active req new server' ), 'active req new server'
assert 'success' in self.conf_delete( assert 'success' in self.conf_delete(
'upstreams/one/servers/127.0.0.1:7083' 'upstreams/one/servers/127.0.0.1:7083'

View File

@@ -59,9 +59,7 @@ class TestUSR1(TestApplicationPython):
body = 'body_for_a_log_new\n' body = 'body_for_a_log_new\n'
assert self.post(body=body)['status'] == 200 assert self.post(body=body)['status'] == 200
assert ( assert self.wait_for_record(body, log_new) is not None, 'rename new'
self.wait_for_record(body, log_new) is not None
), 'rename new'
assert not os.path.isfile(log_path), 'rename old' assert not os.path.isfile(log_path), 'rename old'
os.kill(unit_pid, signal.SIGUSR1) os.kill(unit_pid, signal.SIGUSR1)

View File

@@ -24,8 +24,8 @@ class TestApplicationGo(TestApplicationProto):
env['GOCACHE'] = cache_dir env['GOCACHE'] = cache_dir
shutil.copy2( shutil.copy2(
option.test_dir + '/go/' + script + '/' + name + '.go', option.test_dir + '/go/' + script + '/' + name + '.go', temp_dir
temp_dir) )
if static: if static:
args = [ args = [
@@ -55,7 +55,8 @@ class TestApplicationGo(TestApplicationProto):
f"""module test/app f"""module test/app
require unit.nginx.org/go v0.0.0 require unit.nginx.org/go v0.0.0
replace unit.nginx.org/go => {replace_path} replace unit.nginx.org/go => {replace_path}
""") """
)
if option.detailed: if option.detailed:
print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args)) print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))

View File

@@ -43,7 +43,11 @@ class TestApplicationWebsocket(TestApplicationProto):
'Sec-WebSocket-Version': 13, 'Sec-WebSocket-Version': 13,
} }
_, sock = self.get(headers=headers, no_recv=True, start=True,) _, sock = self.get(
headers=headers,
no_recv=True,
start=True,
)
resp = '' resp = ''
while True: while True:
@@ -218,9 +222,7 @@ class TestApplicationWebsocket(TestApplicationProto):
while pos < message_len: while pos < message_len:
end = min(pos + fragmention_size, message_len) end = min(pos + fragmention_size, message_len)
fin = end == message_len fin = end == message_len
self.frame_write( self.frame_write(sock, op_code, message[pos:end], fin=fin, **kwargs)
sock, op_code, message[pos:end], fin=fin, **kwargs
)
op_code = self.OP_CONT op_code = self.OP_CONT
pos = end pos = end

View File

@@ -30,10 +30,6 @@ def args_handler(conf_func):
class TestControl(TestHTTP): class TestControl(TestHTTP):
# TODO socket reuse
# TODO http client
@args_handler @args_handler
def conf(self, conf, url): def conf(self, conf, url):
return self.put(**self._get_args(url, conf))['body'] return self.put(**self._get_args(url, conf))['body']

View File

@@ -328,9 +328,7 @@ class TestHTTP:
datatype = value['type'] datatype = value['type']
if not isinstance(value['data'], io.IOBase): if not isinstance(value['data'], io.IOBase):
pytest.fail( pytest.fail('multipart encoding of file requires a stream.')
'multipart encoding of file requires a stream.'
)
data = value['data'].read() data = value['data'].read()