Fix:sqs get-queue-attributes response template (#3255)

* Fix:sqs get-queue-attributes response template

* Fix:removed debug statements

* Modified the template

* "fixed build issues"

* Linting

Co-authored-by: usmankb <usman@krazybee.com>
Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
usmangani1 2020-09-01 22:35:25 +05:30 committed by GitHub
parent 127b3e73e9
commit 3ea46617d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 5 deletions

View File

@ -626,7 +626,8 @@ class SQSBackend(BaseBackend):
attributes = queue.attributes
else:
for name in (name for name in attribute_names if name in queue.attributes):
attributes[name] = queue.attributes.get(name)
if queue.attributes.get(name) is not None:
attributes[name] = queue.attributes.get(name)
return attributes

View File

@ -490,10 +490,12 @@ DELETE_QUEUE_RESPONSE = """<DeleteQueueResponse>
GET_QUEUE_ATTRIBUTES_RESPONSE = """<GetQueueAttributesResponse>
<GetQueueAttributesResult>
{% for key, value in attributes.items() %}
<Attribute>
<Name>{{ key }}</Name>
<Value>{{ value }}</Value>
</Attribute>
{% if value is not none %}
<Attribute>
<Name>{{ key }}</Name>
<Value>{{ value }}</Value>
</Attribute>
{% endif %}
{% endfor %}
</GetQueueAttributesResult>
<ResponseMetadata>

View File

@ -45,6 +45,25 @@ sqs_template_with_tags = """
}
}"""
TEST_POLICY = """
{
"Version":"2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Principal": { "AWS": "*" },
"Action": "sqs:SendMessage",
"Resource": "'$sqs_queue_arn'",
"Condition":{
"ArnEquals":{
"aws:SourceArn":"'$sns_topic_arn'"
}
}
}
]
}
"""
@mock_sqs
def test_create_fifo_queue_fail():
@ -1451,6 +1470,36 @@ def test_permissions():
)
@mock_sqs
def test_get_queue_attributes_template_response_validation():
client = boto3.client("sqs", region_name="us-east-1")
resp = client.create_queue(
QueueName="test-dlr-queue.fifo", Attributes={"FifoQueue": "true"}
)
queue_url = resp["QueueUrl"]
attrs = client.get_queue_attributes(QueueUrl=queue_url, AttributeNames=["All"])
assert attrs.get("Attributes").get("Policy") is None
attributes = {"Policy": TEST_POLICY}
client.set_queue_attributes(QueueUrl=queue_url, Attributes=attributes)
attrs = client.get_queue_attributes(QueueUrl=queue_url, AttributeNames=["Policy"])
assert attrs.get("Attributes").get("Policy") is not None
assert (
json.loads(attrs.get("Attributes").get("Policy")).get("Version") == "2012-10-17"
)
assert len(json.loads(attrs.get("Attributes").get("Policy")).get("Statement")) == 1
assert (
json.loads(attrs.get("Attributes").get("Policy"))
.get("Statement")[0]
.get("Action")
== "sqs:SendMessage"
)
@mock_sqs
def test_add_permission_errors():
client = boto3.client("sqs", region_name="us-east-1")