github.com/hyperledger/fabric-ca@v2.0.0-alpha.0.20201120210307-7b4f34729db1+incompatible/internal/pkg/util/configurebccsp_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 util 10 11 import ( 12 "testing" 13 14 "github.com/hyperledger/fabric/bccsp/factory" 15 "github.com/hyperledger/fabric/bccsp/pkcs11" 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestConfigureBCCSP(t *testing.T) { 20 mspDir := "msp" 21 lib, pin, label := pkcs11.FindPKCS11Lib() 22 opts := &factory.FactoryOpts{ 23 ProviderName: "PKCS11", 24 Pkcs11Opts: &pkcs11.PKCS11Opts{ 25 SecLevel: 256, 26 HashFamily: "SHA2", 27 Library: lib, 28 Label: label, 29 Pin: pin, 30 }, 31 } 32 33 err := ConfigureBCCSP(&opts, mspDir, "") 34 if err != nil { 35 t.Fatalf("Failed initialization 1 of BCCSP: %s", err) 36 } 37 } 38 39 func TestSanitizePKCS11Opts(t *testing.T) { 40 lib, pin, label := pkcs11.FindPKCS11Lib() 41 opts := pkcs11.PKCS11Opts{ 42 SecLevel: 256, 43 HashFamily: "SHA2", 44 Library: lib, 45 Label: label, 46 Pin: pin, 47 } 48 p11opts := sanitizePKCS11Opts(opts) 49 assert.Equal(t, p11opts.Label, "******") 50 assert.Equal(t, p11opts.Pin, "******") 51 }