Skip to content

Commit

Permalink
chore: change default value and name to AutoCompleteHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Jun 24, 2023
1 parent 2b2e288 commit c004ee7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 77 deletions.
4 changes: 2 additions & 2 deletions runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func getRequestFromTest(testInput test.Input) *ftwhttp.Request {

// If we use raw or encoded request, then we don't use other fields
if raw != nil {
req = ftwhttp.NewRawRequest(raw, !*testInput.NoAutocompleteHeaders)
req = ftwhttp.NewRawRequest(raw, !*testInput.AutocompleteHeaders)
} else {
rline := &ftwhttp.RequestLine{
Method: testInput.GetMethod(),
Expand All @@ -371,7 +371,7 @@ func getRequestFromTest(testInput test.Input) *ftwhttp.Request {
data := testInput.ParseData()
// create a new request
req = ftwhttp.NewRequest(rline, testInput.Headers,
data, !*testInput.NoAutocompleteHeaders)
data, !*testInput.AutocompleteHeaders)

}
return req
Expand Down
18 changes: 9 additions & 9 deletions runner/run_input_override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var configTemplate = `
testoverride:
input:
{{ with .StopMagic }}stop_magic: {{ . }}{{ end }}
{{ with .NoAutocompleteHeaders }}no_autocomplete_headers: {{ . }}{{ end }}
{{ with .AutocompleteHeaders }}no_autocomplete_headers: {{ . }}{{ end }}
{{ with .BrokenConfig }}this_does_not_exist: "test"{{ end }}
{{ with .Port }}port: {{ . }}{{ end }}
{{ with .DestAddr }}dest_addr: {{ . }}{{ end }}
Expand Down Expand Up @@ -95,8 +95,8 @@ var overrideConfigMap = map[string]interface{}{
"TestApplyInputOverrideStopMagic": map[string]interface{}{
"StopMagic": "true",
},
"TestApplyInputOverrideNoAutocompleteHeaders": map[string]interface{}{
"NoAutocompleteHeaders": "true",
"TestApplyInputOverrideAutocompleteHeaders": map[string]interface{}{
"AutocompleteHeaders": "true",
},
}

Expand Down Expand Up @@ -301,18 +301,18 @@ func (s *inputOverrideTestSuite) TestApplyInputOverrideStopMagic() {
s.Equal(overrideStopMagic, *testInput.StopMagic, "`StopMagic` should have been overridden")
}

func (s *inputOverrideTestSuite) TestApplyInputOverrideNoAutocompleteHeaders() {
noAutocompleteHeadersBool, err := getOverrideConfigValue("NoAutocompleteHeaders")
func (s *inputOverrideTestSuite) TestApplyInputOverrideAutocompleteHeaders() {
autocompleteHeadersBool, err := getOverrideConfigValue("AutocompleteHeaders")
s.NoError(err, "cannot get override value")
overrideNoAutocompleteHeaders, err := strconv.ParseBool(noAutocompleteHeadersBool)
s.NoError(err, "Failed to parse `NoAutocompleteHeaders` override value")
overrideAutocompleteHeaders, err := strconv.ParseBool(autocompleteHeadersBool)
s.NoError(err, "Failed to parse `AutocompleteHeaders` override value")
testInput := test.Input{
NoAutocompleteHeaders: func() *bool { b := false; return &b }(),
AutocompleteHeaders: func() *bool { b := false; return &b }(),
}
test.ApplyInputOverrides(&s.cfg.TestOverride.Overrides, &testInput)
s.NoError(err, "Failed to apply input overrides")
// nolint
s.Equal(overrideNoAutocompleteHeaders, *testInput.NoAutocompleteHeaders, "`NoAutocompleteHeaders` should have been overridden")
s.Equal(overrideAutocompleteHeaders, *testInput.AutocompleteHeaders, "`AutocompleteHeaders` should have been overridden")
}

func (s *inputOverrideTestSuite) TestApplyInputOverrideEncodedRequest() {
Expand Down
6 changes: 3 additions & 3 deletions test/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uri: "/"
input := Input{}
err := yaml.Unmarshal([]byte(yamlString), &input)
s.NoError(err)
s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
}

func (s *dataTestSuite) TestGetPartialDataFromYAML() {
Expand All @@ -57,7 +57,7 @@ uri: "/"
err := yaml.Unmarshal([]byte(yamlString), &input)
s.NoError(err)
s.Empty(*input.Version)
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
}

func (s *dataTestSuite) TestDataTemplateFromYAML() {
Expand All @@ -83,5 +83,5 @@ uri: "/"
data = input.ParseData()
s.Equal([]byte(repeatTestSprig), data)

s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
}
36 changes: 18 additions & 18 deletions test/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func getTestInputDefaults() *Input {
data := "My Data"

inputDefaults := Input{
Headers: make(ftwhttp.Header),
Data: &data,
SaveCookie: func() *bool { b := false; return &b }(),
NoAutocompleteHeaders: func() *bool { b := false; return &b }(),
Headers: make(ftwhttp.Header),
Data: &data,
SaveCookie: func() *bool { b := false; return &b }(),
AutocompleteHeaders: func() *bool { b := false; return &b }(),
}
return &inputDefaults
}
Expand All @@ -38,17 +38,17 @@ func getTestExampleInput() *Input {
version := "HTTP/1.1"

inputTest := Input{
DestAddr: &destaddr,
Port: &port,
Protocol: &protocol,
URI: &uri,
Version: &version,
Headers: make(ftwhttp.Header),
Method: &method,
Data: nil,
EncodedRequest: "TXkgRGF0YQo=",
SaveCookie: func() *bool { b := false; return &b }(),
NoAutocompleteHeaders: func() *bool { b := false; return &b }(),
DestAddr: &destaddr,
Port: &port,
Protocol: &protocol,
URI: &uri,
Version: &version,
Headers: make(ftwhttp.Header),
Method: &method,
Data: nil,
EncodedRequest: "TXkgRGF0YQo=",
SaveCookie: func() *bool { b := false; return &b }(),
AutocompleteHeaders: func() *bool { b := false; return &b }(),
}

return &inputTest
Expand All @@ -75,8 +75,8 @@ Keep-Alive: 300
Proxy-Connection: keep-alive
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
`,
SaveCookie: func() *bool { b := false; return &b }(),
NoAutocompleteHeaders: func() *bool { b := true; return &b }(),
SaveCookie: func() *bool { b := false; return &b }(),
AutocompleteHeaders: func() *bool { b := true; return &b }(),
}

return &inputTest
Expand Down Expand Up @@ -128,7 +128,7 @@ func (s *defaultsTestSuite) TestDefaultGetters() {
func (s *defaultsTestSuite) TestRaw() {
raw := getRawInput()

s.True(*raw.NoAutocompleteHeaders)
s.True(*raw.AutocompleteHeaders)

request, _ := raw.GetRawRequest()
s.NotEqual(2, bytes.Index(request, []byte("Acunetix")))
Expand Down
30 changes: 15 additions & 15 deletions test/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type Input struct {
Method *string `yaml:"method,omitempty"`
Data *string `yaml:"data,omitempty"`
SaveCookie *bool `yaml:"save_cookie,omitempty"`
// Deprecated: replaced with NoAutocompleteHeaders
StopMagic *bool `yaml:"stop_magic"`
NoAutocompleteHeaders *bool `yaml:"no_autocomplete_headers"`
EncodedRequest string `yaml:"encoded_request,omitempty"`
RAWRequest string `yaml:"raw_request,omitempty"`
// Deprecated: replaced with AutocompleteHeaders
StopMagic *bool `yaml:"stop_magic"`
AutocompleteHeaders *bool `yaml:"no_autocomplete_headers"`
EncodedRequest string `yaml:"encoded_request,omitempty"`
RAWRequest string `yaml:"raw_request,omitempty"`
}

// Overrides represents the overridden inputs that have to be applied to tests
Expand All @@ -35,9 +35,9 @@ type Overrides struct {
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 NoAutocompleteHeaders
// Deprecated: replaced with AutocompleteHeaders
StopMagic *bool `yaml:"stop_magic" koanf:"stop_magic,omitempty"`
NoAutocompleteHeaders *bool `yaml:"no_autocomplete_headers" koanf:"no_autocomplete_headers,omitempty"`
AutocompleteHeaders *bool `yaml:"no_autocomplete_headers" koanf:"no_autocomplete_headers,omitempty"`
EncodedRequest *string `yaml:"encoded_request,omitempty" koanf:"encoded_request,omitempty"`
RAWRequest *string `yaml:"raw_request,omitempty" koanf:"raw_request,omitempty"`
OverrideEmptyHostHeader *bool `yaml:"override_empty_host_header,omitempty" koanf:"override_empty_host_header,omitempty"`
Expand Down Expand Up @@ -84,7 +84,7 @@ func ApplyInputOverrides(overrides *Overrides, input *Input) {
applySimpleOverrides(overrides, input)
applyDestAddrOverride(overrides, input)
applyHeadersOverride(overrides, input)
postProcessNoAutocompleteHeaders(overrides.NoAutocompleteHeaders, overrides.StopMagic, input)
postProcessAutocompleteHeaders(overrides.AutocompleteHeaders, overrides.StopMagic, input)
}

func applyDestAddrOverride(overrides *Overrides, input *Input) {
Expand Down Expand Up @@ -165,19 +165,19 @@ func postLoadStage(stage *Stage) {
}

func postLoadInput(input *Input) {
postProcessNoAutocompleteHeaders(input.NoAutocompleteHeaders, input.StopMagic, input)
postProcessAutocompleteHeaders(input.AutocompleteHeaders, input.StopMagic, input)
}

func postProcessNoAutocompleteHeaders(noAutocompleteHeaders *bool, stopMagic *bool, input *Input) {
noAutocompleteHeadersMissing := noAutocompleteHeaders == nil
func postProcessAutocompleteHeaders(autocompleteHeaders *bool, stopMagic *bool, input *Input) {
autocompleteHeadersMissing := autocompleteHeaders == nil
stopMagicMissing := stopMagic == nil
finalValue := false

if noAutocompleteHeadersMissing && !stopMagicMissing {
if autocompleteHeadersMissing && !stopMagicMissing {
finalValue = *stopMagic
} else if !noAutocompleteHeadersMissing {
finalValue = *noAutocompleteHeaders
} else if !autocompleteHeadersMissing {
finalValue = *autocompleteHeaders
}
input.NoAutocompleteHeaders = &finalValue
input.AutocompleteHeaders = &finalValue
input.StopMagic = &finalValue
}
60 changes: 30 additions & 30 deletions test/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestTypesTestSuite(t *testing.T) {
suite.Run(t, new(typesTestSuite))
}

var noAutocompleteHeadersDefaultYaml = `---
var autocompleteHeadersDefaultYaml = `---
meta:
author: "tester"
enabled: true
Expand Down Expand Up @@ -64,7 +64,7 @@ tests:
status: [200]
`

var noAutocompleteHeadersFalseYaml = `---
var autocompleteHeadersFalseYaml = `---
meta:
author: "tester"
enabled: true
Expand Down Expand Up @@ -117,7 +117,7 @@ tests:
status: [200]
`

var noAutocompleteHeadersTrueYaml = `---
var autocompleteHeadersTrueYaml = `---
meta:
author: "tester"
enabled: true
Expand Down Expand Up @@ -170,82 +170,82 @@ tests:
status: [200]
`

func (s *typesTestSuite) TestNoAutocompleteHeadersDefault_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersDefaultYaml))
func (s *typesTestSuite) TestAutocompleteHeadersDefault_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersDefaultYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[0].Stages[0].Stage.Input
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
s.False(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersDefault_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersDefaultYaml))
func (s *typesTestSuite) TestAutocompleteHeadersDefault_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersDefaultYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[1].Stages[0].Stage.Input
s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
s.True(*input.StopMagic)
}
func (s *typesTestSuite) TestNoAutocompleteHeadersDefault_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersDefaultYaml))
func (s *typesTestSuite) TestAutocompleteHeadersDefault_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersDefaultYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[2].Stages[0].Stage.Input
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
s.False(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersFalse_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersFalseYaml))
func (s *typesTestSuite) TestAutocompleteHeadersFalse_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersFalseYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[0].Stages[0].Stage.Input
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
s.False(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersFalse_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersFalseYaml))
func (s *typesTestSuite) TestAutocompleteHeadersFalse_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersFalseYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[1].Stages[0].Stage.Input
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
s.False(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersFalse_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersFalseYaml))
func (s *typesTestSuite) TestAutocompleteHeadersFalse_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersFalseYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[2].Stages[0].Stage.Input
s.False(*input.NoAutocompleteHeaders)
s.False(*input.AutocompleteHeaders)
s.False(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersTrue_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersTrueYaml))
func (s *typesTestSuite) TestAutocompleteHeadersTrue_StopMagicDefault() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersTrueYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[0].Stages[0].Stage.Input
s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
s.True(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersTrue_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersTrueYaml))
func (s *typesTestSuite) TestAutocompleteHeadersTrue_StopMagicTrue() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersTrueYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[1].Stages[0].Stage.Input
s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
s.True(*input.StopMagic)
}

func (s *typesTestSuite) TestNoAutocompleteHeadersTrue_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(noAutocompleteHeadersTrueYaml))
func (s *typesTestSuite) TestAutocompleteHeadersTrue_StopMagicFalse() {
test, err := GetTestFromYaml([]byte(autocompleteHeadersTrueYaml))
s.NoError(err, "Parsing YAML shouldn't fail")

input := test.Tests[2].Stages[0].Stage.Input
s.True(*input.NoAutocompleteHeaders)
s.True(*input.AutocompleteHeaders)
s.True(*input.StopMagic)
}

0 comments on commit c004ee7

Please sign in to comment.