Skip to content

Commit

Permalink
Updating test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishn1412 committed Dec 23, 2024
1 parent 0c61a5e commit c37a6b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion falcon/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions tests/test_media_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
11 changes: 11 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c37a6b8

Please sign in to comment.