github.com/hyperledger-labs/bdls@v2.1.1+incompatible/core/chaincode/accesscontrol/mapper_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package accesscontrol 8 9 import ( 10 "testing" 11 "time" 12 13 "github.com/hyperledger/fabric/bccsp" 14 "github.com/hyperledger/fabric/bccsp/sw" 15 "github.com/hyperledger/fabric/common/crypto/tlsgen" 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestPurge(t *testing.T) { 20 ca, _ := tlsgen.NewCA() 21 backupTTL := ttl 22 defer func() { 23 ttl = backupTTL 24 }() 25 ttl = time.Second 26 m := newCertMapper(ca.NewClientCertKeyPair) 27 k, err := m.genCert("A") 28 assert.NoError(t, err) 29 30 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 31 assert.NoError(t, err) 32 33 hash, err := cryptoProvider.Hash(k.TLSCert.Raw, &bccsp.SHA256Opts{}) 34 assert.NoError(t, err) 35 assert.Equal(t, "A", m.lookup(certHash(hash))) 36 time.Sleep(time.Second * 3) 37 assert.Empty(t, m.lookup(certHash(hash))) 38 }