Skip to content

Commit

Permalink
Merge pull request #5 from coreruleset/current_goftw_schema
Browse files Browse the repository at this point in the history
Schema updated to current go-ftw (Adds AutocompleteHeaders, bools to pointers)
  • Loading branch information
theseion authored Nov 11, 2023
2 parents e10e7a8 + d4a5fe8 commit 93e883a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
47 changes: 30 additions & 17 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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),
}
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -290,5 +303,5 @@ type Output struct {
// examples:
// - name: ExpectError
// value: false
ExpectError bool `yaml:"expect_error,omitempty"`
ExpectError *bool `yaml:"expect_error,omitempty"`
}
7 changes: 4 additions & 3 deletions types/types_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package types

import (
"github.com/goccy/go-yaml"
"testing"

"github.com/goccy/go-yaml"
)

var testInput = `---
Expand Down Expand Up @@ -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.",
},
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 93e883a

Please sign in to comment.