nuclei/v2/pkg/protocols/common/generators/generators_test.go

86 lines
2.5 KiB
Go
Raw Normal View History

2020-12-22 01:02:38 +05:30
package generators
import (
"testing"
"github.com/stretchr/testify/require"
2021-11-25 17:09:20 +02:00
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
2020-12-22 01:02:38 +05:30
)
func TestBatteringRamGenerator(t *testing.T) {
usernames := []string{"admin", "password"}
2020-12-22 01:21:05 +05:30
catalogInstance := catalog.New("")
2021-11-04 02:41:56 +05:30
generator, err := New(map[string]interface{}{"username": usernames}, BatteringRamAttack, "", catalogInstance)
2020-12-22 01:21:05 +05:30
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
count := 0
2020-12-26 22:52:33 +05:30
for {
_, ok := iterator.Value()
2020-12-26 22:52:33 +05:30
if !ok {
break
}
2020-12-22 01:21:05 +05:30
count++
}
require.Equal(t, len(usernames), count, "could not get correct batteringram counts")
2020-12-22 01:21:05 +05:30
}
func TestPitchforkGenerator(t *testing.T) {
usernames := []string{"admin", "token"}
2021-09-01 20:03:53 +05:30
passwords := []string{"password1", "password2", "password3"}
2020-12-22 01:21:05 +05:30
catalogInstance := catalog.New("")
2021-11-04 02:41:56 +05:30
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, PitchForkAttack, "", catalogInstance)
2020-12-22 01:21:05 +05:30
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
count := 0
2020-12-26 22:52:33 +05:30
for {
value, ok := iterator.Value()
if !ok {
break
}
2020-12-22 01:21:05 +05:30
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")
}
2021-09-01 20:03:53 +05:30
require.Equal(t, len(usernames), count, "could not get correct pitchfork counts")
2020-12-22 01:21:05 +05:30
}
func TestClusterbombGenerator(t *testing.T) {
usernames := []string{"admin"}
passwords := []string{"admin", "password", "token"}
catalogInstance := catalog.New("")
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, ClusterBombAttack, "", catalogInstance)
2020-12-22 01:02:38 +05:30
require.Nil(t, err, "could not create generator")
iterator := generator.NewIterator()
2020-12-22 01:21:05 +05:30
count := 0
2020-12-26 22:52:33 +05:30
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
}
2020-12-22 01:21:05 +05:30
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")
2020-12-22 01:02:38 +05:30
}
2020-12-22 01:21:05 +05:30
require.Equal(t, 3, count, "could not get correct clusterbomb counts")
2020-12-22 01:02:38 +05:30
}