OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 # |
| 23 import json |
| 24 from tests.unit import unittest |
| 25 from tests.unit import AWSMockServiceTestCase |
| 26 from mock import Mock |
| 27 |
| 28 from boto.sns.connection import SNSConnection |
| 29 |
| 30 QUEUE_POLICY = { |
| 31 u'Policy': |
| 32 (u'{"Version":"2008-10-17","Id":"arn:aws:sqs:us-east-1:' |
| 33 'idnum:testqueuepolicy/SQSDefaultPolicy","Statement":' |
| 34 '[{"Sid":"sidnum","Effect":"Allow","Principal":{"AWS":"*"},' |
| 35 '"Action":"SQS:GetQueueUrl","Resource":' |
| 36 '"arn:aws:sqs:us-east-1:idnum:testqueuepolicy"}]}')} |
| 37 |
| 38 |
| 39 class TestSNSConnection(AWSMockServiceTestCase): |
| 40 connection_class = SNSConnection |
| 41 |
| 42 def setUp(self): |
| 43 super(TestSNSConnection, self).setUp() |
| 44 |
| 45 def default_body(self): |
| 46 return "{}" |
| 47 |
| 48 def test_sqs_with_existing_policy(self): |
| 49 self.set_http_response(status_code=200) |
| 50 |
| 51 queue = Mock() |
| 52 queue.get_attributes.return_value = QUEUE_POLICY |
| 53 queue.arn = 'arn:aws:sqs:us-east-1:idnum:queuename' |
| 54 |
| 55 self.service_connection.subscribe_sqs_queue('topic_arn', queue) |
| 56 self.assert_request_parameters({ |
| 57 'Action': 'Subscribe', |
| 58 'ContentType': 'JSON', |
| 59 'Endpoint': 'arn:aws:sqs:us-east-1:idnum:queuename', |
| 60 'Protocol': 'sqs', |
| 61 'SignatureMethod': 'HmacSHA256', |
| 62 'SignatureVersion': 2, |
| 63 'TopicArn': 'topic_arn', |
| 64 'Version': '2010-03-31', |
| 65 }, ignore_params_values=['AWSAccessKeyId', 'Timestamp']) |
| 66 |
| 67 # Verify that the queue policy was properly updated. |
| 68 actual_policy = json.loads(queue.set_attribute.call_args[0][1]) |
| 69 self.assertEqual(actual_policy['Version'], '2008-10-17') |
| 70 # A new statement should be appended to the end of the statement list. |
| 71 self.assertEqual(len(actual_policy['Statement']), 2) |
| 72 self.assertEqual(actual_policy['Statement'][1]['Action'], |
| 73 'SQS:SendMessage') |
| 74 |
| 75 def test_sqs_with_no_previous_policy(self): |
| 76 self.set_http_response(status_code=200) |
| 77 |
| 78 queue = Mock() |
| 79 queue.get_attributes.return_value = {} |
| 80 queue.arn = 'arn:aws:sqs:us-east-1:idnum:queuename' |
| 81 |
| 82 self.service_connection.subscribe_sqs_queue('topic_arn', queue) |
| 83 self.assert_request_parameters({ |
| 84 'Action': 'Subscribe', |
| 85 'ContentType': 'JSON', |
| 86 'Endpoint': 'arn:aws:sqs:us-east-1:idnum:queuename', |
| 87 'Protocol': 'sqs', |
| 88 'SignatureMethod': 'HmacSHA256', |
| 89 'SignatureVersion': 2, |
| 90 'TopicArn': 'topic_arn', |
| 91 'Version': '2010-03-31', |
| 92 }, ignore_params_values=['AWSAccessKeyId', 'Timestamp']) |
| 93 actual_policy = json.loads(queue.set_attribute.call_args[0][1]) |
| 94 # Only a single statement should be part of the policy. |
| 95 self.assertEqual(len(actual_policy['Statement']), 1) |
| 96 |
| 97 |
| 98 if __name__ == '__main__': |
| 99 unittest.main() |
OLD | NEW |