nuclei/pkg/operators/matchers/validate_test.go
Tarun Koyalwar dc44105baf
nuclei v3 : misc updates (#4247)
* use parsed options while signing

* update project layout to v3

* fix .gitignore

* remove example template

* misc updates

* bump tlsx version

* hide template sig warning with env

* js: retain value while using log

* fix nil pointer derefernce

* misc doc update

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-10-17 17:44:13 +05:30

32 lines
894 B
Go

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")
}