Example #1
0
 def test_normalize_id(self):
     import autopush.db as db
     abnormal = "deadbeef00000000decafbad00000000"
     normal = "deadbeef-0000-0000-deca-fbad00000000"
     eq_(db.normalize_id(abnormal), normal)
     self.assertRaises(ValueError, db.normalize_id, "invalid")
     eq_(db.normalize_id(abnormal.upper()), normal)
Example #2
0
 def test_normalize_id(self):
     import autopush.db as db
     abnormal = "deadbeef00000000decafbad00000000"
     normal = "deadbeef-0000-0000-deca-fbad00000000"
     eq_(db.normalize_id(abnormal), normal)
     self.assertRaises(ValueError, db.normalize_id, "invalid")
     eq_(db.normalize_id(abnormal.upper()), normal)
Example #3
0
 def test_normalize_id(self):
     # Note, yes, we forbid dashes in UAIDs, and we add them here.
     import autopush.db as db
     abnormal = "deadbeef00000000decafbad00000000"
     normal = "deadbeef-0000-0000-deca-fbad00000000"
     eq_(db.normalize_id(abnormal), normal)
     assert_raises(ValueError, db.normalize_id, "invalid")
     eq_(db.normalize_id(abnormal.upper()), normal)
Example #4
0
 def test_normalize_id(self):
     # Note, yes, we forbid dashes in UAIDs, and we add them here.
     import autopush.db as db
     abnormal = "deadbeef00000000decafbad00000000"
     normal = "deadbeef-0000-0000-deca-fbad00000000"
     assert db.normalize_id(abnormal) == normal
     with pytest.raises(ValueError):
         db.normalize_id("invalid")
     assert db.normalize_id(abnormal.upper()) == normal
Example #5
0
    def _send_notification(self, uaid, node_id, notification):
        """Send a notification to a specific node_id

        This version of the overriden method includes the necessary crypto
        headers for the notification.

        """
        # Firefox currently requires channelIDs to be '-' formatted.
        payload = {
            "channelID": normalize_id(notification.channel_id),
            "version": notification.version,
            "ttl": notification.ttl or 0,
            "timestamp": int(time.time()),
        }
        if notification.data:
            payload["headers"] = self._crypto_headers(notification)
            payload["data"] = notification.data
        url = node_id + "/push/" + uaid
        d = self.ap_settings.agent.request(
            "PUT",
            url.encode("utf8"),
            bodyProducer=FileBodyProducer(StringIO(json.dumps(payload))),
        )
        d.addCallback(IgnoreBody.ignore)
        return d
Example #6
0
    def preflight_check(self, uaid, channel_id):
        """Verifies this routing call can be done successfully"""
        # Locate the user agent's message table
        record = yield deferToThread(self.ap_settings.router.get_uaid, uaid)

        if 'current_month' not in record:
            raise RouterException("No such subscription",
                                  status_code=404,
                                  log_exception=False,
                                  errno=106)

        month_table = record["current_month"]
        exists, chans = yield deferToThread(
            self.ap_settings.message_tables[month_table].all_channels,
            uaid=uaid)

        if (not exists or channel_id.lower() not in map(
                lambda x: normalize_id(x), chans)):
            raise RouterException("No such subscription",
                                  status_code=404,
                                  log_exception=False,
                                  errno=106)
        returnValue(month_table)
Example #7
0
 def chid(self, value):
     """Set the ChannelID and record to _client_info"""
     self._chid = normalize_id(value)
     self._client_info["channelID"] = self._chid
Example #8
0
 def chid(self, value):
     """Set the ChannelID and record to _client_info"""
     self._chid = normalize_id(value)
     self._client_info["channelID"] = self._chid