Skip to content

Commit

Permalink
Merge pull request #3303 from ubaskota/region_redirect
Browse files Browse the repository at this point in the history
This change fixes region redirect issues for opt-in regions
  • Loading branch information
ubaskota authored Nov 21, 2024
2 parents 2c76bb5 + 0af86dc commit e84ae31
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
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_redirect = (
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_redirect,
]
):
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

0 comments on commit e84ae31

Please sign in to comment.