Path: blob/dev/pkg/protocols/javascript/js_test.go
2070 views
package javascript_test12import (3"context"4"log"5"testing"6"time"78"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"9"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"10"github.com/projectdiscovery/nuclei/v3/pkg/loader/workflow"11"github.com/projectdiscovery/nuclei/v3/pkg/progress"12"github.com/projectdiscovery/nuclei/v3/pkg/protocols"13"github.com/projectdiscovery/nuclei/v3/pkg/templates"14"github.com/projectdiscovery/nuclei/v3/pkg/testutils"15"github.com/projectdiscovery/ratelimit"16"github.com/stretchr/testify/require"17)1819var (20testcases = []string{21"testcases/ms-sql-detect.yaml",22"testcases/redis-pass-brute.yaml",23"testcases/ssh-server-fingerprint.yaml",24}25executerOpts *protocols.ExecutorOptions26)2728func setup() {29options := testutils.DefaultOptions30testutils.Init(options)31progressImpl, _ := progress.NewStatsTicker(0, false, false, false, 0)3233executerOpts = &protocols.ExecutorOptions{34Output: testutils.NewMockOutputWriter(options.OmitTemplate),35Options: options,36Progress: progressImpl,37ProjectFile: nil,38IssuesClient: nil,39Browser: nil,40Catalog: disk.NewCatalog(config.DefaultConfig.TemplatesDirectory),41RateLimiter: ratelimit.New(context.Background(), uint(options.RateLimit), time.Second),42Parser: templates.NewParser(),43}44workflowLoader, err := workflow.NewLoader(executerOpts)45if err != nil {46log.Fatalf("Could not create workflow loader: %s\n", err)47}48executerOpts.WorkflowLoader = workflowLoader49}5051func TestCompile(t *testing.T) {52setup()53for index, tpl := range testcases {54// parse template55template, err := templates.Parse(tpl, nil, executerOpts)56require.Nilf(t, err, "failed to parse %v", tpl)5758// compile template59err = template.Executer.Compile()60require.Nilf(t, err, "failed to compile %v", tpl)6162switch index {63case 0:64// requests count should be 165require.Equal(t, 1, template.TotalRequests, "template : %v", tpl)66case 1:67// requests count should be 6 i.e 5 generator payloads + 1 precondition request68require.Equal(t, 5+1, template.TotalRequests, "template : %v", tpl)69case 2:70// requests count should be 171require.Equal(t, 1, template.TotalRequests, "template : %v", tpl)72}73}74}757677