fix(ping): refuse a destination or source that reads as an option

Quoting keeps a value one word, but ping still reads a word starting
with "-" as one of its options: ping(destination="-f") sent a flood
ping option instead of a host, and a source "-f" did the same after -I.
No address or hostname starts with "-", so ping_command now refuses
such a destination or source with ValueError before anything is sent.

Closes #63
This commit is contained in:
Christian Manivong committed 2026-11-02 08:47:23 +01:00
1 parent e4c65945b9
commit a1e8ec78c3
4 files changed
+22 -3

No files matched your search

+12
View File
@@ -540,6 +540,18 @@ class TestPingArguments:
assert sent == "ping -c 3 -W 1 -s 56 -t 64 192.0.2.1 2>&1"
@pytest.mark.parametrize(
("destination", "source"), [("-f", ""), ("192.0.2.1", "-f"), ("-p ff", "")]
)
def test_an_option_in_place_of_a_name_is_refused_before_anything_is_sent(
self, driver, destination, source
):
"""Quoting keeps a word one word, and ping still reads ``-f`` as its option (#63)."""
with patch.object(driver, "_send") as send, pytest.raises(ValueError, match="option"):
driver.ping(destination, source=source)
send.assert_not_called()
def test_a_number_that_is_not_one_is_refused_before_anything_is_sent(self, driver):
with patch.object(driver, "_send") as send, pytest.raises(ValueError):
driver.ping("192.0.2.1", count="5; id")