From 3c41613e2f09dd4206af82578ec17aed960aa88a Mon Sep 17 00:00:00 2001 From: Matteo Pace Date: Sat, 11 Nov 2023 11:05:36 +0100 Subject: [PATCH 1/2] moves bools to pointers, adds AutocompleteHeaders --- types/types.go | 47 +++++++++++++++++++++++++++++---------------- types/types_test.go | 7 ++++--- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/types/types.go b/types/types.go index 45385a6..51f3e69 100644 --- a/types/types.go +++ b/types/types.go @@ -9,6 +9,10 @@ func intPtr(i int) *int { return &i } +func boolPtr(b bool) *bool { + return &b +} + func strPtr(s string) *string { return &s } @@ -29,24 +33,25 @@ var ( "Accept": "*/*", } exampleInput = Input{ - DestAddr: strPtr("192.168.0.1"), - Port: intPtr(8080), - Protocol: strPtr("http"), - URI: strPtr("/test"), - Version: strPtr("HTTP/1.1"), - Headers: exampleHeaders, - Method: strPtr("REPORT"), - Data: nil, - EncodedRequest: "TXkgRGF0YQo=", - SaveCookie: false, - StopMagic: false, + DestAddr: strPtr("192.168.0.1"), + Port: intPtr(8080), + Protocol: strPtr("http"), + URI: strPtr("/test"), + Version: strPtr("HTTP/1.1"), + Headers: exampleHeaders, + Method: strPtr("REPORT"), + Data: nil, + EncodedRequest: "TXkgRGF0YQo=", + SaveCookie: boolPtr(false), + StopMagic: boolPtr(true), + AutocompleteHeaders: boolPtr(false), } exampleOutput = Output{ Status: []int{200}, ResponseContains: "", LogContains: "nothing", NoLogContains: "", - ExpectError: true, + ExpectError: boolPtr(true), } ) @@ -90,7 +95,7 @@ type Meta struct { // examples: // - name: Enabled // value: false - Enabled bool `yaml:"enabled,omitempty"` + Enabled *bool `yaml:"enabled,omitempty"` // description: | // Name is the name of the tests contained in this file. @@ -230,14 +235,22 @@ type Input struct { // examples: // - name: SaveCookie // value: 80 - SaveCookie bool `yaml:"save_cookie,omitempty" koanf:"save_cookie,omitempty"` + SaveCookie *bool `yaml:"save_cookie,omitempty" koanf:"save_cookie,omitempty"` + + // description: | + // StopMagic is deprecated. + // examples: + // - name: StopMagic + // value: false + StopMagic *bool `yaml:"stop_magic" koanf:"stop_magic,omitempty"` // description: | - // StopMagic blocks the test framework to automatically fill the request with Content-Type and Connection headers. + // AutocompleteHeaders allows the test framework to automatically fill the request with Content-Type and Connection headers. + // Defaults to true. // examples: // - name: StopMagic // value: false - StopMagic bool `yaml:"stop_magic" koanf:"stop_magic,omitempty"` + AutocompleteHeaders *bool `yaml:"autocomplete_headers" koanf:"autocomplete_headers,omitempty"` // description: | // EncodedRequest will take a base64 encoded string that will be decoded and sent through as the request. @@ -290,5 +303,5 @@ type Output struct { // examples: // - name: ExpectError // value: false - ExpectError bool `yaml:"expect_error,omitempty"` + ExpectError *bool `yaml:"expect_error,omitempty"` } diff --git a/types/types_test.go b/types/types_test.go index 7e01f1f..cf09e27 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -1,8 +1,9 @@ package types import ( - "github.com/goccy/go-yaml" "testing" + + "github.com/goccy/go-yaml" ) var testInput = `--- @@ -60,7 +61,7 @@ var ftwTest = &FTWTest{ FileName: "testYaml.yaml", Meta: Meta{ Author: "ftw-tests-schema", - Enabled: true, + Enabled: boolPtr(true), Name: "testYaml", Description: "Simple YAML to test that the schema is working.", }, @@ -125,7 +126,7 @@ func TestUnmarshalFTWTest(t *testing.T) { if ftw.Meta.Author != ftwTest.Meta.Author { t.Errorf("Author: %v != %v", ftw.Meta.Author, ftwTest.Meta.Author) } - if ftw.Meta.Enabled != ftwTest.Meta.Enabled { + if *ftw.Meta.Enabled != *ftwTest.Meta.Enabled { t.Errorf("Enabled: %v != %v", ftw.Meta.Enabled, ftwTest.Meta.Enabled) } if ftw.Meta.Name != ftwTest.Meta.Name { From d4a5fe82cfe8050ef4fbae5590c14a7a49ddef5b Mon Sep 17 00:00:00 2001 From: Matteo Pace Date: Sat, 11 Nov 2023 20:37:50 +0100 Subject: [PATCH 2/2] Adds comment about goccy version --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 8d9dc47..3cc4b1e 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21 require github.com/magefile/mage v1.15.0 require ( + // Goccy verion is expected to stay at 1.9.2 (Same of go-ftw) because of https://github.com/goccy/go-yaml/issues/325 github.com/goccy/go-yaml v1.9.2 github.com/projectdiscovery/yamldoc-go v1.0.4 )