From 4b728545d43ff70287ae1d0dce42e995790e6b85 Mon Sep 17 00:00:00 2001 From: David Miller <45697098+dlm6693@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:04:45 -0500 Subject: [PATCH] explicit virtual addressing presigning bug (#3081) --- botocore/signers.py | 2 ++ tests/functional/test_s3.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/botocore/signers.py b/botocore/signers.py index a057b0acd7..b42550e05f 100644 --- a/botocore/signers.py +++ b/botocore/signers.py @@ -863,4 +863,6 @@ def _should_use_global_endpoint(client): and client.meta.config.region_name == 'us-east-1' ): return False + if s3_config.get('addressing_style') == 'virtual': + return False return True diff --git a/tests/functional/test_s3.py b/tests/functional/test_s3.py index ae8a7371fb..f51f41d264 100644 --- a/tests/functional/test_s3.py +++ b/tests/functional/test_s3.py @@ -3506,6 +3506,46 @@ def _addressing_for_presigned_url_test_cases(): expected_url="https://s3.us-west-2.amazonaws.com/foo.b.biz/key", ) + # virtual style addressing expicitly requested always uses + # regional endpoints except for us-east-1 and aws-global + yield dict( + region="us-west-2", + bucket="bucket", + key="key", + signature_version="s3", + s3_config={"addressing_style": "virtual"}, + expected_url="https://bucket.s3.us-west-2.amazonaws.com/key", + ) + yield dict( + region="us-east-2", + bucket="bucket", + key="key", + signature_version="s3v4", + s3_config={"addressing_style": "virtual"}, + expected_url="https://bucket.s3.us-east-2.amazonaws.com/key", + ) + yield dict( + region="us-west-2", + bucket="bucket", + key="key", + s3_config={"addressing_style": "virtual"}, + expected_url="https://bucket.s3.us-west-2.amazonaws.com/key", + ) + yield dict( + region="us-east-1", + bucket="bucket", + key="key", + s3_config={"addressing_style": "virtual"}, + expected_url="https://bucket.s3.amazonaws.com/key", + ) + yield dict( + region="aws-global", + bucket="bucket", + key="key", + s3_config={"addressing_style": "virtual"}, + expected_url="https://bucket.s3.amazonaws.com/key", + ) + @pytest.mark.parametrize( "test_case", _addressing_for_presigned_url_test_cases()