improving workflows (#5318)

* improving workflows

* fixing count
This commit is contained in:
Mzack9999 2024-06-22 19:12:00 +02:00 committed by GitHub
parent cc03b7591a
commit 1c51a6bef6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 2 deletions

View File

@ -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 {

View File

@ -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")
}

View File

@ -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:
@ -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
}

View File

@ -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