Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/tmplexec/multiproto/multi_test.go
2070 views
1
package multiproto_test
2
3
import (
4
"context"
5
"log"
6
"os"
7
"testing"
8
"time"
9
10
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
11
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
12
"github.com/projectdiscovery/nuclei/v3/pkg/input"
13
"github.com/projectdiscovery/nuclei/v3/pkg/loader/workflow"
14
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
15
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
16
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs"
17
"github.com/projectdiscovery/nuclei/v3/pkg/scan"
18
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
19
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
20
"github.com/projectdiscovery/ratelimit"
21
"github.com/stretchr/testify/require"
22
)
23
24
var executerOpts *protocols.ExecutorOptions
25
26
func setup() {
27
options := testutils.DefaultOptions
28
testutils.Init(options)
29
progressImpl, _ := progress.NewStatsTicker(0, false, false, false, 0)
30
31
executerOpts = &protocols.ExecutorOptions{
32
Output: testutils.NewMockOutputWriter(options.OmitTemplate),
33
Options: options,
34
Progress: progressImpl,
35
ProjectFile: nil,
36
IssuesClient: nil,
37
Browser: nil,
38
Catalog: disk.NewCatalog(config.DefaultConfig.TemplatesDirectory),
39
RateLimiter: ratelimit.New(context.Background(), uint(options.RateLimit), time.Second),
40
Parser: templates.NewParser(),
41
InputHelper: input.NewHelper(),
42
}
43
workflowLoader, err := workflow.NewLoader(executerOpts)
44
if err != nil {
45
log.Fatalf("Could not create workflow loader: %s\n", err)
46
}
47
executerOpts.WorkflowLoader = workflowLoader
48
}
49
50
func TestMultiProtoWithDynamicExtractor(t *testing.T) {
51
Template, err := templates.Parse("testcases/multiprotodynamic.yaml", nil, executerOpts)
52
require.Nil(t, err, "could not parse template")
53
54
require.Equal(t, 2, len(Template.RequestsQueue))
55
56
err = Template.Executer.Compile()
57
require.Nil(t, err, "could not compile template")
58
59
input := contextargs.NewWithInput(context.Background(), "http://scanme.sh")
60
ctx := scan.NewScanContext(context.Background(), input)
61
gotresults, err := Template.Executer.Execute(ctx)
62
require.Nil(t, err, "could not execute template")
63
require.True(t, gotresults)
64
}
65
66
func TestMultiProtoWithProtoPrefix(t *testing.T) {
67
Template, err := templates.Parse("testcases/multiprotowithprefix.yaml", nil, executerOpts)
68
require.Nil(t, err, "could not parse template")
69
70
require.Equal(t, 3, len(Template.RequestsQueue))
71
72
err = Template.Executer.Compile()
73
require.Nil(t, err, "could not compile template")
74
75
input := contextargs.NewWithInput(context.Background(), "https://cloud.projectdiscovery.io/sign-in")
76
ctx := scan.NewScanContext(context.Background(), input)
77
gotresults, err := Template.Executer.Execute(ctx)
78
require.Nil(t, err, "could not execute template")
79
require.True(t, gotresults)
80
}
81
82
func TestMain(m *testing.M) {
83
setup()
84
os.Exit(m.Run())
85
}
86
87