示例#1
0
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")],
    )
示例#2
0
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")],
    )
示例#3
0
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]")
示例#4
0
def test_IncomingSessionScope_str():
    scope = IncomingSessionScope(["iface1", "iface2"])
    assert str(scope) == "Incoming Interfaces: [iface1, iface2]"
示例#5
0
def test_SessionScope_from_dict():
    d = {"incomingInterfaces": ["iface"]}
    assert SessionScope.from_dict(d) == IncomingSessionScope(["iface"])
    d = {"originatingVrf": "vrf"}
    assert SessionScope.from_dict(d) == OriginatingSessionScope("vrf")