这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/ffuf/util_test.go
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions pkg/input/wordlist_test.go
Original file line number Diff line number Diff line change
@@ -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 changes: 44 additions & 0 deletions pkg/output/file_csv_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}