diff --git a/v2/cmd/integration-test/template-path.go b/v2/cmd/integration-test/template-path.go index ff85ee8f..984fe296 100644 --- a/v2/cmd/integration-test/template-path.go +++ b/v2/cmd/integration-test/template-path.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "github.com/projectdiscovery/nuclei/v2/pkg/testutils" "github.com/projectdiscovery/nuclei/v2/pkg/utils" @@ -13,6 +14,8 @@ func getTemplatePath() string { } var templatesPathTestCases = map[string]testutils.TestCase{ + //template folder path issue + "http/get.yaml": &folderPathTemplateTest{}, //cwd "./dns/cname-fingerprint.yaml": &cwdTemplateTest{}, //relative path @@ -25,15 +28,10 @@ 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) } @@ -41,15 +39,10 @@ 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) } @@ -57,14 +50,23 @@ 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) } + +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 +} diff --git a/v2/internal/runner/update.go b/v2/internal/runner/update.go index 3fac3eff..0d20d9ab 100644 --- a/v2/internal/runner/update.go +++ b/v2/internal/runner/update.go @@ -96,7 +96,7 @@ func (r *Runner) updateTemplates() error { // TODO this method does more than ju ctx := context.Background() var noTemplatesFound bool - if !fileutil.FileExists(r.templatesConfig.TemplatesDirectory) { + if !fileutil.FolderExists(r.templatesConfig.TemplatesDirectory) { noTemplatesFound = true } diff --git a/v2/pkg/testutils/integration.go b/v2/pkg/testutils/integration.go index 8c41bf19..562655a6 100644 --- a/v2/pkg/testutils/integration.go +++ b/v2/pkg/testutils/integration.go @@ -93,6 +93,21 @@ func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, debug bool, args } return matches[0][1], nil } +func RunNucleiBinaryAndGetCombinedOutput(debug bool, args []string) (string, error) { + cmd := exec.Command("./nuclei", args...) + if debug { + cmd.Args = append(cmd.Args, "-debug") + fmt.Println(cmd.String()) + } + data, err := cmd.CombinedOutput() + if debug { + fmt.Println(string(data)) + } + if err != nil { + return "", err + } + return string(data), nil +} // TestCase is a single integration test case type TestCase interface {