Exemplo n.º 1
0
 def _make_fut(self):
     from autopush.config import AutopushConfig
     from autopush.web.webpush import WebPushRequestSchema
     conf = AutopushConfig(
         hostname="localhost",
         statsd_host=None,
     )
     db = test_db()
     schema = WebPushRequestSchema()
     schema.context.update(conf=conf,
                           metrics=SinkMetrics(),
                           db=db,
                           routers=Mock(),
                           log=Mock())
     db.router.get_uaid.return_value = dict(
         router_type="gcm",
         uaid=dummy_uaid,
         router_data=dict(creds=dict(senderID="bogus")),
     )
     conf.fernet = self.fernet_mock = Mock()
     return schema
Exemplo n.º 2
0
    def test_update_not_needed(self):
        conf = AutopushConfig(
            hostname="google.com", resolve_hostname=True)
        db = DatabaseManager.from_config(
            conf,
            resource=autopush.tests.boto_resource)
        db.create_initial_message_tables()

        # Erase the tables it has on init, and move current month back one
        db.message_tables = []

        # Get the deferred back
        e = Deferred()
        d = db.update_rotating_tables()

        def check_tables(result):
            assert len(db.message_tables) == 1

        d.addCallback(check_tables)
        d.addBoth(lambda x: e.callback(True))
        return e
Exemplo n.º 3
0
    def setUp(self):
        self.timeout = 4
        twisted.internet.base.DelayedCall.debug = True

        conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
        )

        # ignore logging
        logs = _TestingLogObserver()
        begin_or_register(logs)
        self.addCleanup(globalLogPublisher.removeObserver, logs)

        lb_app = EndpointHTTPFactory.for_handler(
            LBHeartbeatHandler, conf, db=None
        )
        ver_app = EndpointHTTPFactory.for_handler(
            VersionHandler, conf, db=None
        )
        self.lb_client = Client(lb_app)
        self.ver_client = Client(ver_app)
Exemplo n.º 4
0
    def setUp(self):
        self.timeout = 0.5
        twisted.internet.base.DelayedCall.debug = True

        conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
        )

        db = DatabaseManager.from_config(conf)
        db.client = autopush.db.g_client
        db.setup_tables()

        # ignore logging
        logs = TestingLogObserver()
        begin_or_register(logs)
        self.addCleanup(globalLogPublisher.removeObserver, logs)

        app = EndpointHTTPFactory.for_handler(HealthHandler, conf, db=db)
        self.router_table = app.db.router.table
        self.message = app.db.message
        self.client = Client(app)
Exemplo n.º 5
0
 def setUp(self, ffcm):
     conf = AutopushConfig(
         hostname="localhost",
         statsd_host=None,
     )
     self.fcm_config = {
         'max_data': 32,
         'ttl': 60,
         'senderID': 'test123',
         "auth": "12345678abcdefg"
     }
     self.fcm = ffcm
     self.router = FCMRouter(conf, self.fcm_config, SinkMetrics())
     self.headers = {
         "content-encoding": "aesgcm",
         "encryption": "test",
         "encryption-key": "test"
     }
     # Payloads are Base64-encoded.
     self.notif = WebPushNotification(uaid=uuid.UUID(dummy_uaid),
                                      channel_id=uuid.UUID(dummy_chid),
                                      data="q60d6g",
                                      headers=self.headers,
                                      ttl=200)
     self.notif.cleanup_headers()
     self.router_data = dict(router_data=dict(
         token="connect_data",
         creds=dict(senderID="test123", auth="12345678abcdefg")))
     mock_result = dict(
         multicast_id="",
         success=0,
         failure=0,
         canonical_ids=0,
         results=[dict()],
     )
     self.mock_result = mock_result
     ffcm.notify_single_device.return_value = mock_result
Exemplo n.º 6
0
 def test_no_sslcontext_cache(self):
     conf = AutopushConfig.from_argparse(self.TestArg)
     assert not conf.no_sslcontext_cache
     self.TestArg._no_sslcontext_cache = True
     conf = AutopushConfig.from_argparse(self.TestArg)
     assert conf.no_sslcontext_cache
Exemplo n.º 7
0
 def test_bad_senders(self):
     old_list = self.TestArg.senderid_list
     self.TestArg.senderid_list = "{}"
     with pytest.raises(InvalidConfig):
         AutopushConfig.from_argparse(self.TestArg)
     self.TestArg.senderid_list = old_list
Exemplo n.º 8
0
 def test_resolve_host(self):
     ip = resolve_ip("example.com")
     conf = AutopushConfig(hostname="example.com", resolve_hostname=True)
     assert conf.hostname == ip
Exemplo n.º 9
0
 def test_client_certs_parse(self):
     conf = AutopushConfig.from_argparse(self.TestArg)
     assert conf.client_certs["1A:" * 31 + "F9"] == 'partner1'
     assert conf.client_certs["2B:" * 31 + "E8"] == 'partner2'
     assert conf.client_certs["3C:" * 31 + "D7"] == 'partner2'