mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 16:15:26 +00:00
* feat: Improve DSL function UX #1295 Sort the output signatures * feat: Improve DSL function UX #1295 Sort the output signatures. Lint: simplified the sorting. * bug: fixed couple of bugs in the DSL functions Input number parameters are stored as float64 types, hence the type conversion should happen accordingly. Affected functions: * rand_int * wait_for * unix_time * rand_text_numeric Added tests for all functions. Related: #1261 * bug: fixed couple of bugs in the DSL functions Handle cases when the optional input character set is an empty string. Affected methods: * rand_char * rand_base * bug: fixed couple of bugs in the DSL functions Change rand_char to return a one character string, instead of the character code * refactor: Minor integration test changes to show the actual and expected result numbers * test: Added integration test for all existing DSL functions * test: Added integration test for all existing DSL functions Fixing linter issues. * feat: Add "repeat" DSL function * test: Add "repeat" DSL function
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
|
)
|
|
|
|
var headlessTestcases = map[string]testutils.TestCase{
|
|
"headless/headless-basic.yaml": &headlessBasic{},
|
|
"headless/headless-header-action.yaml": &headlessHeaderActions{},
|
|
"headless/headless-extract-values.yaml": &headlessExtractValues{},
|
|
}
|
|
|
|
type headlessBasic struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *headlessBasic) Execute(filePath string) error {
|
|
router := httprouter.New()
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
_, _ = w.Write([]byte("<html><body></body></html>"))
|
|
})
|
|
ts := httptest.NewServer(router)
|
|
defer ts.Close()
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-headless")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
}
|
|
|
|
type headlessHeaderActions struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *headlessHeaderActions) Execute(filePath string) error {
|
|
router := httprouter.New()
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
testValue := r.Header.Get("test")
|
|
if r.Header.Get("test") != "" {
|
|
_, _ = w.Write([]byte("<html><body>" + testValue + "</body></html>"))
|
|
}
|
|
})
|
|
ts := httptest.NewServer(router)
|
|
defer ts.Close()
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-headless")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
}
|
|
|
|
type headlessExtractValues struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *headlessExtractValues) Execute(filePath string) error {
|
|
router := httprouter.New()
|
|
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
_, _ = w.Write([]byte("<html><body><a href='/test.html'>test</a></body></html>"))
|
|
})
|
|
ts := httptest.NewServer(router)
|
|
defer ts.Close()
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-headless")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return expectResultsCount(results, 3)
|
|
}
|