Skip to content

18 sites in the natmap_docker suite have a failure branch that cannot fail #58

Description

@FAZuH

Found while closing #56. This is the same defect, 18 more times, and it is the most serious thing the audit has found about the test suite.

The mechanism

tests/natmap_docker.rs uses this shape:

grep -q '<pattern>' && (echo 'FAIL: ...' >&2 && exit 1) || echo 'PASS'

The exit 1 sits inside a subshell — the parentheses create one. exit 1 therefore kills the subshell, not the script. Control returns to the ||, echo 'PASS' runs, and the script exits 0. The harness sees PASS.

Proven:

$ sh -c 'false && (echo "FAIL-branch" >&2; exit 1) || echo PASS; echo "final=$?"'
PASS
final=0

Every test using this shape reports PASS when the condition it checks is violated. The &&/|| chain looks like a guard and behaves like a no-op.

Sites

18 in tests/natmap_docker.rs: lines 201, 216, 273, 293, 313, 333, 352, 371, 382, 405, 407, 462, 479, 496, 515, 537, 739, 821.

Line 739 is docker_mapping_remove_cleans_up_loopback_masquerade, the third hairpin test, so it is both target-blind and vacuous on its removal check.

The second, quieter half

Even with the subshell unwrapped, a bare grep -q absence check is satisfiable by a broken environment: if iptables is missing, the input is empty, grep exits 1, and the rule reads as absent. The test then passes for the wrong reason. #56 fixed this for the loopback negative test with a control grep: assert the thing that should be there is visible, so a broken command fails before the absence check can succeed.

What to build

Per site, both halves:

  1. Unwrap the subshell: if <condition>; then echo 'FAIL' >&2; <diagnostics>; exit 1; fi
  2. Add a control assertion where the check is an absence — something that must be present, so a missing binary or a failed command cannot masquerade as "the rule is gone"
  3. Where the check is a presence, assert the jump target, not just the match fields. That is the The loopback hairpin Docker test greps for the rule but never checks the MASQUERADE target #56 lesson: a rule whose target changed still matches its match fields

Acceptance criteria

  • rg -c 'exit 1\) \|\| echo' tests/natmap_docker.rs is 0
  • Every one of the 18 sites is listed individually with before and after, so a site cannot be quietly skipped
  • A demonstration that each rewritten assertion can fail: inject the violating condition and show the test goes red. Do it for a representative sample covering all three shapes present in the file (presence-by-grep, absence-by-grep, and the compound forms), and say which lines each sample covers
  • The && (…) || shape does not survive anywhere else in tests/, checked across tests/auto_discover/ and tests/natmap_docker.rs
  • cargo test -p lab-ops --all-features --test natmap_docker passes, currently 35
  • No assertion is weakened to make a site pass

Why this was missed

#44 removed a tautological assert_pass helper from tests/auto_discover/, where the tautology was in Rust code. The same tautology exists here in shell strings, where no Rust-side audit reaches. rg for the pattern is the whole check.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions