Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/tests/test_ping.py
Show First 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | |||||
def redact(output): | def redact(output): | ||||
"""Redact some elements of ping's output""" | """Redact some elements of ping's output""" | ||||
pattern_replacements = [ | pattern_replacements = [ | ||||
("localhost \([0-9]{1,3}(\.[0-9]{1,3}){3}\)", "localhost"), | ("localhost \([0-9]{1,3}(\.[0-9]{1,3}){3}\)", "localhost"), | ||||
("from [0-9]{1,3}(\.[0-9]{1,3}){3}", "from"), | ("from [0-9]{1,3}(\.[0-9]{1,3}){3}", "from"), | ||||
("hlim=[0-9]*", "hlim="), | ("hlim=[0-9]*", "hlim="), | ||||
("ttl=[0-9]*", "ttl="), | ("ttl=[0-9]*", "ttl="), | ||||
("time=[0-9.-]*", "time="), | ("time=[0-9.-]*", "time="), | ||||
("cp: .*", "cp: xx xx xx xx xx xx xx xx"), | |||||
("dp: .*", "dp: xx xx xx xx xx xx xx xx"), | |||||
("\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"), | ("\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"), | ||||
("[0-9\.]+/[0-9.]+", "/"), | ("[0-9\.]+/[0-9.]+", "/"), | ||||
] | ] | ||||
for pattern, repl in pattern_replacements: | for pattern, repl in pattern_replacements: | ||||
output = re.sub(pattern, repl, output) | output = re.sub(pattern, repl, output) | ||||
return output | return output | ||||
▲ Show 20 Lines • Show All 1,109 Lines • ▼ Show 20 Lines | |||||
round-trip min/avg/max/stddev = /// ms | round-trip min/avg/max/stddev = /// ms | ||||
""", | """, | ||||
"stderr": """\ | "stderr": """\ | ||||
ping: time of day goes back (- ms), clamping time to 0 | ping: time of day goes back (- ms), clamping time to 0 | ||||
""", | """, | ||||
"redacted": True, | "redacted": True, | ||||
}, | }, | ||||
id="_0_0_special_warp", | id="_0_0_special_warp", | ||||
), | |||||
pytest.param( | |||||
{ | |||||
"src": "192.0.2.1", | |||||
"dst": "192.0.2.2", | |||||
"icmp_type": 0, | |||||
"icmp_code": 0, | |||||
"special": "wrong", | |||||
}, | |||||
{ | |||||
"returncode": 0, | |||||
"stdout": """\ | |||||
PATTERN: 0x01 | |||||
PING 192.0.2.2 (192.0.2.2): 56 data bytes | |||||
64 bytes from: icmp_seq=0 ttl= time= ms | |||||
wrong data byte #55 should be 0x1 but was 0x0 | |||||
cp: xx xx xx xx xx xx xx xx | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 | |||||
dp: xx xx xx xx xx xx xx xx | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |||||
--- 192.0.2.2 ping statistics --- | |||||
1 packets transmitted, 1 packets received, 0.0% packet loss | |||||
round-trip min/avg/max/stddev = /// ms | |||||
""", | |||||
"stderr": "", | |||||
"redacted": True, | |||||
}, | |||||
id="_0_0_special_wrong", | |||||
), | ), | ||||
] | ] | ||||
@pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata) | @pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata) | ||||
@pytest.mark.require_progs(["scapy"]) | @pytest.mark.require_progs(["scapy"]) | ||||
@pytest.mark.require_user("root") | @pytest.mark.require_user("root") | ||||
def test_pinger(self, pinger_kargs, expected): | def test_pinger(self, pinger_kargs, expected): | ||||
"""Test ping using pinger(), a reply faker""" | """Test ping using pinger(), a reply faker""" | ||||
Show All 9 Lines |