Merge pull request #1460 from okomestudio/s3-region-from-url

Support both virtual-hosted and path-style URLs for region name parsing
This commit is contained in:
Steve Pulec 2018-03-06 21:57:57 -05:00 committed by GitHub
commit 326698f3fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 7 deletions

View file

@ -1,6 +1,6 @@
from __future__ import unicode_literals
from sure import expect
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore, parse_region_from_url
def test_base_url():
@ -53,3 +53,21 @@ def test_versioned_key_store():
d.setlist('key', [[1], [2]])
d['key'].should.have.length_of(1)
d.getlist('key').should.be.equal([[1], [2]])
def test_parse_region_from_url():
expected = 'us-west-2'
for url in ['http://s3-us-west-2.amazonaws.com/bucket',
'http://s3.us-west-2.amazonaws.com/bucket',
'http://bucket.s3-us-west-2.amazonaws.com',
'https://s3-us-west-2.amazonaws.com/bucket',
'https://s3.us-west-2.amazonaws.com/bucket',
'https://bucket.s3-us-west-2.amazonaws.com']:
parse_region_from_url(url).should.equal(expected)
expected = 'us-east-1'
for url in ['http://s3.amazonaws.com/bucket',
'http://bucket.s3.amazonaws.com',
'https://s3.amazonaws.com/bucket',
'https://bucket.s3.amazonaws.com']:
parse_region_from_url(url).should.equal(expected)