1
0

test_base.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from synapse.rest.media.v1._base import get_filename_from_headers
  16. from tests import unittest
  17. class GetFileNameFromHeadersTests(unittest.TestCase):
  18. # input -> expected result
  19. TEST_CASES = {
  20. b"inline; filename=abc.txt": "abc.txt",
  21. b'inline; filename="azerty"': "azerty",
  22. b'inline; filename="aze%20rty"': "aze%20rty",
  23. b'inline; filename="aze"rty"': 'aze"rty',
  24. b'inline; filename="azer;ty"': "azer;ty",
  25. b"inline; filename*=utf-8''foo%C2%A3bar": "foo£bar",
  26. }
  27. def tests(self):
  28. for hdr, expected in self.TEST_CASES.items():
  29. res = get_filename_from_headers({b"Content-Disposition": [hdr]})
  30. self.assertEqual(
  31. res,
  32. expected,
  33. "expected output for %s to be %s but was %s" % (hdr, expected, res),
  34. )