Skip to content

reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities

test+monitor: make bats assertions actually assert, and fix what that exposed

six2dezcc613a92da25
diff --git a/modules/core.sh b/modules/core.sh
index 3bfcfcd..42a2805 100644
--- a/modules/core.sh
+++ b/modules/core.sh
@@ -1081,6 +1081,17 @@ function monitor_snapshot() {
local ts snap prev_link prev_dir
ts=$(date +%Y%m%d_%H%M%S)
snap=".incremental/history/${ts}"
+ # Second-resolution timestamps collide whenever two cycles land in the same
+ # second. `mkdir -p` then SUCCEEDS on the existing directory, this cycle's
+ # copies overwrite the previous snapshot, and `latest` still points at it —
+ # so the delta below is computed against the very files just overwritten.
+ # Every count comes out zero, the baseline needed to detect the next change
+ # is gone, and nothing reports an error. Disambiguate before creating.
+ local _snap_seq=1
+ while [[ -e "$snap" ]]; do
+ _snap_seq=$((_snap_seq + 1))
+ snap=".incremental/history/${ts}-${_snap_seq}"
+ done
mkdir -p "$snap"
# Snapshot key artifacts for this cycle.
@@ -1197,7 +1208,13 @@ function monitor_snapshot() {
elif [[ "$delta_total" -gt 0 ]]; then
local alert_stats nuclei_u subs_u webs_u nuclei_s subs_s webs_s critical_u high_u
alert_stats=$(_monitor_alert_summary "$snap")
- read -r nuclei_u subs_u webs_u nuclei_s subs_s webs_s critical_u high_u <<<"$alert_stats"
+ # IFS=' ' is REQUIRED, not stylistic. reconftw.sh:8 sets IFS=$'\n\t'
+ # process-wide, so a bare `read` does not split on spaces: all eight
+ # fields land in $nuclei_u and every numeric test below then dies with
+ # "[[: 1 1 1 0 0 0 0 1: arithmetic syntax error". The alert summary was
+ # therefore never parsed and monitor alerting could not work. Same
+ # narrowing reconftw.sh:128 already applies for the axiom argv split.
+ IFS=' ' read -r nuclei_u subs_u webs_u nuclei_s subs_s webs_s critical_u high_u <<<"$alert_stats"
if [[ "${nuclei_u:-0}" -gt 0 ]]; then
notification "[ALERT] New nuclei findings (>=${MONITOR_MIN_SEVERITY:-high}): ${nuclei_u:-0}" warn
@@ -1219,7 +1236,11 @@ function monitor_snapshot() {
if [[ -L "$prev_link" || -d "$prev_link" ]]; then
rm -rf -- "$prev_link"
fi
- ln -s "$ts" "$prev_link" 2>/dev/null || {
+ # Point at the directory actually written, not at $ts: the collision guard
+ # above may have created ${ts}-2, and a pointer to $ts would then name a
+ # DIFFERENT snapshot than the one just taken — the next cycle would diff
+ # against the wrong baseline.
+ ln -s "${snap##*/}" "$prev_link" 2>/dev/null || {
cp -R "$snap" "$prev_link"
}
diff --git a/tests/helpers/common.bash b/tests/helpers/common.bash
index 229b516..24ac1ee 100644
--- a/tests/helpers/common.bash
+++ b/tests/helpers/common.bash
@@ -11,4 +11,12 @@ setup_recon_env() {
export NOTIFICATION=false
export AXIOM=false
source "$project_root/reconftw.sh" --source-only
+
+ # reconftw.sh:7 runs `set +e`, so sourcing it DISABLES errexit in the test
+ # shell — and bats needs errexit to fail a test at its first failing command.
+ # Without this restore only a body's LAST command decides the verdict and every
+ # assertion above it is inert: a literal `[ 1 -eq 0 ]` mid-test still reports
+ # `ok`. The `set -eo pipefail` at the top of this file runs BEFORE the source
+ # and does not survive it, which is why the restore belongs here.
+ set -eo pipefail
}
diff --git a/tests/unit/test_perf_profile.bats b/tests/unit/test_perf_profile.bats
index 3b56a49..99e5a97 100644
--- a/tests/unit/test_perf_profile.bats
+++ b/tests/unit/test_perf_profile.bats
@@ -8,8 +8,10 @@ setup() {
@test "apply_performance_profile sets numeric values for low profile" {
export PERF_PROFILE="low"
unset PARALLEL_MAX_JOBS
- run apply_performance_profile
- [ "$status" -eq 0 ]
+ # NOT `run`: it executes in a subshell, so the variables the function sets do
+ # not survive into this shell and the assertions below would read the unset
+ # values this test just unset.
+ apply_performance_profile
[[ "$PARALLEL_MAX_JOBS" =~ ^[0-9]+$ ]]
[[ "$FFUF_THREADS" =~ ^[0-9]+$ ]]
[ "$PARALLEL_MAX_JOBS" -ge 1 ]
diff --git a/tests/unit/test_reporting.bats b/tests/unit/test_reporting.bats
index e64b795..5cc949e 100644
--- a/tests/unit/test_reporting.bats
+++ b/tests/unit/test_reporting.bats
@@ -31,7 +31,9 @@ teardown() {
[ -f report/index.html ]
[ -f report/latest/report.json ]
[ -f report/latest/index.html ]
- grep -q '"domain":"example.com"' report/report.json
+ # The report is pretty-printed when jq is available and compact when it is
+ # not, so pin the field, not the whitespace between key and value.
+ grep -qE '"domain":[[:space:]]*"example.com"' report/report.json
}
@test "report includes delta_since_last when monitor data exists" {