Exemple #1
0
def test_build_pipeline(monkeypatch):
    mock_operation = Mock()
    mock_operation_cls = Mock(return_value=mock_operation)
    monkeypatch.setattr(
        'satellite.operations.pipeline.get_operation_class',
        Mock(return_value=mock_operation_cls),
    )

    rule_entry = RuleEntryFactory.build(
        id='1b8f25c2-bd32-4de2-9300-a544fe8b91df',
        route_id='f6a62dec-514f-4a54-b2d8-792c568dbd8b',
        operations_v2=[{
            'name': 'operation-name',
            'parameters': {
                'op_param_name': 'op_param_value'
            },
        }],
    )

    pipeline = build_pipeline(rule_entry)

    assert pipeline.operations == [mock_operation]
    mock_operation_cls.assert_called_once_with(
        route_id=rule_entry.route_id,
        filter_id=rule_entry.id,
        op_param_name='op_param_value',
    )
Exemple #2
0
    def _process(self, flow: HTTPFlow, phase: Phase):
        route, filters = match_route(
            proxy_mode=ctx.get_proxy_context().mode,
            phase=phase,
            flow=flow,
        )
        if not route:
            return

        match_details = {'filters': [], 'route_id': route.id}
        matched_filters = match_details['filters']
        for fltr in filters:
            if fltr.has_operations:
                pipeline = build_pipeline(fltr)
                pipeline.evaluate(flow, phase)
                operation_applied = True
            else:
                operation_applied = transform(flow, phase, fltr)
            matched_filters.append({
                'id': fltr.id,
                'operation_applied': operation_applied,
            })

        phase_obj = getattr(flow, phase.value.lower())
        phase_obj.match_details = match_details