fix(sockets): raise when the listening-socket fallback fails
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m18s
driver / test (3.13) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 33s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m17s
CI / driver (pull_request) Successful in 3m6s
driver / publish (pull_request) Skipped

When the root reading failed, get_listening_sockets ran the fallback
without root and parsed its output without looking at the exit status.
A failing sockstat or netstat returned an empty list, which a caller
reads as every port closed. The fallback now goes through the reader
check and raises with the command's error.

Closes #11
This commit is contained in:
Christian Manivong committed 2026-11-01 21:44:04 +01:00
1 parent 405239d5df
commit a184a9cad1
3 files changed
+21 -1

No files matched your search

+14
View File
@@ -232,6 +232,20 @@ class TestListeningSockets:
}
assert calls == [("fstat -n", True), (OpenBSDDriver.LISTENING_FALLBACK_COMMAND, False)]
@pytest.mark.parametrize("cls", [FreeBSDDriver, OpenBSDDriver])
def test_a_failed_fallback_raises_instead_of_reading_as_no_sockets(self, cls):
"""Both readings failing is no empty host: every port would read as closed."""
driver = _driver(cls, {})
def run(command, privileged=False, timeout=60, stdin=None):
if privileged:
return type("R", (), {"stdout": "", "stderr": "", "exit_code": 1})()
return type("R", (), {"stdout": "", "stderr": "not found", "exit_code": 127})()
driver.run_command = run # type: ignore[method-assign]
with pytest.raises(RuntimeError, match="not found"):
driver.get_listening_sockets()
class _Result:
def __init__(self, stdout: str = "", exit_code: int = 0, stderr: str = "") -> None: