Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/operators/matchers/validate_test.go
2070 views
1
package matchers
2
3
import (
4
"testing"
5
6
"github.com/stretchr/testify/require"
7
)
8
9
func TestValidate(t *testing.T) {
10
m := &Matcher{matcherType: DSLMatcher, DSL: []string{"anything"}}
11
12
err := m.Validate()
13
require.Nil(t, err, "Could not validate correct template")
14
15
m = &Matcher{matcherType: DSLMatcher, Part: "test"}
16
err = m.Validate()
17
require.NotNil(t, err, "Invalid template was correctly validated")
18
19
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//q[@id=\"foo\"]"}}
20
21
err = m.Validate()
22
require.Nil(t, err, "Could not validate correct XPath template")
23
24
m = &Matcher{matcherType: XPathMatcher, Status: []int{123}}
25
err = m.Validate()
26
require.NotNil(t, err, "Invalid XPath template was correctly validated")
27
28
m = &Matcher{matcherType: XPathMatcher, XPath: []string{"//a[@a==1]"}}
29
err = m.Validate()
30
require.NotNil(t, err, "Invalid XPath query was correctly validated")
31
}
32
33