forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_test.go
More file actions
88 lines (76 loc) · 2.49 KB
/
Copy pathvalidate_test.go
File metadata and controls
88 lines (76 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package http
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v3/pkg/fuzz"
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
"github.com/projectdiscovery/nuclei/v3/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v3/pkg/operators/matchers"
)
func TestValidateRedirectsCombinations(t *testing.T) {
t.Run("redirects and host-redirects conflict", func(t *testing.T) {
req := &Request{Redirects: true, HostRedirects: true}
err := req.validate()
require.Error(t, err)
require.Contains(t, err.Error(), "'redirects' and 'host-redirects' can't be used together")
})
t.Run("redirects alone is valid", func(t *testing.T) {
req := &Request{Redirects: true}
err := req.validate()
require.NoError(t, err)
})
t.Run("host-redirects alone is valid", func(t *testing.T) {
req := &Request{HostRedirects: true}
err := req.validate()
require.NoError(t, err)
})
t.Run("protocol-redirects without redirects or host-redirects is invalid", func(t *testing.T) {
req := &Request{ProtocolRedirects: true}
err := req.validate()
require.Error(t, err)
require.Contains(t, err.Error(), "'protocol-redirects' requires 'redirects' or 'host-redirects'")
})
t.Run("protocol-redirects with redirects is valid", func(t *testing.T) {
req := &Request{Redirects: true, ProtocolRedirects: true}
err := req.validate()
require.NoError(t, err)
})
t.Run("protocol-redirects with host-redirects is valid", func(t *testing.T) {
req := &Request{HostRedirects: true, ProtocolRedirects: true}
err := req.validate()
require.NoError(t, err)
})
t.Run("no redirect options is valid", func(t *testing.T) {
req := &Request{}
err := req.validate()
require.NoError(t, err)
})
}
func TestValidateFuzzingWithRequestCondition(t *testing.T) {
t.Run("matcher dsl", func(t *testing.T) {
req := &Request{
Fuzzing: []*fuzz.Rule{{}},
Operators: operators.Operators{
Matchers: []*matchers.Matcher{
{DSL: []string{"duration_1 > 18"}},
},
},
}
err := req.validate()
require.Error(t, err)
require.Contains(t, err.Error(), "'fuzzing' and 'request-condition' can't be used together")
})
t.Run("extractor part", func(t *testing.T) {
req := &Request{
Fuzzing: []*fuzz.Rule{{}},
Operators: operators.Operators{
Extractors: []*extractors.Extractor{
{Part: "body_1"},
},
},
}
err := req.validate()
require.Error(t, err)
require.Contains(t, err.Error(), "'fuzzing' and 'request-condition' can't be used together")
})
}