Skip to content

The agent that grows with you

test(docker): the fail-closed dashboard guard passes only on an observed refusal

kshitijk4poor0c181d3782ce
diff --git a/tests/docker/test_dashboard.py b/tests/docker/test_dashboard.py
index 76710a0837e..91b7a78a803 100644
--- a/tests/docker/test_dashboard.py
+++ b/tests/docker/test_dashboard.py
@@ -219,10 +219,12 @@ def test_dashboard_insecure_env_var_no_longer_bypasses_gate(
)
# Fail-closed: the dashboard process must NOT successfully serve. Probe
# for a few seconds; /api/status should never become reachable because
- # start_server raised SystemExit before binding.
- ok, _ = poll_container(
+ # start_server raised SystemExit before binding. The probe prints curl's
+ # own exit code so a probe that never reached the port (container gone,
+ # curl missing) is not read as "closed": the last attempt must be refused.
+ ok, last = poll_container(
container_name,
- "curl -fsS -m 2 http://127.0.0.1:9119/api/status >/dev/null 2>&1",
+ 'curl -sS -m 2 -o /dev/null http://127.0.0.1:9119/api/status 2>/dev/null; rc=$?; echo "rc=$rc"; exit $rc',
deadline_s=12.0,
)
assert not ok, (
@@ -230,3 +232,7 @@ def test_dashboard_insecure_env_var_no_longer_bypasses_gate(
"auth provider — the gate fails closed. /api/status became reachable, "
"meaning the unauthenticated escape hatch is still open."
)
+ assert last.strip() == "rc=7", (
+ "Expected the dashboard port to refuse connections (curl rc=7); the "
+ f"probe never observed a refusal, so it proves nothing. Last: {last!r}"
+ )
diff --git a/tests/docker/test_poll_stalled_exec.py b/tests/docker/test_poll_stalled_exec.py
index ecc5c0cc082..72ac7c1fb41 100644
--- a/tests/docker/test_poll_stalled_exec.py
+++ b/tests/docker/test_poll_stalled_exec.py
@@ -68,10 +68,34 @@ def test_fail_closed_dashboard_guard_needs_a_completed_probe(monkeypatch):
monkeypatch.setattr(docker_conftest, "time", clock)
monkeypatch.setattr(docker_conftest, "docker_exec_sh", _scripted_exec(clock, ["stall"]))
monkeypatch.setattr(test_dashboard, "start_container", lambda *args, **kwargs: "c")
- with pytest.raises(AssertionError, match="No probe of c completed"):
+ with pytest.raises(AssertionError, match="stalled"):
test_dashboard.test_dashboard_insecure_env_var_no_longer_bypasses_gate("image", "c")
+ ("returncode", "stdout", "failure"),
+ [
+ (7, "rc=7\n", None), # connection refused: the real fail-closed signal
+ (0, "rc=0\n", "must NOT serve"),
+ (1, "", "refusal"), # docker exec into a container that already exited
+ (127, "rc=127\n", "refusal"), # curl missing
+ ],
+ ids=["refused", "served", "container-gone", "curl-missing"],
+)
+def test_fail_closed_dashboard_guard_needs_an_observed_refusal(monkeypatch, returncode, stdout, failure):
+ """A completed probe that never reached the port proves nothing either: only a refusal passes."""
+ clock = _Clock()
+ monkeypatch.setattr(docker_conftest, "time", clock)
+ result = SimpleNamespace(returncode=returncode, stdout=stdout, stderr="")
+ monkeypatch.setattr(docker_conftest, "docker_exec_sh", _scripted_exec(clock, [result]))
+ monkeypatch.setattr(test_dashboard, "start_container", lambda *args, **kwargs: "c")
+ if failure is None:
+ test_dashboard.test_dashboard_insecure_env_var_no_longer_bypasses_gate("image", "c")
+ else:
+ with pytest.raises(AssertionError, match=failure):
+ test_dashboard.test_dashboard_insecure_env_var_no_longer_bypasses_gate("image", "c")
+
+
def test_stall_after_a_completed_probe_keeps_its_output(monkeypatch):
"""A late stall must not replace the last real probe output that positive callers print."""
clock = _Clock()