diff --git a/integration_tests/http/race-multiple.yaml b/integration_tests/http/race-multiple.yaml new file mode 100644 index 00000000..89d4db9d --- /dev/null +++ b/integration_tests/http/race-multiple.yaml @@ -0,0 +1,46 @@ +id: race-condition-testing + +info: + name: Race condition testing with multiple requests + author: pdteam + severity: info + +requests: + - raw: + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + id=1 + + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + id=2 + + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + id=3 + + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + id=4 + + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + id=5 + + threads: 5 + race: true + + matchers: + - type: status + status: + - 200 \ No newline at end of file diff --git a/integration_tests/http/race-simple.yaml b/integration_tests/http/race-simple.yaml new file mode 100644 index 00000000..39a7fb91 --- /dev/null +++ b/integration_tests/http/race-simple.yaml @@ -0,0 +1,23 @@ +id: race-condition-testing + +info: + name: Race Condition testing + author: pdteam + severity: info + +requests: + - raw: + - | + GET / HTTP/1.1 + Host: {{Hostname}} + + test + + race: true + race_count: 10 + + matchers: + - type: status + part: header + status: + - 200 \ No newline at end of file diff --git a/v2/cmd/integration-test/http.go b/v2/cmd/integration-test/http.go index a95cea55..ca03a000 100644 --- a/v2/cmd/integration-test/http.go +++ b/v2/cmd/integration-test/http.go @@ -42,6 +42,8 @@ var httpTestcases = map[string]testutils.TestCase{ "http/get-redirects-chain-headers.yaml": &httpGetRedirectsChainHeaders{}, "http/dsl-matcher-variable.yaml": &httpDSLVariable{}, "http/dsl-functions.yaml": &httpDSLFunctions{}, + "http/race-simple.yaml": &httpRaceSimple{}, + "http/race-multiple.yaml": &httpRaceMultiple{}, } type httpInteractshRequest struct{} @@ -689,3 +691,39 @@ func (h *httpGetRedirectsChainHeaders) Execute(filePath string) error { return expectResultsCount(results, 1) } + +type httpRaceSimple struct{} + +// Execute executes a test case and returns an error if occurred +func (h *httpRaceSimple) Execute(filePath string) error { + router := httprouter.New() + router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + w.WriteHeader(http.StatusOK) + }) + ts := httptest.NewServer(router) + defer ts.Close() + + results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug) + if err != nil { + return err + } + return expectResultsCount(results, 10) +} + +type httpRaceMultiple struct{} + +// Execute executes a test case and returns an error if occurred +func (h *httpRaceMultiple) Execute(filePath string) error { + router := httprouter.New() + router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + w.WriteHeader(http.StatusOK) + }) + ts := httptest.NewServer(router) + defer ts.Close() + + results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug) + if err != nil { + return err + } + return expectResultsCount(results, 5) +}