github.com/hyperledger-labs/bdls@v2.1.1+incompatible/common/crypto/tlsgen/key_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package tlsgen
     8  
     9  import (
    10  	"crypto/tls"
    11  	"crypto/x509"
    12  	"encoding/pem"
    13  	"testing"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func TestLoadCert(t *testing.T) {
    19  	pair, err := newCertKeyPair(false, false, "", nil, nil)
    20  	assert.NoError(t, err)
    21  	assert.NotNil(t, pair)
    22  	tlsCertPair, err := tls.X509KeyPair(pair.Cert, pair.Key)
    23  	assert.NoError(t, err)
    24  	assert.NotNil(t, tlsCertPair)
    25  	block, _ := pem.Decode(pair.Cert)
    26  	cert, err := x509.ParseCertificate(block.Bytes)
    27  	assert.NoError(t, err)
    28  	assert.NotNil(t, cert)
    29  }