Skip to content

Commit

Permalink
improving workflows (#5318)
Browse files Browse the repository at this point in the history
* improving workflows

* fixing count
  • Loading branch information
Mzack9999 authored Jun 22, 2024
1 parent cc03b75 commit 1c51a6b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/templates/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ func parseTemplate(data []byte, options protocols.ExecutorOptions) (*Template, e
return nil, errors.New("no template author field provided")
}

numberOfWorkflows := len(template.Workflows)
if numberOfWorkflows > 0 && numberOfWorkflows != template.Requests() {
return nil, errors.New("workflows cannot have other protocols")
}

// use default unknown severity
if len(template.Workflows) == 0 {
if template.Info.SeverityHolder.Severity == severity.Undefined {
Expand Down
9 changes: 9 additions & 0 deletions pkg/templates/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,12 @@ func Test_WrongTemplate(t *testing.T) {
require.Nil(t, got, "could not parse template")
require.ErrorContains(t, err, "no requests defined ")
}

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

filePath := "tests/workflow-invalid.yaml"
got, err := templates.Parse(filePath, nil, executerOpts)
require.Nil(t, got, "could not parse template")
require.ErrorContains(t, err, "workflows cannot have other protocols")
}
4 changes: 2 additions & 2 deletions pkg/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ func (template *Template) Type() types.ProtocolType {
return types.HeadlessProtocol
case len(template.RequestsNetwork) > 0:
return types.NetworkProtocol
case len(template.Workflow.Workflows) > 0:
return types.WorkflowProtocol
case len(template.RequestsSSL) > 0:
return types.SSLProtocol
case len(template.RequestsWebsocket) > 0:
Expand All @@ -189,6 +187,8 @@ func (template *Template) Type() types.ProtocolType {
return types.CodeProtocol
case len(template.RequestsJavascript) > 0:
return types.JavascriptProtocol
case len(template.Workflow.Workflows) > 0:
return types.WorkflowProtocol
default:
return types.InvalidProtocol
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/templates/tests/workflow-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
id: workflow-example

info:
name: Test Invalid Workflow Template
author: pdteam
severity: info

http:
- raw:
- |
POST /re HTTP/1.1
Host: {{Hostname}}
{{code_response}}
workflows:
- template: tests/match-1.yaml
- template: tests/match-1.yaml

0 comments on commit 1c51a6b

Please sign in to comment.