types

package
v0.16.8 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Types
	ErrorProxy          = "proxyError"
	ErrorConn           = "connectionError"
	ErrorUnkown         = "unknownError"
	ErrorIntented       = "intentedError" // Errors for created intentionally
	ErrorDns            = "dnsError"
	ErrorParse          = "parseError"
	ErrorAddr           = "addressError"
	ErrorInvalidRequest = "invalidRequestError"

	// Reasons
	ReasonProxyFailed  = "proxy connection refused"
	ReasonProxyTimeout = "proxy timeout"
	ReasonConnTimeout  = "connection timeout"
	ReasonReadTimeout  = "read timeout"
	ReasonConnRefused  = "connection refused"

	// In gracefully stop, engine cancels the ongoing requests.
	// We can detect the canceled requests with the help of this.
	ReasonCtxCanceled = "context canceled"
)

Constants for custom error types and reasons

View Source
const (
	// Constants of the Load Types
	LoadTypeLinear      = "linear"
	LoadTypeIncremental = "incremental"
	LoadTypeWaved       = "waved"

	// EngineModes
	EngineModeDistinctUser = "distinct-user"
	EngineModeRepeatedUser = "repeated-user"
	EngineModeDdosify      = "ddosify"

	// Default Values
	DefaultIterCount     = 100
	DefaultLoadType      = LoadTypeLinear
	DefaultDuration      = 10
	DefaultTimeout       = 5
	DefaultMethod        = http.MethodGet
	DefaultOutputType    = "stdout" // TODO: get this value from report.OutputTypeStdout when import cycle resolved.
	DefaultSamplingCount = 3
)

Constants for Hammer field values

View Source
const (
	// Constants of the Protocol types
	ProtocolHTTP  = "HTTP"
	ProtocolHTTPS = "HTTPS"

	// Constants of the Auth types
	AuthHttpBasic = "basic"

	// Should match environment variables, reference
	EnvironmentVariableRegexStr = `{{[a-zA-Z$][a-zA-Z0-9_().-]*}}`

	// Should match environment variables, definition, exact match
	EnvironmentVariableNameStr = `^[a-zA-Z][a-zA-Z0-9_-]*$`
)

Constants for Scenario field values

Variables

View Source
var SupportedProtocols = [...]string{ProtocolHTTP, ProtocolHTTPS}

SupportedProtocols should be updated whenever a new requester.Requester interface implemented

Functions

func IsTargetValid

func IsTargetValid(url string) error

func ParseTLS

func ParseTLS(certFile, keyFile string) (tls.Certificate, *x509.CertPool, error)

Types

type Auth

type Auth struct {
	Type     string
	Username string
	Password string
}

Auth struct should be able to include all necessary authentication realated data for supportedAuthentications.

type CaptureConfigError

type CaptureConfigError struct {
	// contains filtered or unexported fields
}

func (CaptureConfigError) Error

func (sc CaptureConfigError) Error() string

func (CaptureConfigError) Unwrap

func (sc CaptureConfigError) Unwrap() error

type CsvConf

type CsvConf struct {
	Path          string         `json:"path"`
	Delimiter     string         `json:"delimiter"`
	SkipFirstLine bool           `json:"skip_first_line"`
	Vars          map[string]Tag `json:"vars"` // "0":"name", "1":"city","2":"team"
	SkipEmptyLine bool           `json:"skip_empty_line"`
	AllowQuota    bool           `json:"allow_quota"`
	Order         string         `json:"order"`
}

type CsvData

type CsvData struct {
	Rows   []map[string]interface{}
	Random bool
}

type EnvCaptureConf

type EnvCaptureConf struct {
	JsonPath *string           `json:"json_path"`
	Xpath    *string           `json:"xpath"`
	RegExp   *RegexCaptureConf `json:"regexp"`
	Name     string            `json:"as"`
	From     SourceType        `json:"from"`
	Key      *string           `json:"header_key"`
}

type EnvironmentNotDefinedError

type EnvironmentNotDefinedError struct {
	// contains filtered or unexported fields
}

func (EnvironmentNotDefinedError) Error

func (EnvironmentNotDefinedError) Unwrap

func (sc EnvironmentNotDefinedError) Unwrap() error

type FailedAssertion

type FailedAssertion struct {
	Rule     string
	Received map[string]interface{}
	Reason   string
}

type Hammer

type Hammer struct {
	// Total iteration count
	IterationCount int

	// Type of the load.
	LoadType string

	// Total Duration of the test in seconds.
	TestDuration int

	// Duration (in second) - Request count map. Example: {10: 1500, 50: 400, ...}
	TimeRunCountMap TimeRunCount

	// Test Scenario
	Scenario Scenario

	// Proxy/Proxies to use
	Proxy proxy.Proxy

	// Destination of the results data.
	ReportDestination string

	// Dynamic field for extra parameters.
	Others map[string]interface{}

	// Debug mode on/off
	Debug bool

	// Sampling rate
	SamplingRate int

	// Connection reuse
	EngineMode string
	// Test Data Config
	TestDataConf map[string]CsvConf
}

Hammer is like a lighter for the engine. It includes attack metadata and all necessary data to initialize the internal services in the engine.

func (*Hammer) Validate

func (h *Hammer) Validate() error

Validate validates attack metadata and executes the validation methods of the services.

type RegexCaptureConf

type RegexCaptureConf struct {
	Exp *string `json:"exp"`
	No  int     `json:"matchNo"`
}

type RequestError

type RequestError struct {
	Type   string
	Reason string
}

RequestError is our custom error struct created in the requester.Requester implementations.

func (*RequestError) Error

func (e *RequestError) Error() string

Custom error message method of ScenarioError

type Scenario

type Scenario struct {
	Steps   []ScenarioStep
	Envs    map[string]interface{}
	CsvVars []string           // only for validation
	Data    map[string]CsvData // populated data
}

Scenario struct contains a list of ScenarioStep so scenario.ScenarioService can execute the scenario step by step.

type ScenarioResult

type ScenarioResult struct {
	// First request start time for the Scenario
	StartTime time.Time

	ProxyAddr   *url.URL
	StepResults []*ScenarioStepResult

	// Dynamic field for extra data needs in response object consumers.
	Others map[string]interface{}
}

ScenarioResult is corresponding to Scenario. Each Scenario has a ScenarioResult after the scenario is played.

type ScenarioStep

type ScenarioStep struct {
	// ID of the Item. Should be given by the client.
	ID uint16

	// Name of the Item.
	Name string

	// Request Method
	Method string

	// Authentication
	Auth Auth

	// A TLS cert
	Cert tls.Certificate

	// A TLS cert pool
	CertPool *x509.CertPool

	// Request Headers
	Headers map[string]string

	// Request payload
	Payload string

	// Target URL
	URL string

	// Connection timeout duration of the request in seconds
	Timeout int

	// Sleep duration after running the step. Can be a time range like "300-500" or an exact duration like "350" in ms
	Sleep string

	// Protocol spesific request parameters. For ex: DisableRedirects:true for Http requests
	Custom map[string]interface{}

	// Envs to capture from response of this step
	EnvsToCapture []EnvCaptureConf

	// assertion expressions
	Assertions []string
}

ScenarioStep represents one step of a Scenario. This struct should be able to include all necessary data in a network packet for SupportedProtocols.

type ScenarioStepResult

type ScenarioStepResult struct {
	// ID of the ScenarioStep
	StepID uint16

	// Name of the ScenarioStep
	StepName string

	// Each request has a unique ID.
	RequestID uuid.UUID

	// Returned status code. Has different meaning for different protocols.
	StatusCode int

	// Time of the request call.
	RequestTime time.Time

	// Total duration. From request sending to full response receiving.
	Duration time.Duration

	// Response content length
	ContentLength int64

	// Error occurred at request time.
	Err RequestError

	// Url
	Url string

	// Method
	Method string

	// Request Headers
	ReqHeaders http.Header

	// Request Body
	ReqBody []byte

	// Response Headers
	RespHeaders http.Header

	// Response Body
	RespBody []byte

	// Protocol spesific metrics. For ex: DNSLookupDuration: 1s for HTTP
	Custom map[string]interface{}

	// Usable envs in this step
	UsableEnvs map[string]interface{}

	// Captured envs in this step
	ExtractedEnvs map[string]interface{}

	// Failed captures and their reasons
	FailedCaptures map[string]string

	// Failed assertion rules and received values
	FailedAssertions []FailedAssertion
}

ScenarioStepResult is corresponding to ScenarioStep.

type ScenarioValidationError

type ScenarioValidationError struct {
	// contains filtered or unexported fields
}

func (ScenarioValidationError) Error

func (sc ScenarioValidationError) Error() string

func (ScenarioValidationError) Unwrap

func (sc ScenarioValidationError) Unwrap() error

type SourceType

type SourceType string
const (
	Header SourceType = "header"
	Body   SourceType = "body"
)

type Tag

type Tag struct {
	Tag  string `json:"tag"`
	Type string `json:"type"`
}

type TimeRunCount

type TimeRunCount []struct {
	Duration int
	Count    int
}

TimeRunCount is the data structure to store manual load type data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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