Skip to content

Commit

Permalink
Merge pull request #3134 from projectdiscovery/issue-3131-unused-code
Browse files Browse the repository at this point in the history
Removing unused code in integration tests
  • Loading branch information
ehsandeep committed Jan 4, 2023
2 parents 2d7948a + 463f4dd commit c273cbc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 56 deletions.
25 changes: 0 additions & 25 deletions v2/cmd/integration-test/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,53 @@ type dnsBasic struct{}

// Execute executes a test case and returns an error if occurred
func (h *dnsBasic) Execute(filePath string) error {
var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}
return expectResultsCount(results, 1)
}

type dnsPtr struct{}

// Execute executes a test case and returns an error if occurred
func (h *dnsPtr) Execute(filePath string) error {
var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "1.1.1.1", debug)
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}
return expectResultsCount(results, 1)
}

type dnsCAA struct{}

// Execute executes a test case and returns an error if occurred
func (h *dnsCAA) Execute(filePath string) error {
var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "google.com", debug)
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}
return expectResultsCount(results, 1)
}

type dnsTLSA struct{}

// Execute executes a test case and returns an error if occurred
func (h *dnsTLSA) Execute(filePath string) error {
var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "scanme.sh", debug)
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}
return expectResultsCount(results, 0)
}

type dnsVariables struct{}

// Execute executes a test case and returns an error if occurred
func (h *dnsVariables) Execute(filePath string) error {
var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "one.one.one.one", debug)
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}
return expectResultsCount(results, 1)
}
24 changes: 3 additions & 21 deletions v2/cmd/integration-test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ type httpRawGetQuery struct{}
// Execute executes a test case and returns an error if occurred
func (h *httpRawGetQuery) Execute(filePath string) error {
router := httprouter.New()
var routerErr error

router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
if strings.EqualFold(r.URL.Query().Get("test"), "nuclei") {
fmt.Fprintf(w, "Test is test raw-get-query-matcher text")
Expand All @@ -475,9 +473,6 @@ func (h *httpRawGetQuery) Execute(filePath string) error {
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}
Expand All @@ -487,8 +482,6 @@ type httpRawGet struct{}
// Execute executes a test case and returns an error if occurred
func (h *httpRawGet) Execute(filePath string) error {
router := httprouter.New()
var routerErr error

router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprintf(w, "Test is test raw-get-matcher text")
})
Expand All @@ -499,9 +492,6 @@ func (h *httpRawGet) Execute(filePath string) error {
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}
Expand Down Expand Up @@ -639,6 +629,7 @@ func (h *httpRawCookieReuse) Execute(filePath string) error {
return expectResultsCount(results, 1)
}

// TODO: excluded due to parsing errors with console
// type httpRawUnsafeRequest struct{
// Execute executes a test case and returns an error if occurred
// func (h *httpRawUnsafeRequest) Execute(filePath string) error {
Expand Down Expand Up @@ -666,13 +657,12 @@ type httpRequestCondition struct{}
// Execute executes a test case and returns an error if occurred
func (h *httpRequestCondition) Execute(filePath string) error {
router := httprouter.New()
var routerErr error

router.GET("/200", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
})
router.GET("/400", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(400)
w.WriteHeader(http.StatusBadRequest)
})
ts := httptest.NewServer(router)
defer ts.Close()
Expand All @@ -681,9 +671,6 @@ func (h *httpRequestCondition) Execute(filePath string) error {
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}
Expand All @@ -693,8 +680,6 @@ type httpRequestSelContained struct{}
// Execute executes a test case and returns an error if occurred
func (h *httpRequestSelContained) Execute(filePath string) error {
router := httprouter.New()
var routerErr error

router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
_, _ = w.Write([]byte("This is self-contained response"))
})
Expand All @@ -711,9 +696,6 @@ func (h *httpRequestSelContained) Execute(filePath string) error {
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}
Expand Down
5 changes: 0 additions & 5 deletions v2/cmd/integration-test/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ type networkRequestSelContained struct{}

// Execute executes a test case and returns an error if occurred
func (h *networkRequestSelContained) Execute(filePath string) error {
var routerErr error

ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
defer conn.Close()

Expand All @@ -111,9 +109,6 @@ func (h *networkRequestSelContained) Execute(filePath string) error {
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}
Expand Down
6 changes: 1 addition & 5 deletions v2/cmd/integration-test/template-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ type templateDirWithTargetTest struct{}
func (h *templateDirWithTargetTest) Execute(filePath string) error {
defer os.RemoveAll(getTemplatesDir())

var routerErr error

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug, "-ud", getTemplatesDir())
if err != nil {
return err
}
if routerErr != nil {
return routerErr
}

return expectResultsCount(results, 1)
}

0 comments on commit c273cbc

Please sign in to comment.