Skip to content

Commit 1c51a6b

Browse files
authored
improving workflows (#5318)
* improving workflows * fixing count
1 parent cc03b75 commit 1c51a6b

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

pkg/templates/compile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ func parseTemplate(data []byte, options protocols.ExecutorOptions) (*Template, e
342342
return nil, errors.New("no template author field provided")
343343
}
344344

345+
numberOfWorkflows := len(template.Workflows)
346+
if numberOfWorkflows > 0 && numberOfWorkflows != template.Requests() {
347+
return nil, errors.New("workflows cannot have other protocols")
348+
}
349+
345350
// use default unknown severity
346351
if len(template.Workflows) == 0 {
347352
if template.Info.SeverityHolder.Severity == severity.Undefined {

pkg/templates/compile_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,12 @@ func Test_WrongTemplate(t *testing.T) {
197197
require.Nil(t, got, "could not parse template")
198198
require.ErrorContains(t, err, "no requests defined ")
199199
}
200+
201+
func TestWrongWorkflow(t *testing.T) {
202+
setup()
203+
204+
filePath := "tests/workflow-invalid.yaml"
205+
got, err := templates.Parse(filePath, nil, executerOpts)
206+
require.Nil(t, got, "could not parse template")
207+
require.ErrorContains(t, err, "workflows cannot have other protocols")
208+
}

pkg/templates/templates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ func (template *Template) Type() types.ProtocolType {
177177
return types.HeadlessProtocol
178178
case len(template.RequestsNetwork) > 0:
179179
return types.NetworkProtocol
180-
case len(template.Workflow.Workflows) > 0:
181-
return types.WorkflowProtocol
182180
case len(template.RequestsSSL) > 0:
183181
return types.SSLProtocol
184182
case len(template.RequestsWebsocket) > 0:
@@ -189,6 +187,8 @@ func (template *Template) Type() types.ProtocolType {
189187
return types.CodeProtocol
190188
case len(template.RequestsJavascript) > 0:
191189
return types.JavascriptProtocol
190+
case len(template.Workflow.Workflows) > 0:
191+
return types.WorkflowProtocol
192192
default:
193193
return types.InvalidProtocol
194194
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: workflow-example
2+
3+
info:
4+
name: Test Invalid Workflow Template
5+
author: pdteam
6+
severity: info
7+
8+
http:
9+
- raw:
10+
- |
11+
POST /re HTTP/1.1
12+
Host: {{Hostname}}
13+
14+
{{code_response}}
15+
16+
workflows:
17+
- template: tests/match-1.yaml
18+
- template: tests/match-1.yaml

0 commit comments

Comments
 (0)