nuclei/v2/pkg/protocols/common/fuzz/fuzz_test.go
Shubham Rasal a34b94e62f
Issue 3339 headless fuzz (#3790)
* Basic headless fuzzing

* Remove debug statements

* Add integration tests

* Update template

* Fix recognize payload value in matcher

* Update tempalte

* use req.SetURL()

---------

Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
2023-06-09 05:50:44 +05:30

38 lines
1.2 KiB
Go

package fuzz
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestRuleMatchKeyOrValue(t *testing.T) {
rule := &Rule{}
err := rule.Compile(nil, nil)
require.NoError(t, err, "could not compile rule")
result := rule.matchKeyOrValue("url", "")
require.True(t, result, "could not get correct result")
t.Run("key", func(t *testing.T) {
rule := &Rule{Keys: []string{"url"}}
err := rule.Compile(nil, nil)
require.NoError(t, err, "could not compile rule")
result := rule.matchKeyOrValue("url", "")
require.True(t, result, "could not get correct result")
result = rule.matchKeyOrValue("test", "")
require.False(t, result, "could not get correct result")
})
t.Run("value", func(t *testing.T) {
rule := &Rule{ValuesRegex: []string{`https?:\/\/?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)*(\/[\/\d\w\.-]*)*(?:[\?])*(.+)*`}}
err := rule.Compile(nil, nil)
require.NoError(t, err, "could not compile rule")
result := rule.matchKeyOrValue("", "http://localhost:80")
require.True(t, result, "could not get correct result")
result = rule.matchKeyOrValue("test", "random")
require.False(t, result, "could not get correct result")
})
}