Fix duplicate bucket creation with LocationConstraint. Closes #970.
This commit is contained in:
parent
49c947ece7
commit
113bfcb4ea
@ -336,6 +336,12 @@ class ResponseObject(_TemplateEnvironmentMixin):
|
|||||||
self.backend.set_bucket_website_configuration(bucket_name, body)
|
self.backend.set_bucket_website_configuration(bucket_name, body)
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
|
if body:
|
||||||
|
try:
|
||||||
|
region_name = xmltodict.parse(body)['CreateBucketConfiguration']['LocationConstraint']
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_bucket = self.backend.create_bucket(
|
new_bucket = self.backend.create_bucket(
|
||||||
bucket_name, region_name)
|
bucket_name, region_name)
|
||||||
|
@ -1207,6 +1207,22 @@ def test_boto3_bucket_create():
|
|||||||
"utf-8").should.equal("some text")
|
"utf-8").should.equal("some text")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_s3
|
||||||
|
def test_bucket_create_duplicate():
|
||||||
|
s3 = boto3.resource('s3', region_name='us-west-2')
|
||||||
|
s3.create_bucket(Bucket="blah", CreateBucketConfiguration={
|
||||||
|
'LocationConstraint': 'us-west-2',
|
||||||
|
})
|
||||||
|
with assert_raises(ClientError) as exc:
|
||||||
|
s3.create_bucket(
|
||||||
|
Bucket="blah",
|
||||||
|
CreateBucketConfiguration={
|
||||||
|
'LocationConstraint': 'us-west-2',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
exc.exception.response['Error']['Code'].should.equal('BucketAlreadyExists')
|
||||||
|
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
def test_boto3_bucket_create_eu_central():
|
def test_boto3_bucket_create_eu_central():
|
||||||
s3 = boto3.resource('s3', region_name='eu-central-1')
|
s3 = boto3.resource('s3', region_name='eu-central-1')
|
||||||
|
Loading…
Reference in New Issue
Block a user