git: 9fc2d858b4e9 - main - ping tests: Add a regression test
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 27 Mar 2023 03:49:08 UTC
The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=9fc2d858b4e9457a122a54c1a25715314032bf41 commit 9fc2d858b4e9457a122a54c1a25715314032bf41 Author: Jose Luis Duran <jlduran@gmail.com> AuthorDate: 2023-03-26 03:11:50 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-03-27 02:54:29 +0000 ping tests: Add a regression test Test regression fixed in 4630a3252ac8. Add two tests that do not use the verbose flag, so the code path in question can be reached: 1. Respond with a proper ICMP destination host unreachable packet. 2. Respond with a doctored ICMP destination host unreachable packet, that has the ICMP Identifier field modified (+1 bit). Reviewed by: cy MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39244 --- sbin/ping/tests/test_ping.py | 61 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index f1c961c5b551..79cde1f4936c 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -56,6 +56,9 @@ def build_response_packet(echo, ip, icmp, oip_ihl, special): # Build a package with a wrong last byte payload_no_last_byte = sc.bytes_hex(load)[:-2] load = (sc.hex_bytes(payload_no_last_byte)) + b"\x00" + if special == "not-mine": + # Modify the ICMP Identifier field + oicmp.id += 1 if icmp.type in icmp_id_seq_types: pkt = ip / icmp / load @@ -148,6 +151,7 @@ def pinger( # Miscellaneous arguments count: int = 1, dup: bool = False, + verbose: bool = True, ) -> subprocess.CompletedProcess: """P I N G E R @@ -173,8 +177,8 @@ def pinger( :type opts: str, optional :keyword oip_ihl: Inner packet's Internet Header Length, defaults to None :type oip_ihl: class:`scapy.fields.BitField`, optional - :keyword special: Send a special packet - one of `no-payload`, `tcp`, - `udp`, `wrong` or `warp`, defaults to None + :keyword special: Send a special packet - one of `no-payload`, `not-mine`, + `tcp`, `udp`, `wrong` or `warp`, defaults to None :type special: str, optional :keyword icmp_pptr: ICMP pointer, defaults to 0 :type icmp_pptr: class:`scapy.fields.ByteField` @@ -197,6 +201,8 @@ def pinger( :type count: int :keyword dup: Duplicate packets, defaults to `False` :type dup: bool + :keyword verbose: Turn on/off verbosity, defaults to `True` + :type verbose: bool :return: A class:`subprocess.CompletedProcess` with the output from the ping utility @@ -213,8 +219,9 @@ def pinger( str(count), "-t", str(count), - "-v", ] + if verbose: + command += ["-v"] if request == "mask": command += ["-Mm"] if request == "timestamp": @@ -1210,6 +1217,54 @@ ping: quoted data too short (28 bytes) from 192.0.2.2 }, id="_3_1_special_udp", ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 3, + "icmp_code": 1, + "verbose": False, + }, + { + "returncode": 2, + "stdout": """\ +PING 192.0.2.2 (192.0.2.2): 56 data bytes +92 bytes from 192.0.2.2: Destination Host Unreachable +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 0054 0001 0 0000 40 01 f6a4 192.0.2.1 192.0.2.2 + + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 0 packets received, 100.0% packet loss +""", + "stderr": "", + "redacted": False, + }, + id="_3_1_verbose_false", + ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 3, + "icmp_code": 1, + "special": "not-mine", + "verbose": False, + }, + { + "returncode": 2, + "stdout": """\ +PATTERN: 0x01 +PING 192.0.2.2 (192.0.2.2): 56 data bytes + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 0 packets received, 100.0% packet loss +""", + "stderr": "", + "redacted": False, + }, + id="_3_1_special_not_mine_verbose_false", + ), pytest.param( { "src": "192.0.2.1",