github.com/true-sqn/fabric@v2.1.1+incompatible/bccsp/pkcs11/ecdsakey_test.go (about)

     1  // +build pkcs11
     2  
     3  /*
     4  Copyright IBM Corp. All Rights Reserved.
     5  
     6  SPDX-License-Identifier: Apache-2.0
     7  */
     8  
     9  package pkcs11
    10  
    11  import (
    12  	"crypto/x509"
    13  	"testing"
    14  
    15  	"github.com/hyperledger/fabric/bccsp"
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestX509PublicKeyImportOptsKeyImporter(t *testing.T) {
    20  	if testing.Short() {
    21  		t.Skip("Skipping TestX509PublicKeyImportOptsKeyImporter")
    22  	}
    23  	ki := currentBCCSP
    24  
    25  	_, err := ki.KeyImport("Hello World", &bccsp.X509PublicKeyImportOpts{})
    26  	assert.Error(t, err)
    27  	assert.Contains(t, err.Error(), "[X509PublicKeyImportOpts] Invalid raw material. Expected *x509.Certificate")
    28  
    29  	_, err = ki.KeyImport(nil, &bccsp.X509PublicKeyImportOpts{})
    30  	assert.Error(t, err)
    31  	assert.Contains(t, err.Error(), "Invalid raw. Cannot be nil")
    32  
    33  	cert := &x509.Certificate{}
    34  	cert.PublicKey = "Hello world"
    35  	_, err = ki.KeyImport(cert, &bccsp.X509PublicKeyImportOpts{})
    36  	assert.Error(t, err)
    37  	assert.Contains(t, err.Error(), "Certificate's public key type not recognized. Supported keys: [ECDSA]")
    38  }