forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generators_test.go
92 lines (78 loc) · 2.76 KB
/
generators_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
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
81
82
83
84
85
86
87
88
89
90
91
92
package generators
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
)
func TestBatteringRamGenerator(t *testing.T) {
usernames := []string{"admin", "password"}
catalogInstance := disk.NewCatalog("")
generator, err := New(map[string]interface{}{"username": usernames}, BatteringRamAttack, "", catalogInstance, "", getOptions(false))
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
count := 0
for {
_, ok := iterator.Value()
if !ok {
break
}
count++
}
require.Equal(t, len(usernames), count, "could not get correct batteringram counts")
}
func TestPitchforkGenerator(t *testing.T) {
usernames := []string{"admin", "token"}
passwords := []string{"password1", "password2", "password3"}
catalogInstance := disk.NewCatalog("")
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, PitchForkAttack, "", catalogInstance, "", getOptions(false))
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
count := 0
for {
value, ok := iterator.Value()
if !ok {
break
}
count++
require.Contains(t, usernames, value["username"], "Could not get correct pitchfork username")
require.Contains(t, passwords, value["password"], "Could not get correct pitchfork password")
}
require.Equal(t, len(usernames), count, "could not get correct pitchfork counts")
}
func TestClusterbombGenerator(t *testing.T) {
usernames := []string{"admin"}
passwords := []string{"admin", "password", "token"}
catalogInstance := disk.NewCatalog("")
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, ClusterBombAttack, "", catalogInstance, "", getOptions(false))
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
count := 0
for {
value, ok := iterator.Value()
if !ok {
break
}
count++
require.Contains(t, usernames, value["username"], "Could not get correct clusterbomb username")
require.Contains(t, passwords, value["password"], "Could not get correct clusterbomb password")
}
require.Equal(t, 3, count, "could not get correct clusterbomb counts")
iterator.Reset()
count = 0
for {
value, ok := iterator.Value()
if !ok {
break
}
count++
require.Contains(t, usernames, value["username"], "Could not get correct clusterbomb username")
require.Contains(t, passwords, value["password"], "Could not get correct clusterbomb password")
}
require.Equal(t, 3, count, "could not get correct clusterbomb counts")
}
func getOptions(allowLocalFileAccess bool) *types.Options {
opts := types.DefaultOptions()
opts.AllowLocalFileAccess = allowLocalFileAccess
return opts
}