change on pkg
Pedro Loami Barbosa dos Santos
3 years ago
0 | |
package filter
|
1 | |
|
2 | |
import (
|
3 | |
"strings"
|
4 | |
"testing"
|
5 | |
|
6 | |
"github.com/ffuf/ffuf/pkg/ffuf"
|
7 | |
)
|
8 | |
|
9 | |
func TestNewLineFilter(t *testing.T) {
|
10 | |
f, _ := NewLineFilter("200,301,400-410,500")
|
11 | |
linesRepr := f.Repr()
|
12 | |
if strings.Index(linesRepr, "200,301,400-410,500") == -1 {
|
13 | |
t.Errorf("Word filter was expected to have 4 values")
|
14 | |
}
|
15 | |
}
|
16 | |
|
17 | |
func TestNewLineFilterError(t *testing.T) {
|
18 | |
_, err := NewLineFilter("invalid")
|
19 | |
if err == nil {
|
20 | |
t.Errorf("Was expecting an error from errenous input data")
|
21 | |
}
|
22 | |
}
|
23 | |
|
24 | |
func TestLineFiltering(t *testing.T) {
|
25 | |
f, _ := NewLineFilter("200,301,402-450,500")
|
26 | |
for i, test := range []struct {
|
27 | |
input int64
|
28 | |
output bool
|
29 | |
}{
|
30 | |
{200, true},
|
31 | |
{301, true},
|
32 | |
{500, true},
|
33 | |
{4, false},
|
34 | |
{444, true},
|
35 | |
{302, false},
|
36 | |
{401, false},
|
37 | |
{402, true},
|
38 | |
{450, true},
|
39 | |
{451, false},
|
40 | |
} {
|
41 | |
var data []string
|
42 | |
for i := int64(0); i < test.input; i++ {
|
43 | |
data = append(data, "A")
|
44 | |
}
|
45 | |
resp := ffuf.Response{Data: []byte(strings.Join(data, " "))}
|
46 | |
filterReturn, _ := f.Filter(&resp)
|
47 | |
if filterReturn != test.output {
|
48 | |
t.Errorf("Filter test %d: Was expecing filter return value of %t but got %t", i, test.output, filterReturn)
|
49 | |
}
|
50 | |
}
|
51 | |
}
|
|
0 |
package filter
|
|
1 |
|
|
2 |
import (
|
|
3 |
"strings"
|
|
4 |
"testing"
|
|
5 |
|
|
6 |
"github.com/ffuf/ffuf/pkg/ffuf"
|
|
7 |
)
|
|
8 |
|
|
9 |
func TestNewLineFilter(t *testing.T) {
|
|
10 |
f, _ := NewLineFilter("200,301,400-410,500")
|
|
11 |
linesRepr := f.Repr()
|
|
12 |
if strings.Index(linesRepr, "200,301,400-410,500") == -1 {
|
|
13 |
t.Errorf("Word filter was expected to have 4 values")
|
|
14 |
}
|
|
15 |
}
|
|
16 |
|
|
17 |
func TestNewLineFilterError(t *testing.T) {
|
|
18 |
_, err := NewLineFilter("invalid")
|
|
19 |
if err == nil {
|
|
20 |
t.Errorf("Was expecting an error from errenous input data")
|
|
21 |
}
|
|
22 |
}
|
|
23 |
|
|
24 |
func TestLineFiltering(t *testing.T) {
|
|
25 |
f, _ := NewLineFilter("200,301,402-450,500")
|
|
26 |
for i, test := range []struct {
|
|
27 |
input int64
|
|
28 |
output bool
|
|
29 |
}{
|
|
30 |
{200, true},
|
|
31 |
{301, true},
|
|
32 |
{500, true},
|
|
33 |
{4, false},
|
|
34 |
{444, true},
|
|
35 |
{302, false},
|
|
36 |
{401, false},
|
|
37 |
{402, true},
|
|
38 |
{450, true},
|
|
39 |
{451, false},
|
|
40 |
} {
|
|
41 |
var data []string
|
|
42 |
for i := int64(0); i < test.input; i++ {
|
|
43 |
data = append(data, "A")
|
|
44 |
}
|
|
45 |
resp := ffuf.Response{Data: []byte(strings.Join(data, " "))}
|
|
46 |
filterReturn, _ := f.Filter(&resp)
|
|
47 |
if filterReturn != test.output {
|
|
48 |
t.Errorf("Filter test %d: Was expecing filter return value of %t but got %t", i, test.output, filterReturn)
|
|
49 |
}
|
|
50 |
}
|
|
51 |
}
|