コード例 #1
0
    def setUp(self):
        super(TestShardedNode, self).setUp()

        # get the options from the config
        self.config = testing.setUp()
        self.ini = os.path.join(os.path.dirname(__file__),
                                'test_sharded.ini')
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)

        # instantiate the backend to test
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)

        # adding a node with 100 slots

        self.backend._safe_execute(
              """insert into nodes (`node`, `service`, `available`,
                    `capacity`, `current_load`, `downed`, `backoff`)
                  values ("https://phx12", "sync-1.0", 100, 100, 0, 0, 0)""",
                  service=_SERVICE)

        self.backend._safe_execute(
                """insert into service_pattern
                (`service`, `pattern`)
                values
                ("sync-1.0", "{node}/{version}/{uid}")""",
                service="sync-1.0")

        self._sqlite = self.backend._dbs['sync'][0].driver == 'pysqlite'
        read_endpoints(self.config)
コード例 #2
0
    def setUp(self):
        super(TestSQLBackend, self).setUp()

        # get the options from the config
        self.config = testing.setUp()
        self.ini = os.path.join(os.path.dirname(__file__), 'test_sql.ini')
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)

        # instantiate the backend to test
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)

        # adding a service and a node with 100 slots
        try:
            self.backend.add_service("sync-1.1", "{node}/1.1/{uid}")
        except IntegrityError:
            # ignore if the service was already added by another test.
            pass
        self.backend.add_node("sync-1.1", "https://phx12", 100)

        self._sqlite = self.backend._engine.driver == 'pysqlite'
        endpoints = {}
        load_endpoints(endpoints, self.config)
        get_current_registry()['endpoints_patterns'] = endpoints
コード例 #3
0
 def setUpClass(cls):
     cls.config = testing.setUp()
     settings = {}
     try:
         fileConfig(cls.get_ini())
     except NoSectionError:
         pass
     load_into_settings(cls.get_ini(), settings)
     cls.config.add_settings(settings)
     metlog_wrapper = load_from_settings('metlog',
                                         cls.config.registry.settings)
     for logger in ('tokenserver', 'mozsvc', 'powerhose'):
         hook_logger(logger, metlog_wrapper.client)
     cls.config.registry['metlog'] = metlog_wrapper.client
     cls.config.include("tokenserver")
     load_and_register("tokenserver", cls.config)
     cls.backend = cls.config.registry.getUtility(INodeAssignment)
     cls.cluster = get_cluster(
         'tokenserver.tests.mockworker.crypto_worker',
         numprocesses=1,
         background=True,
         # debug=True,
         worker_params={'config': cls.get_ini()})
     cls.cluster.start()
     time.sleep(1.)
コード例 #4
0
ファイル: __init__.py プロジェクト: almet/tokenserver
def includeme(config):
    config.include("cornice")
    config.include("mozsvc")
    config.include("pyramid_whoauth")
    config.scan("tokenserver.views")

    # initializes the assignment backend
    load_and_register("tokenserver", config)

    # initializes the powerhose backend
    try:
        load_and_register("powerhose", config)
    except NoSectionError:
        pass

    # load apps and set them up back in the setting
    settings = config.registry.settings
    key = 'tokenserver.applications'
    applications = defaultdict(list)
    for element in settings.get(key, '').split(','):
        element = element.strip()
        if element == '':
            continue
        element = element.split('-')
        if len(element) != 2:
            continue
        app, version = element
        applications[app].append(version)

    settings[key] = applications

    # load the secrets file
    key = 'tokenserver.secrets_file'
    settings[key] = Secrets(settings[key])
コード例 #5
0
ファイル: test_plugin.py プロジェクト: LilyLME/shavar
 def test_loading_with_conflict_detection(self):
     settings = {
         "test1.backend": "mozsvc.tests.test_plugin.Test1",
         "test_both.backend": "mozsvc.tests.test_plugin.Test1And2",
     }
     config = Configurator(settings=settings)
     load_and_register("test1", config)
     load_and_register("test_both", config)
     self.assertRaises(ConfigurationConflictError, config.commit)
コード例 #6
0
 def test_loading_with_conflict_detection(self):
     settings = {
         "test1.backend": "mozsvc.tests.test_plugin.Test1",
         "test_both.backend": "mozsvc.tests.test_plugin.Test1And2",
     }
     config = Configurator(settings=settings)
     load_and_register("test1", config)
     load_and_register("test_both", config)
     self.assertRaises(ConfigurationConflictError, config.commit)
コード例 #7
0
ファイル: __init__.py プロジェクト: adamchainz/tokenserver
def includeme(config):
    settings = config.registry.settings
    if settings.get('tokenserver.monkey_patch_gevent', True):
        monkey_patch_gevent()

    config.include("cornice")
    config.include("mozsvc")
    config.include("tokenserver.tweens")
    config.scan("tokenserver.views")

    # initializes the assignment backend
    load_and_register("tokenserver", config)

    # initialize the and browserid backend if it exists
    if "browserid.backend" in settings:
        load_and_register("browserid", config)

    # load apps and set them up back in the setting
    key = 'tokenserver.applications'
    applications = defaultdict(list)
    for element in settings.get(key, '').split(','):
        element = element.strip()
        if element == '':
            continue
        element = element.split('-')
        if len(element) != 2:
            continue
        app, version = element
        applications[app].append(version)

    settings[key] = applications

    # load the secrets backend, with a b/w-compat hook
    # for the old 'secrets_file' setting.
    secrets_file = settings.get('tokenserver.secrets_file')
    if secrets_file is not None:
        if 'tokenserver.secrets.backend' in settings:
            raise ValueError("can't use secrets_file with secrets.backend")
        if isinstance(secrets_file, basestring):
            secrets_file = secrets_file.split()
        settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets'
        settings['tokenserver.secrets.filename'] = secrets_file
    secrets = load_from_settings('tokenserver.secrets', settings)
    settings['tokenserver.secrets'] = secrets

    # ensure the metrics_id_secret_key is an ascii string.
    id_key = settings.get('fxa.metrics_uid_secret_key')
    if id_key is None:
        logger.warning(
            'fxa.metrics_uid_secret_key is not set. '
            'This will allow PII to be more easily identified')
    elif isinstance(id_key, unicode):
        settings['fxa.metrics_uid_secret_key'] = id_key.encode('ascii')

    read_endpoints(config)
コード例 #8
0
ファイル: __init__.py プロジェクト: forkme7/tokenserver
def includeme(config):
    settings = config.registry.settings
    if settings.get('tokenserver.monkey_patch_gevent', True):
        monkey_patch_gevent()

    config.include("cornice")
    config.include("mozsvc")
    config.include("tokenserver.tweens")
    config.scan("tokenserver.views")

    # initializes the assignment backend
    load_and_register("tokenserver", config)

    # initialize the and browserid backend if it exists
    if "browserid.backend" in settings:
        load_and_register("browserid", config)

    # load apps and set them up back in the setting
    key = 'tokenserver.applications'
    applications = defaultdict(list)
    for element in settings.get(key, '').split(','):
        element = element.strip()
        if element == '':
            continue
        element = element.split('-')
        if len(element) != 2:
            continue
        app, version = element
        applications[app].append(version)

    settings[key] = applications

    # load the secrets backend, with a b/w-compat hook
    # for the old 'secrets_file' setting.
    secrets_file = settings.get('tokenserver.secrets_file')
    if secrets_file is not None:
        if 'tokenserver.secrets.backend' in settings:
            raise ValueError("can't use secrets_file with secrets.backend")
        if isinstance(secrets_file, basestring):
            secrets_file = secrets_file.split()
        settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets'
        settings['tokenserver.secrets.filename'] = secrets_file
    secrets = load_from_settings('tokenserver.secrets', settings)
    settings['tokenserver.secrets'] = secrets

    # ensure the metrics_id_secret_key is an ascii string.
    id_key = settings.get('fxa.metrics_uid_secret_key')
    if id_key is None:
        logger.warning('fxa.metrics_uid_secret_key is not set. '
                       'This will allow PII to be more easily identified')
    elif isinstance(id_key, unicode):
        settings['fxa.metrics_uid_secret_key'] = id_key.encode('ascii')

    read_endpoints(config)
コード例 #9
0
 def setUp(self):
     self.config = testing.setUp()
     settings = {}
     load_into_settings(self.get_ini(), settings)
     self.config.add_settings(settings)
     self.config.include("tokenserver")
     load_and_register("tokenserver", self.config)
     self.backend = self.config.registry.getUtility(INodeAssignment)
     self.backend.add_service(SERVICE, PATTERN)
     self.backend.add_node(SERVICE, "https://phx12", 100)
     self.logs = LogCapture()
コード例 #10
0
 def setUp(self):
     self.config = testing.setUp()
     settings = {}
     load_into_settings(self.get_ini(), settings)
     self.config.add_settings(settings)
     self.config.include("tokenserver")
     load_and_register("tokenserver", self.config)
     self.backend = self.config.registry.getUtility(INodeAssignment)
     self.backend.add_service(SERVICE, "{node}/{version}/{uid}")
     self.backend.add_node(SERVICE, "https://phx12", 100)
     self.logs = LogCapture()
コード例 #11
0
ファイル: test_powerhose.py プロジェクト: jrgm/tokenserver
 def setUpClass(cls):
     cls.config = testing.setUp()
     settings = {}
     try:
         fileConfig(cls.get_ini())
     except NoSectionError:
         pass
     load_into_settings(cls.get_ini(), settings)
     cls.config.add_settings(settings)
     cls.config.include("tokenserver")
     load_and_register("tokenserver", cls.config)
     cls.backend = cls.config.registry.getUtility(INodeAssignment)
コード例 #12
0
ファイル: __init__.py プロジェクト: anantn/appsync
def includeme(config):
    # adds cornice
    config.include("cornice")

    # adds Mozilla default views
    config.include("mozsvc")

    # adds local views
    config.scan("appsync.views")

    # initializes the storage backend
    load_and_register("storage", config)
コード例 #13
0
ファイル: session.py プロジェクト: rtilder/sauropod
def includeme(config):
    """Include the default app-session-management definitions.

    Call this function on a pyramid configurator to register a utility for
    the IAppSessionDB interface.  The particular implementation to use will
    be taken from the configurator settings dict, falling back to a simple
    in-memory implementation as the default.
    """
    settings = config.get_settings()
    if "sauropod.session.backend" not in settings:
        default_backend = "pysauropod.server.session.SignedSessionManager"
        settings["sauropod.session.backend"] = default_backend
    plugin.load_and_register("sauropod.session", config)
コード例 #14
0
ファイル: session.py プロジェクト: mozilla/sauropod
def includeme(config):
    """Include the default app-session-management definitions.

    Call this function on a pyramid configurator to register a utility for
    the IAppSessionDB interface.  The particular implementation to use will
    be taken from the configurator settings dict, falling back to a simple
    in-memory implementation as the default.
    """
    settings = config.get_settings()
    if "sauropod.session.backend" not in settings:
        default_backend = "pysauropod.server.session.SignedSessionManager"
        settings["sauropod.session.backend"] = default_backend
    plugin.load_and_register("sauropod.session", config)
コード例 #15
0
ファイル: test_service.py プロジェクト: forkme7/tokenserver
 def setUp(self):
     self.config = testing.setUp()
     settings = {}
     load_into_settings(self.get_ini(), settings)
     self.config.add_settings(settings)
     self.config.include("tokenserver")
     load_and_register("tokenserver", self.config)
     self.backend = self.config.registry.getUtility(INodeAssignment)
     wsgiapp = self.config.make_wsgi_app()
     self.app = TestApp(wsgiapp)
     # Mock out the verifier to return successfully by default.
     self.mock_verifier_context = self.mock_verifier()
     self.mock_verifier_context.__enter__()
     self.logs = LogCapture()
コード例 #16
0
def includeme(config):
    """Include the default credential-checking definitions.

    Call this function on a pyramid configurator to register a utility for
    the ICredentialChecker interface.  The particular implementation to use
    will  be taken from the configurator settings dict, falling back to a
    BrowserID-based scheme as the default.
    """
    settings = config.get_settings()
    if "sauropod.credentials.backend" not in settings:
        #        default_backend = "pysauropod.server.credentials.BrowserIDCredentials"
        default_backend = "pysauropod.server.credentials.DummyCredentials"
        settings["sauropod.credentials.backend"] = default_backend
    plugin.load_and_register("sauropod.credentials", config)
コード例 #17
0
ファイル: credentials.py プロジェクト: dclarke/sauropod
def includeme(config):
    """Include the default credential-checking definitions.

    Call this function on a pyramid configurator to register a utility for
    the ICredentialChecker interface.  The particular implementation to use
    will  be taken from the configurator settings dict, falling back to a
    BrowserID-based scheme as the default.
    """
    settings = config.get_settings()
    if "sauropod.credentials.backend" not in settings:
#        default_backend = "pysauropod.server.credentials.BrowserIDCredentials"
        default_backend = "pysauropod.server.credentials.DummyCredentials"
        settings["sauropod.credentials.backend"] = default_backend
    plugin.load_and_register("sauropod.credentials", config)
コード例 #18
0
def includeme(config):
    config.include("cornice")
    config.include("mozsvc")
    config.include("pysauropod.server.security")
    config.include("pysauropod.server.session")
    config.include("pysauropod.server.credentials")
    config.scan("pysauropod.server.views")
    settings = config.get_settings()
    if "sauropod.storage.backend" not in settings:
        default_backend = "pysauropod.backends.sql:SQLBackend"
        settings["sauropod.storage.backend"] = default_backend
        #settings["sauropod.storage.sqluri"] = "sqlite:///:memory:"
        settings["sauropod.storage.sqluri"] = "sqlite:////tmp/sauropod.db"
        settings["sauropod.storage.create_tables"] = True
    plugin.load_and_register("sauropod.storage", config)
コード例 #19
0
 def setUp(self):
     self.config = testing.setUp()
     settings = {}
     load_into_settings(self.get_ini(), settings)
     self.config.add_settings(settings)
     self.config.include("tokenserver")
     load_and_register("tokenserver", self.config)
     self.backend = self.config.registry.getUtility(INodeAssignment)
     wsgiapp = self.config.make_wsgi_app()
     wsgiapp = CatchErrors(wsgiapp)
     self.app = TestApp(wsgiapp)
     # Mock out the verifier to return successfully by default.
     self.mock_verifier_context = self.mock_verifier()
     self.mock_verifier_context.__enter__()
     self.logs = LogCapture()
コード例 #20
0
 def test_nopool_is_disabled_when_using_memory_database(self):
     config = get_test_configurator(__file__, "tests-nopool.ini")
     # Using no_pool=True will give you a NullPool when using file db.
     storage = load_and_register("storage-file", config)
     self.assertEqual(storage.dbconnector.engine.pool.__class__.__name__, "NullPool")
     # Using no_pool=True will give you an error when using :memory: db.
     self.assertRaises(ValueError, load_and_register, "storage-memory", config)
コード例 #21
0
ファイル: console.py プロジェクト: rfk/moz-account-portal
def includeme(config):
    try:
        reset = load_and_register('reset_codes', config)
    except Exception, e:
        logger.error(traceback.format_exc())
        logger.error("unable to load reset codes. Problem? %s" % e)
        reset = None
コード例 #22
0
ファイル: __init__.py プロジェクト: crankycoder/demoapp
def main(global_config, **settings):
    config = get_configurator(global_config, **settings)
    config.set_root_factory(Root)

    # adds authorization
    # option 1: auth via repoze.who
    # config.include("pyramid_whoauth")
    # option 2: auth based on IP address
    # config.include("pyramid_ipauth")
    # option 3: multiple stacked auth modules
    # config.include("pyramid_multiauth")

    # adds cornice
    config.include("cornice")

    # adds Mozilla default views
    config.include("mozsvc")

    # adds application-specific views
    config.add_route("whoami", "/whoami")

    # initialize the metrics plugin
    config.registry["metrics"] = load_and_register("metrics", config)

    config.scan("demoapp.views")

    return config.make_wsgi_app()
コード例 #23
0
    def test_shard(self):
        # Use a configuration with sharding enabled.
        config = get_test_configurator(__file__, 'tests-shard.ini')
        storage = load_and_register("storage", config)

        # Make sure it's using the expected table name.
        table = storage.dbconnector.get_bso_table(_USER['uid']).name
        self.assertEqual(table, 'bso1')

        # The table should initially be empty.
        COUNT_ITEMS = 'select count(*) from bso1 /* queryName=COUNT_ITEMS */'
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 0)

        # Do a few things on the DB
        id1 = 'ec1b7457-003a-45a9-bf1c-c34e37225ad7'
        id2 = '339f52e1-deed-497c-837a-1ab25a655e37'
        storage.set_item(_USER, 'xxx_col1', id1, {'payload': _PLD})
        storage.set_item(_USER, 'xxx_col1', id2, {'payload': _PLD * 89})
        self.assertEquals(
            len(storage.get_items(_USER, 'xxx_col1')["items"]), 2)

        # Now make sure we did that in the right table
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 2)
コード例 #24
0
def main(global_config, **settings):
    config = get_configurator(global_config, **settings)
    config.set_root_factory(Root)

    # adds authorization
    # option 1: auth via repoze.who
    #config.include("pyramid_whoauth")
    # option 2: auth based on IP address
    #config.include("pyramid_ipauth")
    # option 3: multiple stacked auth modules
    #config.include("pyramid_multiauth")

    # adds cornice
    config.include("cornice")

    # adds Mozilla default views
    config.include("mozsvc")

    # adds application-specific views
    config.add_route("whoami", "/whoami")

    # initialize the metrics plugin
    config.registry['metrics'] = load_and_register('metrics', config)

    config.scan("demoapp.views")

    return config.make_wsgi_app()
コード例 #25
0
    def test_shard(self):
        # Use a configuration with sharding enabled.
        config = get_test_configurator(__file__, 'tests-shard.ini')
        storage = load_and_register("storage", config)

        # Make sure it's using the expected table name.
        table = storage.dbconnector.get_bso_table(_UID).name
        self.assertEqual(table, 'bso1')

        # The table should initially be empty.
        COUNT_ITEMS = 'select count(*) from bso1 /* queryName=COUNT_ITEMS */'
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 0)

        # Do a few things on the DB
        id1 = 'ec1b7457-003a-45a9-bf1c-c34e37225ad7'
        id2 = '339f52e1-deed-497c-837a-1ab25a655e37'
        storage.set_item(_UID, 'col1', id1, {'payload': _PLD})
        storage.set_item(_UID, 'col1', id2, {'payload': _PLD * 89})
        self.assertEquals(len(storage.get_items(_UID, 'col1')["items"]), 2)

        # Now make sure we did that in the right table
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 2)
コード例 #26
0
ファイル: test_powerhose.py プロジェクト: almet/tokenserver
 def setUp(self):
     logger.debug("TestPowerService.setUp")
     self.config = testing.setUp()
     settings = {}
     try:
         fileConfig(self.get_ini())
     except NoSectionError:
         pass
     load_into_settings(self.get_ini(), settings)
     self.config.add_settings(settings)
     self.config.include("tokenserver")
     load_and_register("tokenserver", self.config)
     self.backend = self.config.registry.getUtility(INodeAssignment)
     wsgiapp = self.config.make_wsgi_app()
     wsgiapp = CatchErrors(wsgiapp)
     self.app = TestApp(wsgiapp)
     time.sleep(1.)
コード例 #27
0
ファイル: __init__.py プロジェクト: jrgm/tokenserver
def includeme(config):
    config.include("cornice")
    config.include("mozsvc")
    config.scan("tokenserver.views")

    # initializes the assignment backend
    load_and_register("tokenserver", config)

    # initialize the powerhose and browserid backends if they exist
    for section in ("powerhose", "browserid"):
        try:
            load_and_register(section, config)
        except NoSectionError:
            pass

    # load apps and set them up back in the setting
    settings = config.registry.settings
    key = 'tokenserver.applications'
    applications = defaultdict(list)
    for element in settings.get(key, '').split(','):
        element = element.strip()
        if element == '':
            continue
        element = element.split('-')
        if len(element) != 2:
            continue
        app, version = element
        applications[app].append(version)

    settings[key] = applications

    # load the secrets file(s)
    key = 'tokenserver.secrets_file'
    secret_file = settings[key]
    if not isinstance(secret_file, list):
        secret_file = [secret_file]

    files = []
    for line in secret_file:
        secret_file = [file for file in [file.strip() for file in line.split()]
                       if file != '']
        files.extend(secret_file)

    settings[key] = Secrets(files)
    read_endpoints(config)
def includeme(config):
    # adds cornice
    config.include("cornice")

    # adds Mozilla default views
    config.include("mozsvc")

    # adds local views
    config.scan("appsync.views")

    # initializes the storage backend
    load_and_register("storage", config)

    # initializes the cache tool
    try:
        load_and_register("cache", config)
    except NoSectionError:
        pass
コード例 #29
0
ファイル: __init__.py プロジェクト: mozilla/appsync
def includeme(config):
    # adds cornice
    config.include("cornice")

    # adds Mozilla default views
    config.include("mozsvc")

    # adds local views
    config.scan("appsync.views")

    # initializes the storage backend
    load_and_register("storage", config)

    # initializes the cache tool
    try:
        load_and_register("cache", config)
    except NoSectionError:
        pass
コード例 #30
0
 def test_nopool_is_disabled_when_using_memory_database(self):
     config = get_test_configurator(__file__, 'tests-nopool.ini')
     # Using no_pool=True will give you a NullPool when using file db.
     storage = load_and_register("storage-file", config)
     self.assertEqual(storage.dbconnector.engine.pool.__class__.__name__,
                      'NullPool')
     # Using no_pool=True will give you an error when using :memory: db.
     self.assertRaises(ValueError,
                       load_and_register, "storage-memory", config)
コード例 #31
0
    def test_no_create(self):
        # Storage with no create_tables option; it should default to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-nocreate.ini')
        storage = load_and_register("storage", config)
        bsos = [{"id": "TEST", "payload": _PLD}]
        self.assertRaises(BackendError, storage.set_items, _USER, "test", bsos)

        # Storage with create_tables explicitly set to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-dontcreate.ini')
        storage = load_and_register("storage", config)
        self.assertRaises(BackendError, storage.set_items, _USER, "test", bsos)

        # Storage with create_tables explicit set to true.
        # This should succeed because the table gets created.
        config = get_test_configurator(__file__, 'tests-docreate.ini')
        storage = load_and_register("storage", config)
        storage.set_items(_USER, "test", bsos)
コード例 #32
0
    def test_no_create(self):
        # Storage with no create_tables option; it should default to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-nocreate.ini')
        storage = load_and_register("storage", config)
        bsos = [{"id": "TEST", "payload": _PLD}]
        self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)

        # Storage with create_tables explicitly set to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-dontcreate.ini')
        storage = load_and_register("storage", config)
        self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)

        # Storage with create_tables explicit set to true.
        # This should succeed because the table gets created.
        config = get_test_configurator(__file__, 'tests-docreate.ini')
        storage = load_and_register("storage", config)
        storage.set_items(_UID, "test", bsos)
コード例 #33
0
    def setUp(self):
        self.config = testing.setUp()
        settings = {}
        load_into_settings(self.get_ini(), settings)
        self.config.add_settings(settings)
        metlog_wrapper = load_from_settings('metlog',
                                            self.config.registry.settings)
        for logger in ('tokenserver', 'mozsvc', 'powerhose'):
            hook_logger(logger, metlog_wrapper.client)

        self.config.registry['metlog'] = metlog_wrapper.client
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)
        wsgiapp = self.config.make_wsgi_app()
        wsgiapp = CatchErrors(wsgiapp)
        self.app = TestApp(wsgiapp)
        # Mock out the verifier to return successfully by default.
        self.mock_verifier_context = self.mock_verifier()
        self.mock_verifier_context.__enter__()
コード例 #34
0
ファイル: test_plugin.py プロジェクト: LilyLME/shavar
    def test_loading_several_plugins(self):
        settings = {
            "test1.backend": "mozsvc.tests.test_plugin.Test1",
            "test1.hello": "world",
            "test2.backend": "mozsvc.tests.test_plugin.Test2",
        }
        config = Configurator(settings=settings)
        plugin1 = load_and_register("test1", config)
        plugin2 = load_and_register("test2", config)
        config.commit()

        self.assertTrue(verifyObject(ITest1, plugin1))
        self.assertTrue(isinstance(plugin1, Test1))
        self.assertEqual(plugin1.kwds["hello"], "world")
        self.assertEqual(len(plugin1.kwds), 1)
        self.assertTrue(config.registry.queryUtility(ITest1) is plugin1)

        self.assertTrue(verifyObject(ITest2, plugin2))
        self.assertTrue(isinstance(plugin2, Test2))
        self.assertEqual(len(plugin2.kwds), 0)
        self.assertTrue(config.registry.queryUtility(ITest2) is plugin2)
コード例 #35
0
 def setUp(self):
     config = Config(StringIO(dedent("""
     [test1]
     enabled=true
     backend = mozsvc.metrics.MetlogPlugin
     sender_class=metlog.senders.DebugCaptureSender
     disable_timeit=true
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
コード例 #36
0
    def test_loading_several_plugins(self):
        settings = {
            "test1.backend": "mozsvc.tests.test_plugin.Test1",
            "test1.hello": "world",
            "test2.backend": "mozsvc.tests.test_plugin.Test2",
        }
        config = Configurator(settings=settings)
        plugin1 = load_and_register("test1", config)
        plugin2 = load_and_register("test2", config)
        config.commit()

        self.failUnless(verifyObject(ITest1, plugin1))
        self.failUnless(isinstance(plugin1, Test1))
        self.assertEquals(plugin1.kwds["hello"], "world")
        self.assertEquals(len(plugin1.kwds), 1)
        self.failUnless(config.registry.queryUtility(ITest1) is plugin1)

        self.failUnless(verifyObject(ITest2, plugin2))
        self.failUnless(isinstance(plugin2, Test2))
        self.assertEquals(len(plugin2.kwds), 0)
        self.failUnless(config.registry.queryUtility(ITest2) is plugin2)
コード例 #37
0
ファイル: __init__.py プロジェクト: ncalexan/server-fxap
def includeme(config):
    config.include("cornice")
    config.include("mozsvc")
    config.scan("fxap.views")
    settings = config.registry.settings

    # default metlog setup
    if "metlog.backend" not in settings:
        settings["metlog.backend"] = "mozsvc.metrics.MetlogPlugin"
        settings["metlog.enabled"] = True
        settings["metlog.sender_class"] = "metlog.senders.StdOutSender"

    metlog_wrapper = load_from_settings("metlog", settings)

    if settings["metlog.enabled"]:
        for logger in ("fxap", "mozsvc"):
            hook_logger(logger, metlog_wrapper.client)

    config.registry["metlog"] = metlog_wrapper.client

    # initializes the backend
    load_and_register("fxap", config)
コード例 #38
0
ファイル: test_backend_sql.py プロジェクト: almet/tokenserver
    def setUp(self):
        super(TestCase, self).setUp()

        # get the options from the config
        self.config = testing.setUp()
        self.ini = os.path.join(os.path.dirname(__file__),
                                'test_sql.ini')
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)

        # instantiate the backend to test
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)

        # adding a node with 100 slots
        self.backend._safe_execute(
              """insert into nodes (`node`, `service`, `available`,
                    `capacity`, `current_load`, `downed`, `backoff`)
                  values ("phx12", "sync", 100, 100, 0, 0, 0)""")
        self._sqlite = self.backend._engine.driver == 'pysqlite'
コード例 #39
0
ファイル: test_service.py プロジェクト: almet/tokenserver
    def setUp(self):
        self.config = testing.setUp()
        settings = {}
        load_into_settings(self.get_ini(), settings)
        self.config.add_settings(settings)
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)
        wsgiapp = self.config.make_wsgi_app()
        wsgiapp = CatchErrors(wsgiapp)
        self.app = TestApp(wsgiapp)

        def urlopen(url, data): # NOQA
            class response(object):
                @staticmethod
                def read():
                    key = fetch_public_key("browserid.org")
                    return json.dumps({"public-key": key})
            return response

        self.patched = patched_urlopen(urlopen)
        self.patched.__enter__()
コード例 #40
0
ファイル: test_powerhose.py プロジェクト: hfeeki/tokenserver
 def setUpClass(cls):
     cls.config = testing.setUp()
     settings = {}
     try:
         fileConfig(cls.get_ini())
     except NoSectionError:
         pass
     load_into_settings(cls.get_ini(), settings)
     cls.config.add_settings(settings)
     metlog_wrapper = load_from_settings('metlog',
             cls.config.registry.settings)
     for logger in ('tokenserver', 'mozsvc', 'powerhose'):
         hook_logger(logger, metlog_wrapper.client)
     cls.config.registry['metlog'] = metlog_wrapper.client
     cls.config.include("tokenserver")
     load_and_register("tokenserver", cls.config)
     cls.backend = cls.config.registry.getUtility(INodeAssignment)
     cls.cluster = get_cluster('tokenserver.tests.mockworker.crypto_worker',
                               numprocesses=1, background=True,
                               #debug=True,
                               worker_params={'config': cls.get_ini()})
     cls.cluster.start()
     time.sleep(1.)
コード例 #41
0
ファイル: test_service.py プロジェクト: hfeeki/tokenserver
    def setUp(self):
        self.config = testing.setUp()
        settings = {}
        load_into_settings(self.get_ini(), settings)
        self.config.add_settings(settings)
        metlog_wrapper = load_from_settings('metlog',
                self.config.registry.settings)
        for logger in ('tokenserver', 'mozsvc', 'powerhose'):
            hook_logger(logger, metlog_wrapper.client)

        self.config.registry['metlog'] = metlog_wrapper.client
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)
        wsgiapp = self.config.make_wsgi_app()
        wsgiapp = CatchErrors(wsgiapp)
        self.app = TestApp(wsgiapp)

        self.patched = patched_supportdoc_fetching()
        self.patched.__enter__()

        # by default the conditions are accepted
        self.backend.set_accepted_conditions_flag('aitc-1.0', True)
コード例 #42
0
    def setUp(self):
        super(TestSQLBackend, self).setUp()

        # get the options from the config
        self.config = testing.setUp()
        self.ini = os.path.join(os.path.dirname(__file__),
                                'test_sql.ini')
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)

        # instantiate the backend to test
        self.config.include("tokenserver")
        load_and_register("tokenserver", self.config)
        self.backend = self.config.registry.getUtility(INodeAssignment)

        # adding a service and a node with 100 slots
        self.backend.add_service("sync-1.0", "{node}/{version}/{uid}")
        self.backend.add_node("sync-1.0", "https://phx12", 100)

        self._sqlite = self.backend._engine.driver == 'pysqlite'
        endpoints = {}
        load_endpoints(endpoints, self.config)
        get_current_registry()['endpoints_patterns'] = endpoints
コード例 #43
0
 def test_loading_from_settings(self):
     settings = {
         "test1.backend": "mozsvc.tests.test_plugin.Test1",
         "test1.arg1": 1,
         "test1.hello": "world",
         "test2.dontusethis": "seriously",
     }
     config = Configurator(settings=settings)
     plugin = load_and_register("test1", config)
     config.commit()
     self.failUnless(verifyObject(ITest1, plugin))
     self.failUnless(isinstance(plugin, Test1))
     self.assertEquals(plugin.kwds["arg1"], 1)
     self.assertEquals(plugin.kwds["hello"], "world")
     self.assertEquals(len(plugin.kwds), 2)
     self.failUnless(config.registry.queryUtility(ITest1) is plugin)
コード例 #44
0
ファイル: __init__.py プロジェクト: jrgm/mozservices
def includeme(config):
    """Include mozsvc user-handling into a pyramid config.

    This function will set up user-handling via the mozsvc.user system.
    Things configured include:

        * use RequestWithUser as the request object factory
        * load a user database backend from config section "auth"

    """
    config.set_request_factory(RequestWithUser)
    try:
        config.registry["auth"] = load_and_register("auth", config)
    except Exception, e:
        logger.warning("Unable to load auth backend. Problem? %s" % e)
        config.registry["auth"] = None
コード例 #45
0
ファイル: test_plugin.py プロジェクト: LilyLME/shavar
 def test_loading_from_settings(self):
     settings = {
         "test1.backend": "mozsvc.tests.test_plugin.Test1",
         "test1.arg1": 1,
         "test1.hello": "world",
         "test2.dontusethis": "seriously",
     }
     config = Configurator(settings=settings)
     plugin = load_and_register("test1", config)
     config.commit()
     self.assertTrue(verifyObject(ITest1, plugin))
     self.assertTrue(isinstance(plugin, Test1))
     self.assertEqual(plugin.kwds["arg1"], 1)
     self.assertEqual(plugin.kwds["hello"], "world")
     self.assertEqual(len(plugin.kwds), 2)
     self.assertTrue(config.registry.queryUtility(ITest1) is plugin)
コード例 #46
0
 def setUp(self):
     if not metlog:
         raise(unittest2.SkipTest('no metlog'))
     self.orig_globals = CLIENT_HOLDER.global_config.copy()
     config = Config(StringIO(dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     logger = test
     sender_class=metlog.senders.DebugCaptureSender
     global_disabled_decorators = timeit
                                  something
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
コード例 #47
0
 def setUp(self):
     if not metlog:
         raise (unittest2.SkipTest('no metlog'))
     self.orig_globals = CLIENT_HOLDER.global_config.copy()
     config = Config(
         StringIO(
             dedent("""
     [test1]
     backend = mozsvc.metrics.MetlogPlugin
     logger = test
     sender_class=metlog.senders.DebugCaptureSender
     global_disabled_decorators = timeit
                                  something
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     self.plugin = load_and_register("test1", config)
     config.commit()
コード例 #48
0
ファイル: test_plugin.py プロジェクト: LilyLME/shavar
    def test_loading_with_conflict_resolution(self):
        settings = {
            "test1.backend": "mozsvc.tests.test_plugin.Test1",
            "test2.backend": "mozsvc.tests.test_plugin.Test2",
            "test_both.backend": "mozsvc.tests.test_plugin.Test1And2",
        }

        # Load plugin_both last, it will win for both interfaces.
        config = Configurator(settings=settings, autocommit=True)
        load_and_register("test1", config)
        plugin2 = load_and_register("test2", config)
        plugin_both = load_and_register("test_both", config)
        self.assertTrue(config.registry.queryUtility(ITest1) is plugin_both)
        self.assertTrue(config.registry.queryUtility(ITest2) is plugin_both)

        # Load plugin_both before plugin2, it will be beaten only for that.
        config = Configurator(settings=settings, autocommit=True)
        load_and_register("test1", config)
        plugin_both = load_and_register("test_both", config)
        plugin2 = load_and_register("test2", config)
        self.assertTrue(config.registry.queryUtility(ITest1) is plugin_both)
        self.assertTrue(config.registry.queryUtility(ITest2) is plugin2)
コード例 #49
0
ファイル: test_plugin.py プロジェクト: LilyLME/shavar
 def test_loading_from_config(self):
     config = Config(
         StringIO(
             dedent("""
     [test1]
     backend = mozsvc.tests.test_plugin.Test1
     arg1 = 1
     hello = world
     [test2]
     dontusethis =  seriously
     """)))
     settings = {"config": config}
     config = Configurator(settings=settings)
     plugin = load_and_register("test1", config)
     config.commit()
     self.assertTrue(verifyObject(ITest1, plugin))
     self.assertTrue(isinstance(plugin, Test1))
     self.assertEqual(plugin.kwds["arg1"], 1)
     self.assertEqual(plugin.kwds["hello"], "world")
     self.assertEqual(len(plugin.kwds), 2)
     self.assertTrue(config.registry.queryUtility(ITest1) is plugin)
コード例 #50
0
def includeme(config):
    config.include("cornice")
    config.include("mozsvc")
    config.scan("stokenserver.views")
    load_and_register("metadatadb", config)
コード例 #51
0
def includeme(config):
    settings = config.registry.settings
    if settings.get('tokenserver.monkey_patch_gevent', True):
        monkey_patch_gevent()

    config.include("cornice")
    config.include("mozsvc")
    config.include("tokenserver.tweens")
    config.scan("tokenserver.views")

    # default metlog setup
    if 'metlog.backend' not in settings:
        settings['metlog.backend'] = 'mozsvc.metrics.MetlogPlugin'
        settings['metlog.enabled'] = True
        settings['metlog.sender_class'] = 'metlog.senders.StdOutSender'

    metlog_wrapper = load_from_settings('metlog', settings)

    if settings['metlog.enabled']:
        for logger in ('tokenserver', 'mozsvc', 'powerhose'):
            hook_logger(logger, metlog_wrapper.client)

    config.registry['metlog'] = metlog_wrapper.client

    # initializes the assignment backend
    load_and_register("tokenserver", config)

    # initialize the powerhose and browserid backends if they exist
    if "powerhose.backend" in settings:
        load_and_register("powerhose", config)
    if "browserid.backend" in settings:
        load_and_register("browserid", config)

    # load apps and set them up back in the setting
    key = 'tokenserver.applications'
    applications = defaultdict(list)
    for element in settings.get(key, '').split(','):
        element = element.strip()
        if element == '':
            continue
        element = element.split('-')
        if len(element) != 2:
            continue
        app, version = element
        applications[app].append(version)

    settings[key] = applications

    # load the secrets backend, with a b/w-compat hook
    # for the old 'secrets_file' setting.
    secrets_file = settings.get('tokenserver.secrets_file')
    if secrets_file is not None:
        if 'tokenserver.secrets.backend' in settings:
            raise ValueError("can't use secrets_file with secrets.backend")
        if isinstance(secrets_file, basestring):
            secrets_file = secrets_file.split()
        settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets'
        settings['tokenserver.secrets.filename'] = secrets_file
    secrets = load_from_settings('tokenserver.secrets', settings)
    settings['tokenserver.secrets'] = secrets

    read_endpoints(config)
コード例 #52
0
def includeme(config):
    config.include("pyramid_multiauth")
    config.include("cornice")
    config.include("mozsvc")
    load_and_register("storage", config)
    config.scan("keyretrieval.views")