2020-12-21 19:32:38 +00:00
|
|
|
package generators
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSniperGenerator(t *testing.T) {
|
2020-12-30 08:27:15 +00:00
|
|
|
usernames := []string{"admin", "password"}
|
|
|
|
moreUsernames := []string{"login", "test"}
|
2020-12-21 19:51:05 +00:00
|
|
|
|
2020-12-30 08:27:15 +00:00
|
|
|
generator, err := New(map[string]interface{}{"username": usernames, "aliases": moreUsernames}, Sniper, "")
|
2020-12-21 19:51:05 +00:00
|
|
|
require.Nil(t, err, "could not create generator")
|
|
|
|
|
|
|
|
iterator := generator.NewIterator()
|
|
|
|
count := 0
|
2020-12-26 17:22:33 +00:00
|
|
|
for {
|
2020-12-30 08:27:15 +00:00
|
|
|
_, ok := iterator.Value()
|
2020-12-26 17:22:33 +00:00
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
2020-12-21 19:51:05 +00:00
|
|
|
count++
|
|
|
|
}
|
2020-12-30 08:27:15 +00:00
|
|
|
require.Equal(t, len(usernames)+len(moreUsernames), count, "could not get correct sniper counts")
|
2020-12-21 19:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPitchforkGenerator(t *testing.T) {
|
|
|
|
usernames := []string{"admin", "token"}
|
|
|
|
passwords := []string{"admin", "password"}
|
|
|
|
|
2020-12-29 06:38:46 +00:00
|
|
|
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, PitchFork, "")
|
2020-12-21 19:51:05 +00:00
|
|
|
require.Nil(t, err, "could not create generator")
|
|
|
|
|
|
|
|
iterator := generator.NewIterator()
|
|
|
|
count := 0
|
2020-12-26 17:22:33 +00:00
|
|
|
for {
|
|
|
|
value, ok := iterator.Value()
|
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
2020-12-21 19:51:05 +00:00
|
|
|
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(passwords), count, "could not get correct pitchfork counts")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClusterbombGenerator(t *testing.T) {
|
|
|
|
usernames := []string{"admin"}
|
|
|
|
passwords := []string{"admin", "password", "token"}
|
|
|
|
|
2020-12-29 06:38:46 +00:00
|
|
|
generator, err := New(map[string]interface{}{"username": usernames, "password": passwords}, ClusterBomb, "")
|
2020-12-21 19:32:38 +00:00
|
|
|
require.Nil(t, err, "could not create generator")
|
|
|
|
|
|
|
|
iterator := generator.NewIterator()
|
2020-12-21 19:51:05 +00:00
|
|
|
count := 0
|
2020-12-26 17:22:33 +00:00
|
|
|
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-21 19:51:05 +00:00
|
|
|
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-21 19:32:38 +00:00
|
|
|
}
|
2020-12-21 19:51:05 +00:00
|
|
|
require.Equal(t, 3, count, "could not get correct clusterbomb counts")
|
2020-12-21 19:32:38 +00:00
|
|
|
}
|