mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-15 17:51:10 +00:00
2c9ed5e510
Some checks failed
Tests / changes (push) Has been cancelled
Tests / check-lockfile (push) Has been cancelled
Tests / lint-crlf (push) Has been cancelled
Tests / lint-newsfile (push) Has been cancelled
Build release artifacts / Calculate list of debian distros (push) Has been cancelled
Build release artifacts / Build wheels on ubuntu-20.04 for aarch64 (push) Has been cancelled
Build release artifacts / Build wheels on macos-12 for x86_64 (push) Has been cancelled
Build release artifacts / Build wheels on ubuntu-20.04 for x86_64 (push) Has been cancelled
Build release artifacts / Build sdist (push) Has been cancelled
Build docker images / build (push) Has been cancelled
Deploy the documentation / Calculate variables for GitHub Pages deployment (push) Has been cancelled
/ Check locked dependencies have sdists (push) Has been cancelled
Tests / check-sampleconfig (push) Has been cancelled
Tests / check-schema-delta (push) Has been cancelled
Tests / lint (push) Has been cancelled
Tests / Typechecking (push) Has been cancelled
Build release artifacts / Build .deb packages (push) Has been cancelled
Tests / lint-pydantic (push) Has been cancelled
Tests / lint-clippy (push) Has been cancelled
Tests / lint-clippy-nightly (push) Has been cancelled
Tests / lint-rustfmt (push) Has been cancelled
Tests / lint-readme (push) Has been cancelled
Tests / linting-done (push) Has been cancelled
Tests / calculate-test-jobs (push) Has been cancelled
Tests / trial (push) Has been cancelled
Tests / cargo-bench (push) Has been cancelled
Tests / tests-done (push) Has been cancelled
Deploy the documentation / GitHub Pages (push) Has been cancelled
Build release artifacts / Attach assets to release (push) Has been cancelled
Tests / trial-olddeps (push) Has been cancelled
Tests / trial-pypy (all, pypy-3.8) (push) Has been cancelled
Tests / sytest (push) Has been cancelled
Tests / export-data (push) Has been cancelled
Tests / portdb (11, 3.8) (push) Has been cancelled
Tests / portdb (15, 3.11) (push) Has been cancelled
Tests / complement (monolith, Postgres) (push) Has been cancelled
Tests / complement (monolith, SQLite) (push) Has been cancelled
Tests / complement (workers, Postgres) (push) Has been cancelled
Tests / cargo-test (push) Has been cancelled
```py from twisted.web.http_headers import Headers Headers()._canonicalNameCaps Headers()._encodeName ``` Introduced in https://github.com/matrix-org/synapse/pull/15913 <- https://github.com/matrix-org/synapse/pull/15773
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
#
|
|
# This file is licensed under the Affero General Public License (AGPL) version 3.
|
|
#
|
|
# Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
# Copyright (C) 2023 New Vector, Ltd
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# See the GNU Affero General Public License for more details:
|
|
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
|
#
|
|
# Originally licensed under the Apache License, Version 2.0:
|
|
# <http://www.apache.org/licenses/LICENSE-2.0>.
|
|
#
|
|
# [This file includes modifications made by New Vector Limited]
|
|
#
|
|
#
|
|
from typing import Set
|
|
|
|
from parameterized import parameterized
|
|
|
|
from synapse.http.proxy import (
|
|
HOP_BY_HOP_HEADERS_LOWERCASE,
|
|
parse_connection_header_value,
|
|
)
|
|
|
|
from tests.unittest import TestCase
|
|
|
|
|
|
def mix_case(s: str) -> str:
|
|
"""
|
|
Mix up the case of each character in the string (upper or lower case)
|
|
"""
|
|
return "".join(c.upper() if i % 2 == 0 else c.lower() for i, c in enumerate(s))
|
|
|
|
|
|
class ProxyTests(TestCase):
|
|
@parameterized.expand(
|
|
[
|
|
[b"close, X-Foo, X-Bar", {"close", "x-foo", "x-bar"}],
|
|
# No whitespace
|
|
[b"close,X-Foo,X-Bar", {"close", "x-foo", "x-bar"}],
|
|
# More whitespace
|
|
[b"close, X-Foo, X-Bar", {"close", "x-foo", "x-bar"}],
|
|
# "close" directive in not the first position
|
|
[b"X-Foo, X-Bar, close", {"x-foo", "x-bar", "close"}],
|
|
# Normalizes header capitalization
|
|
[b"keep-alive, x-fOo, x-bAr", {"keep-alive", "x-foo", "x-bar"}],
|
|
# Handles header names with whitespace
|
|
[
|
|
b"keep-alive, x foo, x bar",
|
|
{"keep-alive", "x foo", "x bar"},
|
|
],
|
|
# Make sure we handle all of the hop-by-hop headers
|
|
[
|
|
mix_case(", ".join(HOP_BY_HOP_HEADERS_LOWERCASE)).encode("ascii"),
|
|
HOP_BY_HOP_HEADERS_LOWERCASE,
|
|
],
|
|
]
|
|
)
|
|
def test_parse_connection_header_value(
|
|
self,
|
|
connection_header_value: bytes,
|
|
expected_extra_headers_to_remove: Set[str],
|
|
) -> None:
|
|
"""
|
|
Tests that the connection header value is parsed correctly
|
|
"""
|
|
self.assertIncludes(
|
|
expected_extra_headers_to_remove,
|
|
parse_connection_header_value(connection_header_value),
|
|
exact=True,
|
|
)
|