nuclei/v2/cmd/integration-test/template-path.go

72 lines
2.1 KiB
Go
Raw Normal View History

2022-03-08 15:50:08 +00:00
package main
import (
"fmt"
2022-04-11 06:29:22 +00:00
"strings"
2022-03-08 15:50:08 +00:00
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
2022-03-08 15:50:08 +00:00
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
)
func getTemplatePath() string {
return config.DefaultConfig.TemplatesDirectory
2022-03-08 15:50:08 +00:00
}
var templatesPathTestCases = map[string]testutils.TestCase{
2022-04-11 06:29:22 +00:00
//template folder path issue
"http/get.yaml": &folderPathTemplateTest{},
2022-03-08 15:50:08 +00:00
//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 {
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
if err != nil {
return err
}
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 {
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
if err != nil {
return err
}
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 {
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "8x8exch02.8x8.com", debug)
if err != nil {
return err
}
return expectResultsCount(results, 1)
}
2022-04-11 06:29:22 +00:00
type folderPathTemplateTest struct{}
// Execute executes a test case and returns an error if occurred
func (h *folderPathTemplateTest) Execute(filePath string) error {
results, err := testutils.RunNucleiBinaryAndGetCombinedOutput(debug, []string{"-t", filePath, "-target", "http://example.com"})
if err != nil {
return err
}
if strings.Contains(results, "installing") {
return fmt.Errorf("couldn't find template path,re-installing")
}
return nil
}