Skip to content

Commit

Permalink
fix: use host header for markandflush
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <[email protected]>
  • Loading branch information
fzipi committed Nov 27, 2024
1 parent d2d7c18 commit 5c2a285
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package runner
import (
"errors"
"fmt"
"net"
"time"

schema "github.com/coreruleset/ftw-tests-schema/v2/types"
Expand Down Expand Up @@ -166,8 +165,14 @@ func RunStage(runContext *TestRunContext, ftwCheck *check.FTWCheck, testCase sch
Protocol: testInput.GetProtocol(),
}

// Get the host header from the test input
host := testInput.GetHeaders().Get("Host")
if host == "" {
host = "localhost"
}

if notRunningInCloudMode(ftwCheck) {
startMarker, err := markAndFlush(runContext, dest, stageID)
startMarker, err := markAndFlush(runContext, host, dest, stageID)
if err != nil && !expectErr {
return fmt.Errorf("failed to find start marker: %w", err)
}
Expand All @@ -191,7 +196,7 @@ func RunStage(runContext *TestRunContext, ftwCheck *check.FTWCheck, testCase sch
}

if notRunningInCloudMode(ftwCheck) {
endMarker, err := markAndFlush(runContext, dest, stageID)
endMarker, err := markAndFlush(runContext, host, dest, stageID)
if err != nil && !expectErr {
return fmt.Errorf("failed to find end marker: %w", err)

Expand Down Expand Up @@ -221,9 +226,7 @@ func RunStage(runContext *TestRunContext, ftwCheck *check.FTWCheck, testCase sch
return nil
}

func markAndFlush(runContext *TestRunContext, dest *ftwhttp.Destination, stageID string) ([]byte, error) {
host := "localhost"

func markAndFlush(runContext *TestRunContext, host string, dest *ftwhttp.Destination, stageID string) ([]byte, error) {
rline := &ftwhttp.RequestLine{
Method: "GET",
// Use the `/status` endpoint of `httpbin` (http://httpbingo.org), if possible,
Expand All @@ -233,18 +236,6 @@ func markAndFlush(runContext *TestRunContext, dest *ftwhttp.Destination, stageID
Version: "HTTP/1.1",
}

// check if destination host is an alias for localhost
addrs, err := net.LookupHost(dest.DestAddr)
if err != nil {
return nil, fmt.Errorf("ftw/run: can't resolve destination %+v: %w", dest, err)
}
// we only take the first IP address
if net.ParseIP(addrs[0]).IsLoopback() {
// With multiple locations / virtual hosts, logs can be written to different files,
// in which case the internal requests for marking and flushing must end up in the
// same log file (host name match).
host = dest.DestAddr
}
headers := &ftwhttp.Header{
"Accept": "*/*",
"User-Agent": "go-ftw test agent",
Expand Down

0 comments on commit 5c2a285

Please sign in to comment.