config

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CloudRunMode is the string that will be used to override the run mode of execution to cloud
	CloudRunMode RunMode = "cloud"
	// DefaultRunMode is the default execution run mode
	DefaultRunMode RunMode = "default"
	// DefaultLogMarkerHeaderName is the default log marker header name
	DefaultLogMarkerHeaderName string = "X-CRS-Test"
	// DefaultMaxMarkerRetries is the default amount of retries that will be attempted to find the log markers
	DefaultMaxMarkerRetries uint = 20
	// DefaultMaxMarkerLogLines is the default lines we are going read back in a logfile to find the markers
	DefaultMaxMarkerLogLines uint = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FTWConfiguration

type FTWConfiguration struct {
	// Logfile is the path to the file that contains the WAF logs to check. The path may be absolute or relative, in which case it will be interpreted as relative to the current working directory.
	LogFile string `koanf:"logfile"`
	// TestOverride holds the test overrides that will apply globally
	TestOverride FTWTestOverride `koanf:"testoverride"`
	// LogMarkerHeaderName is the name of the header that will be used by the test framework to mark positions in the log file
	LogMarkerHeaderName string `koanf:"logmarkerheadername"`
	// RunMode stores the mode used to interpret test results. See https://github.com/coreruleset/go-ftw/v2#%EF%B8%8F-cloud-mode.
	RunMode RunMode `koanf:"mode"`
	// MaxMarkerRetries is the maximum number of times the search for log markers will be repeated; each time an additional request is sent to the web server, eventually forcing the log to be flushed
	MaxMarkerRetries uint `koanf:"maxmarkerretries"`
	// MaxMarkerLogLines is the maximum number of lines to search for a marker before aborting
	MaxMarkerLogLines uint `koanf:"maxmarkerloglines"`
	// IncludeTests is a regular expression for tests to include, matched against the rule ID (same as --include)
	IncludeTests *FTWRegexp `koanf:"include"`
	// ExcludeTests is a regular expression for tests to exclude, matched against the rule ID (same as --exclude)
	ExcludeTests *FTWRegexp `koanf:"exclude"`
	// IncludeTags is a regular expression for tests to include, matched aginst the tags of tests (same as --tag)
	IncludeTags *FTWRegexp `koanf:"include_tags"`
	// to domains with a self-signed certificate.
	SkipTlsVerification bool `koanf:"skip_tls_verification"`
}

FTWConfiguration FTW global Configuration

func NewCloudConfig

func NewCloudConfig() *FTWConfiguration

NewCloudConfig initializes the configuration with cloud values

func NewConfigFromEnv

func NewConfigFromEnv() (*FTWConfiguration, error)

NewConfigFromEnv reads configuration information from environment variables that start with `FTW_`

func NewConfigFromFile

func NewConfigFromFile(cfgFile string) (*FTWConfiguration, error)

NewConfigFromFile reads configuration information from the config file if it exists, or uses `.ftw.yaml` as default file

func NewConfigFromString

func NewConfigFromString(conf string) (*FTWConfiguration, error)

NewConfigFromString initializes the configuration from a yaml formatted string. Useful for testing.

func NewDefaultConfig

func NewDefaultConfig() *FTWConfiguration

NewDefaultConfig initializes the configuration with default values

type FTWRegexp

type FTWRegexp regexp.Regexp

FTWRegexp is a wrapper around regexp.Regexp that implements the Unmarshaler interface

func NewFTWRegexp

func NewFTWRegexp(s string) (*FTWRegexp, error)

NewFTWRegexp creates a new FTWRegexp from a string

func (*FTWRegexp) MatchString

func (r *FTWRegexp) MatchString(s string) bool

MatchString implements the MatchString method of the regexp.Regexp struct

func (*FTWRegexp) UnmarshalText

func (r *FTWRegexp) UnmarshalText(b []byte) error

UnmarshalText implements the Unmarshaler interface

type FTWTestOverride

type FTWTestOverride struct {
	Overrides Overrides             `koanf:"input"`
	Ignore    map[*FTWRegexp]string `koanf:"ignore"`
	ForcePass map[*FTWRegexp]string `koanf:"forcepass"`
	ForceFail map[*FTWRegexp]string `koanf:"forcefail"`
}

FTWTestOverride holds four lists:

Overrides allows you to override input parameters in tests. An example usage is if you want to change the `dest_addr` of all tests to point to an external IP or host.
Ignore is for tests you want to ignore. You should add a comment on why you ignore the test
ForcePass is for tests you want to pass unconditionally. You should add a comment on why you force to pass the test
ForceFail is for tests you want to fail unconditionally. You should add a comment on why you force to fail the test

type Overrides

type Overrides struct {
	DestAddr *string `yaml:"dest_addr,omitempty" koanf:"dest_addr,omitempty"`
	Port     *int    `yaml:"port,omitempty" koanf:"port,omitempty"`
	Protocol *string `yaml:"protocol,omitempty" koanf:"protocol,omitempty"`
	URI      *string `yaml:"uri,omitempty" koanf:"uri,omitempty"`
	Version  *string `yaml:"version,omitempty" koanf:"version,omitempty"`
	// Deprecated: use OrderedHeaders instead
	Headers        map[string]string    `yaml:"headers,omitempty" koanf:"headers,omitempty"`
	OrderedHeaders []schema.HeaderTuple `yaml:"ordered_headers,omitempty" koanf:"ordered_headers,omitempty"`
	Method         *string              `yaml:"method,omitempty" koanf:"method,omitempty"`
	Data           *string              `yaml:"data,omitempty" koanf:"data,omitempty"`
	SaveCookie     *bool                `yaml:"save_cookie,omitempty" koanf:"save_cookie,omitempty"`
	// Deprecated: replaced with AutocompleteHeaders
	StopMagic               *bool   `yaml:"stop_magic" koanf:"stop_magic,omitempty"`
	AutocompleteHeaders     *bool   `yaml:"autocomplete_headers" koanf:"autocomplete_headers,omitempty"`
	EncodedRequest          *string `yaml:"encoded_request,omitempty" koanf:"encoded_request,omitempty"`
	OverrideEmptyHostHeader *bool   `yaml:"override_empty_host_header,omitempty" koanf:"override_empty_host_header,omitempty"`
	VirtualHostMode         *bool   `yaml:"virtual_host_mode,omitempty" koanf:"virtual_host_mode,omitempty"`
}

Overrides represents the overridden inputs that have to be applied to tests

type PlatformOverrides

type PlatformOverrides struct {
	schema.FTWOverrides
	OverridesMap map[uint][]*schema.TestOverride
}

type RunMode

type RunMode string

RunMode represents the mode of the test run

type RunnerConfig

type RunnerConfig struct {
	// Include is a regular expression to filter tests to include. If nil, all tests are included.
	Include *regexp.Regexp
	// Exclude is a regular expression to filter tests to exclude. If nil, no tests are excluded.
	Exclude *regexp.Regexp
	// IncludeTags is a regular expression to filter tests to count the ones tagged with the mathing label. If nil, no impact on test runner.
	IncludeTags *regexp.Regexp
	// ShowTime determines whether to show the time taken to run each test.
	ShowTime bool
	// ShowOnlyFailed will only output information related to failed tests
	ShowOnlyFailed bool
	// Output determines the type of output the user wants.
	Output output.Type
	// ConnectTimeout is the timeout for connecting to endpoints during test execution.
	ConnectTimeout time.Duration
	// ReadTimeout is the timeout for receiving responses during test execution.
	ReadTimeout time.Duration
	// RateLimit is the rate limit for requests to the server. 0 is unlimited.
	RateLimit time.Duration
	// FailFast determines whether to stop running tests when the first failure is encountered.
	FailFast            bool
	RunMode             RunMode
	LogMarkerHeaderName string
	LogFilePath         string
	PlatformOverrides   PlatformOverrides
	TestOverride        FTWTestOverride
	MaxMarkerRetries    uint
	MaxMarkerLogLines   uint
	// SkipTlsVerification skips certificate validation. Useful for connecting
	// to domains with a self-signed certificate.
	SkipTlsVerification bool
}

RunnerConfig provides configuration for the test runner.

func NewRunnerConfiguration

func NewRunnerConfiguration(cfg *FTWConfiguration) *RunnerConfig

func (*RunnerConfig) LoadPlatformOverrides

func (c *RunnerConfig) LoadPlatformOverrides(overridesFile string) error

LoadPlatformOverrides reads platform overrides from the specified file path

Jump to

Keyboard shortcuts

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