types

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Types
	ErrorProxy    = "proxyError"
	ErrorConn     = "connectionError"
	ErrorUnkown   = "unkownError"
	ErrorIntented = "intentedError" // Errors for created intentionally

	// 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"

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

Constants for Hammer field values

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

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

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 AdjustUrlProtocol added in v0.8.0

func AdjustUrlProtocol(url string, proto string) (string, string, error)

AdjustUrlProtocol adjusts the proper url-proto pair for the given ones. If url includes protocol then the new protocol will be the protocol in the url If url does not include protocol, then the new url will include the given protocol If url is not valid, then error will be returned

func ParseTLS added in v0.9.0

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 Hammer

type Hammer struct {
	// Total request count
	TotalReqCount 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{}
}

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 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 RequestError

type Response

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

	ProxyAddr     *url.URL
	ResponseItems []*ResponseItem

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

Response is corresponding to Scenario. Each Scenario has a Response after the request is done.

type ResponseItem

type ResponseItem struct {
	// ID of the ScenarioItem
	ScenarioItemID int16

	// Name of the ScenarioItem
	ScenarioItemName 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

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

ResponseItem is corresponding to ScenarioItem.

type Scenario

type Scenario struct {
	Scenario []ScenarioItem
}

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

type ScenarioItem

type ScenarioItem struct {
	// ID of the Item. Should be given by the client.
	ID int16

	// Name of the Item.
	Name string

	// Protocol of the requests.
	Protocol 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{}
}

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

type TimeRunCount added in v0.6.0

type TimeRunCount []struct {
	Duration int
	Count    int
}

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

Jump to

Keyboard shortcuts

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