Beispiel #1
0
    def test_post_ok(self):
        uuid_patch = patch(
            'satellite.aliases.manager.uuid.uuid4',
            Mock(side_effect=[
                'c20b81b0-d90d-42d1-bf6d-eea5e6981196',
                '884a0c8e-de04-46de-945a-c77c3acf783e',
            ]))
        uuid_patch.start()
        self.addCleanup(uuid_patch.stop)

        response = self.fetch(
            self.get_url('/aliases'),
            method='POST',
            body=json.dumps({
                'data': [
                    {
                        'value': 123321,
                        'format': 'UUID'
                    },
                    {
                        'value': 'abccba',
                        'format': 'UUID'
                    },
                ]
            }),
        )

        self.assertEqual(response.code, 200, response.body)
        self.assertMatchSnapshot(json.loads(response.body))

        store = AliasStore()
        self.assertEqual(len(store.get_by_value('123321')), 1)
        self.assertEqual(len(store.get_by_value('abccba')), 1)
def test_save():
    alias = make_alias(False)
    store = AliasStore()

    store.save(alias)

    stored_alias = get_session().query(Alias).filter(
        Alias.id == alias.id).first()
    assert stored_alias == alias
Beispiel #3
0
def main(**kwargs):
    set_start_method('fork')  # PyInstaller supports only fork start method

    pickling_support.install()

    init_satellite_dir()

    try:
        config = configure(**{
            name: value
            for name, value in kwargs.items() if value is not None
        })
    except InvalidConfigError as exc:
        raise click.ClickException(f'Invalid config: {exc}') from exc

    satellite_logging.configure(log_path=config.log_path, silent=config.silent)

    db.configure(config.db_path)
    try:
        db.init()
    except db.DBVersionMismatch as exc:
        raise click.ClickException(exc) from exc

    deleted_aliases = AliasStore.cleanup()
    logger = logging.getLogger()
    logger.info(f'Deleted {deleted_aliases} expired aliases.')

    app = WebApplication(config)
    app.start()
Beispiel #4
0
def main(**kwargs):
    set_start_method('fork')  # PyInstaller supports only fork start method

    pickling_support.install()

    init_satellite_dir()

    try:
        config = configure(**{
            name: value
            for name, value in kwargs.items() if value is not None
        })
    except InvalidConfigError as exc:
        raise click.ClickException(f'Invalid config: {exc}') from exc

    satellite_logging.configure(log_path=config.log_path, silent=config.silent)
    logger = logging.getLogger()

    db.configure(config.db_path)
    try:
        db.init()
    except db.DBVersionMismatch as exc:
        raise click.ClickException(exc) from exc

    if config.routes_path:
        with open(config.routes_path, 'r') as stream:
            try:
                loaded_routes_count = load_from_yaml(stream)
            except LoadError as exc:
                raise click.ClickException(
                    f'Unable to load routes from file: {exc}') from exc
        logger.info(
            f'Loaded {loaded_routes_count} routes from routes config file.')

    deleted_aliases = AliasStore.cleanup()
    logger.info(f'Deleted {deleted_aliases} expired aliases.')

    app = WebApplication(config)
    app.start()
def test_get_by_value():
    value = 'secret'
    alias1 = make_alias(
        True,
        value=value,
        alias_generator=AliasGeneratorType.UUID,
    )
    alias2 = make_alias(
        True,
        value=value,
        alias_generator=AliasGeneratorType.RAW_UUID,
    )

    store = AliasStore()
    assert store.get_by_value(value) == [alias1, alias2]
    assert store.get_by_value(value, AliasGeneratorType.UUID) == [alias1]
    assert store.get_by_value(value, AliasGeneratorType.RAW_UUID) == [alias2]
    assert store.get_by_value(value[::-1]) == []
def test_cleanup():
    session = get_session()
    session.query(Alias).delete()
    session.commit()

    persistent_store = AliasStore()
    alias1 = make_alias(False)
    persistent_store.save(alias1)

    volatile_store = AliasStore(60)
    alias2 = make_alias(False)
    volatile_store.save(alias2)

    alias3 = make_alias(False)
    AliasStore(-1).save(alias3)

    assert AliasStore.cleanup() == 1
    persistent_store.get_by_value(alias1.value) is not None
    volatile_store.get_by_value(alias2.value) is not None
    volatile_store.get_by_value(alias3.value) is None
def test_get_by_alias_with_ttl_expired():
    alias = make_alias(False)
    store = AliasStore(-1)
    store.save(alias)
    assert store.get_by_alias(alias.public_alias) is None
def test_get_by_alias_with_ttl():
    alias = make_alias(False)
    store = AliasStore(60)
    store.save(alias)
    assert store.get_by_alias(alias.public_alias) == alias
    assert AliasStore().get_by_alias(alias.public_alias) is None
def test_get_by_value_with_ttl_expired():
    alias = make_alias(False)
    store = AliasStore(-1)
    store.save(alias)
    assert store.get_by_value(alias.value) == []
Beispiel #10
0
def test_get_by_value_with_ttl():
    alias = make_alias(False)
    store = AliasStore(60)
    store.save(alias)
    assert store.get_by_value(alias.value) == [alias]
    assert AliasStore().get_by_value(alias.value) == []
Beispiel #11
0
def test_get_by_alias():
    alias = make_alias(True)
    store = AliasStore()
    assert store.get_by_alias(alias.value) is None
    assert store.get_by_alias(alias.public_alias) == alias