Skip to content

Commit f003159

Browse files
Fixes #292 (#293)
* Fix flaky test * Update transport/httpcommon/diag.go Co-authored-by: Mauri de Souza Meneguzzo <[email protected]> --------- Co-authored-by: Mauri de Souza Meneguzzo <[email protected]>
1 parent 1178069 commit f003159

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

transport/httpcommon/diag.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"net/http/httptrace"
3131
"net/textproto"
3232
"net/url"
33+
"strings"
3334

3435
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
3536
)
@@ -181,15 +182,19 @@ func diagError(err error) string {
181182
// keep unwrapping to url.Error as the last error as other failures can be embedded in a url.Error
182183
// Can detect if an HTTPS request is made to an HTTP server
183184
var uErr *url.Error
185+
184186
if errors.As(err, &uErr) {
185-
switch uErr.Err.Error() {
186-
case "http: server gave HTTP response to HTTPS client":
187+
errString := uErr.Err.Error()
188+
if strings.Contains(errString, "http: server gave HTTP response to HTTPS client") {
187189
return fmt.Sprintf("%v: caused by using HTTPS schema on HTTP server.", uErr)
188-
case "remote error: tls: certificate required":
189-
return fmt.Sprintf("%v: caused by missing mTLS client cert.", uErr)
190-
case "remote error: tls: expired certificate":
190+
}
191+
if strings.Contains(errString, "remote error: tls: certificate required") {
192+
return fmt.Sprintf("%v: caused by missing mTLS client cert.", uErr)
193+
}
194+
if strings.Contains(errString, "remote error: tls: expired certificate") {
191195
return fmt.Sprintf("%v: caused by expired mTLS client cert.", uErr)
192-
case "remote error: tls: bad certificate":
196+
}
197+
if strings.Contains(errString, "remote error: tls: bad certificate") {
193198
return fmt.Sprintf("%v: caused by invalid mTLS client cert, does the server trust the CA used for the client cert?.", uErr)
194199
}
195200
}

0 commit comments

Comments
 (0)