Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving workflows #5318

Merged
merged 2 commits into from
Jun 22, 2024
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
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
Loading