aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_networking.py
diff options
context:
space:
mode:
authorcoletdjnz <coletdjnz@protonmail.com>2023-07-29 10:40:20 +1200
committerGitHub <noreply@github.com>2023-07-28 22:40:20 +0000
commit4bf912282a34b58b6b35d8f7e6be535770c89c76 (patch)
tree829a0271e2e709a8a79f2a9de29f72dea8108d05 /test/test_networking.py
parenta15fcd299e767a510debd8dc1646fe863b96ce0e (diff)
downloadhypervideo-pre-4bf912282a34b58b6b35d8f7e6be535770c89c76.tar.lz
hypervideo-pre-4bf912282a34b58b6b35d8f7e6be535770c89c76.tar.xz
hypervideo-pre-4bf912282a34b58b6b35d8f7e6be535770c89c76.zip
[networking] Remove dot segments during URL normalization (#7662)
This implements RFC3986 5.2.4 remove_dot_segments during the URL normalization process. Closes #3355, #6526 Authored by: coletdjnz
Diffstat (limited to 'test/test_networking.py')
-rw-r--r--test/test_networking.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_networking.py b/test/test_networking.py
index f0938ab91..684bf5f96 100644
--- a/test/test_networking.py
+++ b/test/test_networking.py
@@ -173,6 +173,12 @@ class HTTPTestRequestHandler(http.server.BaseHTTPRequestHandler):
self.send_header('Location', self.path)
self.send_header('Content-Length', '0')
self.end_headers()
+ elif self.path == '/redirect_dotsegments':
+ self.send_response(301)
+ # redirect to /headers but with dot segments before
+ self.send_header('Location', '/a/b/./../../headers')
+ self.send_header('Content-Length', '0')
+ self.end_headers()
elif self.path.startswith('/redirect_'):
self._redirect()
elif self.path.startswith('/method'):
@@ -356,6 +362,21 @@ class TestHTTPRequestHandler(TestRequestHandlerBase):
res.close()
@pytest.mark.parametrize('handler', ['Urllib'], indirect=True)
+ def test_remove_dot_segments(self, handler):
+ with handler() as rh:
+ # This isn't a comprehensive test,
+ # but it should be enough to check whether the handler is removing dot segments
+ res = validate_and_send(rh, Request(f'http://127.0.0.1:{self.http_port}/a/b/./../../headers'))
+ assert res.status == 200
+ assert res.url == f'http://127.0.0.1:{self.http_port}/headers'
+ res.close()
+
+ res = validate_and_send(rh, Request(f'http://127.0.0.1:{self.http_port}/redirect_dotsegments'))
+ assert res.status == 200
+ assert res.url == f'http://127.0.0.1:{self.http_port}/headers'
+ res.close()
+
+ @pytest.mark.parametrize('handler', ['Urllib'], indirect=True)
def test_unicode_path_redirection(self, handler):
with handler() as rh:
r = validate_and_send(rh, Request(f'http://127.0.0.1:{self.http_port}/302-non-ascii-redirect'))