testutils

package
v3.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &types.Options{
	Metrics:                    false,
	Debug:                      false,
	DebugRequests:              false,
	DebugResponse:              false,
	Silent:                     false,
	Verbose:                    false,
	NoColor:                    true,
	UpdateTemplates:            false,
	JSONL:                      false,
	OmitRawRequests:            false,
	EnableProgressBar:          false,
	TemplateList:               false,
	Stdin:                      false,
	StopAtFirstMatch:           false,
	NoMeta:                     false,
	Project:                    false,
	MetricsPort:                0,
	BulkSize:                   25,
	TemplateThreads:            10,
	Timeout:                    5,
	Retries:                    1,
	RateLimit:                  150,
	RateLimitDuration:          time.Second,
	ProbeConcurrency:           50,
	ProjectPath:                "",
	Severities:                 severity.Severities{},
	Targets:                    []string{},
	TargetsFilePath:            "",
	Output:                     "",
	Proxy:                      []string{},
	TraceLogFile:               "",
	Templates:                  []string{},
	ExcludedTemplates:          []string{},
	CustomHeaders:              []string{},
	InteractshURL:              "https://oast.fun",
	InteractionsCacheSize:      5000,
	InteractionsEviction:       60,
	InteractionsCoolDownPeriod: 5,
	InteractionsPollDuration:   5,
	GitHubTemplateRepo:         []string{},
	GitHubToken:                "",
}

DefaultOptions is the default options structure for nuclei during mocking.

Functions

func Cleanup

func Cleanup(options *types.Options)

Cleanup cleans up the protocols and their configurations.

func Init

func Init(options *types.Options)

Init initializes the protocols and their configurations.

func NewMockExecuterOptions

func NewMockExecuterOptions(options *types.Options, info *TemplateInfo) *protocols.ExecutorOptions

NewMockExecuterOptions creates a new mock executeroptions struct.

func NewWebsocketServer

func NewWebsocketServer(path string, handler func(conn net.Conn), originValidate func(origin string) bool, port ...int) *httptest.Server

NewWebsocketServer creates a new websocket server from a handler.

func RunNucleiAndGetResults

func RunNucleiAndGetResults(isTemplate bool, template, url string, debug bool, extra ...string) ([]string, error)

func RunNucleiArgsAndGetErrors

func RunNucleiArgsAndGetErrors(debug bool, env []string, extra ...string) ([]string, error)

RunNucleiArgsAndGetErrors returns a list of errors in nuclei output (ERR,WRN,FTL).

func RunNucleiArgsWithEnvAndGetResults

func RunNucleiArgsWithEnvAndGetResults(debug bool, env []string, extra ...string) ([]string, error)

RunNucleiArgsWithEnvAndGetResults returns a list of results in nuclei output (ERR,WRN,FTL).

func RunNucleiBareArgsAndGetResults

func RunNucleiBareArgsAndGetResults(debug bool, env []string, extra ...string) ([]string, error)

func RunNucleiBinaryAndGetCombinedOutput

func RunNucleiBinaryAndGetCombinedOutput(debug bool, args []string) (string, error)

func RunNucleiBinaryAndGetLoadedTemplates

func RunNucleiBinaryAndGetLoadedTemplates(nucleiBinary string, debug bool, args []string) (string, error)

RunNucleiBinaryAndGetLoadedTemplates returns a list of results for a template.

func RunNucleiTemplateAndGetResults

func RunNucleiTemplateAndGetResults(template, url string, debug bool, extra ...string) ([]string, error)

RunNucleiTemplateAndGetResults returns a list of results for a template.

func RunNucleiWithArgsAndGetResults

func RunNucleiWithArgsAndGetResults(debug bool, args ...string) ([]string, error)

RunNucleiWithArgsAndGetResults returns result,and runtime errors.

func RunNucleiWorkflowAndGetResults

func RunNucleiWorkflowAndGetResults(template, url string, debug bool, extra ...string) ([]string, error)

RunNucleiWorkflowAndGetResults returns a list of results for a workflow.

func SetDefaultRunner

func SetDefaultRunner(runner *Runner)

Types

type MockOutputWriter

type MockOutputWriter struct {
	RequestCallback func(templateID, url, requestType string, err error)
	FailureCallback func(result *output.InternalEvent)
	WriteCallback   func(o *output.ResultEvent)
	// contains filtered or unexported fields
}

MockOutputWriter is a mocked output writer.

func NewMockOutputWriter

func NewMockOutputWriter(omomitTemplate bool) *MockOutputWriter

NewMockOutputWriter creates a new mock output writer.

func (*MockOutputWriter) Close

func (m *MockOutputWriter) Close()

Close closes the output writer interface.

func (*MockOutputWriter) Colorizer

func (m *MockOutputWriter) Colorizer() *aurora.Aurora

Colorizer returns the colorizer instance for writer.

func (*MockOutputWriter) Request

func (m *MockOutputWriter) Request(templateID, url, requestType string, err error)

Request writes a log the requests trace log.

func (*MockOutputWriter) RequestStatsLog

func (m *MockOutputWriter) RequestStatsLog(statusCode, response string)

func (*MockOutputWriter) ResultCount

func (m *MockOutputWriter) ResultCount() int

func (*MockOutputWriter) Write

func (m *MockOutputWriter) Write(result *output.ResultEvent) error

Write writes the event to file and/or screen.

func (*MockOutputWriter) WriteFailure

func (m *MockOutputWriter) WriteFailure(wrappedEvent *output.InternalWrappedEvent) error

WriteFailure writes the event to file and/or screen.

func (*MockOutputWriter) WriteStoreDebugData

func (m *MockOutputWriter) WriteStoreDebugData(host, templateID, eventType string, data string)

type MockProgressClient

type MockProgressClient struct{}

func (*MockProgressClient) AddToTotal

func (m *MockProgressClient) AddToTotal(delta int64)

AddToTotal adds a value to the total request count.

func (*MockProgressClient) IncrementErrorsBy

func (m *MockProgressClient) IncrementErrorsBy(count int64)

IncrementErrorsBy increments the error counter by count.

func (*MockProgressClient) IncrementFailedRequestsBy

func (m *MockProgressClient) IncrementFailedRequestsBy(count int64)

IncrementFailedRequestsBy increments the number of requests counter by count along with errors.

func (*MockProgressClient) IncrementMatched

func (m *MockProgressClient) IncrementMatched()

IncrementMatched increments the matched counter by 1.

func (*MockProgressClient) IncrementRequests

func (m *MockProgressClient) IncrementRequests()

IncrementRequests increments the requests counter by 1.

func (*MockProgressClient) Init

func (m *MockProgressClient) Init(hostCount int64, rulesCount int, requestCount int64)

Init inits the progress bar with initial details for scan.

func (*MockProgressClient) SetRequests

func (m *MockProgressClient) SetRequests(count uint64)

SetRequests sets the counter by incrementing it with a delta.

func (*MockProgressClient) Stop

func (m *MockProgressClient) Stop()

Stop stops the progress recorder.

type NoopWriter

type NoopWriter struct{}

NoopWriter is a NooP gologger writer.

func (*NoopWriter) Write

func (n *NoopWriter) Write(data []byte, level levels.Level)

Write writes the data to an output writer.

type Runner

type Runner struct {
	BinaryPath                 string
	WorkingDir                 string
	BaseEnv                    []string
	ExtraArgs                  []string
	DisableAutoUpdate          bool
	AllowLocalFileAccess       bool
	InteractionsPollDuration   string
	InteractionsCooldownPeriod string
}

func DefaultRunner

func DefaultRunner() *Runner

func NewRunner

func NewRunner(options ...RunnerOption) *Runner

func (*Runner) ArgsErrors

func (r *Runner) ArgsErrors(debug bool, env []string, args ...string) ([]string, error)

func (*Runner) ArgsResults

func (r *Runner) ArgsResults(debug bool, args ...string) ([]string, error)

func (*Runner) ArgsResultsWithEnv

func (r *Runner) ArgsResultsWithEnv(debug bool, env []string, args ...string) ([]string, error)

func (*Runner) BareResults

func (r *Runner) BareResults(debug bool, env []string, args ...string) ([]string, error)

func (*Runner) Clone

func (r *Runner) Clone(options ...RunnerOption) *Runner

func (*Runner) CombinedOutput

func (r *Runner) CombinedOutput(debug bool, args []string) (string, error)

func (*Runner) LoadedTemplates

func (r *Runner) LoadedTemplates(binaryPath string, debug bool, args []string) (string, error)

func (*Runner) TemplateResults

func (r *Runner) TemplateResults(template, url string, debug bool, extra ...string) ([]string, error)

func (*Runner) WorkflowResults

func (r *Runner) WorkflowResults(workflow, url string, debug bool, extra ...string) ([]string, error)

type RunnerOption

type RunnerOption func(*Runner)

func WithBaseEnv

func WithBaseEnv(env ...string) RunnerOption

func WithBinaryPath

func WithBinaryPath(path string) RunnerOption

func WithExtraArgs

func WithExtraArgs(args ...string) RunnerOption

func WithWorkingDir

func WithWorkingDir(dir string) RunnerOption

type TCPServer

type TCPServer struct {
	URL string
	// contains filtered or unexported fields
}

TCPServer creates a new tcp server that returns a response.

func NewTCPServer

func NewTCPServer(tlsConfig *tls.Config, port int, handler func(conn net.Conn)) *TCPServer

NewTCPServer creates a new TCP server from a handler.

func (*TCPServer) Close

func (s *TCPServer) Close()

Close closes the TCP server.

type TemplateInfo

type TemplateInfo struct {
	ID   string
	Info model.Info
	Path string
}

TemplateInfo contains info for a mock executed template.

type TestCase

type TestCase interface {
	// Execute executes a test case and returns any errors if occurred
	Execute(filePath string) error
}

TestCase is a single integration test case.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL