Files
projectdiscovery-httpx/internal/testutils/integration.go
T
Sajad e31c1250a2 add dsl match/filter condtion (#782)
* add dsl match/filter condtion

* update README

* add test cases
2022-10-06 17:11:12 +05:30

87 lines
1.9 KiB
Go

package testutils
import (
"fmt"
"os"
"os/exec"
"strings"
)
// RunNucleiAndGetResults returns a list of results for a template
func RunHttpxAndGetResults(url string, debug bool, extra ...string) ([]string, error) {
cmd := exec.Command("bash", "-c")
cmdLine := `echo "` + url + `" | ./httpx `
cmdLine += strings.Join(extra, " ")
if debug {
cmdLine += " -debug"
cmd.Stderr = os.Stderr
} else {
cmdLine += " -silent"
}
cmd.Args = append(cmd.Args, cmdLine)
data, err := cmd.Output()
if err != nil {
return nil, err
}
parts := []string{}
items := strings.Split(string(data), "\n")
for _, i := range items {
if i != "" {
parts = append(parts, i)
}
}
return parts, nil
}
// RunNucleiAndGetResults returns a list of results for a template
func RunHttpxAndGetCombinedResults(url string, debug bool, extra ...string) (string, error) {
cmd := exec.Command("bash", "-c")
cmdLine := `echo "` + url + `" | ./httpx `
cmdLine += strings.Join(extra, " ")
if debug {
cmdLine += " -debug"
} else {
cmdLine += " -silent"
}
cmd.Args = append(cmd.Args, cmdLine)
data, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
return string(data), nil
}
func RunHttpxBinaryAndGetResults(target string, httpxBinary string, debug bool, args []string) ([]string, error) {
cmd := exec.Command("bash", "-c")
cmdLine := fmt.Sprintf(`echo %s | %s `, target, httpxBinary)
cmdLine += strings.Join(args, " ")
if debug {
cmdLine += " -debug"
cmd.Stderr = os.Stderr
} else {
cmdLine += " -silent"
}
cmd.Args = append(cmd.Args, cmdLine)
data, err := cmd.Output()
if err != nil {
return nil, err
}
parts := []string{}
items := strings.Split(string(data), "\n")
for _, i := range items {
if i != "" {
parts = append(parts, i)
}
}
return parts, nil
}
// TestCase is a single integration test case
type TestCase interface {
// Execute executes a test case and returns any errors if occurred
Execute() error
}