Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/python/lib/k2_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def _process_json_log(self, log_record):
log_record.pop("time", "")
log_record.pop("thread_id", "")
log_record.pop("component_name", "")
log_record.pop("component_version", "")
log_record.pop("level", "")
log_record.pop("target", "")
log_record.pop("instance_id", "")
Expand Down
30 changes: 18 additions & 12 deletions tests/python/tests/http_server/test_multipart.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
import re
from urllib.parse import urlencode

from python.lib.testcase import WebServerAutoTestCase

def get_multipart_temp_files():
"""Get files that look like multipart temp files (6 random alphanumeric chars in /tmp/, optionally with tmp. prefix)."""
pattern = re.compile(r'^(tmp\.)?[a-zA-Z0-9]{6}$')
return set(f for f in os.listdir("/tmp/") if pattern.match(f) and os.path.isfile(f"/tmp/{f}"))


class TestMultipartContentType(WebServerAutoTestCase):

Expand Down Expand Up @@ -190,7 +196,7 @@ def test_multipart_non_terminating_boundary(self):

def test_multipart_filename_attribute(self):

tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()
boundary = "------------------------d74496d66958873e"

file_bytes = b"Hello from test.txt\nSecond line\n"
Expand Down Expand Up @@ -221,12 +227,12 @@ def test_multipart_filename_attribute(self):
self.assertTrue(response.content.find(b"filename : test.txt") != -1)
self.assertTrue(response.content.find(b"Hello from test.txt") != -1)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

def test_multipart_filename_array_attribute(self):
tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()

boundary = "------------------------d74496d66958873e"

Expand Down Expand Up @@ -270,13 +276,13 @@ def test_multipart_filename_array_attribute(self):
self.assertTrue(response.content.find(b"Hello from a.txt") != -1)
self.assertTrue(response.content.find(b"Hello from b.txt") != -1)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

def test_multipart_superglobal_modify(self):

tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()
boundary = "------------------------d74496d66958873e"

file_bytes = b"Hello from test.txt\nSecond line\n"
Expand Down Expand Up @@ -305,13 +311,13 @@ def test_multipart_superglobal_modify(self):

self.assertEqual(200, response.status_code)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

def test_multipart_mixed_files_and_fields(self):
"""Test mixing files and regular form fields in the same request."""
tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()
boundary = '------------------------d74496d66958873e'

file_bytes = b'File content here\n'
Expand Down Expand Up @@ -350,13 +356,13 @@ def test_multipart_mixed_files_and_fields(self):
self.assertTrue(response.content.find(b'filename : test.txt') != -1)
self.assertTrue(response.content.find(b'another : another value') != -1)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

def test_multipart_file_without_content_type(self):
"""Test file upload without explicit Content-Type header."""
tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()
boundary = '------------------------d74496d66958873e'

file_bytes = b'File without content type\n'
Expand Down Expand Up @@ -387,13 +393,13 @@ def test_multipart_file_without_content_type(self):
# Should default to text/plain
self.assertTrue(response.content.find(b'type : text/plain') != -1)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

def test_multipart_binary_file(self):
"""Test uploading binary file content."""
tmp_files = os.listdir("/tmp/")
tmp_files = get_multipart_temp_files()
boundary = '------------------------d74496d66958873e'

# Binary content with null bytes
Expand Down Expand Up @@ -424,7 +430,7 @@ def test_multipart_binary_file(self):
self.assertTrue(response.content.find(b'size : 8') != -1)
self.assertTrue(response.content.find(b'filename : data.bin') != -1)

tmp_files_after_script = os.listdir("/tmp/")
tmp_files_after_script = get_multipart_temp_files()
# check that script delete tmp files at the end
self.assertEqual(sorted(tmp_files), sorted(tmp_files_after_script))

Expand Down
Loading