Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/workflows/workflows_test.go
2070 views
1
package workflows
2
3
import (
4
"testing"
5
6
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/stringslice"
7
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
8
"github.com/stretchr/testify/require"
9
)
10
11
func TestWorkflowMatchAndCompile(t *testing.T) {
12
t.Run("name", func(t *testing.T) {
13
matcher := &Matcher{Name: stringslice.StringSlice{Value: "sphinx"}}
14
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
15
require.True(t, matched, "could not match value")
16
})
17
t.Run("name-negative", func(t *testing.T) {
18
matcher := &Matcher{Name: stringslice.StringSlice{Value: "tomcat"}}
19
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"apache": {}}, Extracts: map[string][]string{}})
20
require.False(t, matched, "could not match value")
21
})
22
t.Run("names-or", func(t *testing.T) {
23
matcher := &Matcher{Name: stringslice.StringSlice{Value: []string{"sphinx", "elastic"}}, Condition: "or"}
24
_ = matcher.Compile()
25
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"elastic": {}}, Extracts: map[string][]string{}})
26
require.True(t, matched, "could not match value")
27
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
28
require.True(t, matched, "could not match value")
29
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"random": {}}, Extracts: map[string][]string{}})
30
require.False(t, matched, "could not match value")
31
})
32
t.Run("names-and", func(t *testing.T) {
33
matcher := &Matcher{Name: stringslice.StringSlice{Value: []string{"sphinx", "elastic"}}, Condition: "and"}
34
_ = matcher.Compile()
35
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"elastic": {}, "sphinx": {}}, Extracts: map[string][]string{}})
36
require.True(t, matched, "could not match value")
37
38
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
39
require.False(t, matched, "could not match value")
40
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"random": {}}, Extracts: map[string][]string{}})
41
require.False(t, matched, "could not match value")
42
})
43
}
44
45