def setUp(self):
        twisted.internet.base.DelayedCall.debug = True
        conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
            bear_hash_key='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB=',
        )
        self.fernet_mock = conf.fernet = Mock(spec=Fernet)

        self.db = db = test_db()
        db.router = Mock(spec=Router)
        db.router.register_user.return_value = (True, {}, {})
        db.router.get_uaid.return_value = {
            "router_type": "test",
            "router_data": dict()
        }
        db.create_initial_message_tables()

        self.routers = routers = routers_from_config(conf, db, Mock())
        routers["test"] = Mock(spec=IRouter)
        app = EndpointHTTPFactory(conf, db=db, routers=routers)
        self.client = Client(app)

        self.request_mock = Mock(body=b'', arguments={}, headers={})
        self.reg = NewRegistrationHandler(app, self.request_mock)
        self.auth = ("WebPush %s" %
                     generate_hash(conf.bear_hash_key[0], dummy_uaid.hex))

        self.conf = conf
Esempio n. 2
0
    def setUp(self):
        from autopush.web.base import BaseWebHandler

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

        self.request_mock = Mock(body=b'',
                                 arguments={},
                                 headers={"ttl": "0"},
                                 host='example.com:8080')

        self.base = BaseWebHandler(
            EndpointHTTPFactory(conf, db=test_db(SinkMetrics()), routers=None),
            self.request_mock)
        self.status_mock = self.base.set_status = Mock()
        self.write_mock = self.base.write = Mock()
        self.base.log = Mock(spec=Logger)
        d = self.finish_deferred = Deferred()
        self.base.finish = lambda: d.callback(True)

        # Attach some common cors stuff for testing
        self.base.cors_methods = "POST,PUT"
        self.base.cors_request_headers = [
            "content-encoding", "encryption", "crypto-key", "ttl",
            "encryption-key", "content-type", "authorization"
        ]
        self.base.cors_response_headers = ["location", "www-authenticate"]
Esempio n. 3
0
 def setUp(self):
     twisted.internet.base.DelayedCall.debug = True
     conf = AutopushConfig(
         hostname="localhost",
         statsd_host=None,
     )
     self.request_mock = Mock()
     self.status = StatusHandler(
         EndpointHTTPFactory(conf, db=None, routers=None),
         self.request_mock)
     self.write_mock = self.status.write = Mock()
Esempio n. 4
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)
    def setUp(self):
        twisted.internet.base.DelayedCall.debug = True
        conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
            crypto_key='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
        )
        db = test_db()
        self.message_mock = db._message = Mock(spec=Message)
        self.fernet_mock = conf.fernet = Mock(spec=Fernet)

        app = EndpointHTTPFactory.for_handler(MessageHandler, conf, db=db)
        self.client = Client(app)
Esempio n. 6
0
    def setUp(self):
        twisted.internet.base.DelayedCall.debug = True

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

        self.logs = _TestingLogObserver()
        begin_or_register(self.logs, discardBuffer=True)
        self.addCleanup(globalLogPublisher.removeObserver, self.logs)

        app = EndpointHTTPFactory.for_handler(LogCheckHandler, conf)
        self.client = Client(app)
Esempio n. 7
0
 def test_bad_version(self, mopen):
     reader = Mock()
     reader.read.side_effect = IOError
     mopen.__enter__.return_value = reader
     mopen.return_value = mopen
     conf = AutopushConfig(
         hostname="localhost",
         statsd_host=None,
     )
     self.request_mock = Mock()
     bad_ver = VersionHandler(
         EndpointHTTPFactory(conf, db=None, routers=None),
         self.request_mock
     )
     with pytest.raises(IOError):
         bad_ver._get_version()
Esempio n. 8
0
    def setUp(self):
        self.timeout = 0.5
        twisted.internet.base.DelayedCall.debug = True

        self.mock_dynamodb2 = mock_dynamodb2()
        self.mock_dynamodb2.start()
        self.addCleanup(self.mock_dynamodb2.stop)

        settings = AutopushSettings(
            hostname="localhost",
            statsd_host=None,
        )
        self.request_mock = Mock()
        self.status = StatusHandler(
            EndpointHTTPFactory(settings, db=None, routers=None),
            self.request_mock)
        self.write_mock = self.status.write = Mock()
Esempio n. 9
0
    def setUp(self):
        from autopush.web.webpush import WebPushHandler

        self.conf = conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
            use_cryptography=True,
        )
        self.fernet_mock = conf.fernet = Mock(spec=Fernet)

        self.db = db = test_db()
        self.message_mock = db.message = Mock(spec=Message)
        self.message_mock.all_channels.return_value = (True, [dummy_chid])

        app = EndpointHTTPFactory.for_handler(WebPushHandler, conf, db=db)
        self.wp_router_mock = app.routers["webpush"] = Mock(spec=IRouter)
        self.client = Client(app)
Esempio n. 10
0
    def test_decorator(self):
        from autopush.http import EndpointHTTPFactory
        from autopush.web.base import BaseWebHandler, threaded_validate
        from autopush.tests.client import Client
        schema = self._make_basic_schema()

        class AHandler(BaseWebHandler):
            def authenticate_peer_cert(self):
                pass

            @threaded_validate(schema)
            def get(self):
                self.write("done")
                self.finish()

        app = EndpointHTTPFactory(Mock(),
                                  db=test_db(),
                                  routers=None,
                                  handlers=[('/test', AHandler)])
        client = Client(app)
        resp = yield client.get('/test')
        assert resp.content == "done"
Esempio n. 11
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)
Esempio n. 12
0
    def setUp(self):
        self.timeout = 0.5
        twisted.internet.base.DelayedCall.debug = True

        self.mock_dynamodb2 = mock_dynamodb2()
        self.mock_dynamodb2.start()
        self.addCleanup(self.mock_dynamodb2.stop)

        settings = AutopushSettings(
            hostname="localhost",
            statsd_host=None,
        )

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

        app = EndpointHTTPFactory.for_handler(HealthHandler, settings)
        self.router_table = app.db.router.table
        self.storage_table = app.db.storage.table
        self.client = Client(app)