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 1 commit
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
29 changes: 29 additions & 0 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,5 +532,34 @@ 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))
endpoint = self.service.get_endpoint('eu-central-1')
operation = self.service.get_operation('CreateBucket')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should be using the clients instead of service and operation objects since we are trying to move toward clients.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point. I'll update what all the test fixture setup/teardown to use clients. I think we still need the service/operation in the actual tests themselves (in addition to the client interfaces) until we can actually deprecate the service/operation objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I figure that catching ourselves now, while we are adding more code, will save us time down the road when we make the switch.

response = operation.call(endpoint, bucket=self.bucket_name,
create_bucket_configuration={'LocationConstraint': 'eu-central-1'})
self.assertEqual(response[0].status_code, 200)

def tearDown(self):
super(TestGetBucketLocationForEUCentral1, self).tearDown()
endpoint = self.service.get_endpoint('eu-central-1')
operation = self.service.get_operation('DeleteBucket')
response = operation.call(endpoint, bucket=self.bucket_name)
self.assertEqual(response[0].status_code, 204)

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.
response = operation.call(self.endpoint, Bucket=self.bucket_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the endpoint region being used is "eu-central-1" still? I would like to see using different regions for endpoints.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious from this test, but self.endpoint is actually the endpoint for us-east-1, defined in the base classes's setUp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my bad. I saw endpoint in the setUp() and assumed it was self.endpoint

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