nuclei/v2/internal/testutils/testutils.go

93 lines
2.7 KiB
Go
Raw Normal View History

2021-02-03 13:08:31 +05:30
package testutils
import (
"go.uber.org/ratelimit"
"github.com/projectdiscovery/gologger/levels"
2021-02-26 13:13:11 +05:30
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
2021-02-03 13:08:31 +05:30
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/progress"
2021-02-03 13:08:31 +05:30
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolinit"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
// Init initializes the protocols and their configurations
func Init(options *types.Options) {
2021-02-26 13:13:11 +05:30
_ = protocolinit.Init(options)
2021-02-03 13:08:31 +05:30
}
// DefaultOptions is the default options structure for nuclei during mocking.
var DefaultOptions = &types.Options{
Metrics: false,
Debug: false,
DebugRequests: false,
DebugResponse: false,
Silent: false,
Version: false,
Verbose: false,
NoColor: true,
UpdateTemplates: false,
JSON: false,
JSONRequests: false,
EnableProgressBar: false,
TemplatesVersion: false,
TemplateList: false,
Stdin: false,
StopAtFirstMatch: false,
NoMeta: false,
Project: false,
MetricsPort: 0,
BulkSize: 25,
TemplateThreads: 10,
Timeout: 5,
Retries: 1,
RateLimit: 150,
ProjectPath: "",
Severities: severity.Severities{},
Targets: []string{},
TargetsFilePath: "",
Output: "",
ProxyURL: "",
ProxySocksURL: "",
TemplatesDirectory: "",
TraceLogFile: "",
Templates: []string{},
ExcludedTemplates: []string{},
CustomHeaders: []string{},
2021-02-03 13:08:31 +05:30
}
// TemplateInfo contains info for a mock executed template.
type TemplateInfo struct {
ID string
Info model.Info
2021-02-03 13:08:31 +05:30
Path string
}
// NewMockExecuterOptions creates a new mock executeroptions struct
func NewMockExecuterOptions(options *types.Options, info *TemplateInfo) *protocols.ExecuterOptions {
progressImpl, _ := progress.NewStatsTicker(0, false, false, false, 0)
2021-02-03 13:08:31 +05:30
executerOpts := &protocols.ExecuterOptions{
TemplateID: info.ID,
TemplateInfo: info.Info,
TemplatePath: info.Path,
Output: output.NewMockOutputWriter(),
2021-02-03 13:08:31 +05:30
Options: options,
2021-02-26 13:13:11 +05:30
Progress: progressImpl,
2021-02-03 13:08:31 +05:30
ProjectFile: nil,
2021-02-08 02:07:19 +05:30
IssuesClient: nil,
Browser: nil,
2021-02-26 13:13:11 +05:30
Catalog: catalog.New(options.TemplatesDirectory),
2021-02-03 13:08:31 +05:30
RateLimiter: ratelimit.New(options.RateLimit),
}
return executerOpts
}
// NoopWriter is a NooP gologger writer.
type NoopWriter struct{}
// Write writes the data to an output writer.
func (n *NoopWriter) Write(data []byte, level levels.Level) {}