Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/templates/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/generators"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/globalmatchers"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/variables"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/http"
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
Expand Down Expand Up @@ -184,6 +185,26 @@ func Test_ParseWorkflow(t *testing.T) {
require.Equal(t, len(expectedTemplate.Workflows), len(got.Workflows))
}

func Test_ParseWorkflowWithGlobalMatchers(t *testing.T) {
setup()
previousGlobalMatchers := executerOpts.Options.EnableGlobalMatchersTemplates
executerOpts.Options.EnableGlobalMatchersTemplates = true
defer func() {
executerOpts.Options.EnableGlobalMatchersTemplates = previousGlobalMatchers
executerOpts.GlobalMatchers = nil
}()
executerOpts.GlobalMatchers = globalmatchers.New()

filePath := "tests/workflow-global-matchers.yaml"
got, err := templates.Parse(filePath, nil, executerOpts)
require.NoError(t, err, "could not parse workflow template")
require.NotNil(t, got, "workflow template should not be nil")
require.NotNil(t, got.CompiledWorkflow, "compiled workflow should not be nil")
require.Len(t, got.CompiledWorkflow.Workflows, 2)
require.Len(t, got.CompiledWorkflow.Workflows[0].Executers, 1)
require.Len(t, got.CompiledWorkflow.Workflows[1].Executers, 0)
}

func Test_WrongTemplate(t *testing.T) {
setup()

Expand Down
17 changes: 17 additions & 0 deletions pkg/templates/tests/global-matcher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id: global-matcher-test

info:
name: Global Matcher Test Template
author: pdteam
severity: info

http:
- method: GET
path:
- "{{BaseURL}}"
global-matchers: true
matchers:
- type: word
part: body
words:
- "test"
10 changes: 10 additions & 0 deletions pkg/templates/tests/workflow-global-matchers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: workflow-global-matchers

info:
name: Workflow With Global Matchers
author: pdteam
severity: info

workflows:
- template: tests/match-1.yaml
- template: tests/global-matcher.yaml
3 changes: 3 additions & 0 deletions pkg/templates/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func parseWorkflowTemplate(workflow *workflows.WorkflowTemplate, preprocessor Pr
gologger.Warning().Msgf("Could not parse workflow template %s: %v\n", path, err)
continue
}
if template == nil {
continue
}
if template.Executer == nil {
gologger.Warning().Msgf("Could not parse workflow template %s: no executer found\n", path)
continue
Expand Down
Loading