-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsif_scantarget_test.go
More file actions
79 lines (69 loc) · 3.08 KB
/
Copy pathsif_scantarget_test.go
File metadata and controls
79 lines (69 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
: :
: █▀ █ █▀▀ · Blazing-fast pentesting suite :
: ▄█ █ █▀ · BSD 3-Clause License :
: :
: (c) 2022-2026 vmfunc, xyzeva, :
: lunchcat alumni & contributors :
: :
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
*/
package sif
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/vmfunc/sif/internal/config"
)
// headersOnlyApp builds an App that runs only the HTTP headers scan against
// live servers, with every network-touching scanner gated off. it isolates the
// scanTarget path to a single deterministic scan.
func headersOnlyApp() *App {
return &App{settings: &config.Settings{
Headers: true,
NoScan: true,
Dirlist: "none",
Dnslist: "none",
Ports: "none",
Timeout: 5 * time.Second,
}}
}
func okServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("X-Sif-Test", "1")
w.WriteHeader(http.StatusOK)
}))
}
// TestScanTargetIsolatesPerTargetState is the accumulator seam the worker pool
// depends on: each scanTarget call must own its scansRun rather than share a
// run-wide slice. two sequential scans of different targets must each report a
// single scan, not a growing total; a shared accumulator would make the second
// call report two.
func TestScanTargetIsolatesPerTargetState(t *testing.T) {
srvA := okServer()
defer srvA.Close()
srvB := okServer()
defer srvB.Close()
app := headersOnlyApp()
tsA, err := app.scanTarget(context.Background(), srvA.URL, "", false)
if err != nil {
t.Fatalf("scanTarget(A): %v", err)
}
if len(tsA.scansRun) != 1 || tsA.scansRun[0] != "HTTP Headers" {
t.Fatalf("target A scansRun = %v, want exactly [HTTP Headers]", tsA.scansRun)
}
tsB, err := app.scanTarget(context.Background(), srvB.URL, "", false)
if err != nil {
t.Fatalf("scanTarget(B): %v", err)
}
if len(tsB.scansRun) != 1 || tsB.scansRun[0] != "HTTP Headers" {
t.Fatalf("target B scansRun = %v, want exactly [HTTP Headers] (accumulator leaked across targets)", tsB.scansRun)
}
// no log dir configured, so no per-target log file should be recorded.
if len(tsA.logFiles) != 0 || len(tsB.logFiles) != 0 {
t.Errorf("logFiles should be empty without a log dir, got A=%v B=%v", tsA.logFiles, tsB.logFiles)
}
}