Ejemplo n.º 1
0
def test_redact_existing_token(
    monkeypatch,
    proxy_context,
    flow_context,
    route_context,
):
    monkeypatch.setattr(
        'satellite.aliases.store.get_session',
        Mock(),
    )
    monkeypatch.setattr(
        'satellite.aliases.store.AliasStore.get_by_value',
        Mock(return_value=[
            Mock(
                id='ead9d833-eb9a-474c-9894-16de59682dce',
                public_alias='tok_sat_medNmHNXKxwuHq8AvfAhmo',
            )
        ]),
    )
    emit_audit_log = Mock()
    monkeypatch.setattr(
        'satellite.aliases.manager.audit_logs.emit',
        emit_audit_log,
    )
    monkeypatch.setattr(
        'satellite.aliases.manager.uuid.uuid4',
        Mock(return_value='ead9d833-eb9a-474c-9894-16de59682dce'),
    )

    with ctx.use_context(proxy_context), ctx.use_context(
            flow_context), ctx.use_context(route_context):
        alias = alias_manager.redact(
            'value',
            generator_type=AliasGeneratorType.UUID,
            store_type=AliasStoreType.PERSISTENT,
        )

    assert alias.public_alias == 'tok_sat_medNmHNXKxwuHq8AvfAhmo'
    emit_audit_log.assert_called_once_with(
        records.VaultRecordUsageLogRecord(
            action_type=records.ActionType.DE_DUPE,
            alias_generator=AliasGeneratorType.UUID,
            flow_id='313980a8-ff6c-4b13-b5a3-03909389295b',
            phase=Phase.REQUEST,
            proxy_mode=ProxyMode.REVERSE,
            record_id='ead9d833-eb9a-474c-9894-16de59682dce',
            record_type=AliasStoreType.PERSISTENT,
            route_id='41265f94-3ea5-46ad-b5f5-26221a41db34',
        ))
Ejemplo n.º 2
0
    def test_get_ok(self):
        uuid_patch = patch(
            'satellite.aliases.manager.uuid.uuid4',
            Mock(return_value='7612e3e6-0a62-4ed8-a329-403bd26ce538'),
        )
        uuid_patch.start()
        self.addCleanup(uuid_patch.stop)

        alias = redact(
            '123321',
            generator_type=AliasGeneratorType.UUID,
            store_type=AliasStoreType.PERSISTENT,
        )

        response = self.fetch(self.get_url(f'/aliases/{alias.public_alias}'))

        self.assertEqual(response.code, 200, response.body)
        self.assertMatchSnapshot(json.loads(response.body))
Ejemplo n.º 3
0
    def test_get_ok(self):
        uuid_patch = patch(
            'satellite.aliases.manager.uuid.uuid4',
            Mock(return_value='29e34c80-c9f2-4c59-97a5-355e1ed3018f'),
        )
        uuid_patch.start()
        self.addCleanup(uuid_patch.stop)

        alias = redact(
            '123321',
            generator_type=AliasGeneratorType.UUID,
            store_type=AliasStoreType.PERSISTENT,
        )

        response = self.fetch(self.get_url(f'/aliases?q={alias.public_alias}'))

        self.assertEqual(response.code, 200, response.body)
        self.assertMatchSnapshot(json.loads(response.body))
Ejemplo n.º 4
0
    def test_get_unknown_alias(self):
        uuid_patch = patch(
            'satellite.aliases.manager.uuid.uuid4',
            Mock(return_value='b93104db-67c3-4c11-9131-d4955e740a19'),
        )
        uuid_patch.start()
        self.addCleanup(uuid_patch.stop)

        alias = redact(
            '123321',
            generator_type=AliasGeneratorType.UUID,
            store_type=AliasStoreType.PERSISTENT,
        )

        response = self.fetch(
            self.get_url(
                f'/aliases?q={alias.public_alias},tok_tas_kgq94RpcPrAMSHJWh7o7P6',
            ))

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