2022-05-30 10:15:28 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
|
2022-05-30 10:15:28 +02:00
|
|
|
)
|
|
|
|
|
|
2023-07-28 18:50:57 +03:00
|
|
|
var fileTestcases = []TestCaseInfo{
|
2023-08-04 20:21:22 +05:30
|
|
|
{Path: "protocols/file/matcher-with-or.yaml", TestCase: &fileWithOrMatcher{}},
|
|
|
|
|
{Path: "protocols/file/matcher-with-and.yaml", TestCase: &fileWithAndMatcher{}},
|
|
|
|
|
{Path: "protocols/file/matcher-with-nested-and.yaml", TestCase: &fileWithAndMatcher{}},
|
|
|
|
|
{Path: "protocols/file/extract.yaml", TestCase: &fileWithExtractor{}},
|
2022-05-30 10:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type fileWithOrMatcher struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *fileWithOrMatcher) Execute(filePath string) error {
|
2024-11-19 19:30:28 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/file/data/", debug, "-file")
|
2022-05-30 10:15:28 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type fileWithAndMatcher struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *fileWithAndMatcher) Execute(filePath string) error {
|
2024-11-19 19:30:28 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/file/data/", debug, "-file")
|
2022-05-30 10:15:28 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type fileWithExtractor struct{}
|
|
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
|
func (h *fileWithExtractor) Execute(filePath string) error {
|
2024-11-19 19:30:28 +03:00
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "protocols/file/data/", debug, "-file")
|
2022-05-30 10:15:28 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
|
}
|