Simplify condition for certificate error

Instead of two `expired certificate` and `bad certificate` comparisons, we can just check for `certificate` in error output. This satisfies us when checking there is something wrong with the certificate.

Co-authored-by: Scott Blum <dragonsinth@gmail.com>
This commit is contained in:
Valters Jansons 2023-08-31 18:22:48 +03:00 committed by GitHub
parent a418397a77
commit 744827a432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 4 deletions

View File

@ -213,10 +213,7 @@ func TestBrokenTLS_ClientHasExpiredCert(t *testing.T) {
e.Close() e.Close()
t.Fatal("expecting TLS failure setting up server and client") t.Fatal("expecting TLS failure setting up server and client")
} }
// Go 1.21 uses "expired certificate" in the error message. if !strings.Contains(err.Error(), "certificate") {
// Older Go versions use a simpler "bad certificate".
// `runtime.Version()` exists, but we don't want to parse a version String for comparison.
if !strings.Contains(err.Error(), "expired certificate") && !strings.Contains(err.Error(), "bad certificate") {
t.Fatalf("expecting TLS certificate error, got: %v", err) t.Fatalf("expecting TLS certificate error, got: %v", err)
} }
} }