From d001f6a22617f8adef0c2c382b886f8bf2dd5fae Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 20 Feb 2023 19:48:59 -0100 Subject: [PATCH] S3: Fix Signature calculation for requests that contain a querystring (#5949) --- moto/core/responses.py | 6 +++++- tests/test_s3/test_s3_auth.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/moto/core/responses.py b/moto/core/responses.py index ccffe4332..14e892b18 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -130,10 +130,14 @@ class ActionAuthenticatorMixin(object): ActionAuthenticatorMixin.request_count >= settings.INITIAL_NO_AUTH_ACTION_COUNT ): + parsed_url = urlparse(self.uri) # type: ignore[attr-defined] + path = parsed_url.path + if parsed_url.query: + path += "?" + parsed_url.query iam_request = iam_request_cls( account_id=self.current_account, # type: ignore[attr-defined] method=self.method, # type: ignore[attr-defined] - path=self.path, # type: ignore[attr-defined] + path=path, data=self.data, # type: ignore[attr-defined] headers=self.headers, # type: ignore[attr-defined] ) diff --git a/tests/test_s3/test_s3_auth.py b/tests/test_s3/test_s3_auth.py index c915ee26e..35288baf9 100644 --- a/tests/test_s3/test_s3_auth.py +++ b/tests/test_s3/test_s3_auth.py @@ -52,6 +52,11 @@ def test_head_bucket_with_correct_credentials(): aws_secret_access_key=iam_keys["SecretAccessKey"], ) + # Verify we can make calls that contain a querystring + # Specifically, verify that we are able to build/match the AWS signature for a URL with a querystring + s3.get_bucket_location(Bucket="mock_bucket") + s3.list_objects_v2(Bucket="mock_bucket") + @set_initial_no_auth_action_count(4) @mock_s3