A negated command only asserts in final position, and one that could never pass #16
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Keel-Linux/keel-nodebb!16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "test/negations-that-assert"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Every negation in these suites now asserts wherever it stands. Six did not assert at all — and turning one on found a second bug in the same test.
Closes #15. Part of Keel-Linux/tracker#19, which has the organization-wide sweep.
Why a bare
!is inertA bats test body has no assertions of its own: its verdict is the exit status of the last command it ran. Bash does not apply errexit to a negated command, so
! cmddecides the test in final position and is inert everywhere else. shellcheck grades the two apart,error:for the inert ones andnote:for the rest:What was not being checked
All six are about trusting a proxy.
conf.ddefault trusts nobody, and that it never matchesgeoon$remote_addr. Two of those four assertions ran.nodebb_valid_proxy "2001:db8::13; }"— the value that would close thegeoblock and append directives of its own. The injection case. Onlyhellodecided anything.geois on$realip_remote_addrand never on$remote_addr— the redirect loop the file's own comment warns about at length.All of them are
run !now, together with the eight that were in final position and did assert: a line whose meaning depends on its position is the trap itself.The bug this found
nodebb.bats, "proxy_conf without an address trusts nobody", asserted:Unanchored — against a file whose own explanatory comment names the directive:
So that assertion could never have held, for any input, and nobody could know, because nothing ever ran it. It is anchored now:
which is the property that was meant, and the spelling the positive case at line 167 already used (
^set_real_ip_from 2001:db8::13;$). The rendered file is correct — with no address it emits noset_real_ip_fromdirective. Only the assertion was wrong, so nothing shipped broken.A second shape of the same defect
runreplaces$output,$statusand$lines. Two tests here dorun nodebb_proxy_conf …and then grep<<< "$output"several times; once the first of those becomes arun !, the next one greps the refutation's empty output and passes for a new reason. Both tests now keep the rendered file in a local first:That was caught by an audit over every converted site, not by the suite — the vacuous pass is green by construction. It is written up in the
docs/traps.mdentry that goes with this sweep.What else was verified
The shipped
overlay/etc/nginx/conf.d/nodebb-proxy.confand the rendered output were both read directly, andnodebb_valid_proxywas run against all five of its cases by hand, before the conversion. Everything except the assertion above is correct.Test plan
The validator's five cases and both rendered files verified by hand, before the conversion.
shellcheck -f gcc --shell=bash --severity=error --include=SC2314 tests/*.batsreports nothing.Every converted site audited for
runclobbering$output/$status/$lines; the two real cases fixed.bats tests/*.batsgreen, 134 tests.tests/coverage.sh, threshold 95, unchanged:Tests ship nothing, so
package / changelogpasses by reporting that nothing that ships changed. No changelog entry and no version bump.Reviewed: every converted refutation goes red when its property is broken; emitting set_real_ip_from with no trusted address fails the anchored check. None reads the output of the run it replaced. No changes needed; merged main so the renamed appliance check runs on this head.