diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2023-10-11 07:50:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 07:50:34 -0400 |
commit | d6b7d49a61ca4c6f87d93ff9eb6a9fa6faef443c (patch) | |
tree | 0dd8e55176756df134de9bc37adbdd13399f48c3 /tests/media | |
parent | Inline simple_search_list/simple_search_list_txn. (#16434) (diff) | |
download | synapse-d6b7d49a61ca4c6f87d93ff9eb6a9fa6faef443c.tar.xz |
Handle content types with parameters. (#16440)
Diffstat (limited to 'tests/media')
-rw-r--r-- | tests/media/test_base.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/media/test_base.py b/tests/media/test_base.py index 119d7ba66f..144948f23c 100644 --- a/tests/media/test_base.py +++ b/tests/media/test_base.py @@ -42,18 +42,35 @@ class GetFileNameFromHeadersTests(unittest.TestCase): class AddFileHeadersTests(unittest.TestCase): TEST_CASES = { + # Safe values use inline. "text/plain": b"inline; filename=file.name", "text/csv": b"inline; filename=file.name", "image/png": b"inline; filename=file.name", + # Unlisted values are set to attachment. "text/html": b"attachment; filename=file.name", "any/thing": b"attachment; filename=file.name", + # Parameters get ignored. + "text/plain; charset=utf-8": b"inline; filename=file.name", + "text/markdown; charset=utf-8; variant=CommonMark": b"attachment; filename=file.name", + # Parsed as lowercase. + "Text/Plain": b"inline; filename=file.name", + # Bad values don't choke. + "": b"attachment; filename=file.name", + ";": b"attachment; filename=file.name", } def test_content_disposition(self) -> None: for media_type, expected in self.TEST_CASES.items(): request = Mock() add_file_headers(request, media_type, 0, "file.name") - request.setHeader.assert_any_call(b"Content-Disposition", expected) + # There should be a single call to set Content-Disposition. + for call in request.setHeader.call_args_list: + args, _ = call + if args[0] == b"Content-Disposition": + break + else: + self.fail(f"No Content-Disposition header found for {media_type}") + self.assertEqual(args[1], expected, media_type) def test_no_filename(self) -> None: request = Mock() |