diff options
author | Richard Brežák <richard@brezak.sk> | 2023-10-24 15:45:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 13:45:21 +0000 |
commit | 95076f77c1b370ecef780c7bbf631bd34868c982 (patch) | |
tree | a0bdf97d0ef58b79a09988f9f4e70fe2fb37e348 /tests | |
parent | Revert "Add test case to detect dodgy b64 encoding" (diff) | |
download | synapse-95076f77c1b370ecef780c7bbf631bd34868c982.tar.xz |
Fix http/s proxy authentication with long username/passwords (#16504)
Diffstat (limited to '')
-rw-r--r-- | tests/http/test_proxyagent.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/http/test_proxyagent.py b/tests/http/test_proxyagent.py index 8164b0b78e..41dfd5dc17 100644 --- a/tests/http/test_proxyagent.py +++ b/tests/http/test_proxyagent.py @@ -217,6 +217,27 @@ class ProxyParserTests(TestCase): ) +class TestBasicProxyCredentials(TestCase): + def test_long_user_pass_string_encoded_without_newlines(self) -> None: + """Reproduces https://github.com/matrix-org/synapse/pull/16504.""" + proxy_connection_string = b"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonguser:pass@proxy.local:9988" + _, _, _, creds = parse_proxy(proxy_connection_string) + assert creds is not None # for mypy's benefit + self.assertIsInstance(creds, BasicProxyCredentials) + + auth_value = creds.as_proxy_authorization_value() + self.assertNotIn(b"\n", auth_value) + self.assertEqual( + creds.as_proxy_authorization_value(), + b"Basic bG9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vbmd1c2VyOnBhc3M=", + ) + basic_auth_payload = creds.as_proxy_authorization_value().split(b" ")[1] + self.assertEqual( + base64.b64decode(basic_auth_payload), + b"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonguser:pass", + ) + + class MatrixFederationAgentTests(TestCase): def setUp(self) -> None: self.reactor = ThreadedMemoryReactorClock() |