Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/cmd/integration-test/offline-http.go
2070 views
1
package main
2
3
import (
4
"fmt"
5
6
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
7
)
8
9
var offlineHttpTestcases = []TestCaseInfo{
10
{Path: "protocols/offlinehttp/rfc-req-resp.yaml", TestCase: &RfcRequestResponse{}},
11
{Path: "protocols/offlinehttp/offline-allowed-paths.yaml", TestCase: &RequestResponseWithAllowedPaths{}},
12
{Path: "protocols/offlinehttp/offline-raw.yaml", TestCase: &RawRequestResponse{}},
13
}
14
15
type RfcRequestResponse struct{}
16
17
// Execute executes a test case and returns an error if occurred
18
func (h *RfcRequestResponse) Execute(filePath string) error {
19
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
20
if err != nil {
21
return err
22
}
23
24
return expectResultsCount(results, 1)
25
}
26
27
type RequestResponseWithAllowedPaths struct{}
28
29
// Execute executes a test case and returns an error if occurred
30
func (h *RequestResponseWithAllowedPaths) Execute(filePath string) error {
31
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
32
if err != nil {
33
return err
34
}
35
36
return expectResultsCount(results, 1)
37
}
38
39
type RawRequestResponse struct{}
40
41
// Execute executes a test case and returns an error if occurred
42
func (h *RawRequestResponse) Execute(filePath string) error {
43
_, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/offlinehttp/data/", debug, "-passive")
44
if err == nil {
45
return fmt.Errorf("incorrect result: no error (actual) vs error expected")
46
}
47
return nil
48
}
49
50