Compare commits

...
Author SHA1 Message Date
Mzack9999 17d5bd4272 merge dev 2026-11-04 00:56:00 +01:00
Mzack9999 3aa5af8fd8 merge dev 2026-11-03 12:45:46 +01:00
Mzack9999 8d4960ad60 discard runtimes 2026-10-29 21:25:29 +01:00
3 changed files with 71 additions and 0 deletions

No files matched your search

+31
View File
@@ -414,3 +414,34 @@ http:
})
}
}
// TestFlowRuntimeIsNotSharedAcrossTemplates checks that a flow which changes the
// globals of its runtime does not change the flow of a later template.
func TestFlowRuntimeIsNotSharedAcrossTemplates(t *testing.T) {
setup()
router := httprouter.New()
router.GET("/first", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
_, _ = fmt.Fprint(w, "first-ok")
})
router.GET("/second", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
_, _ = fmt.Fprint(w, "second-ok")
})
ts := httptest.NewServer(router)
defer ts.Close()
execute := func(path string) bool {
tmpl, err := templates.Parse(path, nil, executerOpts)
require.Nil(t, err, "could not parse template")
require.Nil(t, tmpl.Executer.Compile(), "could not compile template")
input := contextargs.NewWithInput(context.Background(), ts.URL)
gotresults, err := tmpl.Executer.Execute(scan.NewScanContext(context.Background(), input))
require.Nil(t, err, "could not execute template")
return gotresults
}
for i := 0; i < 10; i++ {
execute("testcases/flow-runtime-first.yaml")
require.True(t, execute("testcases/flow-runtime-second.yaml"), "second flow ran in a runtime changed by another template (run %d)", i)
}
}
@@ -0,0 +1,17 @@
id: flow-runtime-first
info:
name: Flow that changes the globals of its runtime
author: test
severity: info
flow: |
// Export
globalThis.leftover = true;
iterate = function () { return []; };
http(1);
http:
- method: GET
path:
- "{{BaseURL}}/first"
@@ -0,0 +1,23 @@
id: flow-runtime-second
info:
name: Flow that uses the builtins of its runtime
author: test
severity: info
flow: |
if (typeof leftover === 'undefined') {
for (let path of iterate(["second"])) {
http(1);
}
}
http:
- method: GET
path:
- "{{BaseURL}}/second"
matchers:
- type: word
words:
- "second-ok"