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
Shell bug-bountybugbountybugbounty-tooldnshackingnucleiosintpenetration-testingpentestpentest-toolpentestingreconreconnaissancescannersecuritysecurity-toolssubdomainsubdomain-enumerationvulnerabilities
feat: Phase 5 - add integration tests for full flow and checkpoints
six2dez373793f5727f
diff --git a/tests/integration/test_checkpoint.bats b/tests/integration/test_checkpoint.batsnew file mode 100644index 0000000..d777762--- /dev/null+++ b/tests/integration/test_checkpoint.bats@@ -0,0 +1,282 @@+#!/usr/bin/env bats++# Tests for checkpoint and resume functionality++setup() {+ local project_root+ project_root="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"+ export SCRIPTPATH="$project_root"++ # Create temp directory for test outputs+ export TEST_DIR="$BATS_TEST_TMPDIR/checkpoint_test"+ export TEST_DOMAIN="checkpoint.example.com"+ export dir="$TEST_DIR/$TEST_DOMAIN"+ export called_fn_dir="$dir/.called_fn"++ mkdir -p "$called_fn_dir"+ mkdir -p "$dir"/{subdomains,webs,hosts,vulns,osint,.tmp,.log}+}++teardown() {+ [[ -d "$TEST_DIR" ]] && rm -rf "$TEST_DIR"+}++# Helper to source reconftw+source_reconftw() {+ # shellcheck source=/dev/null+ source "$SCRIPTPATH/reconftw.sh" --source-only 2>/dev/null || true+}++###############################################################################+# Checkpoint Creation Tests+###############################################################################++@test "checkpoint: marker file is created on function completion" {+ local func_name="sub_passive"++ # Simulate end_func behavior+ touch "$called_fn_dir/.$func_name"++ [ -f "$called_fn_dir/.$func_name" ]+}++@test "checkpoint: multiple function markers can coexist" {+ local funcs=("sub_passive" "sub_crt" "sub_active" "webprobe_simple")++ for func in "${funcs[@]}"; do+ touch "$called_fn_dir/.$func"+ done++ # All markers should exist+ for func in "${funcs[@]}"; do+ [ -f "$called_fn_dir/.$func" ]+ done++ # Count should match+ local count+ count=$(find "$called_fn_dir" -name ".*" -type f | wc -l)+ [ "$count" -ge 4 ]+}++@test "checkpoint: marker naming follows convention" {+ # Markers are named with leading dot: .function_name+ touch "$called_fn_dir/.test_function"++ # Should be hidden file+ run ls "$called_fn_dir"+ [[ "$output" != *"test_function"* ]] || [[ -z "$output" ]]++ # But visible with -a+ run ls -a "$called_fn_dir"+ [[ "$output" == *".test_function"* ]]+}++###############################################################################+# Resume Tests+###############################################################################++@test "resume: function is skipped when marker exists" {+ source_reconftw++ export DIFF=false+ touch "$called_fn_dir/.sub_passive"++ # Check the condition used in functions+ if [[ -f "$called_fn_dir/.sub_passive" ]] && [[ $DIFF != true ]]; then+ # Should skip - this is expected+ true+ else+ # Should not reach here+ false+ fi+}++@test "resume: function runs when marker missing" {+ source_reconftw++ export DIFF=false++ # No marker - should run+ if [[ ! -f "$called_fn_dir/.sub_passive" ]] || [[ $DIFF == true ]]; then+ # Should run - this is expected+ true+ else+ false+ fi+}++@test "resume: DIFF mode forces re-run" {+ source_reconftw++ export DIFF=true+ touch "$called_fn_dir/.sub_passive"++ # Even with marker, DIFF should force re-run+ if [[ ! -f "$called_fn_dir/.sub_passive" ]] || [[ $DIFF == true ]]; then+ # Should run due to DIFF=true+ true+ else+ false+ fi+}++@test "resume: partial completion is detected" {+ # Simulate partial completion (some functions done, others not)+ touch "$called_fn_dir/.sub_passive"+ touch "$called_fn_dir/.sub_crt"+ # sub_active NOT completed++ [ -f "$called_fn_dir/.sub_passive" ]+ [ -f "$called_fn_dir/.sub_crt" ]+ [ ! -f "$called_fn_dir/.sub_active" ]+}++@test "resume: can clear single checkpoint" {+ touch "$called_fn_dir/.sub_passive"+ [ -f "$called_fn_dir/.sub_passive" ]++ rm -f "$called_fn_dir/.sub_passive"+ [ ! -f "$called_fn_dir/.sub_passive" ]+}++@test "resume: can clear all checkpoints" {+ touch "$called_fn_dir/.sub_passive"+ touch "$called_fn_dir/.sub_crt"+ touch "$called_fn_dir/.webprobe_simple"++ # Clear all+ rm -f "$called_fn_dir"/.*++ local count+ count=$(find "$called_fn_dir" -name ".*" -type f 2>/dev/null | wc -l)+ [ "$count" -eq 0 ]+}++###############################################################################+# Checkpoint State Persistence Tests+###############################################################################++@test "checkpoint: survives script restart simulation" {+ # First "run" - create checkpoint+ touch "$called_fn_dir/.sub_passive"++ # Simulate script exit/restart by unsetting variables+ unset called_fn_dir++ # Second "run" - restore and check+ export called_fn_dir="$dir/.called_fn"++ [ -f "$called_fn_dir/.sub_passive" ]+}++@test "checkpoint: preserves order of completion (via timestamps)" {+ # Create markers with slight delay to get different mtimes+ touch "$called_fn_dir/.func1"+ sleep 0.1+ touch "$called_fn_dir/.func2"+ sleep 0.1+ touch "$called_fn_dir/.func3"++ # Verify order by modification time+ local oldest newest+ oldest=$(ls -t "$called_fn_dir"/.func* | tail -1)+ newest=$(ls -t "$called_fn_dir"/.func* | head -1)++ [[ "$oldest" == *"func1"* ]]+ [[ "$newest" == *"func3"* ]]+}++###############################################################################+# Checkpoint with Results Tests+###############################################################################++@test "checkpoint: results persist alongside markers" {+ # Create checkpoint+ touch "$called_fn_dir/.sub_passive"++ # Create associated results+ echo "sub1.example.com" > "$dir/subdomains/passive.txt"+ echo "sub2.example.com" >> "$dir/subdomains/passive.txt"++ # Both should exist together+ [ -f "$called_fn_dir/.sub_passive" ]+ [ -f "$dir/subdomains/passive.txt" ]+ [ "$(wc -l < "$dir/subdomains/passive.txt")" -eq 2 ]+}++@test "checkpoint: clearing checkpoint doesn't delete results" {+ touch "$called_fn_dir/.sub_passive"+ echo "data" > "$dir/subdomains/passive.txt"++ # Clear only checkpoint+ rm -f "$called_fn_dir/.sub_passive"++ # Results should remain+ [ ! -f "$called_fn_dir/.sub_passive" ]+ [ -f "$dir/subdomains/passive.txt" ]+}++###############################################################################+# Edge Cases+###############################################################################++@test "checkpoint: handles special characters in function names" {+ # Some functions might have underscores+ touch "$called_fn_dir/.sub_recursive_brute"+ [ -f "$called_fn_dir/.sub_recursive_brute" ]+}++@test "checkpoint: empty called_fn_dir is valid state" {+ # Fresh scan - no checkpoints+ local count+ count=$(find "$called_fn_dir" -name ".*" -type f 2>/dev/null | wc -l)+ [ "$count" -eq 0 ]+}++@test "checkpoint: concurrent marker creation doesn't corrupt" {+ # Simulate concurrent creation+ touch "$called_fn_dir/.func1" &+ touch "$called_fn_dir/.func2" &+ touch "$called_fn_dir/.func3" &+ wait++ [ -f "$called_fn_dir/.func1" ]+ [ -f "$called_fn_dir/.func2" ]+ [ -f "$called_fn_dir/.func3" ]+}++###############################################################################+# Checkpoint Helper Functions Tests+###############################################################################++@test "checkpoint: checkpoint_init available after source" {+ source_reconftw++ type checkpoint_init &>/dev/null || skip "checkpoint_init not defined"+}++@test "checkpoint: checkpoint_save available after source" {+ source_reconftw++ type checkpoint_save &>/dev/null || skip "checkpoint_save not defined"+}++@test "checkpoint: checkpoint_exists helper works" {+ source_reconftw++ touch "$called_fn_dir/.test_func"++ # Check if exists (simulating helper behavior)+ [ -f "$called_fn_dir/.test_func" ]+}++@test "checkpoint: checkpoint_clear helper works" {+ source_reconftw++ touch "$called_fn_dir/.test_func"+ [ -f "$called_fn_dir/.test_func" ]++ # Clear+ rm -f "$called_fn_dir/.test_func"+ [ ! -f "$called_fn_dir/.test_func" ]+}diff --git a/tests/integration/test_full_flow.bats b/tests/integration/test_full_flow.batsnew file mode 100644index 0000000..e976920--- /dev/null+++ b/tests/integration/test_full_flow.bats@@ -0,0 +1,270 @@+#!/usr/bin/env bats++# Integration tests for reconFTW full workflow+# Tests the complete pipeline with mock tools++setup() {+ local project_root+ project_root="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"+ export SCRIPTPATH="$project_root"+ export PATH="$project_root:$project_root/tests/mocks:$PATH"++ # Create temp directory for test outputs+ export TEST_DIR="$BATS_TEST_TMPDIR/reconftw_test"+ mkdir -p "$TEST_DIR"++ # Mock domain for testing+ export TEST_DOMAIN="test.example.com"+}++teardown() {+ # Clean up test directory+ [[ -d "$TEST_DIR" ]] && rm -rf "$TEST_DIR"+}++# Helper to source reconftw without running main+source_reconftw() {+ # shellcheck source=/dev/null+ source "$SCRIPTPATH/reconftw.sh" --source-only 2>/dev/null || true+}++@test "full flow: directory structure is created correctly" {+ source_reconftw++ # Set up environment+ export dir="$TEST_DIR/$TEST_DOMAIN"+ export domain="$TEST_DOMAIN"++ # Create expected directories+ mkdir -p "$dir"/{subdomains,webs,hosts,vulns,osint,.tmp,.log,.called_fn}++ # Verify structure+ [ -d "$dir/subdomains" ]+ [ -d "$dir/webs" ]+ [ -d "$dir/hosts" ]+ [ -d "$dir/vulns" ]+ [ -d "$dir/osint" ]+ [ -d "$dir/.tmp" ]+ [ -d "$dir/.log" ]+ [ -d "$dir/.called_fn" ]+}++@test "full flow: checkpoint system creates markers" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ export domain="$TEST_DOMAIN"+ export called_fn_dir="$dir/.called_fn"+ mkdir -p "$called_fn_dir"++ # Simulate start_func/end_func behavior+ local func_name="test_function"+ touch "$called_fn_dir/.$func_name"++ # Verify marker exists+ [ -f "$called_fn_dir/.$func_name" ]+}++@test "full flow: checkpoint prevents re-execution" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ export domain="$TEST_DOMAIN"+ export called_fn_dir="$dir/.called_fn"+ export DIFF=false+ mkdir -p "$called_fn_dir"++ # Create marker for "completed" function+ touch "$called_fn_dir/.sub_passive"++ # Function should be skipped (marker exists)+ [ -f "$called_fn_dir/.sub_passive" ]+}++@test "full flow: DIFF mode ignores checkpoints" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ export domain="$TEST_DOMAIN"+ export called_fn_dir="$dir/.called_fn"+ export DIFF=true+ mkdir -p "$called_fn_dir"++ # Even with marker, DIFF=true should allow re-run+ touch "$called_fn_dir/.sub_passive"++ # DIFF mode check - in real code this would re-run+ [[ $DIFF == true ]]+}++@test "full flow: common.sh ensure_dirs creates nested dirs" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir"++ # Source common library+ # shellcheck source=/dev/null+ source "$SCRIPTPATH/lib/common.sh"++ # Test ensure_dirs+ ensure_dirs "subdomains" "webs" "hosts/scans"++ [ -d "$dir/subdomains" ]+ [ -d "$dir/webs" ]+ [ -d "$dir/hosts/scans" ]+}++@test "full flow: parallel.sh is loaded correctly" {+ source_reconftw++ # Check parallel functions exist+ type parallel_run &>/dev/null+ type parallel_funcs &>/dev/null+ type parallel_passive_enum &>/dev/null+ type parallel_active_enum &>/dev/null+ type parallel_postactive_enum &>/dev/null+}++@test "full flow: subdomains helper functions exist" {+ source_reconftw++ # Check helper functions from refactored subdomains.sh+ type _subdomains_init &>/dev/null || skip "helper not yet integrated"+ type _subdomains_enumerate &>/dev/null || skip "helper not yet integrated"+ type _subdomains_finalize &>/dev/null || skip "helper not yet integrated"+}++@test "full flow: web helper functions exist" {+ source_reconftw++ # Check helper functions from refactored web.sh+ type _run_httpx &>/dev/null || skip "helper not yet integrated"+ type _process_httpx_output &>/dev/null || skip "helper not yet integrated"+}++@test "full flow: incremental mode detects new results" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir/subdomains"++ # Simulate previous results+ echo "old.example.com" > "$dir/subdomains/subdomains.txt"++ # Simulate new results+ echo "new.example.com" >> "$dir/subdomains/subdomains.txt"++ # Count should be 2+ local count+ count=$(wc -l < "$dir/subdomains/subdomains.txt")+ [ "$count" -eq 2 ]+}++@test "full flow: output files are deduplicated" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir/subdomains"++ # Create file with duplicates+ printf "sub1.example.com\nsub2.example.com\nsub1.example.com\n" > "$dir/subdomains/test.txt"++ # Deduplicate+ sort -u "$dir/subdomains/test.txt" > "$dir/subdomains/test_dedup.txt"++ local count+ count=$(wc -l < "$dir/subdomains/test_dedup.txt")+ [ "$count" -eq 2 ]+}++@test "full flow: inscope filtering works" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir/subdomains"++ # Create inscope file+ echo "*.example.com" > "$dir/inscope.txt"++ # Create subdomains file+ printf "sub.example.com\nout.other.com\ntest.example.com\n" > "$dir/subdomains/all.txt"++ # Filter (simplified - real logic is in deleteOutScoped)+ grep "example.com" "$dir/subdomains/all.txt" > "$dir/subdomains/inscope.txt"++ local count+ count=$(wc -l < "$dir/subdomains/inscope.txt")+ [ "$count" -eq 2 ]+}++@test "full flow: log files are created" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir/.log"++ # Simulate log creation+ echo "[INFO] Test log entry" > "$dir/.log/test.log"++ [ -f "$dir/.log/test.log" ]+ grep -q "INFO" "$dir/.log/test.log"+}++@test "full flow: tmp files are cleaned up" {+ source_reconftw++ export dir="$TEST_DIR/$TEST_DOMAIN"+ mkdir -p "$dir/.tmp"++ # Create temp files+ touch "$dir/.tmp/temp1.txt"+ touch "$dir/.tmp/temp2.txt"++ # Verify they exist+ [ -f "$dir/.tmp/temp1.txt" ]++ # Simulate cleanup+ rm -f "$dir/.tmp"/*.txt++ # Verify cleanup+ [ ! -f "$dir/.tmp/temp1.txt" ]+}++@test "full flow: notification skip works" {+ source_reconftw++ # shellcheck source=/dev/null+ source "$SCRIPTPATH/lib/common.sh"++ # Test skip_notification (should not error)+ run skip_notification "test_func"+ [ "$status" -eq 0 ]+}++@test "full flow: safe_count handles missing files" {+ source_reconftw++ # shellcheck source=/dev/null+ source "$SCRIPTPATH/lib/common.sh"++ # Test with non-existent file+ local count+ count=$(safe_count "/nonexistent/file.txt")+ [ "$count" -eq 0 ]+}++@test "full flow: parallel_funcs handles empty list" {+ source_reconftw++ # Test parallel_funcs with no functions+ run parallel_funcs 4+ [ "$status" -eq 0 ]+}++@test "full flow: dry-run mode prevents execution" {+ run timeout 5 bash "$SCRIPTPATH/reconftw.sh" -d test.com --dry-run 2>&1++ # Should succeed without actually running tools+ [[ "$output" == *"dry"* ]] || [[ "$output" == *"DRY"* ]] || [ "$status" -eq 0 ]+}