Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This change fixes region redirect issues for opt-in regions #3303

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions botocore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,13 +1776,18 @@ def redirect_from_error(self, request_dict, response, operation, **kwargs):
0
].status_code in (301, 302, 307)
is_permanent_redirect = error_code == 'PermanentRedirect'
is_opt_in_region = (
ubaskota marked this conversation as resolved.
Show resolved Hide resolved
error_code == 'IllegalLocationConstraintException'
and operation.name != 'CreateBucket'
)
if not any(
[
is_special_head_object,
is_wrong_signing_region,
is_permanent_redirect,
is_special_head_bucket,
is_redirect_status,
is_opt_in_region,
]
):
return
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,66 @@ def test_does_not_redirect_if_None_response(self):
)
self.assertIsNone(redirect_response)

def test_redirects_on_illegal_location_constraint_from_opt_in_region(self):
request_dict = {
'url': 'https://il-central-1.amazonaws.com/foo',
'context': {
's3_redirect': {
'bucket': 'foo',
'redirected': False,
'params': {'Bucket': 'foo'},
},
'signing': {},
},
}
response = (
None,
{
'Error': {'Code': 'IllegalLocationConstraintException'},
'ResponseMetadata': {
'HTTPHeaders': {'x-amz-bucket-region': 'eu-central-1'}
},
},
)

self.operation.name = 'GetObject'
redirect_response = self.redirector.redirect_from_error(
request_dict, response, self.operation
)
self.assertEqual(redirect_response, 0)

def test_no_redirect_on_illegal_location_constraint_from_bad_location_constraint(
self,
):
request_dict = {
'url': 'https://us-west-2.amazonaws.com/foo',
'context': {
's3_redirect': {
'bucket': 'foo',
'redirected': False,
'params': {
'Bucket': 'foo',
'CreateBucketConfiguration': {
'LocationConstraint': 'eu-west-2',
},
},
},
'signing': {},
},
}
response = (
None,
{
'Error': {'Code': 'IllegalLocationConstraintException'},
},
)

self.operation.name = 'CreateBucket'
redirect_response = self.redirector.redirect_from_error(
request_dict, response, self.operation
)
self.assertIsNone(redirect_response)

def test_get_region_from_response(self):
response = (
None,
Expand Down
Loading