Total Lines | 69 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package producer_test |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | "sort" |
||
6 | "testing" |
||
7 | "time" |
||
8 | |||
9 | "github.com/stefanoj3/dirstalk/pkg/common/test" |
||
10 | |||
11 | "github.com/stefanoj3/dirstalk/pkg/scan" |
||
12 | "github.com/stefanoj3/dirstalk/pkg/scan/producer" |
||
13 | "github.com/stretchr/testify/assert" |
||
14 | ) |
||
15 | |||
16 | func TestNewReProducer(t *testing.T) { |
||
17 | t.Parallel() |
||
18 | |||
19 | methods := []string{http.MethodGet} |
||
20 | dictionary := []string{"/home"} |
||
21 | |||
22 | dictionaryProducer := producer.NewDictionaryProducer(methods, dictionary, 1) |
||
23 | |||
24 | sut := producer.NewReProducer( |
||
25 | methods, |
||
26 | dictionary, |
||
27 | dictionaryProducer, |
||
28 | time.Millisecond*100, |
||
29 | ) |
||
30 | |||
31 | go sut.Reproduce(scan.Result{ |
||
32 | Target: scan.Target{ |
||
33 | Path: "/home", |
||
34 | Method: http.MethodGet, |
||
35 | Depth: 1, |
||
36 | }, |
||
37 | Response: &http.Response{ |
||
38 | StatusCode: 200, |
||
39 | Request: &http.Request{ |
||
40 | Method: http.MethodGet, |
||
41 | URL: test.MustParseUrl(t, "http://mysite/contacts"), |
||
42 | }, |
||
43 | }, |
||
44 | }) |
||
45 | |||
46 | targets := make([]scan.Target, 0, 10) |
||
47 | for tar := range sut.Produce() { |
||
48 | targets = append(targets, tar) |
||
49 | } |
||
50 | |||
51 | sort.Slice(targets, func(i, j int) bool { |
||
52 | return targets[i].Path < targets[j].Path |
||
53 | }) |
||
54 | |||
55 | assert.Len(t, targets, 2) |
||
56 | |||
57 | expectedTargets := []scan.Target{ |
||
58 | { |
||
59 | Path: "/home", |
||
60 | Method: http.MethodGet, |
||
61 | Depth: 1, |
||
62 | }, |
||
63 | { |
||
64 | Path: "/home/home", |
||
65 | Method: http.MethodGet, |
||
66 | Depth: 0, |
||
67 | }, |
||
68 | } |
||
69 | assert.Equal(t, expectedTargets, targets) |
||
70 | } |
||
71 |