8000 fix GetTopicAttributes exception (#9310) · codeperl/localstack@106f5e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 106f5e0

Browse files
authored
fix GetTopicAttributes exception (localstack#9310)
1 parent dbe71cc commit 106f5e0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

localstack/services/sns/provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def _get_topic(arn: str, context: RequestContext) -> Topic:
112112
def get_topic_attributes(
113113
self, context: RequestContext, topic_arn: topicARN
114114
) -> GetTopicAttributesResponse:
115+
# get the Topic from moto manually first, because Moto does not handle well the case where the ARN is malformed
116+
# (raises ValueError: not enough values to unpack (expected 6, got 1))
117+
moto_topic_model = self._get_topic(topic_arn, context)
115118
moto_response: GetTopicAttributesResponse = call_moto(context)
116119
# TODO: fix some attributes by moto, see snapshot
117120
# DeliveryPolicy
@@ -120,7 +123,6 @@ def get_topic_attributes(
120123
# TODO: very hacky way to get the attributes we need instead of a moto patch
121124
# see the attributes we need: https://docs.aws.amazon.com/sns/latest/dg/sns-topic-attributes.html
122125
# would need more work to have the proper format out of moto, maybe extract the model to our store
123-
moto_topic_model = self._get_topic(topic_arn, context)
124126
for attr in vars(moto_topic_model):
125127
if "success_feedback" in attr:
126128
key = camelcase_to_pascal(underscores_to_camelcase(attr))

tests/aws/services/sns/test_sns.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def test_create_topic_with_attributes(self, sns_create_topic, snapshot, aws_clie
112112

113113
snapshot.match("get-attrs-nonexistent-topic", e.value.response)
114114

115+
with pytest.raises(ClientError) as e:
116+
aws_client.sns.get_topic_attributes(TopicArn="test-topic")
117+
118+
snapshot.match("get-attrs-malformed-topic", e.value.response)
119+
115120
@markers.aws.validated
116121
def test_tags(self, sns_create_topic, snapshot, aws_client):
117122

tests/aws/services/sns/test_sns.snapshot.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tests/aws/services/sns/test_sns.py::TestSNSTopicCrud::test_create_topic_with_attributes": {
3-
"recorded-date": "24-08-2023, 22:30:43",
3+
"recorded-date": "06-10-2023, 20:11:02",
44
"recorded-content": {
55
"get-topic-attrs": {
66
"Attributes": {
@@ -75,6 +75,17 @@
7575
"HTTPHeaders": {},
7676
"HTTPStatusCode": 404
7777
}
78+
},
79+
"get-attrs-malformed-topic": {
80+
"Error": {
81+
"Code": "InvalidParameter",
82+
"Message": "Invalid parameter: TopicArn Reason: An ARN must have at least 6 elements, not 1",
83+
"Type": "Sender"
84+
},
85+
"ResponseMetadata": {
86 5195 +
"HTTPHeaders": {},
87+
"HTTPStatusCode": 400
88+
}
7889
}
7990
}
8091
},

0 commit comments

Comments
 (0)
0