github.com/blend/go-sdk@v1.20220411.3/certutil/client_config_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package certutil
     9  
    10  import (
    11  	"bytes"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  	"github.com/blend/go-sdk/uuid"
    16  )
    17  
    18  func TestNewClientConfig(t *testing.T) {
    19  	t.Parallel()
    20  
    21  	assert := assert.New(t)
    22  
    23  	caKeyPair := KeyPair{
    24  		Cert: string(caCertLiteral),
    25  		Key:  string(caKeyLiteral),
    26  	}
    27  	ca, err := NewCertBundle(caKeyPair)
    28  	assert.Nil(err)
    29  
    30  	uid := uuid.V4().String()
    31  	client, err := CreateClient(uid, ca)
    32  	assert.Nil(err)
    33  
    34  	caPEM := new(bytes.Buffer)
    35  	assert.Nil(ca.WriteCertPem(caPEM))
    36  	clientCertPEM := new(bytes.Buffer)
    37  	assert.Nil(client.WriteCertPem(clientCertPEM))
    38  	clientKeyPEM := new(bytes.Buffer)
    39  	assert.Nil(client.WriteKeyPem(clientKeyPEM))
    40  
    41  	tlsConfig, err := NewClientTLSConfig(
    42  		KeyPair{Cert: clientCertPEM.String(), Key: clientKeyPEM.String()},
    43  		[]KeyPair{{Cert: caPEM.String()}},
    44  	)
    45  
    46  	assert.Nil(err)
    47  	assert.NotNil(tlsConfig)
    48  }