Fix: Adding fix when setting empty policy attr to queue (#4091)
This commit is contained in:
parent
ec958da2b9
commit
44624593f1
@ -202,8 +202,17 @@ class SQSResponse(BaseResponse):
|
|||||||
|
|
||||||
def set_queue_attributes(self):
|
def set_queue_attributes(self):
|
||||||
# TODO validate self.get_param('QueueUrl')
|
# TODO validate self.get_param('QueueUrl')
|
||||||
|
attribute = self.attribute
|
||||||
|
|
||||||
|
# Fixes issue with Policy set to empty str
|
||||||
|
attribute_names = self._get_multi_param("Attribute")
|
||||||
|
if attribute_names:
|
||||||
|
for attr in attribute_names:
|
||||||
|
if attr["Name"] == "Policy" and len(attr["Value"]) == 0:
|
||||||
|
attribute = {attr["Name"]: None}
|
||||||
|
|
||||||
queue_name = self._get_queue_name()
|
queue_name = self._get_queue_name()
|
||||||
self.sqs_backend.set_queue_attributes(queue_name, self.attribute)
|
self.sqs_backend.set_queue_attributes(queue_name, attribute)
|
||||||
|
|
||||||
return SET_QUEUE_ATTRIBUTE_RESPONSE
|
return SET_QUEUE_ATTRIBUTE_RESPONSE
|
||||||
|
|
||||||
|
@ -205,6 +205,31 @@ def test_create_queue_with_policy():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
def test_set_queue_attribute_empty_policy_removes_attr():
|
||||||
|
client = boto3.client("sqs", region_name="us-east-1")
|
||||||
|
response = client.create_queue(
|
||||||
|
QueueName="test-queue",
|
||||||
|
Attributes={
|
||||||
|
"Policy": json.dumps(
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Id": "test",
|
||||||
|
"Statement": [{"Effect": "Allow", "Principal": "*", "Action": "*"}],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
queue_url = response["QueueUrl"]
|
||||||
|
|
||||||
|
empty_policy = {"Policy": ""}
|
||||||
|
client.set_queue_attributes(QueueUrl=queue_url, Attributes=empty_policy)
|
||||||
|
response = client.get_queue_attributes(QueueUrl=queue_url, AttributeNames=["All"])[
|
||||||
|
"Attributes"
|
||||||
|
]
|
||||||
|
response.shouldnt.have.key("Policy")
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
def test_get_queue_url():
|
def test_get_queue_url():
|
||||||
client = boto3.client("sqs", region_name="us-east-1")
|
client = boto3.client("sqs", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user