Path: blob/dev/cmd/integration-test/matcher-status.go
2070 views
package main12import (3"fmt"4"strings"56"github.com/projectdiscovery/nuclei/v3/pkg/output"7"github.com/projectdiscovery/nuclei/v3/pkg/testutils"8"github.com/projectdiscovery/nuclei/v3/pkg/utils/json"9)1011var matcherStatusTestcases = []TestCaseInfo{12{Path: "protocols/http/get.yaml", TestCase: &httpNoAccess{}},13{Path: "protocols/network/net-https.yaml", TestCase: &networkNoAccess{}},14{Path: "protocols/headless/headless-basic.yaml", TestCase: &headlessNoAccess{}},15{Path: "protocols/javascript/net-https.yaml", TestCase: &javascriptNoAccess{}},16{Path: "protocols/websocket/basic.yaml", TestCase: &websocketNoAccess{}},17{Path: "protocols/dns/a.yaml", TestCase: &dnsNoAccess{}},18}1920type httpNoAccess struct{}2122func (h *httpNoAccess) Execute(filePath string) error {23results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "trust_me_bro.real", debug, "-ms", "-j")24if err != nil {25return err26}27event := &output.ResultEvent{}28_ = json.Unmarshal([]byte(results[0]), event)29expectedError := "no address found for host"30if !strings.Contains(event.Error, expectedError) {31return fmt.Errorf("unexpected result: expecting \"%s\" error but got \"%s\"", expectedError, event.Error)32}33return nil34}3536type networkNoAccess struct{}3738// Execute executes a test case and returns an error if occurred39func (h *networkNoAccess) Execute(filePath string) error {40results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "trust_me_bro.real", debug, "-ms", "-j")41if err != nil {42return err43}44event := &output.ResultEvent{}45_ = json.Unmarshal([]byte(results[0]), event)4647if event.Error != "no address found for host" {48return fmt.Errorf("unexpected result: expecting \"no address found for host\" error but got \"%s\"", event.Error)49}50return nil51}5253type headlessNoAccess struct{}5455// Execute executes a test case and returns an error if occurred56func (h *headlessNoAccess) Execute(filePath string) error {57results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "trust_me_bro.real", debug, "-headless", "-ms", "-j")58if err != nil {59return err60}61event := &output.ResultEvent{}62_ = json.Unmarshal([]byte(results[0]), event)6364if event.Error == "" {65return fmt.Errorf("unexpected result: expecting an error but got \"%s\"", event.Error)66}67return nil68}6970type javascriptNoAccess struct{}7172// Execute executes a test case and returns an error if occurred73func (h *javascriptNoAccess) Execute(filePath string) error {74results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "trust_me_bro.real", debug, "-ms", "-j")75if err != nil {76return err77}78event := &output.ResultEvent{}79_ = json.Unmarshal([]byte(results[0]), event)8081if event.Error == "" {82return fmt.Errorf("unexpected result: expecting an error but got \"%s\"", event.Error)83}84return nil85}8687type websocketNoAccess struct{}8889// Execute executes a test case and returns an error if occurred90func (h *websocketNoAccess) Execute(filePath string) error {91results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "ws://trust_me_bro.real", debug, "-ms", "-j")92if err != nil {93return err94}95event := &output.ResultEvent{}96_ = json.Unmarshal([]byte(results[0]), event)9798if event.Error == "" {99return fmt.Errorf("unexpected result: expecting an error but got \"%s\"", event.Error)100}101return nil102}103104type dnsNoAccess struct{}105106// Execute executes a test case and returns an error if occurred107func (h *dnsNoAccess) Execute(filePath string) error {108results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "trust_me_bro.real", debug, "-ms", "-j")109if err != nil {110return err111}112event := &output.ResultEvent{}113_ = json.Unmarshal([]byte(results[0]), event)114115if event.Error == "" {116return fmt.Errorf("unexpected result: expecting an error but got \"%s\"", event.Error)117}118return nil119}120121122