2021-02-25 18:02:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/logrusorgru/aurora"
|
2021-02-26 20:53:06 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
|
2021-02-25 18:02:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
debug = os.Getenv("DEBUG") == "true"
|
|
|
|
customTest = os.Getenv("TEST")
|
2021-02-26 20:53:06 +00:00
|
|
|
protocol = os.Getenv("PROTO")
|
2021-02-25 18:02:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
success := aurora.Green("[✓]").String()
|
|
|
|
failed := aurora.Red("[✘]").String()
|
|
|
|
|
2021-02-26 20:53:06 +00:00
|
|
|
protocolTests := map[string]map[string]testutils.TestCase{
|
2021-02-27 15:24:22 +00:00
|
|
|
"http": httpTestcases,
|
|
|
|
"network": networkTestcases,
|
|
|
|
"dns": dnsTestCases,
|
|
|
|
"workflow": workflowTestcases,
|
2021-02-26 20:53:06 +00:00
|
|
|
}
|
|
|
|
for proto, tests := range protocolTests {
|
|
|
|
if protocol == "" || protocol == proto {
|
|
|
|
fmt.Printf("Running test cases for \"%s\" protocol\n", aurora.Blue(proto))
|
|
|
|
|
|
|
|
for file, test := range tests {
|
|
|
|
if customTest != "" && !strings.Contains(file, customTest) {
|
|
|
|
continue // only run tests user asked
|
|
|
|
}
|
|
|
|
err := test.Execute(file)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, file, err)
|
2021-02-27 07:12:35 +00:00
|
|
|
os.Exit(1)
|
2021-02-26 20:53:06 +00:00
|
|
|
} else {
|
|
|
|
fmt.Printf("%s Test \"%s\" passed!\n", success, file)
|
|
|
|
}
|
|
|
|
}
|
2021-02-25 18:02:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func errIncorrectResultsCount(results []string) error {
|
|
|
|
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t"))
|
|
|
|
}
|