From 3a0a7b72db187527f9ed68d0c2447f4b1513a02e Mon Sep 17 00:00:00 2001 From: jonathan343 Date: Thu, 5 Sep 2024 08:50:08 -0700 Subject: [PATCH] Add S3 tests to ensure dot segments are preserved --- tests/functional/botocore/test_s3.py | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/functional/botocore/test_s3.py b/tests/functional/botocore/test_s3.py index 1f91fbfa4f11..31c6849dee66 100644 --- a/tests/functional/botocore/test_s3.py +++ b/tests/functional/botocore/test_s3.py @@ -2925,3 +2925,44 @@ def test_escape_keys_in_xml_put_bucket_lifecycle_configuration(self): self.assertNotIn(b'my\r\n\rprefix', request.body) self.assertIn(b'my prefix', request.body) self.assert_correct_content_md5(request) + + +@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