Skip to content

Commit

Permalink
e2e/tests: harden ProxyBadGateway test to validate error message prop…
Browse files Browse the repository at this point in the history
…agation
  • Loading branch information
Choraden authored and mmatczuk committed Nov 9, 2023
1 parent f1c334d commit 4a91f5f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion e2e/tests/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,30 @@ func TestProxyBadGateway(t *testing.T) {
"httpbin:1",
}

var expectedErrorMessage string
switch {
case os.Getenv("FORWARDER_PROXY") != "":
expectedErrorMessage = forwarder.UpstreamProxyServiceName + " failed to connect to remote host"
case os.Getenv("FORWARDER_PAC") != "":
// Proxy name depends on the PAC file. Skip it for now.
expectedErrorMessage = "failed to connect to remote host"
default:
expectedErrorMessage = "forwarder failed to connect to remote host"
}

for _, scheme := range []string{"http", "https"} {
for _, h := range hosts {
newClient(t, scheme+"://"+h).GET("/status/200").ExpectStatus(http.StatusBadGateway)
t.Run(scheme+"_"+h, func(t *testing.T) {
res := newClient(t, scheme+"://"+h).GET("/status/200")
res.ExpectStatus(http.StatusBadGateway)

// Check if the error message is correctly propagated to the client.
// Especially when several proxies are chained.
// FIXME(hg): When HTTPS CONNECT request fails it does not propagate error message - HTTP client does not return it.
if scheme == "http" && !strings.Contains(string(res.Body), expectedErrorMessage) {
t.Fatalf("Expected valid error message, got %s", res.Body)
}
})
}
}
}
Expand Down

0 comments on commit 4a91f5f

Please sign in to comment.