Skip to content

Commit

Permalink
Add S3 tests to ensure dot segments are preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Sep 4, 2024
1 parent 96bd920 commit 672cc58
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 672cc58

Please sign in to comment.