Path: blob/dev/pkg/tmplexec/multiproto/multi_test.go
2070 views
package multiproto_test12import (3"context"4"log"5"os"6"testing"7"time"89"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"10"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"11"github.com/projectdiscovery/nuclei/v3/pkg/input"12"github.com/projectdiscovery/nuclei/v3/pkg/loader/workflow"13"github.com/projectdiscovery/nuclei/v3/pkg/progress"14"github.com/projectdiscovery/nuclei/v3/pkg/protocols"15"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs"16"github.com/projectdiscovery/nuclei/v3/pkg/scan"17"github.com/projectdiscovery/nuclei/v3/pkg/templates"18"github.com/projectdiscovery/nuclei/v3/pkg/testutils"19"github.com/projectdiscovery/ratelimit"20"github.com/stretchr/testify/require"21)2223var executerOpts *protocols.ExecutorOptions2425func setup() {26options := testutils.DefaultOptions27testutils.Init(options)28progressImpl, _ := progress.NewStatsTicker(0, false, false, false, 0)2930executerOpts = &protocols.ExecutorOptions{31Output: testutils.NewMockOutputWriter(options.OmitTemplate),32Options: options,33Progress: progressImpl,34ProjectFile: nil,35IssuesClient: nil,36Browser: nil,37Catalog: disk.NewCatalog(config.DefaultConfig.TemplatesDirectory),38RateLimiter: ratelimit.New(context.Background(), uint(options.RateLimit), time.Second),39Parser: templates.NewParser(),40InputHelper: input.NewHelper(),41}42workflowLoader, err := workflow.NewLoader(executerOpts)43if err != nil {44log.Fatalf("Could not create workflow loader: %s\n", err)45}46executerOpts.WorkflowLoader = workflowLoader47}4849func TestMultiProtoWithDynamicExtractor(t *testing.T) {50Template, err := templates.Parse("testcases/multiprotodynamic.yaml", nil, executerOpts)51require.Nil(t, err, "could not parse template")5253require.Equal(t, 2, len(Template.RequestsQueue))5455err = Template.Executer.Compile()56require.Nil(t, err, "could not compile template")5758input := contextargs.NewWithInput(context.Background(), "http://scanme.sh")59ctx := scan.NewScanContext(context.Background(), input)60gotresults, err := Template.Executer.Execute(ctx)61require.Nil(t, err, "could not execute template")62require.True(t, gotresults)63}6465func TestMultiProtoWithProtoPrefix(t *testing.T) {66Template, err := templates.Parse("testcases/multiprotowithprefix.yaml", nil, executerOpts)67require.Nil(t, err, "could not parse template")6869require.Equal(t, 3, len(Template.RequestsQueue))7071err = Template.Executer.Compile()72require.Nil(t, err, "could not compile template")7374input := contextargs.NewWithInput(context.Background(), "https://cloud.projectdiscovery.io/sign-in")75ctx := scan.NewScanContext(context.Background(), input)76gotresults, err := Template.Executer.Execute(ctx)77require.Nil(t, err, "could not execute template")78require.True(t, gotresults)79}8081func TestMain(m *testing.M) {82setup()83os.Exit(m.Run())84}858687