-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsif_concurrency_test.go
More file actions
80 lines (70 loc) · 3.06 KB
/
Copy pathsif_concurrency_test.go
File metadata and controls
80 lines (70 loc) · 3.06 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
80
/*
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
: :
: █▀ █ █▀▀ · Blazing-fast pentesting suite :
: ▄█ █ █▀ · BSD 3-Clause License :
: :
: (c) 2022-2026 vmfunc, xyzeva, :
: lunchcat alumni & contributors :
: :
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
*/
package sif
import (
"testing"
"github.com/vmfunc/sif/internal/output"
)
// TestScanAllTargetsConcurrentIsolation runs the target pool at concurrency 3
// against three separate servers and asserts each target's result is isolated:
// exactly one scan recorded per target, results in input order. Run under -race
// it also backstops scanTarget's concurrency safety and the serialized sink.
func TestScanAllTargetsConcurrentIsolation(t *testing.T) {
defer output.SetConcurrent(false)
srvA := okServer()
defer srvA.Close()
srvB := okServer()
defer srvB.Close()
srvC := okServer()
defer srvC.Close()
app := headersOnlyApp()
app.targets = []string{srvA.URL, srvB.URL, srvC.URL}
app.settings.Concurrency = 3
results, err := app.scanAllTargets("", false)
if err != nil {
t.Fatalf("scanAllTargets: %v", err)
}
if len(results) != len(app.targets) {
t.Fatalf("got %d results, want %d", len(results), len(app.targets))
}
for i, ts := range results {
if len(ts.scansRun) != 1 || ts.scansRun[0] != "HTTP Headers" {
t.Errorf("target %d scansRun = %v, want exactly [HTTP Headers] (accumulator leaked across targets)", i, ts.scansRun)
}
}
}
// TestScanAllTargetsSequentialMatchesInputOrder pins that concurrency 1 keeps the
// plain sequential path: one result per target, in order, no pool engaged.
func TestScanAllTargetsSequentialMatchesInputOrder(t *testing.T) {
srvA := okServer()
defer srvA.Close()
srvB := okServer()
defer srvB.Close()
app := headersOnlyApp()
app.targets = []string{srvA.URL, srvB.URL}
app.settings.Concurrency = 1
results, err := app.scanAllTargets("", false)
if err != nil {
t.Fatalf("scanAllTargets: %v", err)
}
if len(results) != 2 {
t.Fatalf("got %d results, want 2", len(results))
}
for i, ts := range results {
if len(ts.scansRun) != 1 || ts.scansRun[0] != "HTTP Headers" {
t.Errorf("target %d scansRun = %v, want exactly [HTTP Headers]", i, ts.scansRun)
}
}
if output.Concurrent() {
t.Error("concurrency 1 must not switch output into concurrent mode")
}
}