mirror of
https://github.com/openbsd/src.git
synced 2024-12-22 16:42:56 -08:00
Add regress coverage for tls_peer_cert_common_name()
This commit is contained in:
parent
5ad0d35887
commit
7f9db3f573
@ -202,6 +202,15 @@ func (t *TLS) PeerCertIssuer() (string, error) {
|
||||
return C.GoString(issuer), nil
|
||||
}
|
||||
|
||||
// PeerCertCommonName returns the common name of the peer certificate.
|
||||
func (t *TLS) PeerCertCommonName() (string, error) {
|
||||
commonName := C.tls_peer_cert_common_name(t.ctx)
|
||||
if commonName == nil {
|
||||
return "", errors.New("no peer cert common name returned")
|
||||
}
|
||||
return C.GoString(commonName), nil
|
||||
}
|
||||
|
||||
// PeerCertSubject returns the subject of the peer certificate.
|
||||
func (t *TLS) PeerCertSubject() (string, error) {
|
||||
subject := C.tls_peer_cert_subject(t.ctx)
|
||||
|
@ -418,6 +418,9 @@ func TestTLSInfo(t *testing.T) {
|
||||
if _, err := tls.PeerCertSubject(); err == nil {
|
||||
t.Error("PeerCertSubject() returned nil error, want error")
|
||||
}
|
||||
if _, err := tls.PeerCertCommonName(); err == nil {
|
||||
t.Error("PeerCertCommonName() returned nil error, want error")
|
||||
}
|
||||
if _, err := tls.PeerCertHash(); err == nil {
|
||||
t.Error("PeerCertHash() returned nil error, want error")
|
||||
}
|
||||
@ -468,6 +471,11 @@ func TestTLSInfo(t *testing.T) {
|
||||
} else {
|
||||
t.Logf("Subject: %v", subject)
|
||||
}
|
||||
if commonName, err := tls.PeerCertCommonName(); err != nil {
|
||||
t.Errorf("PeerCertCommonName() returned error: %v", err)
|
||||
} else {
|
||||
t.Logf("Subject: %v", commonName)
|
||||
}
|
||||
if hash, err := tls.PeerCertHash(); err != nil {
|
||||
t.Errorf("PeerCertHash() returned error: %v", err)
|
||||
} else if hash != certHash {
|
||||
|
Loading…
Reference in New Issue
Block a user