forked from projectdiscovery/nuclei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_test.go
31 lines (22 loc) · 894 Bytes
/
validate_test.go
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
package matchers
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestValidate(t *testing.T) {
m := &Matcher{matcherType: DSLMatcher, DSL: []string{"anything"}}
err := m.Validate()
require.Nil(t, err, "Could not validate correct template")
m = &Matcher{matcherType: DSLMatcher, Part: "test"}
err = m.Validate()
require.NotNil(t, err, "Invalid template was correctly validated")
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//q[@id=\"foo\"]"}}
err = m.Validate()
require.Nil(t, err, "Could not validate correct XPath template")
m = &Matcher{matcherType: XPathMatcher, Status: []int{123}}
err = m.Validate()
require.NotNil(t, err, "Invalid XPath template was correctly validated")
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//a[@a==1]"}}
err = m.Validate()
require.NotNil(t, err, "Invalid XPath query was correctly validated")
}