SNS: Disable cross-region access (#6355)

This commit is contained in:
Bert Blommers 2023-06-02 09:35:31 +00:00 committed by GitHub
parent 37cb6cee94
commit c171781223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -493,7 +493,7 @@ class SNSBackend(BaseBackend):
def get_topic(self, arn: str) -> Topic:
parsed_arn = parse_arn(arn)
try:
return sns_backends[parsed_arn.account][parsed_arn.region].topics[arn]
return sns_backends[parsed_arn.account][self.region_name].topics[arn]
except KeyError:
raise TopicNotFound

View File

@ -1,7 +1,8 @@
import boto3
import json
import pytest
# import sure # noqa # pylint: disable=unused-import
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError
from moto import mock_sns
@ -131,9 +132,23 @@ def test_create_topic_should_be_of_certain_length():
def test_create_topic_in_multiple_regions():
for region in ["us-west-1", "us-west-2"]:
conn = boto3.client("sns", region_name=region)
conn.create_topic(Name="some-topic")
topic_arn = conn.create_topic(Name="some-topic")["TopicArn"]
# We can find the topic
list(conn.list_topics()["Topics"]).should.have.length_of(1)
# We can read the Topic details
topic = boto3.resource("sns", region_name=region).Topic(topic_arn)
topic.load()
# Topic does not exist in different region though
with pytest.raises(ClientError) as exc:
sns_resource = boto3.resource("sns", region_name="eu-north-1")
topic = sns_resource.Topic(topic_arn)
topic.load()
err = exc.value.response["Error"]
assert err["Code"] == "NotFound"
assert err["Message"] == "Topic does not exist"
@mock_sns
def test_topic_corresponds_to_region():