Skip to content

Commit

Permalink
improving workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jun 21, 2024
1 parent cc03b75 commit d0570a6
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 @@ -119,6 +119,7 @@ func (template *Template) parseSelfContainedRequests() {
}

// Requests returns the total request count for the template
// this does not include workflows
func (template *Template) Requests() int {
return len(template.RequestsDNS) +
len(template.RequestsHTTP) +
Expand Down Expand Up @@ -342,6 +343,10 @@ func parseTemplate(data []byte, options protocols.ExecutorOptions) (*Template, e
return nil, errors.New("no template author field provided")
}

if len(template.Workflows) > 0 && template.Requests() > 0 {
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 d0570a6

Please sign in to comment.