github.com/hxx258456/fabric-ca-gm@v0.0.3-0.20221111064038-a268ad7e3a37/internal/pkg/util/configurebccsp_test.go (about)

     1  //go:build pkcs11
     2  // +build pkcs11
     3  
     4  /*
     5  Copyright IBM Corp. All Rights Reserved.
     6  
     7  SPDX-License-Identifier: Apache-2.0
     8  */
     9  
    10  package util
    11  
    12  import (
    13  	"io/ioutil"
    14  	"os"
    15  	"testing"
    16  
    17  	"github.com/hxx258456/fabric-gm/bccsp/factory"
    18  	"github.com/hxx258456/fabric-gm/bccsp/pkcs11"
    19  	"github.com/stretchr/testify/assert"
    20  )
    21  
    22  func TestConfigureBCCSP(t *testing.T) {
    23  	mspDir, err := ioutil.TempDir("", "util-bccsp")
    24  	assert.NoError(t, err)
    25  	defer os.RemoveAll(mspDir)
    26  
    27  	lib, pin, label := pkcs11.FindPKCS11Lib()
    28  	opts := &factory.FactoryOpts{
    29  		ProviderName: "PKCS11",
    30  		Pkcs11Opts: &pkcs11.PKCS11Opts{
    31  			SecLevel:   256,
    32  			HashFamily: "SHA2",
    33  			Library:    lib,
    34  			Label:      label,
    35  			Pin:        pin,
    36  		},
    37  	}
    38  
    39  	err = ConfigureBCCSP(&opts, mspDir, "")
    40  	assert.NoError(t, err, "bccsp initialization failed")
    41  }
    42  
    43  func TestSanitizePKCS11Opts(t *testing.T) {
    44  	lib, pin, label := pkcs11.FindPKCS11Lib()
    45  	opts := pkcs11.PKCS11Opts{
    46  		SecLevel:   256,
    47  		HashFamily: "SHA2",
    48  		Library:    lib,
    49  		Label:      label,
    50  		Pin:        pin,
    51  	}
    52  	p11opts := sanitizePKCS11Opts(opts)
    53  	assert.Equal(t, p11opts.Label, "******")
    54  	assert.Equal(t, p11opts.Pin, "******")
    55  }