2022-03-08 15:50:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
2022-04-04 22:33:49 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
|
2022-03-08 15:50:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getTemplatePath() string {
|
2022-04-04 22:33:49 +00:00
|
|
|
templatePath, _ := utils.GetDefaultTemplatePath()
|
|
|
|
return templatePath
|
2022-03-08 15:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var templatesPathTestCases = map[string]testutils.TestCase{
|
|
|
|
//cwd
|
|
|
|
"./dns/cname-fingerprint.yaml": &cwdTemplateTest{},
|
|
|
|
//relative path
|
|
|
|
"dns/cname-fingerprint.yaml": &relativePathTemplateTest{},
|
|
|
|
//absolute path
|
|
|
|
fmt.Sprintf("%v/dns/cname-fingerprint.yaml", getTemplatePath()): &absolutePathTemplateTest{},
|
|
|
|
}
|
|
|
|
|
|
|
|
type cwdTemplateTest struct{}
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
func (h *cwdTemplateTest) Execute(filePath string) error {
|
|
|
|
var routerErr error
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if routerErr != nil {
|
|
|
|
return routerErr
|
|
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
type relativePathTemplateTest struct{}
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
func (h *relativePathTemplateTest) Execute(filePath string) error {
|
|
|
|
var routerErr error
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if routerErr != nil {
|
|
|
|
return routerErr
|
|
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
type absolutePathTemplateTest struct{}
|
|
|
|
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
|
|
func (h *absolutePathTemplateTest) Execute(filePath string) error {
|
|
|
|
var routerErr error
|
|
|
|
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if routerErr != nil {
|
|
|
|
return routerErr
|
|
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
|
|
}
|