From c37a6b810b1f0c9709d71ca54c12637ee2046b12 Mon Sep 17 00:00:00 2001 From: Krishn Parasar <76171905+Krishn1412@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:31:37 +0530 Subject: [PATCH] Updating test cases --- falcon/util/misc.py | 2 +- tests/test_media_multipart.py | 9 --------- tests/test_utils.py | 11 +++++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/falcon/util/misc.py b/falcon/util/misc.py index 12a41ecd9..4d55887ec 100644 --- a/falcon/util/misc.py +++ b/falcon/util/misc.py @@ -358,7 +358,7 @@ def secure_filename(filename: str, max_length: Optional[int] = None) -> str: Args: filename (str): Arbitrary filename input from the request, such as a multipart form filename field. - max_length (int, optional): Maximum length of the sanitized filename, + max_length: Maximum length of the sanitized filename, including the file extension. If None, no truncation is applied. Returns: diff --git a/tests/test_media_multipart.py b/tests/test_media_multipart.py index b56ad45f5..b2ad8db3f 100644 --- a/tests/test_media_multipart.py +++ b/tests/test_media_multipart.py @@ -10,7 +10,6 @@ from falcon import testing from falcon.media.multipart import MultipartParseOptions from falcon.util import BufferedReader -from falcon.util.misc import secure_filename try: import msgpack @@ -748,14 +747,6 @@ def test_unsupported_charset(client): } -def test_max_length_filename(client): - filename = secure_filename('averylongfilename.txt', 17) - assert filename == 'averylongfile.txt' - - filename = secure_filename('file.withlongextension', 9) - assert filename == 'file.with' - - def test_filename_star(client): # NOTE(vytas): Generated by requests_toolbelt 0.9.1 on Py2 # (interestingly, one gets a "normal" filename on Py3.7). diff --git a/tests/test_utils.py b/tests/test_utils.py index 14da664f7..b93cfcf07 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -628,6 +628,17 @@ def test_misc_isascii(self): with pytest.warns(deprecation.DeprecatedWarning): assert misc.isascii('foobar') + @pytest.mark.parametrize( + 'filename,max_length,expected', + [ + ('averylongfilename.txt', 17, 'averylongfile.txt'), + ('short.txt', 10, 'short.txt'), + ('file.withlongextension', 9, 'file.with'), + ], + ) + def test_secure_filename_max_length(self, filename, max_length, expected): + assert misc.secure_filename(filename, max_length=max_length) == expected + @pytest.mark.parametrize( 'protocol,method',