testing

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Profile

type Profile struct {
	Rules string `yaml:"rules,omitempty"`
	Pass  bool
	Meta  struct {
		Author      string `yaml:"author,omitempty"`
		Description string `yaml:"description,omitempty"`
		Enabled     bool   `yaml:"enabled,omitempty"`
		Name        string `yaml:"name,omitempty"`
	} `yaml:"meta,omitempty"`
	Tests []struct {
		Title       string `yaml:"test_title,omitempty"`
		Description string `yaml:"desc,omitempty"`
		Stages      []struct {
			Stage struct {
				Input struct {
					DestAddr       string            `yaml:"dest_addr,omitempty"`
					Port           int               `yaml:"port,omitempty"`
					Method         string            `yaml:"method,omitempty"`
					URI            string            `yaml:"uri,omitempty"`
					Version        string            `yaml:"version,omitempty"`
					Data           interface{}       `yaml:"data,omitempty"` // Accepts array or string
					Headers        map[string]string `yaml:"headers,omitempty"`
					RawRequest     []byte            `yaml:"raw_request,omitempty"`
					EncodedRequest string            `yaml:"encoded_request,omitempty"`
					StopMagic      bool              `yaml:"stop_magic,omitempty"`
				} `yaml:"input,omitempty"`
				Output expectedOutput `yaml:"output,omitempty"`
			} `yaml:"stage,omitempty"`
		} `yaml:"stages,omitempty"`
	} `yaml:"tests,omitempty"`
}

Profile represents a test profile It contains metadata and instructions for a test It requires more documentation

func NewProfile

func NewProfile(path string) (*Profile, error)

NewProfile creates a new profile from a file

func (*Profile) TestList

func (p *Profile) TestList(waf *coraza.Waf) ([]*Test, error)

TestList returns a list of tests created for a profile

type Test

type Test struct {
	Name string

	// public variables
	// RequestAddress contains the address of the request
	RequestAddress string
	// RequestPort contains the port of the request
	RequestPort int
	// RequestURI contains the uri of the request
	RequestURI string
	// RequestMethod contains the method of the request
	RequestMethod string
	// RequestProtocol contains the protocol of the request
	RequestProtocol string
	// RequestHeaders contains the headers of the request
	RequestHeaders map[string]string
	// ResponseHeaders contains the headers of the response
	ResponseHeaders map[string]string
	// ResponseCode contains the response code of the response
	ResponseCode int
	// ResponseProtocol contains the protocol of the response
	ResponseProtocol string
	// ServerAddress contains the address of the server
	ServerAddress string
	// ServerPort contains the port of the server
	ServerPort int
	// Expected contains the expected result of the test
	ExpectedOutput expectedOutput
	// contains filtered or unexported fields
}

Test represents a unique transaction within a WAF instance for a test case

func NewTest

func NewTest(name string, waf *engine.Waf) *Test

NewTest creates a new test with default properties

func (*Test) DisableMagic

func (t *Test) DisableMagic()

DisableMagic disables the magic flag which auto sets content-type and content-length

func (*Test) LogContains

func (t *Test) LogContains(log string) bool

LogContains checks if the log contains a string

func (*Test) OutputErrors

func (t *Test) OutputErrors() []string

OutputErrors returns a list of errors that occurred during the test

func (*Test) Request

func (t *Test) Request() string

Request returns the raw request

func (*Test) RunPhases

func (t *Test) RunPhases() error

RunPhases runs the phases of the test from 1 to 5

func (*Test) SetEncodedRequest

func (t *Test) SetEncodedRequest(request string) error

SetEncodedRequest reads a base64 encoded request and sets it as the current request

func (*Test) SetRawRequest

func (t *Test) SetRawRequest(request []byte) error

SetRawRequest reads a raw request and sets it as the current request

func (*Test) SetRequestBody

func (t *Test) SetRequestBody(body interface{}) error

SetRequestBody sets the request body

func (*Test) SetResponseBody

func (t *Test) SetResponseBody(body interface{}) error

SetResponseBody sets the request body

func (*Test) SetWaf

func (t *Test) SetWaf(waf *engine.Waf)

SetWaf sets the waf instance pointer

func (*Test) String

func (t *Test) String() string

String returns a string representation of the test for debugging

func (*Test) Transaction

func (t *Test) Transaction() *engine.Transaction

Transaction returns the transaction

Jump to

Keyboard shortcuts

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