示例#1
0
    def test_verify_subscription_notification(self, mock):
        """Test the verification of a valid subscription notification"""
        mock.return_value = self.pemfile

        notification = loader('subscriptionconfirmation')
        result = utils.verify_notification(notification)
        self.assertTrue(result)
示例#2
0
    def test_signal_sent(self, mock):
        """
        Test that the subscription signal was sent

        Based on http://stackoverflow.com/questions/3817213/
        """
        # pylint: disable=attribute-defined-outside-init, unused-variable
        responsemock = Mock()
        responsemock.read.return_value = 'Return Value'
        mock.return_value = responsemock
        notification = loader('subscriptionconfirmation')
        self.signal_count = 0

        @receiver(signals.subscription)
        def _signal_receiver(sender, **kwargs):
            """Signal Test Receiver"""
            self.signal_count += 1
            self.signal_sender = sender
            self.signal_notification = kwargs['notification']
            self.signal_result = kwargs['result']

        response = utils.approve_subscription(notification)

        self.assertEqual(response.content.decode('ascii'), 'Return Value')
        self.assertEqual(self.signal_count, 1)
        self.assertEqual(self.signal_result, 'Return Value')
        self.assertEqual(self.signal_notification, notification)
示例#3
0
    def test_signal_sent(self, mock):
        """
        Test that the subscription signal was sent

        Based on http://stackoverflow.com/questions/3817213/
        """
        # pylint: disable=attribute-defined-outside-init, unused-variable
        responsemock = Mock()
        responsemock.read.return_value = 'Return Value'
        mock.return_value = responsemock
        notification = loader('subscriptionconfirmation')
        self.signal_count = 0

        @receiver(signals.subscription)
        def _signal_receiver(sender, **kwargs):
            """Signal Test Receiver"""
            self.signal_count += 1
            self.signal_sender = sender
            self.signal_notification = kwargs['notification']
            self.signal_result = kwargs['result']

        response = utils.approve_subscription(notification)

        self.assertEqual(response.content.decode('ascii'), 'Return Value')
        self.assertEqual(self.signal_count, 1)
        self.assertEqual(self.signal_result, 'Return Value')
        self.assertEqual(self.signal_notification, notification)
示例#4
0
    def test_verify_subscription_notification(self, mock):
        """Test the verification of a valid subscription notification"""
        mock.return_value = self.pemfile

        notification = loader('subscriptionconfirmation')
        result = utils.verify_notification(notification)
        self.assertTrue(result)
示例#5
0
    def test_subscription_verification_failure(self, mock):
        """Test the failure of an invalid subscription notification"""
        mock.return_value = self.pemfile
        notification = loader('subscriptionconfirmation')
        notification['TopicArn'] = 'BadArn'
        result = utils.verify_notification(notification)

        self.assertFalse(result)
示例#6
0
 def test_unknown_message(self):
     """Test a JSON message without a type returns an error"""
     message = loader('bounce')
     message['notificationType'] = 'Not A Valid Notification'
     result = views.process_message(message, self.notification)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(
         result.content.decode('ascii'), 'Unknown Notification Type')
示例#7
0
 def test_approve_subscription_called(self, mock):
     """Test that a approve_subscription is called"""
     mock.return_value = 'Test Return Value'
     notification = loader('subscriptionconfirmation')
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertTrue(mock.called)
     self.assertEqual(result, 'Test Return Value')
示例#8
0
    def test_subscription_verification_failure(self, mock):
        """Test the failure of an invalid subscription notification"""
        mock.return_value = self.pemfile
        notification = loader('subscriptionconfirmation')
        notification['TopicArn'] = 'BadArn'
        result = utils.verify_notification(notification)

        self.assertFalse(result)
示例#9
0
 def test_approve_subscription_called(self, mock):
     """Test that a approve_subscription is called"""
     mock.return_value = 'Test Return Value'
     notification = loader('subscriptionconfirmation')
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertTrue(mock.called)
     self.assertEqual(result, 'Test Return Value')
示例#10
0
 def test_missing_fields(self):
     """Test that missing vital fields returns an error"""
     message = loader('bounce')
     del(message['mail'])
     result = views.process_message(message, self.notification)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(
         result.content.decode('ascii'), 'Missing Vital Fields')
示例#11
0
 def test_missing_fields(self):
     """Test that missing vital fields returns an error"""
     message = loader('bounce')
     del (message['mail'])
     result = views.process_message(message, self.notification)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(result.content.decode('ascii'),
                      'Missing Vital Fields')
示例#12
0
 def test_unknown_message(self):
     """Test a JSON message without a type returns an error"""
     message = loader('bounce')
     message['notificationType'] = 'Not A Valid Notification'
     result = views.process_message(message, self.notification)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(result.content.decode('ascii'),
                      'Unknown Notification Type')
示例#13
0
 def test_bad_certificate_url(self):
     """Test an unknown certificate hostname"""
     notification = loader('bounce_notification')
     notification['SigningCertURL'] = 'https://baddomain.com/cert.pem'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 400)
     self.assertEqual(
         result.content.decode('ascii'), 'Improper Certificate Location')
示例#14
0
 def test_unknown_notification_type(self):
     """Test an unknown notification type"""
     notification = loader('bounce_notification')
     notification['Type'] = 'NotAKnownType'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 400)
     self.assertEqual(
         result.content.decode('ascii'), 'Unknown Notification Type')
示例#15
0
 def test_unknown_notification_type(self):
     """Test an unknown notification type"""
     notification = loader('bounce_notification')
     notification['Type'] = 'NotAKnownType'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 400)
     self.assertEqual(result.content.decode('ascii'),
                      'Unknown Notification Type')
示例#16
0
 def test_non_json_message_not_allowed(self):
     """Test that a non-JSON message is properly ignored"""
     notification = loader('bounce_notification')
     notification['Message'] = 'Non JSON Message'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(
         result.content.decode('ascii'), 'Message is not valid JSON')
示例#17
0
 def test_non_json_message_not_allowed(self):
     """Test that a non-JSON message is properly ignored"""
     notification = loader('bounce_notification')
     notification['Message'] = 'Non JSON Message'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(result.content.decode('ascii'),
                      'Message is not valid JSON')
示例#18
0
 def test_unsubscribe_confirmation_not_handled(self):
     """Test that an unsubscribe notification is properly ignored"""
     notification = loader('bounce_notification')
     notification['Type'] = 'UnsubscribeConfirmation'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(result.content.decode('ascii'),
                      'UnsubscribeConfirmation Not Handled')
示例#19
0
 def test_bad_certificate_url(self):
     """Test an unknown certificate hostname"""
     notification = loader('bounce_notification')
     notification['SigningCertURL'] = 'https://baddomain.com/cert.pem'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 400)
     self.assertEqual(result.content.decode('ascii'),
                      'Improper Certificate Location')
示例#20
0
 def test_unsubscribe_confirmation_not_handled(self):
     """Test that an unsubscribe notification is properly ignored"""
     notification = loader('bounce_notification')
     notification['Type'] = 'UnsubscribeConfirmation'
     self.request._body = json.dumps(notification)
     result = views.endpoint(self.request)
     self.assertEqual(result.status_code, 200)
     self.assertEqual(
         result.content.decode('ascii'),
         'UnsubscribeConfirmation Not Handled'
     )
示例#21
0
    def test_approve_subscription(self, mock):
        """Test the subscription approval mechanism"""
        responsemock = Mock()
        responsemock.read.return_value = 'Return Value'
        mock.return_value = responsemock
        notification = loader('subscriptionconfirmation')

        response = utils.approve_subscription(notification)

        mock.assert_called_with(notification['SubscribeURL'])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('ascii'), 'Return Value')
示例#22
0
    def test_approve_subscription(self, mock):
        """Test the subscription approval mechanism"""
        responsemock = Mock()
        responsemock.read.return_value = 'Return Value'
        mock.return_value = responsemock
        notification = loader('subscriptionconfirmation')

        response = utils.approve_subscription(notification)

        mock.assert_called_with(notification['SubscribeURL'])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('ascii'), 'Return Value')
示例#23
0
 def test_subscription_throws_404(self):
     """
     Test that a subscription request sent to bouncy throws a 404 if not
     permitted
     """
     original_setting = getattr(settings, 'BOUNCY_AUTO_SUBSCRIBE', True)
     settings.BOUNCY_AUTO_SUBSCRIBE = False
     with self.assertRaises(Http404):
         notification = loader('subscriptionconfirmation')
         self.request._body = json.dumps(notification)
         views.endpoint(self.request)
     settings.BOUNCY_AUTO_SUBSCRIBE = original_setting
示例#24
0
 def test_subscription_throws_404(self):
     """
     Test that a subscription request sent to bouncy throws a 404 if not
     permitted
     """
     original_setting = getattr(settings, 'BOUNCY_AUTO_SUBSCRIBE', True)
     settings.BOUNCY_AUTO_SUBSCRIBE = False
     with self.assertRaises(Http404):
         notification = loader('subscriptionconfirmation')
         self.request._body = json.dumps(notification)
         views.endpoint(self.request)
     settings.BOUNCY_AUTO_SUBSCRIBE = original_setting
示例#25
0
    def test_bad_url(self):
        """Test to make sure an invalid URL isn't requested by our system"""
        old_setting = getattr(settings, 'BOUNCY_SUBSCRIBE_DOMAIN_REGEX', None)
        settings.BOUNCY_SUBSCRIBE_DOMAIN_REGEX = \
            r"sns.[a-z0-9\-]+.amazonaws.com$"
        notification = loader('bounce_notification')
        notification['SubscribeURL'] = 'http://bucket.s3.amazonaws.com'
        result = utils.approve_subscription(notification)

        self.assertEqual(result.status_code, 400)
        self.assertEqual(
            result.content.decode('ascii'), 'Improper Subscription Domain')

        if old_setting is not None:
            settings.BOUNCY_SUBSCRIBE_DOMAIN_REGEX = old_setting
示例#26
0
    def test_bad_url(self):
        """Test to make sure an invalid URL isn't requested by our system"""
        old_setting = getattr(settings, 'BOUNCY_SUBSCRIBE_DOMAIN_REGEX', None)
        settings.BOUNCY_SUBSCRIBE_DOMAIN_REGEX = \
            r"sns.[a-z0-9\-]+.amazonaws.com$"
        notification = loader('bounce_notification')
        notification['SubscribeURL'] = 'http://bucket.s3.amazonaws.com'
        result = utils.approve_subscription(notification)

        self.assertEqual(result.status_code, 400)
        self.assertEqual(result.content.decode('ascii'),
                         'Improper Subscription Domain')

        if old_setting is not None:
            settings.BOUNCY_SUBSCRIBE_DOMAIN_REGEX = old_setting
示例#27
0
 def setUp(self):
     """Setup the process delivery test"""
     self.delivery = loader('delivery')
     self.delivery_notification = loader('delivery_notification')
示例#28
0
 def setUp(self):
     self.complaint_notification = loader('complaint_notification')
示例#29
0
 def test_complaint(self, mock):
     """Test that a complaint is sent to process_complaint"""
     notification = loader('complaint_notification')
     views.process_message(self.complaint, notification)
     mock.assert_called_with(self.complaint, notification)
示例#30
0
 def test_complaint(self, mock):
     """Test that a complaint is sent to process_complaint"""
     notification = loader('complaint_notification')
     views.process_message(self.complaint, notification)
     mock.assert_called_with(self.complaint, notification)
示例#31
0
 def setUp(self):
     self.complaint_notification = loader('complaint_notification')
示例#32
0
 def setUp(self):
     """Setup the process delivery test"""
     self.delivery = loader('delivery')
     self.delivery_notification = loader('delivery_notification')