From 22a63835c18b348a3fb09c4f70395f3d142daee7 Mon Sep 17 00:00:00 2001 From: jonathan343 Date: Wed, 4 Sep 2024 14:53:56 -0700 Subject: [PATCH] Add S3 tests to ensure dot segments are preserved --- tests/functional/test_s3.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/functional/test_s3.py b/tests/functional/test_s3.py index 0c04f858e0..1465287d38 100644 --- a/tests/functional/test_s3.py +++ b/tests/functional/test_s3.py @@ -3686,3 +3686,44 @@ def _verify_bucket_and_key_in_context(self, request, **kwargs): request.context['input_params']['Bucket'], self.BUCKET ) self.assertEqual(request.context['input_params']['Key'], self.KEY) + + +@pytest.mark.parametrize( + "bucket, key, expected_path, expected_hostname", + [ + ( + "mybucket", + "../key.txt", + "/../key.txt", + "mybucket.s3.us-west-2.amazonaws.com", + ), + ( + "mybucket", + "foo/../key.txt", + "/foo/../key.txt", + "mybucket.s3.us-west-2.amazonaws.com", + ), + ( + "mybucket", + "foo/../../key.txt", + "/foo/../../key.txt", + "mybucket.s3.us-west-2.amazonaws.com", + ), + ], +) +def test_dot_segments_preserved_in_url_path( + patched_session, bucket, key, expected_path, expected_hostname +): + s3 = patched_session.create_client( + 's3', + 'us-west-2', + config=Config( + s3={"addressing_style": "virtual"}, + ), + ) + with ClientHTTPStubber(s3) as http_stubber: + http_stubber.add_response() + s3.get_object(Bucket=bucket, Key=key) + url_parts = urlsplit(http_stubber.requests[0].url) + assert url_parts.path == expected_path + assert url_parts.hostname == expected_hostname