github.com/canhui/fabric_ca2_2@v2.0.0-alpha+incompatible/lib/client/credential/x509/signer_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package x509_test 8 9 import ( 10 "path/filepath" 11 "testing" 12 13 . "github.com/hyperledger/fabric-ca/lib/client/credential/x509" 14 "github.com/hyperledger/fabric-ca/util" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestNewSignerError(t *testing.T) { 19 _, err := NewSigner(nil, []byte{}) 20 assert.Error(t, err, "NewSigner should return an error if cert byte array is empty") 21 } 22 23 func TestNewSigner(t *testing.T) { 24 certBytes, err := util.ReadFile(filepath.Join(testDataDir, "ec256-1-cert.pem")) 25 if err != nil { 26 t.Fatalf("Failed to read the cert: %s", err.Error()) 27 } 28 signer, err := NewSigner(nil, certBytes) 29 assert.NoError(t, err, "NewSigner should not return an error if cert bytes are valid") 30 31 assert.NotNil(t, signer.GetX509Cert()) 32 assert.Nil(t, signer.Key()) 33 assert.NotEmpty(t, signer.GetName()) 34 _, err = signer.Attributes() 35 assert.NoError(t, err) 36 }