From bd134ee09354ee9f933376c7204a9aaf5c2a1372 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Tue, 30 Dec 2014 14:49:25 -0800 Subject: [PATCH] [aws/sns] mock subscription confirmation Conflicts: lib/fog/aws/sns.rb --- lib/fog/aws/requests/sns/subscribe.rb | 26 ++++++++++++++++++++++++++ lib/fog/aws/sns.rb | 2 ++ 2 files changed, 28 insertions(+) diff --git a/lib/fog/aws/requests/sns/subscribe.rb b/lib/fog/aws/requests/sns/subscribe.rb index 1cf22931b..d4c0a0c0a 100644 --- a/lib/fog/aws/requests/sns/subscribe.rb +++ b/lib/fog/aws/requests/sns/subscribe.rb @@ -51,6 +51,32 @@ module Fog "Endpoint" => endpoint, } + mock_data = Fog::AWS::SQS::Mock.data.values.find { |a| a.values.find { |d| d[:queues][endpoint] } } + access_key = mock_data && mock_data.keys.first + + if protocol == "sqs" && access_key + token = SecureRandom.hex(128) + message = "You have chosen to subscribe to the topic #{arn}.\nTo confirm the subscription, visit the SubscribeURL included in this message." + signature = Fog::HMAC.new("sha256", token).sign(message) + + Fog::AWS::SQS.new( + :region => self.region, + :aws_access_key_id => access_key, + :aws_secret_access_key => SecureRandom.hex(3), + ).send_message(endpoint, Fog::JSON.encode( + "Type" => "SubscriptionConfirmation", + "MessageId" => SecureRandom.uuid, + "Token" => token, + "TopicArn" => arn, + "Message" => message, + "SubscribeURL" => "https://sns.#{self.region}.amazonaws.com/?Action=ConfirmSubscription&TopicArn=#{arn}&Token=#{token}", + "Timestamp" => Time.now.iso8601, + "SignatureVersion" => "1", + "Signature" => signature, + "SigningCertURL" => "https://sns.#{self.region}.amazonaws.com/SimpleNotificationService-#{SecureRandom.hex(16)}.pem" + )) + end + response.body = { 'SubscriptionArn' => 'pending confirmation', 'RequestId' => Fog::AWS::Mock.request_id } response end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 7abe6f39c..e112c9295 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -100,6 +100,8 @@ module Fog setup_credentials(options) end + attr_reader :region + def reload @connection.reset end