You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.9 KiB

  1. # Copyright 2023 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Set
  15. from parameterized import parameterized
  16. from synapse.http.proxy import parse_connection_header_value
  17. from tests.unittest import TestCase
  18. class ProxyTests(TestCase):
  19. @parameterized.expand(
  20. [
  21. [b"close, X-Foo, X-Bar", {"Close", "X-Foo", "X-Bar"}],
  22. # No whitespace
  23. [b"close,X-Foo,X-Bar", {"Close", "X-Foo", "X-Bar"}],
  24. # More whitespace
  25. [b"close, X-Foo, X-Bar", {"Close", "X-Foo", "X-Bar"}],
  26. # "close" directive in not the first position
  27. [b"X-Foo, X-Bar, close", {"X-Foo", "X-Bar", "Close"}],
  28. # Normalizes header capitalization
  29. [b"keep-alive, x-fOo, x-bAr", {"Keep-Alive", "X-Foo", "X-Bar"}],
  30. # Handles header names with whitespace
  31. [
  32. b"keep-alive, x foo, x bar",
  33. {"Keep-Alive", "X foo", "X bar"},
  34. ],
  35. ]
  36. )
  37. def test_parse_connection_header_value(
  38. self,
  39. connection_header_value: bytes,
  40. expected_extra_headers_to_remove: Set[str],
  41. ) -> None:
  42. """
  43. Tests that the connection header value is parsed correctly
  44. """
  45. self.assertEqual(
  46. expected_extra_headers_to_remove,
  47. parse_connection_header_value(connection_header_value),
  48. )