def test_transformation_step_detail_str(): no_diffs = TransformationStepDetail("type", []) one_diff = TransformationStepDetail("type", [FlowDiff("field", "old", "new")]) two_diffs = TransformationStepDetail("type", [FlowDiff("field1", "old1", "new1"), FlowDiff("field2", "old2", "new2")]) step = Step(no_diffs, "ACTION") assert str(step) == "ACTION(type)" step = Step(one_diff, "ACTION") assert str(step) == "ACTION(type field: old -> new)" step = Step(two_diffs, "ACTION") assert str(step) == "ACTION(type field1: old1 -> new1, field2: old2 -> new2)"
def test_MatchSessionStepDetail_from_dict_bw_compat(): """ For backward compatibility, allow "incomingInterfaces" instead of "sessionScope". """ d = { "incomingInterfaces": ["reth0.6"], "sessionAction": { "type": "Accept" }, "matchCriteria": { "ipProtocol": "ICMP", "srcIp": "2.2.2.2", "dstIp": "3.3.3.3" }, "transformation": [{ "fieldName": "srcIp", "oldValue": "2.2.2.2", "newValue": "1.1.1.1" }], } assert MatchSessionStepDetail.from_dict(d) == MatchSessionStepDetail( IncomingSessionScope(["reth0.6"]), Accept(), SessionMatchExpr("ICMP", "2.2.2.2", "3.3.3.3"), [FlowDiff("srcIp", "2.2.2.2", "1.1.1.1")], )
def test_SetupSessionStepDetail_from_dict(): d = { "sessionScope": { "incomingInterfaces": ["reth0.6"] }, "sessionAction": { "type": "Accept" }, "matchCriteria": { "ipProtocol": "ICMP", "srcIp": "2.2.2.2", "dstIp": "3.3.3.3" }, "transformation": [{ "fieldName": "srcIp", "oldValue": "2.2.2.2", "newValue": "1.1.1.1" }], } assert SetupSessionStepDetail.from_dict(d) == SetupSessionStepDetail( IncomingSessionScope(["reth0.6"]), Accept(), SessionMatchExpr("ICMP", "2.2.2.2", "3.3.3.3"), [FlowDiff("srcIp", "2.2.2.2", "1.1.1.1")], )
def test_MatchSessionStepDetail_str(): detail = MatchSessionStepDetail( IncomingSessionScope(["reth0.6"]), Accept(), SessionMatchExpr("ICMP", "2.2.2.2", "3.3.3.3"), [FlowDiff("srcIp", "2.2.2.2", "1.1.1.1")], ) assert str(detail) == ( "Incoming Interfaces: [reth0.6], " "Action: Accept, " "Match Criteria: [ipProtocol=ICMP, srcIp=2.2.2.2, dstIp=3.3.3.3], " "Transformation: [srcIp: 2.2.2.2 -> 1.1.1.1]") detail = MatchSessionStepDetail( IncomingSessionScope(["reth0.6"]), Accept(), SessionMatchExpr("ICMP", "2.2.2.2", "3.3.3.3"), ) assert str(detail) == ( "Incoming Interfaces: [reth0.6], " "Action: Accept, " "Match Criteria: [ipProtocol=ICMP, srcIp=2.2.2.2, dstIp=3.3.3.3]")