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

Dont use DNS style addressing for GetBucketLocation #380

Merged
merged 2 commits into from
Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def fix_s3_host(event_name, endpoint, request, auth, **kwargs):
# retried request). We don't need to perform this
# customization again.
return
elif _is_get_bucket_location_request(request):
# For the GetBucketLocation response, we should not be using
# the virtual host style addressing so we can avoid any sigv4
# issues.
logger.debug("Request is GetBucketLocation operation, not checking "
"for DNS compatibility.")
return
parts = urlsplit(request.url)
request.auth_path = parts.path
path_parts = parts.path.split('/')
Expand Down Expand Up @@ -202,6 +209,10 @@ def fix_s3_host(event_name, endpoint, request, auth, **kwargs):
bucket_name)


def _is_get_bucket_location_request(request):
return request.url.endswith('?location')


def _allowed_region(region_name):
return region_name not in RESTRICTED_REGIONS

Expand Down
28 changes: 28 additions & 0 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,5 +532,33 @@ def test_bucket_in_other_region_using_http(self):
self.keys.append('foo.txt')


class TestGetBucketLocationForEUCentral1(BaseS3Test):
def setUp(self):
super(TestGetBucketLocationForEUCentral1, self).setUp()
self.bucket_name = 'botocoretest%s-%s' % (
int(time.time()), random.randint(1, 1000))
client = self.session.create_client('s3', 'eu-central-1')
client.create_bucket(Bucket=self.bucket_name,
CreateBucketConfiguration={
'LocationConstraint': 'eu-central-1',
})

def tearDown(self):
super(TestGetBucketLocationForEUCentral1, self).tearDown()
client = self.session.create_client('s3', 'eu-central-1')
client.delete_bucket(Bucket=self.bucket_name)

def test_can_get_bucket_location(self):
# Even though the bucket is in eu-central-1, we should still be able to
# use the us-east-1 endpoint class to get the bucket location.
operation = self.service.get_operation('GetBucketLocation')
# Also keep in mind that while this test is useful, it doesn't test
# what happens once DNS propogates which is arguably more interesting,
# as DNS will point us to the eu-central-1 endpoint.
us_east_1 = self.service.get_endpoint('us-east-1')
response = operation.call(us_east_1, Bucket=self.bucket_name)
self.assertEqual(response[1]['LocationConstraint'], 'eu-central-1')


if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions tests/unit/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ def test_fix_s3_host_only_applied_once(self):
# Otherwise we'll get signature errors.
self.assertEqual(request.auth_path, '/bucket/key.txt')

def test_dns_style_not_used_for_get_bucket_location(self):
endpoint = mock.Mock(region_name='us-west-2')
original_url = 'https://s3-us-west-2.amazonaws.com/bucket?location'
request = AWSRequest(
method='GET',headers={},
url=original_url,
)
auth = mock.Mock()
handlers.fix_s3_host('foo', endpoint, request, auth)
# The request url should not have been modified because this is
# a request for GetBucketLocation.
self.assertEqual(request.url, original_url)


class TestRetryHandlerOrder(BaseSessionTest):
def get_handler_names(self, responses):
Expand Down