SNS create_topic should only accept valid characters (#1329)

* SNS create_topic should only accept valid characters

Closes #1328

* Fix flake8 errors

* Updated regex to match full TopicName constraints

Fixed test_server as it contained invalid TopicNames’ per constraints

* fix error message for invalid topic name
This commit is contained in:
Adam Gilman 2017-11-13 18:27:11 +00:00 committed by Terry Cain
commit 2ad0f2fc1c
4 changed files with 38 additions and 7 deletions

View file

@ -13,12 +13,12 @@ def test_sns_server_get():
backend = server.create_backend_app("sns")
test_client = backend.test_client()
topic_data = test_client.action_data("CreateTopic", Name="test topic")
topic_data = test_client.action_data("CreateTopic", Name="testtopic")
topic_data.should.contain("CreateTopicResult")
topic_data.should.contain(
"<TopicArn>arn:aws:sns:us-east-1:123456789012:test topic</TopicArn>")
"<TopicArn>arn:aws:sns:us-east-1:123456789012:testtopic</TopicArn>")
topics_data = test_client.action_data("ListTopics")
topics_data.should.contain("ListTopicsResult")
topic_data.should.contain(
"<TopicArn>arn:aws:sns:us-east-1:123456789012:test topic</TopicArn>")
"<TopicArn>arn:aws:sns:us-east-1:123456789012:testtopic</TopicArn>")

View file

@ -50,17 +50,35 @@ def test_create_topic_should_be_indempodent():
topic_display_name = conn.get_topic_attributes(
TopicArn=topic_arn
)['Attributes']['DisplayName']
topic_display_name.should.be.equal("should_be_set")
@mock_sns
def test_get_missing_topic():
conn = boto3.client("sns", region_name="us-east-1")
conn.get_topic_attributes.when.called_with(
TopicArn="a-fake-arn").should.throw(ClientError)
@mock_sns
def test_create_topic_must_meet_constraints():
conn = boto3.client("sns", region_name="us-east-1")
common_random_chars = [':', ";", "!", "@", "|", "^", "%"]
for char in common_random_chars:
conn.create_topic.when.called_with(
Name="no%s_invalidchar" % char).should.throw(ClientError)
conn.create_topic.when.called_with(
Name="no spaces allowed").should.throw(ClientError)
@mock_sns
def test_create_topic_should_be_of_certain_length():
conn = boto3.client("sns", region_name="us-east-1")
too_short = ""
conn.create_topic.when.called_with(
Name=too_short).should.throw(ClientError)
too_long = "x" * 257
conn.create_topic.when.called_with(
Name=too_long).should.throw(ClientError)
@mock_sns
def test_create_topic_in_multiple_regions():