Merge pull request #1970 from jbmchuck/bucket-duplicate-tag-keys
Raise a client error if PutBucketTags request contains duplicate keys
This commit is contained in:
commit
3a98d2cd03
@ -178,3 +178,13 @@ class InvalidStorageClass(S3ClientError):
|
|||||||
"InvalidStorageClass",
|
"InvalidStorageClass",
|
||||||
"The storage class you specified is not valid",
|
"The storage class you specified is not valid",
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateTagKeys(S3ClientError):
|
||||||
|
code = 400
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(DuplicateTagKeys, self).__init__(
|
||||||
|
"InvalidTag",
|
||||||
|
"Cannot provide multiple Tags with the same key",
|
||||||
|
*args, **kwargs)
|
||||||
|
@ -15,7 +15,7 @@ from bisect import insort
|
|||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel
|
||||||
from moto.core.utils import iso_8601_datetime_with_milliseconds, rfc_1123_datetime
|
from moto.core.utils import iso_8601_datetime_with_milliseconds, rfc_1123_datetime
|
||||||
from .exceptions import BucketAlreadyExists, MissingBucket, InvalidPart, EntityTooSmall, MissingKey, \
|
from .exceptions import BucketAlreadyExists, MissingBucket, InvalidPart, EntityTooSmall, MissingKey, \
|
||||||
InvalidNotificationDestination, MalformedXML, InvalidStorageClass
|
InvalidNotificationDestination, MalformedXML, InvalidStorageClass, DuplicateTagKeys
|
||||||
from .utils import clean_key_name, _VersionedKeyStore
|
from .utils import clean_key_name, _VersionedKeyStore
|
||||||
|
|
||||||
UPLOAD_ID_BYTES = 43
|
UPLOAD_ID_BYTES = 43
|
||||||
@ -773,6 +773,9 @@ class S3Backend(BaseBackend):
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
def put_bucket_tagging(self, bucket_name, tagging):
|
def put_bucket_tagging(self, bucket_name, tagging):
|
||||||
|
tag_keys = [tag.key for tag in tagging.tag_set.tags]
|
||||||
|
if len(tag_keys) != len(set(tag_keys)):
|
||||||
|
raise DuplicateTagKeys()
|
||||||
bucket = self.get_bucket(bucket_name)
|
bucket = self.get_bucket(bucket_name)
|
||||||
bucket.set_tags(tagging)
|
bucket.set_tags(tagging)
|
||||||
|
|
||||||
|
@ -1553,6 +1553,24 @@ def test_boto3_put_bucket_tagging():
|
|||||||
})
|
})
|
||||||
resp['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
resp['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||||
|
|
||||||
|
# With duplicate tag keys:
|
||||||
|
with assert_raises(ClientError) as err:
|
||||||
|
resp = s3.put_bucket_tagging(Bucket=bucket_name,
|
||||||
|
Tagging={
|
||||||
|
"TagSet": [
|
||||||
|
{
|
||||||
|
"Key": "TagOne",
|
||||||
|
"Value": "ValueOne"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": "TagOne",
|
||||||
|
"Value": "ValueOneAgain"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
e = err.exception
|
||||||
|
e.response["Error"]["Code"].should.equal("InvalidTag")
|
||||||
|
e.response["Error"]["Message"].should.equal("Cannot provide multiple Tags with the same key")
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
def test_boto3_get_bucket_tagging():
|
def test_boto3_get_bucket_tagging():
|
||||||
|
Loading…
Reference in New Issue
Block a user