Add some tests (#479)
This commit is contained in:
parent
2fdbd25655
commit
415ec0fd23
26
pkg/ffuf/util_test.go
Normal file
26
pkg/ffuf/util_test.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package ffuf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRandomString(t *testing.T) {
|
||||||
|
length := 1 + rand.Intn(65535)
|
||||||
|
str := RandomString(length)
|
||||||
|
|
||||||
|
if len(str) != length {
|
||||||
|
t.Errorf("Length of generated string was %d, was expecting %d", len(str), length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUniqStringSlice(t *testing.T) {
|
||||||
|
slice := []string{"foo", "foo", "bar", "baz", "baz", "foo", "baz", "baz", "foo"}
|
||||||
|
expectedLength := 3
|
||||||
|
|
||||||
|
uniqSlice := UniqStringSlice(slice)
|
||||||
|
|
||||||
|
if len(uniqSlice) != expectedLength {
|
||||||
|
t.Errorf("Length of slice was %d, was expecting %d", len(uniqSlice), expectedLength)
|
||||||
|
}
|
||||||
|
}
|
||||||
21
pkg/input/wordlist_test.go
Normal file
21
pkg/input/wordlist_test.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package input
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStripCommentsIgnoresCommentLines(t *testing.T) {
|
||||||
|
text, _ := stripComments("# text")
|
||||||
|
|
||||||
|
if text != "" {
|
||||||
|
t.Errorf("Returned text was not a blank string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStripCommentsStripsCommentAfterText(t *testing.T) {
|
||||||
|
text, _ := stripComments("text # comment")
|
||||||
|
|
||||||
|
if text != "text" {
|
||||||
|
t.Errorf("Comment was not stripped or pre-comment text was not returned")
|
||||||
|
}
|
||||||
|
}
|
||||||
44
pkg/output/file_csv_test.go
Normal file
44
pkg/output/file_csv_test.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package output
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ffuf/ffuf/pkg/ffuf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToCSV(t *testing.T) {
|
||||||
|
result := ffuf.Result{
|
||||||
|
Input: map[string][]byte{"x": {66}},
|
||||||
|
Position: 1,
|
||||||
|
StatusCode: 200,
|
||||||
|
ContentLength: 3,
|
||||||
|
ContentWords: 4,
|
||||||
|
ContentLines: 5,
|
||||||
|
ContentType: "application/json",
|
||||||
|
RedirectLocation: "http://no.pe",
|
||||||
|
Url: "http://as.df",
|
||||||
|
Duration: time.Duration(123),
|
||||||
|
ResultFile: "resultfile",
|
||||||
|
Host: "host",
|
||||||
|
}
|
||||||
|
|
||||||
|
csv := toCSV(result)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(csv, []string{
|
||||||
|
"B",
|
||||||
|
"http://as.df",
|
||||||
|
"http://no.pe",
|
||||||
|
"1",
|
||||||
|
"200",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"application/json",
|
||||||
|
"123ns",
|
||||||
|
"resultfile"}) {
|
||||||
|
|
||||||
|
t.Errorf("CSV was not generated in expected format")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user