Files
skillshare/scripts/test_redteam_signal.sh
T
Willie 52ca5f3ba3 test(redteam): inject the signal mutation into the shared audit gate
The tracked-repo update refactor moved the rollback decision from
update_handlers.go into install.AuditGate.Run, so the mutation found
nothing to replace and redteam-signal failed every push to main,
including the 0.25.1 release verification. Install and update now both
decide through that one gate, so one mutation point covers them.
2026-10-07 14:37:57 +08:00

83 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Verify red_team_test.sh has real detection signal.
#
# Strategy:
# 1) Run baseline red team test (must pass).
# 2) Introduce a temporary mutation that bypasses HIGH/CRITICAL rollback gate.
# 3) Rebuild binary and run red team test again (must fail).
# 4) Restore original source and rebuild.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
GATE_GO="$PROJECT_ROOT/internal/install/install_audit.go"
BACKUP_FILE=""
BACKUP_READY=false
RESTORED=false
backup_source() {
BACKUP_FILE="$(mktemp "${TMPDIR:-/tmp}/install_audit.go.backup.XXXXXX")"
cp "$GATE_GO" "$BACKUP_FILE"
BACKUP_READY=true
}
restore_source() {
if [ "$RESTORED" = false ] && [ "$BACKUP_READY" = true ] && [ -f "$BACKUP_FILE" ]; then
cp "$BACKUP_FILE" "$GATE_GO"
RESTORED=true
fi
if [ -n "$BACKUP_FILE" ]; then
rm -f "$BACKUP_FILE"
fi
}
cleanup() {
restore_source
}
trap cleanup EXIT
echo "==> [1/4] Baseline: running make test-redteam (should pass)"
(cd "$PROJECT_ROOT" && make test-redteam)
echo "==> [2/4] Injecting mutation: bypass rollback on HIGH/CRITICAL findings"
backup_source
# install and update both decide through AuditGate.Run; skip its threshold check.
perl -0pi -e 's@if !scanResult\.HasSeverityAtOrAbove\(threshold\) \{@if true { // MUTATION: bypass rollback gate@g' "$GATE_GO"
if command -v rg >/dev/null 2>&1; then
MUTATION_COUNT="$(rg -c "MUTATION: bypass rollback gate" "$GATE_GO" || true)"
else
MUTATION_COUNT="$(grep -c "MUTATION: bypass rollback gate" "$GATE_GO" || true)"
fi
MUTATION_COUNT="${MUTATION_COUNT:-0}"
if ! [[ "$MUTATION_COUNT" =~ ^[0-9]+$ ]]; then
echo "ERROR: mutation count is not numeric: $MUTATION_COUNT"
exit 2
fi
if [ "$MUTATION_COUNT" -ne 1 ]; then
echo "ERROR: expected to inject 1 mutation point, got $MUTATION_COUNT"
exit 2
fi
echo "==> [3/4] Rebuild mutated binary and run red team (should fail)"
(cd "$PROJECT_ROOT" && go build -o bin/skillshare ./cmd/skillshare)
set +e
(cd "$PROJECT_ROOT" && ./scripts/red_team_test.sh)
MUTATED_EXIT=$?
set -e
if [ "$MUTATED_EXIT" -eq 0 ]; then
echo "ERROR: mutated run unexpectedly passed; red team signal check failed"
exit 1
fi
echo "PASS: mutated run failed as expected (exit=$MUTATED_EXIT)"
echo "==> [4/4] Restoring original source and rebuilding"
restore_source
(cd "$PROJECT_ROOT" && go build -o bin/skillshare ./cmd/skillshare)
echo "PASS: test-redteam signal verified (baseline pass + mutation fail)"