예제 #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',
        ))
예제 #2
0
def test_reveal(
    monkeypatch,
    proxy_context,
    flow_context,
    route_context,
):
    monkeypatch.setattr(
        'satellite.service.alias_manager.get_session',
        Mock(),
    )
    monkeypatch.setattr(
        'satellite.service.alias_manager.get_by_alias',
        Mock(return_value=Mock(
            alias_generator='UUID',
            id='ead9d833-eb9a-474c-9894-16de59682dce',
            value='value',
        )),
    )
    emit_audit_log = Mock()
    monkeypatch.setattr(
        'satellite.service.alias_manager.audit_logs.emit',
        emit_audit_log,
    )
    monkeypatch.setattr(
        'satellite.service.alias_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):
        result = alias_manager.reveal('tok_sat_medNmHNXKxwuHq8AvfAhmo')

    assert result == 'value'
    emit_audit_log.assert_called_once_with(
        audit_logs.VaultRecordUsageLogRecord(
            action_type=audit_logs.ActionType.RETRIEVED,
            alias_generator='UUID',
            flow_id='313980a8-ff6c-4b13-b5a3-03909389295b',
            phase=Phase.REQUEST,
            proxy_mode=ProxyMode.REVERSE,
            record_id='ead9d833-eb9a-474c-9894-16de59682dce',
            route_id='41265f94-3ea5-46ad-b5f5-26221a41db34',
        ))
예제 #3
0
    def _process(self, flow: HTTPFlow, phase: Phase,
                 content: bytes) -> Tuple[str, dict]:
        route, route_filters = match_route(
            proxy_mode=ctx.get_proxy_context().mode,
            phase=phase,
            flow=flow,
        )
        if not route_filters:
            return content, None

        with ctx.use_context(ctx.FlowContext(
                flow=flow,
                phase=phase)), ctx.use_context(ctx.RouteContext(route=route)):
            # TODO: Encapsulate flow transformation somewere else
            content, ops_applications = transform_body(route_filters, content)
            matched_filters = [{
                'id': rule.id,
                'operation_applied': op_applied
            } for rule, op_applied in zip(route_filters, ops_applications)]
            return content, {'route_id': route.id, 'filters': matched_filters}
예제 #4
0
def test_use_context(context):
    with ctx.use_context(context):
        assert ctx.get_proxy_context() == context
    with pytest.raises(ctx.ContextError):
        ctx.del_context(ctx.ProxyContext)