-
Notifications
You must be signed in to change notification settings - Fork 61
/
mutator_test.go
51 lines (45 loc) · 1.38 KB
/
mutator_test.go
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
package alterx
import (
"bytes"
"math"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
var testConfig = Config{
Patterns: []string{
"{{sub}}-{{word}}.{{root}}", // ex: api-prod.scanme.sh
"{{word}}-{{sub}}.{{root}}", // ex: prod-api.scanme.sh
"{{word}}.{{sub}}.{{root}}", // ex: prod.api.scanme.sh
"{{sub}}.{{word}}.{{root}}", // ex: api.prod.scanme.sh
},
Payloads: map[string][]string{
"word": {"dev", "lib", "prod", "stage", "wp"},
},
}
func TestMutatorCount(t *testing.T) {
opts := &Options{
Domains: []string{"api.scanme.sh", "chaos.scanme.sh", "nuclei.scanme.sh", "cloud.nuclei.scanme.sh"},
}
opts.Patterns = testConfig.Patterns
opts.Payloads = testConfig.Payloads
expectedCount := len(opts.Patterns) * len(opts.Payloads["word"]) * len(opts.Domains)
m, err := New(opts)
require.Nil(t, err)
require.EqualValues(t, expectedCount, m.EstimateCount())
}
func TestMutatorResults(t *testing.T) {
opts := &Options{
Domains: []string{"api.scanme.sh", "chaos.scanme.sh", "nuclei.scanme.sh", "cloud.nuclei.scanme.sh"},
}
opts.Patterns = testConfig.Patterns
opts.Payloads = testConfig.Payloads
opts.MaxSize = math.MaxInt
m, err := New(opts)
require.Nil(t, err)
var buff bytes.Buffer
err = m.ExecuteWithWriter(&buff)
require.Nil(t, err)
count := strings.Split(strings.TrimSpace(buff.String()), "\n")
require.EqualValues(t, 80, len(count), buff.String())
}