diff --git a/pkg/ffuf/util_test.go b/pkg/ffuf/util_test.go new file mode 100644 index 00000000..4dc21fe2 --- /dev/null +++ b/pkg/ffuf/util_test.go @@ -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) + } +} diff --git a/pkg/input/wordlist_test.go b/pkg/input/wordlist_test.go new file mode 100644 index 00000000..0938bcdb --- /dev/null +++ b/pkg/input/wordlist_test.go @@ -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") + } +} diff --git a/pkg/output/file_csv_test.go b/pkg/output/file_csv_test.go new file mode 100644 index 00000000..a858ece7 --- /dev/null +++ b/pkg/output/file_csv_test.go @@ -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") + } +}