Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more offline http tests #2276

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions integration_tests/offlinehttp/offline-allowed-paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
id: offline-allowed-paths

info:
name: offline-allowed-paths
author: pdteam
severity: info
description: offline-allowed-paths

requests:
- path:
- "{{BaseURL}}"
- "{{BaseURL}}/"
- "/"

matchers:
- type: status
status:
- 200
16 changes: 16 additions & 0 deletions integration_tests/offlinehttp/offline-raw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: offline-raw
info:
name: Test Offline raw Template
author: pdteam
severity: info

requests:
- raw:
- |
GET / HTTP/1.1
Host: {{Hostname}}

matchers:
- type: status
status:
- 200
29 changes: 28 additions & 1 deletion v2/cmd/integration-test/offline-http.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package main

import (
"fmt"

"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
)

var offlineHttpTestcases = map[string]testutils.TestCase{
"offlinehttp/rfc-req-resp.yaml": &RfcRequestResponse{},
"offlinehttp/rfc-req-resp.yaml": &RfcRequestResponse{},
"offlinehttp/offline-allowed-paths.yaml": &RequestResponseWithAllowedPaths{},
"offlinehttp/offline-raw.yaml": &RawRequestResponse{},
}

type RfcRequestResponse struct{}
Expand All @@ -19,3 +23,26 @@ func (h *RfcRequestResponse) Execute(filePath string) error {

return expectResultsCount(results, 1)
}

type RequestResponseWithAllowedPaths struct{}

// Execute executes a test case and returns an error if occurred
func (h *RequestResponseWithAllowedPaths) Execute(filePath string) error {
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "offlinehttp/data/", debug, "-passive")
if err != nil {
return err
}

return expectResultsCount(results, 1)
}

type RawRequestResponse struct{}

// Execute executes a test case and returns an error if occurred
func (h *RawRequestResponse) Execute(filePath string) error {
_, err := testutils.RunNucleiTemplateAndGetResults(filePath, "offlinehttp/data/", debug, "-passive")
if err == nil {
return fmt.Errorf("incorrect result: no error (actual) vs error expected")
}
return nil
}