vclib: Modify x509.UnknownAuthorityError unwrap check

Modify unwrap error utility to make it work with go1.20
This version of Go introduces a new layer of wrapping via
a new error type. The commit accounts for that while being
compatible with go1.19

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
This commit is contained in:
Madhav Jivrajani 2023-01-06 14:11:20 +05:30
parent e15cdb3513
commit c31cc5ec46

View File

@ -21,6 +21,7 @@ import (
"crypto/sha1"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net/http"
@ -187,12 +188,9 @@ func verifyWrappedX509UnkownAuthorityErr(t *testing.T, err error) {
if !ok {
t.Fatalf("Expected to receive an url.Error, got '%s' (%#v)", err.Error(), err)
}
x509Err, ok := urlErr.Err.(x509.UnknownAuthorityError)
if !ok {
t.Fatalf("Expected to receive a wrapped x509.UnknownAuthorityError, got: '%s' (%#v)", urlErr.Error(), urlErr)
}
if msg := x509Err.Error(); msg != "x509: certificate signed by unknown authority" {
t.Fatalf("Expected 'signed by unknown authority' error, got: '%s'", msg)
var x509err x509.UnknownAuthorityError
if !errors.As(urlErr.Err, &x509err) {
t.Fatalf("Expected to receive a wrapped x509.UnknownAuthorityError, got: '%s' (%#v)", urlErr.Err.Error(), urlErr.Err)
}
}