2222
2323from parameterized import parameterized
2424
25- from synapse .http .proxy import parse_connection_header_value
25+ from synapse .http .proxy import (
26+ HOP_BY_HOP_HEADERS_LOWERCASE ,
27+ parse_connection_header_value ,
28+ )
2629
2730from tests .unittest import TestCase
2831
2932
33+ def mix_case (s : str ) -> str :
34+ """
35+ Mix up the case of each character in the string (upper or lower case)
36+ """
37+ return "" .join (c .upper () if i % 2 == 0 else c .lower () for i , c in enumerate (s ))
38+
39+
3040class ProxyTests (TestCase ):
3141 @parameterized .expand (
3242 [
33- [b"close, X-Foo, X-Bar" , {"Close " , "X-Foo " , "X-Bar " }],
43+ [b"close, X-Foo, X-Bar" , {"close " , "x-foo " , "x-bar " }],
3444 # No whitespace
35- [b"close,X-Foo,X-Bar" , {"Close " , "X-Foo " , "X-Bar " }],
45+ [b"close,X-Foo,X-Bar" , {"close " , "x-foo " , "x-bar " }],
3646 # More whitespace
37- [b"close, X-Foo, X-Bar" , {"Close " , "X-Foo " , "X-Bar " }],
47+ [b"close, X-Foo, X-Bar" , {"close " , "x-foo " , "x-bar " }],
3848 # "close" directive in not the first position
39- [b"X-Foo, X-Bar, close" , {"X-Foo " , "X-Bar " , "Close " }],
49+ [b"X-Foo, X-Bar, close" , {"x-foo " , "x-bar " , "close " }],
4050 # Normalizes header capitalization
41- [b"keep-alive, x-fOo, x-bAr" , {"Keep-Alive " , "X-Foo " , "X-Bar " }],
51+ [b"keep-alive, x-fOo, x-bAr" , {"keep-alive " , "x-foo " , "x-bar " }],
4252 # Handles header names with whitespace
4353 [
4454 b"keep-alive, x foo, x bar" ,
45- {"Keep-Alive" , "X foo" , "X bar" },
55+ {"keep-alive" , "x foo" , "x bar" },
56+ ],
57+ # Make sure we handle all of the hop-by-hop headers
58+ [
59+ mix_case (", " .join (HOP_BY_HOP_HEADERS_LOWERCASE )).encode ("ascii" ),
60+ HOP_BY_HOP_HEADERS_LOWERCASE ,
4661 ],
4762 ]
4863 )
@@ -54,7 +69,8 @@ def test_parse_connection_header_value(
5469 """
5570 Tests that the connection header value is parsed correctly
5671 """
57- self .assertEqual (
72+ self .assertIncludes (
5873 expected_extra_headers_to_remove ,
5974 parse_connection_header_value (connection_header_value ),
75+ exact = True ,
6076 )
0 commit comments