Adding offline http tests (#2276)

This commit is contained in:
Mzack9999 2022-07-11 23:28:36 +02:00 committed by GitHub
parent 1c332bb85b
commit 57b2ec7ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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{}
@ -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
}