1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

[aws/sns] mock subscription confirmation

Conflicts:
	lib/fog/aws/sns.rb
This commit is contained in:
Josh Lane 2014-12-30 14:49:25 -08:00
parent 76d86d9631
commit bd134ee093
2 changed files with 28 additions and 0 deletions

View file

@ -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

View file

@ -100,6 +100,8 @@ module Fog
setup_credentials(options)
end
attr_reader :region
def reload
@connection.reset
end