8000 fix GetTopicAttributes exception when arn is malformed by bentsku · Pull Request #9310 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content
8000

fix GetTopicAttributes exception when arn is malformed #9310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion localstack/services/sns/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def _get_topic(arn: str, context: RequestContext) -> Topic:
def get_topic_attributes(
self, context: RequestContext, topic_arn: topicARN
) -> GetTopicAttributesResponse:
# get the Topic from moto manually first, because Moto does not handle well the case where the ARN is malformed
# (raises ValueError: not enough values to unpack (expected 6, got 1))
moto_topic_model = self._get_topic(topic_arn, context)
moto_response: GetTopicAttributesResponse = call_moto(context)
# TODO: fix some attributes by moto, see snapshot
# DeliveryPolicy
Expand All @@ -120,7 +123,6 @@ def get_topic_attributes(
# TODO: very hacky way to get the attributes we need instead of a moto patch
# see the attributes we need: https://docs.aws.amazon.com/sns/latest/dg/sns-topic-attributes.html
# would need more work to have the proper format out of moto, maybe extract the model to our store
moto_topic_model = self._get_topic(topic_arn, context)
for attr in vars(moto_topic_model):
if "success_feedback" in attr:
key = camelcase_to_pascal(underscores_to_camelcase(attr))
Expand Down
5 changes: 5 additions & 0 deletions tests/aws/services/sns/test_sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def test_create_topic_with_attributes(self, sns_create_topic, snapshot, aws_clie

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

with pytest.raises(ClientError) as e:
aws_client.sns.get_topic_attributes(TopicArn="test-topic")

snapshot.match("get-attrs-malformed-topic", e.value.response)

@markers.aws.validated
def test_tags(self, sns_create_topic, snapshot, aws_client):

Expand Down
13 changes: 12 additions & 1 deletion tests/aws/services/sns/test_sns.snapshot.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/aws/services/sns/test_sns.py::TestSNSTopicCrud::test_create_topic_with_attributes": {
"recorded-date": "24-08-2023, 22:30:43",
"recorded-date": "06-10-2023, 20:11:02",
"recorded-content": {
"get-topic-attrs": {
"Attributes": {
Expand Down Expand Up @@ -75,6 +75,17 @@
"HTTPHeaders": {},
"HTTPStatusCode": 404
}
},
"get-attrs-malformed-topic": {
"Error": {
"Code": "InvalidParameter",
"Message": "Invalid parameter: TopicArn Reason: An ARN must have at least 6 elements, not 1",
"Type": "Sender"
},
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 400
}
}
}
},
Expand Down
0