2022-07-11 19:13:10 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2022-07-11 23:28:36 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
|
2022-07-11 19:13:10 +02:00
|
|
|
)
|
|
|
|
|
|
2023-07-28 18:50:57 +03:00
|
|
|
var offlineHttpTestcases = []TestCaseInfo{
|
2023-08-04 20:21:22 +05:30
|
|
|
{Path: "protocols/offlinehttp/rfc-req-resp.yaml", TestCase: &RfcRequestResponse{}},
|
|
|
|
|
{Path: "protocols/offlinehttp/offline-allowed-paths.yaml", TestCase: &RequestResponseWithAllowedPaths{}},
|
|
|
|
|
{Path: "protocols/offlinehttp/offline-raw.yaml", TestCase: &RawRequestResponse{}},
|
2022-07-11 19:13:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RfcRequestResponse struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *RfcRequestResponse) Execute(filePath string) error {
|
2023-06-09 17:24:24 +02:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
|
2022-07-11 19:13:10 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
2022-07-11 23:28:36 +02:00
|
|
|
|
|
|
|
|
type RequestResponseWithAllowedPaths struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *RequestResponseWithAllowedPaths) Execute(filePath string) error {
|
2023-06-09 17:24:24 +02:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
|
2022-07-11 23:28:36 +02:00
|
|
|
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 {
|
2023-06-09 17:24:24 +02:00
|
|
|
_, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
|
2022-07-11 23:28:36 +02:00
|
|
|
if err == nil {
|
|
|
|
|
return fmt.Errorf("incorrect result: no error (actual) vs error expected")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|