-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
workflows_test.go
43 lines (39 loc) · 2.2 KB
/
workflows_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
32
33
34
35
36
37
38
39
40
41
42
43
package workflows
import (
"testing"
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/stringslice"
"github.com/projectdiscovery/nuclei/v3/pkg/operators"
"github.com/stretchr/testify/require"
)
func TestWorkflowMatchAndCompile(t *testing.T) {
t.Run("name", func(t *testing.T) {
matcher := &Matcher{Name: stringslice.StringSlice{Value: "sphinx"}}
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
require.True(t, matched, "could not match value")
})
t.Run("name-negative", func(t *testing.T) {
matcher := &Matcher{Name: stringslice.StringSlice{Value: "tomcat"}}
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"apache": {}}, Extracts: map[string][]string{}})
require.False(t, matched, "could not match value")
})
t.Run("names-or", func(t *testing.T) {
matcher := &Matcher{Name: stringslice.StringSlice{Value: []string{"sphinx", "elastic"}}, Condition: "or"}
_ = matcher.Compile()
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"elastic": {}}, Extracts: map[string][]string{}})
require.True(t, matched, "could not match value")
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
require.True(t, matched, "could not match value")
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"random": {}}, Extracts: map[string][]string{}})
require.False(t, matched, "could not match value")
})
t.Run("names-and", func(t *testing.T) {
matcher := &Matcher{Name: stringslice.StringSlice{Value: []string{"sphinx", "elastic"}}, Condition: "and"}
_ = matcher.Compile()
matched := matcher.Match(&operators.Result{Matches: map[string][]string{"elastic": {}, "sphinx": {}}, Extracts: map[string][]string{}})
require.True(t, matched, "could not match value")
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"sphinx": {}}, Extracts: map[string][]string{}})
require.False(t, matched, "could not match value")
matched = matcher.Match(&operators.Result{Matches: map[string][]string{"random": {}}, Extracts: map[string][]string{}})
require.False(t, matched, "could not match value")
})
}