diff --git a/lib/fog/aws/requests/sns/add_permission.rb b/lib/fog/aws/requests/sns/add_permission.rb index 6b6898697..98e5ee0ed 100644 --- a/lib/fog/aws/requests/sns/add_permission.rb +++ b/lib/fog/aws/requests/sns/add_permission.rb @@ -14,7 +14,19 @@ module Fog class Mock def add_permission(options = {}) - Fog::Mock.not_implemented + topic_arn = options.delete('TopicArn') + label = options.delete('Label') + actions = options.select { |k,v| k.match(/^ActionName/) }.values + members = options.select { |k,v| k.match(/^AWSAccountId/) }.values + + self.data[:permissions][topic_arn][label] = { + :members => members, + :actions => actions, + } + + response = Excon::Response.new + response.body = {"RequestId" => Fog::AWS::Mock.request_id} + response end end end diff --git a/lib/fog/aws/requests/sns/create_topic.rb b/lib/fog/aws/requests/sns/create_topic.rb index 5c780edac..1cc1e9bd6 100644 --- a/lib/fog/aws/requests/sns/create_topic.rb +++ b/lib/fog/aws/requests/sns/create_topic.rb @@ -38,6 +38,7 @@ module Fog "EffectiveDeliveryPolicy" => %Q|{"http":{"defaultHealthyRetryPolicy":{"minDelayTarget":20,"maxDelayTarget":20,"numRetries":3,"numMaxDelayRetries":0,"numNoDelayRetries":0,"numMinDelayRetries":0,"backoffFunction":"linear"},"disableSubscriptionOverrides":false}}|, "Policy" => %Q|{"Version":"2008-10-17","Id":"__default_policy_ID","Statement":[{"Sid":"__default_statement_ID","Effect":"Allow","Principal":{"AWS":"*"},"Action":["SNS:Publish","SNS:RemovePermission","SNS:SetTopicAttributes","SNS:DeleteTopic","SNS:ListSubscriptionsByTopic","SNS:GetTopicAttributes","SNS:Receive","SNS:AddPermission","SNS:Subscribe"],"Resource":"arn:aws:sns:us-east-1:990279267269:Smithy","Condition":{"StringEquals":{"AWS:SourceOwner":"990279267269"}}}]}| } + self.data[:permissions][topic_arn] = {} response.body = {"TopicArn" => topic_arn, "RequestId" => Fog::AWS::Mock.request_id} response end diff --git a/lib/fog/aws/requests/sns/remove_permission.rb b/lib/fog/aws/requests/sns/remove_permission.rb index 743b00beb..6ce6c8d66 100644 --- a/lib/fog/aws/requests/sns/remove_permission.rb +++ b/lib/fog/aws/requests/sns/remove_permission.rb @@ -14,7 +14,14 @@ module Fog class Mock def remove_permission(options = {}) - Fog::Mock.not_implemented + topic_arn = options['TopicArn'] + label = options['Label'] + + self.data[:permissions][topic_arn].delete(label) + + response = Excon::Response.new + response.body = {"RequestId" => Fog::AWS::Mock.request_id} + response end end end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index dee901405..5c4d76e0d 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -32,6 +32,7 @@ module Fog region_hash[key] = { :topics => {}, :subscriptions => {}, + :permissions => {}, } end end diff --git a/tests/requests/sns/topic_tests.rb b/tests/requests/sns/topic_tests.rb index bb5dea138..31e631b7a 100644 --- a/tests/requests/sns/topic_tests.rb +++ b/tests/requests/sns/topic_tests.rb @@ -32,6 +32,14 @@ Shindo.tests('AWS::SNS | topic lifecycle tests', ['aws', 'sns']) do Fog::AWS[:sns].get_topic_attributes(@topic_arn).body end + tests("#add_permission('#{@topic_arn}')").formats(AWS::SNS::Formats::BASIC) do + Fog::AWS[:sns].add_permission('TopicArn' => @topic_arn, 'Label' => 'Test', 'ActionName.member.1' => 'Subscribe', 'AWSAccountId.member.1' => '1234567890').body + end + + tests("#remove_permission('#{@topic_arn}')").formats(AWS::SNS::Formats::BASIC) do + Fog::AWS[:sns].remove_permission('TopicArn' => @topic_arn, 'Label' => 'Test').body + end + tests("#delete_topic('#{@topic_arn}')").formats(AWS::SNS::Formats::BASIC) do Fog::AWS[:sns].delete_topic(@topic_arn).body end