8000 fix: no longer negate `autocomplete_headers` option by theseion · Pull Request #176 · coreruleset/go-ftw · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: no longer negate autocomplete_headers option #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,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.AutocompleteHeaders)
req = ftwhttp.NewRawRequest(raw, *testInput.AutocompleteHeaders)
} else {
rline := &ftwhttp.RequestLine{
Method: testInput.GetMethod(),
Expand All @@ -373,7 +373,7 @@ func getRequestFromTest(testInput test.Input) *ftwhttp.Request {
data := testInput.ParseData()
// create a new request
req = ftwhttp.NewRequest(rline, testInput.Headers,
data, !*testInput.AutocompleteHeaders)
data, *testInput.AutocompleteHeaders)

}
return req
Expand Down
97 changes: 96 additions & 1 deletion runner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ func (s *runTestSuite) BeforeTest(_ string, name string) {
}
// get tests template from file
tmpl, err := template.ParseFiles(fmt.Sprintf("testdata/%s.yaml", name))
s.Require().NoError(err)
if err != nil {
log.Info().Msgf("No test data found for test %s, assuming that's ok", name)
return
}

// create a temporary file to hold the test
testFileContents, err := os.CreateTemp("testdata", "mock-test-*.yaml")
s.Require().NoError(err, "cannot create temporary file")
Expand Down Expand Up @@ -347,3 +351,94 @@ func (s *runTestSuite) TestIgnoredTestsRun() {
s.Require().NoError(err)
s.Equal(res.Stats.TotalFailed(), 1, "Oops, test run failed!")
}

func (s *runTestSuite) TestGetRequestFromTestWithAutocompleteHeaders() {
boolean := true
method := "POST"
input := test.Input{
AutocompleteHeaders: &boolean,
Method: &method,
Headers: ftwhttp.Header{},
DestAddr: &s.dest.DestAddr,
Port: &s.dest.Port,
Protocol: &s.dest.Protocol,
}
request := getRequestFromTest(input)

client, err := ftwhttp.NewClient(ftwhttp.NewClientConfig())
s.Require().NoError(err)

dest := &ftwhttp.Destination{
DestAddr: input.GetDestAddr(),
Port: input.GetPort(),
Protocol: input.GetProtocol(),
}
err = client.NewConnection(*dest)
s.Require().NoError(err)
_, err = client.Do(*request)
s.Require().NoError(err)

s.Equal("0", request.Headers().Get("Content-Length"), "Autocompletion should add 'Content-Length' header to POST requests")
s.Equal("close", request.Headers().Get("Connection"), "Autocompletion should add 'Connection: close' header")
}

func (s *runTestSuite) TestGetRawRequestFromTestWithAutocompleteHeaders() {
boolean := true
method := "POST"
input := test.Input{
AutocompleteHeaders: &boolean,
Method: &method,
Headers: ftwhttp.Header{},
DestAddr: &s.dest.DestAddr,
Port: &s.dest.Port,
Protocol: &s.dest.Protocol,
RAWRequest: "POST / HTTP/1.1\r\nHost: localhost\r\nUser-Agent: test\r\n\r\n",
}
request := getRequestFromTest(input)

client, err := ftwhttp.NewClient(ftwhttp.NewClientConfig())
s.Require().NoError(err)

dest := &ftwhttp.Destination{
DestAddr: input.GetDestAddr(),
Port: input.GetPort(),
Protocol: input.GetProtocol(),
}
err = client.NewConnection(*dest)
s.Require().NoError(err)
_, err = client.Do(*request)
s.Require().NoError(err)

s.Equal("", request.Headers().Get("Content-Length"), "Raw requests should not be modified")
s.Equal("", request.Headers().Get("Connection"), "Raw requests should not be modified")
}

func (s *runTestSuite) TestGetRequestFromTestWithoutAutocompleteHeaders() {
boolean := false
method := "POST"
input := test.Input{
AutocompleteHeaders: &boolean,
Method: &method,
Headers: ftwhttp.Header{},
DestAddr: &s.dest.DestAddr,
Port: &s.dest.Port,
Protocol: &s.dest.Protocol,
}
request := getRequestFromTest(input)

client, err := ftwhttp.NewClient(ftwhttp.NewClientConfig())
s.Require().NoError(err)

dest := &ftwhttp.Destination{
DestAddr: input.GetDestAddr(),
Port: input.GetPort(),
Protocol: input.GetProtocol(),
}
err = client.NewConnection(*dest)
s.Require().NoError(err)
_, err = client.Do(*request)
s.Require().NoError(err)

s.Equal("", request.Headers().Get("Content-Length"), "Autocompletion is disabled")
s.Equal("", request.Headers().Get("Connection"), "Autocompletion is disabled")
}
0