Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/javascript/js_test.go
2070 views
1
package javascript_test
2
3
import (
4
"context"
5
"log"
6
"testing"
7
"time"
8
9
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
10
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
11
"github.com/projectdiscovery/nuclei/v3/pkg/loader/workflow"
12
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
13
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
14
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
15
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
16
"github.com/projectdiscovery/ratelimit"
17
"github.com/stretchr/testify/require"
18
)
19
20
var (
21
testcases = []string{
22
"testcases/ms-sql-detect.yaml",
23
"testcases/redis-pass-brute.yaml",
24
"testcases/ssh-server-fingerprint.yaml",
25
}
26
executerOpts *protocols.ExecutorOptions
27
)
28
29
func setup() {
30
options := testutils.DefaultOptions
31
testutils.Init(options)
32
progressImpl, _ := progress.NewStatsTicker(0, false, false, false, 0)
33
34
executerOpts = &protocols.ExecutorOptions{
35
Output: testutils.NewMockOutputWriter(options.OmitTemplate),
36
Options: options,
37
Progress: progressImpl,
38
ProjectFile: nil,
39
IssuesClient: nil,
40
Browser: nil,
41
Catalog: disk.NewCatalog(config.DefaultConfig.TemplatesDirectory),
42
RateLimiter: ratelimit.New(context.Background(), uint(options.RateLimit), time.Second),
43
Parser: templates.NewParser(),
44
}
45
workflowLoader, err := workflow.NewLoader(executerOpts)
46
if err != nil {
47
log.Fatalf("Could not create workflow loader: %s\n", err)
48
}
49
executerOpts.WorkflowLoader = workflowLoader
50
}
51
52
func TestCompile(t *testing.T) {
53
setup()
54
for index, tpl := range testcases {
55
// parse template
56
template, err := templates.Parse(tpl, nil, executerOpts)
57
require.Nilf(t, err, "failed to parse %v", tpl)
58
59
// compile template
60
err = template.Executer.Compile()
61
require.Nilf(t, err, "failed to compile %v", tpl)
62
63
switch index {
64
case 0:
65
// requests count should be 1
66
require.Equal(t, 1, template.TotalRequests, "template : %v", tpl)
67
case 1:
68
// requests count should be 6 i.e 5 generator payloads + 1 precondition request
69
require.Equal(t, 5+1, template.TotalRequests, "template : %v", tpl)
70
case 2:
71
// requests count should be 1
72
require.Equal(t, 1, template.TotalRequests, "template : %v", tpl)
73
}
74
}
75
}
76
77