Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/cmd/integration-test/dsl.go
2070 views
1
package main
2
3
import (
4
"fmt"
5
"net/http"
6
"net/http/httptest"
7
8
"github.com/julienschmidt/httprouter"
9
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
10
)
11
12
var dslTestcases = []TestCaseInfo{
13
{Path: "dsl/hide-version-warning.yaml", TestCase: &dslVersionWarning{}},
14
{Path: "dsl/show-version-warning.yaml", TestCase: &dslShowVersionWarning{}},
15
}
16
17
var defaultDSLEnvs = []string{"HIDE_TEMPLATE_SIG_WARNING=true"}
18
19
type dslVersionWarning struct{}
20
21
func (d *dslVersionWarning) Execute(templatePath string) error {
22
router := httprouter.New()
23
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
24
_, _ = fmt.Fprintf(w, "DSL version parsing warning test")
25
})
26
ts := httptest.NewServer(router)
27
defer ts.Close()
28
results, err := testutils.RunNucleiArgsAndGetErrors(debug, defaultDSLEnvs, "-t", templatePath, "-target", ts.URL, "-v")
29
if err != nil {
30
return err
31
}
32
return expectResultsCount(results, 0)
33
}
34
35
type dslShowVersionWarning struct{}
36
37
func (d *dslShowVersionWarning) Execute(templatePath string) error {
38
router := httprouter.New()
39
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
40
_, _ = fmt.Fprintf(w, "DSL version parsing warning test")
41
})
42
ts := httptest.NewServer(router)
43
defer ts.Close()
44
results, err := testutils.RunNucleiArgsAndGetErrors(debug, append(defaultDSLEnvs, "SHOW_DSL_ERRORS=true"), "-t", templatePath, "-target", ts.URL, "-v")
45
if err != nil {
46
return err
47
}
48
return expectResultsCount(results, 1)
49
}
50
51