Skip to content

Commit

Permalink
adding integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jun 20, 2023
1 parent 9936375 commit a4ca96c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
16 changes: 16 additions & 0 deletions integration_tests/workflow/headless-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: headless-1
info:
name: Headless 1
author: pdteam
severity: info
tags: headless

headless:
- cookie-reuse: true
steps:
- action: navigate
args:
url: "{{BaseURL}}/headless1"

- action: waitload

12 changes: 12 additions & 0 deletions integration_tests/workflow/http-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: http1

info:
name: http1
author: pdteam
severity: info

requests:
- method: GET
path:
- "{{BaseURL}}/http1"
cookie-reuse: true
12 changes: 12 additions & 0 deletions integration_tests/workflow/http-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: http2

info:
name: http2
author: pdteam
severity: info

requests:
- method: GET
path:
- "{{BaseURL}}/http2"
cookie-reuse: true
12 changes: 12 additions & 0 deletions integration_tests/workflow/http-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: http3

info:
name: http3
author: pdteam
severity: info

requests:
- method: GET
path:
- "{{BaseURL}}/http3"
cookie-reuse: true
15 changes: 15 additions & 0 deletions integration_tests/workflow/shared-cookie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: workflow-shared-cookies

info:
name: Test Workflow Shared Cookies
author: pdteam
severity: info

workflows:
# store cookies to standard http client cookie-jar
- template: workflow/http-1.yaml
- template: workflow/http-2.yaml
# store cookie in native browser context
- template: workflow/headless-1.yaml
# retrive 2 standard library cookies + headless cookie
- template: workflow/http-3.yaml
37 changes: 37 additions & 0 deletions v2/cmd/integration-test/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var workflowTestcases = map[string]testutils.TestCase{
"workflow/matcher-name.yaml": &workflowMatcherName{},
"workflow/http-value-share-workflow.yaml": &workflowHttpKeyValueShare{},
"workflow/dns-value-share-workflow.yaml": &workflowDnsKeyValueShare{},
"workflow/shared-cookie.yaml": &workflowSharedCookies{},
}

type workflowBasic struct{}
Expand Down Expand Up @@ -131,3 +132,39 @@ func (h *workflowDnsKeyValueShare) Execute(filePath string) error {
// no results - ensure that the variable sharing works
return expectResultsCount(results, 1)
}

type workflowSharedCookies struct{}

// Execute executes a test case and returns an error if occurred
func (h *workflowSharedCookies) Execute(filePath string) error {
handleFunc := func(name string, w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
cookie := &http.Cookie{Name: name, Value: name}
http.SetCookie(w, cookie)
}

var gotCookies []string
router := httprouter.New()
router.GET("/http1", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
handleFunc("http1", w, r, p)
})
router.GET("/http2", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
handleFunc("http2", w, r, p)
})
router.GET("/headless1", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
handleFunc("headless1", w, r, p)
})
router.GET("/http3", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
for _, cookie := range r.Cookies() {
gotCookies = append(gotCookies, cookie.Name)
}
})
ts := httptest.NewServer(router)
defer ts.Close()

_, err := testutils.RunNucleiWorkflowAndGetResults(filePath, ts.URL, debug, "-headless")
if err != nil {
return err
}

return expectResultsCount(gotCookies, 3)
}

0 comments on commit a4ca96c

Please sign in to comment.