#!/usr/bin/env bash # R1 integration tests (Docker live-test lane; run from the repo root with a # built tree). Uses the SYNTHETIC fixture tests/fixtures/rules-snapshot, never # the real pack. # 1. install_feed_snapshot lays the pinned layout; check-rules loads it offline. # 2. rule_auto_fetch=false: `rules fetch` no-ops with the message, touches # nothing, constructs no fetcher (run without network when unshare allows). # 3. --force overrides the gate (the disabled message must not appear). set -euo pipefail BIN="${BIN:-builddir/src/strawberry}" FIXTURE=tests/fixtures/rules-snapshot . ./scripts/install_common.sh tmp=$(mktemp -d "${TMPDIR:-/var/tmp}/strawberry-r1.XXXXXX") feeds="$tmp/feeds" conf="$tmp/strawberry.conf" group=$(id -gn) fail() { echo "FAIL: $*" >&2; exit 1; } (cd "$FIXTURE" && sha256sum -c MANIFEST.sha256 --quiet) || fail "fixture manifest" # 1. install + check-rules install_feed_snapshot "$FIXTURE" "$feeds" "$group" || fail "install_feed_snapshot" [ -L "$feeds/yara-forge-core/current" ] || fail "current is not a symlink" [ "$(readlink "$feeds/yara-forge-core/current")" = "20990101-fixture" ] || fail "current target" [ "$(stat -c %a "$feeds/yara-forge-core/20990101-fixture")" = "750" ] || fail "version dir mode" [ ! -e "$feeds/malware-hashes" ] || fail "IOC feeds must not be installed in R1" mkdir -p "$tmp/local-rules" { echo "feeds_dir=$feeds" echo "yara_rules_path=$tmp/local-rules" echo "control_socket_path=" echo "rule_auto_fetch=false" } > "$conf" out=$("$BIN" --config "$conf" rules check) || fail "rules check exit" echo "$out" echo "$out" | grep -q "Rules OK: 2 rules" || fail "expected 2 rules from yara-forge-core" echo "$out" | grep -q "yara-forge-core" || fail "yara-forge-core namespace missing" # 2. fetch disabled: no network, no filesystem change before=$(stat -c %Y "$feeds" "$feeds/yara-forge-core") if command -v unshare >/dev/null 2>&1 && unshare -rn true 2>/dev/null; then run=(unshare -rn) else echo "note: unshare -rn unavailable; relying on the gate returning before the fetcher" run=() fi out=$("${run[@]}" "$BIN" --config "$conf" rules fetch) || fail "disabled fetch must exit 0" echo "$out" | grep -q "rule auto-fetch disabled" || fail "disabled message missing" after=$(stat -c %Y "$feeds" "$feeds/yara-forge-core") [ "$before" = "$after" ] || fail "feeds_dir changed while fetch was disabled" # 3. --force overrides the gate (offline, so the fetch itself may fail) set +e out=$("${run[@]}" "$BIN" --config "$conf" rules fetch --force 2>&1) set -e echo "$out" | grep -q "rule auto-fetch disabled" && fail "--force did not override the gate" echo "rules snapshot tests: ALL PASSED"