Exemplo n.º 1
0
    def setUp(self):
        settings = AutopushSettings(
            hostname="localhost",
            statsd_host=None,
        )

        self.headers = headers = {
            "content-encoding": "aes128",
            "encryption": "awesomecrypto",
            "crypto-key": "niftykey"
        }
        self.router = WebPushRouter(settings, {})
        self.notif = Notification("EncMessageId", "data",
                                  dummy_chid, headers, 20)
        mock_result = Mock(spec=gcmclient.gcm.Result)
        mock_result.canonical = dict()
        mock_result.failed = dict()
        mock_result.not_registered = dict()
        mock_result.needs_retry.return_value = False
        self.router_mock = settings.router = Mock(spec=Router)
        self.message_mock = settings.message = Mock(spec=Message)
        self.agent_mock = Mock(spec=settings.agent)
        settings.agent = self.agent_mock
        self.router.metrics = Mock()
        self.settings = settings
Exemplo n.º 2
0
 def setUp(self, fgcm):
     settings = AutopushSettings(
         hostname="localhost",
         statsd_host=None,
     )
     self.gcm_config = {'s3_bucket': 'None',
                        'max_data': 32,
                        'ttl': 60,
                        'senderid_list': {'test123':
                                          {"auth": "12345678abcdefg"}}}
     self.gcm = fgcm
     self.router = GCMRouter(settings, self.gcm_config)
     self.headers = {"content-encoding": "aesgcm",
                     "encryption": "test",
                     "encryption-key": "test"}
     # Payloads are Base64-encoded.
     self.notif = Notification(10, "q60d6g", dummy_chid, self.headers,
                               200)
     self.router_data = dict(
         router_data=dict(
             token="connect_data",
             creds=dict(senderID="test123", auth="12345678abcdefg")))
     mock_result = Mock(spec=gcmclient.gcm.Result)
     mock_result.canonical = dict()
     mock_result.failed = dict()
     mock_result.not_registered = dict()
     mock_result.needs_retry.return_value = False
     self.mock_result = mock_result
     fgcm.send.return_value = mock_result
Exemplo n.º 3
0
    def test_route_crypto_key(self):
        headers = {"content-encoding": "aesgcm",
                   "encryption": "test",
                   "crypto-key": "test"}
        self.notif = Notification(10, "q60d6g", dummy_chid, headers, 200)
        now = int(time.time())
        self.router.messages = {now: {'token': 'dump', 'payload': {}},
                                now-60: {'token': 'dump', 'payload': {}}}
        d = self.router.route_notification(self.notif, self.router_data)

        def check_results(result):
            ok_(isinstance(result, RouterResponse))
            assert(self.mock_apns.gateway_server.send_notification.called)
            eq_(len(self.router.messages), 1)

            payload = self.router.messages[now]['payload']
            eq_(payload.alert, 'SimplePush')

            custom = payload.custom
            eq_(custom['Msg'], self.notif.data)
            eq_(custom['Ver'], self.notif.version)
            eq_(custom['Con'], 'aesgcm')
            eq_(custom['Enc'], 'test')
            eq_(custom['Cryptokey'], 'test')
            eq_(custom['Chid'], self.notif.channel_id)
            ok_('Enckey' not in custom)

        d.addCallback(check_results)
        return d
Exemplo n.º 4
0
    def test_route_to_busy_node_with_ttl_zero(self):
        notif = Notification("EncMessageId", "data", dummy_chid, self.headers,
                             0)
        self.agent_mock.request.return_value = response_mock = Mock()
        response_mock.addCallback.return_value = response_mock
        type(response_mock).code = PropertyMock(
            side_effect=MockAssist([202, 200]))
        self.message_mock.store_message.return_value = True
        self.message_mock.all_channels.return_value = (True, [dummy_chid])
        router_data = dict(node_id="http://somewhere",
                           uaid=dummy_uaid,
                           current_month=self.settings.current_msg_month)
        self.router_mock.get_uaid.return_value = router_data
        self.router.message_id = uuid.uuid4().hex

        d = self.router.route_notification(notif, router_data)

        def verify_deliver(fail):
            exc = fail.value
            ok_(exc, RouterResponse)
            eq_(exc.status_code, 201)
            eq_(len(self.router.metrics.increment.mock_calls), 0)
            ok_("Location" in exc.headers)

        d.addBoth(verify_deliver)
        return d
Exemplo n.º 5
0
 def setUp(self):
     settings = AutopushSettings(
         hostname="localhost",
         statsd_host=None,
     )
     apns_config = {'cert_file': 'fake.cert', 'key_file': 'fake.key'}
     self.mock_apns = Mock(spec=apns.APNs)
     self.router = APNSRouter(settings, apns_config)
     self.router.apns = self.mock_apns
     self.notif = Notification(10, "data", dummy_chid, None, 200)
     self.router_data = dict(router_data=dict(token="connect_data"))
Exemplo n.º 6
0
    def test_long_data(self):
        self.router.gcm = self.gcm
        badNotif = Notification(10, "\x01abcdefghijklmnopqrstuvwxyz0123456789",
                                dummy_chid, self.headers, 200)
        d = self.router.route_notification(badNotif, self.router_data)

        def check_results(result):
            ok_(isinstance(result.value, RouterException))
            eq_(result.value.status_code, 413)
            eq_(result.value.errno, 104)

        d.addBoth(check_results)
        return d
Exemplo n.º 7
0
 def setUp(self):
     from twisted.logger import Logger
     settings = AutopushSettings(
         hostname="localhost",
         statsd_host=None,
     )
     apns_config = {'cert_file': 'fake.cert', 'key_file': 'fake.key'}
     self.mock_apns = Mock(spec=apns.APNs)
     self.router = APNSRouter(settings, apns_config)
     self.router.apns = self.mock_apns
     self.router.log = Mock(spec=Logger)
     self.headers = {"content-encoding": "aesgcm",
                     "encryption": "test",
                     "encryption-key": "test"}
     self.notif = Notification(10, "q60d6g", dummy_chid, self.headers,
                               200)
     self.router_data = dict(router_data=dict(token="connect_data"))
Exemplo n.º 8
0
    def setUp(self):
        settings = AutopushSettings(
            hostname="localhost",
            statsd_host=None,
        )

        self.router = SimpleRouter(settings, {})
        self.notif = Notification(10, "data", dummy_chid, None, 200)
        mock_result = Mock(spec=gcmclient.gcm.Result)
        mock_result.canonical = dict()
        mock_result.failed = dict()
        mock_result.not_registered = dict()
        mock_result.needs_retry.return_value = False
        self.router_mock = settings.router = Mock(spec=Router)
        self.storage_mock = settings.storage = Mock(spec=Storage)
        self.agent_mock = Mock(spec=settings.agent)
        settings.agent = self.agent_mock
        self.router.metrics = Mock()
Exemplo n.º 9
0
 def setUp(self, fgcm):
     settings = AutopushSettings(
         hostname="localhost",
         statsd_host=None,
     )
     gcm_config = {'s3_bucket': 'None',
                   'senderid_list': {'test123':
                                     {"auth": "12345678abcdefg"}}}
     self.gcm = fgcm
     self.router = GCMRouter(settings, gcm_config)
     self.notif = Notification(10, "data", dummy_chid, None, 200)
     self.router_data = dict(
         router_data=dict(
             token="connect_data",
             creds=dict(senderID="test123", auth="12345678abcdefg")))
     mock_result = Mock(spec=gcmclient.gcm.Result)
     mock_result.canonical = dict()
     mock_result.failed = dict()
     mock_result.not_registered = dict()
     mock_result.needs_retry.return_value = False
     self.mock_result = mock_result
     fgcm.send.return_value = mock_result
Exemplo n.º 10
0
    def test_ttl_none(self):
        self.router.gcm = self.gcm
        self.notif = Notification(version=10,
                                  data="q60d6g",
                                  channel_id=dummy_chid,
                                  headers=self.headers,
                                  ttl=None)
        d = self.router.route_notification(self.notif, self.router_data)

        def check_results(result):
            ok_(isinstance(result, RouterResponse))
            assert(self.router.gcm.send.called)
            # Make sure the data was encoded as base64
            data = self.router.gcm.send.call_args[0][0].data
            options = self.router.gcm.send.call_args[0][0].options
            eq_(data['body'], 'q60d6g')
            eq_(data['enc'], 'test')
            eq_(data['enckey'], 'test')
            eq_(data['con'], 'aesgcm')
            # use the defined min TTL
            eq_(options['time_to_live'], 60)
        d.addCallback(check_results)
        return d