2020-04-06 00:05:01 +05:30
|
|
|
package extractors
|
|
|
|
|
|
|
|
|
|
import "regexp"
|
|
|
|
|
|
|
|
|
|
// Extractor is used to extract part of response using a regex.
|
|
|
|
|
type Extractor struct {
|
2020-07-10 09:04:38 +02:00
|
|
|
// Name is the extractor's name
|
|
|
|
|
Name string `yaml:"name,omitempty"`
|
2020-07-15 00:47:01 +02:00
|
|
|
// Type is the type of the extractor
|
2020-04-06 00:44:45 +05:30
|
|
|
Type string `yaml:"type"`
|
2020-07-15 00:47:01 +02:00
|
|
|
// extractorType is the internal type of the extractor
|
|
|
|
|
extractorType ExtractorType
|
2020-04-06 00:44:45 +05:30
|
|
|
|
2020-04-06 00:05:01 +05:30
|
|
|
// Regex are the regex pattern required to be present in the response
|
2020-04-06 00:44:45 +05:30
|
|
|
Regex []string `yaml:"regex"`
|
2020-09-17 12:01:51 +05:30
|
|
|
// RegexGroup specifies a group to extract from the regex
|
|
|
|
|
RegexGroup int `yaml:"group"`
|
2020-04-06 00:05:01 +05:30
|
|
|
// regexCompiled is the compiled variant
|
2020-04-06 00:44:45 +05:30
|
|
|
regexCompiled []*regexp.Regexp
|
2020-04-06 00:05:01 +05:30
|
|
|
|
2020-07-16 10:32:00 +02:00
|
|
|
// KVal are the kval to be present in the response headers/cookies
|
|
|
|
|
KVal []string `yaml:"kval,omitempty"`
|
|
|
|
|
|
2020-04-06 00:05:01 +05:30
|
|
|
// Part is the part of the request to match
|
|
|
|
|
//
|
|
|
|
|
// By default, matching is performed in request body.
|
|
|
|
|
Part string `yaml:"part,omitempty"`
|
2020-07-25 21:15:28 +02:00
|
|
|
// Internal defines if this is used internally
|
|
|
|
|
Internal bool `yaml:"internal,omitempty"`
|
2020-04-06 00:05:01 +05:30
|
|
|
}
|
|
|
|
|
|
2020-04-06 00:44:45 +05:30
|
|
|
// ExtractorType is the type of the extractor specified
|
|
|
|
|
type ExtractorType = int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// RegexExtractor extracts responses with regexes
|
|
|
|
|
RegexExtractor ExtractorType = iota + 1
|
2020-07-15 00:47:01 +02:00
|
|
|
// KValExtractor extracts responses with key:value
|
|
|
|
|
KValExtractor
|
2020-04-06 00:44:45 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ExtractorTypes is an table for conversion of extractor type from string.
|
|
|
|
|
var ExtractorTypes = map[string]ExtractorType{
|
|
|
|
|
"regex": RegexExtractor,
|
2020-07-15 00:47:01 +02:00
|
|
|
"kval": KValExtractor,
|
2020-04-06 00:44:45 +05:30
|
|
|
}
|