예제 #1
0
def test_SessionMatchExpr_str():
    match = SessionMatchExpr("ICMP", "1.1.1.1", "2.2.2.2")
    assert str(match) == "[ipProtocol=ICMP, srcIp=1.1.1.1, dstIp=2.2.2.2]"
    match = SessionMatchExpr("ICMP", "1.1.1.1", "2.2.2.2", 1111, 2222)
    assert str(match) == (
        "[ipProtocol=ICMP, srcIp=1.1.1.1, dstIp=2.2.2.2, srcPort=1111, dstPort=2222]"
    )
예제 #2
0
def test_SessionMatchExpr_from_dict():
    d = {"ipProtocol": "ICMP", "srcIp": "1.1.1.1", "dstIp": "2.2.2.2"}
    assert SessionMatchExpr.from_dict(d) == SessionMatchExpr(
        "ICMP", "1.1.1.1", "2.2.2.2")
    d = {
        "ipProtocol": "ICMP",
        "srcIp": "1.1.1.1",
        "dstIp": "2.2.2.2",
        "srcPort": 1111,
        "dstPort": 2222,
    }
    assert SessionMatchExpr.from_dict(d) == SessionMatchExpr(
        "ICMP", "1.1.1.1", "2.2.2.2", 1111, 2222)
예제 #3
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")],
    )
예제 #4
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")],
    )
예제 #5
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]")