diff --git a/test/integration/e2e/end_to_end.go b/test/integration/e2e/end_to_end.go index 992fd7f7ba..00bebc859e 100644 --- a/test/integration/e2e/end_to_end.go +++ b/test/integration/e2e/end_to_end.go @@ -48,6 +48,11 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option) } defer sdk.Close() + // Delete all private keys from the crypto suite store + // and users from the user store at the end + integration.CleanupUserData(t, sdk) + defer integration.CleanupUserData(t, sdk) + //clientContext allows creation of transactions using the supplied identity as the credential. clientContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(ordererOrgName)) diff --git a/test/integration/e2e/no_orderer_config.go b/test/integration/e2e/no_orderer_config.go index 5b503dc06f..010a8459cd 100644 --- a/test/integration/e2e/no_orderer_config.go +++ b/test/integration/e2e/no_orderer_config.go @@ -32,6 +32,11 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts } defer sdk.Close() + // Delete all private keys from the crypto suite store + // and users from the user store at the end + integration.CleanupUserData(t, sdk) + defer integration.CleanupUserData(t, sdk) + // ************ Test setup complete ************** // //TODO : discovery filter should be fixed diff --git a/test/integration/msp/enrollment_test.go b/test/integration/msp/enrollment_test.go index 0cd2e2da5a..7849be8c4d 100644 --- a/test/integration/msp/enrollment_test.go +++ b/test/integration/msp/enrollment_test.go @@ -33,11 +33,8 @@ func TestRegisterEnroll(t *testing.T) { // Delete all private keys from the crypto suite store // and users from the user store at the end - netConfig := sdk.Config() - keyStorePath := netConfig.KeyStorePath() - credentialStorePath := netConfig.CredentialStorePath() - defer integration.CleanupTestPath(t, keyStorePath) - defer integration.CleanupTestPath(t, credentialStorePath) + integration.CleanupUserData(t, sdk) + defer integration.CleanupUserData(t, sdk) ctxProvider := sdk.Context() diff --git a/test/integration/orgs/multiple_orgs_test.go b/test/integration/orgs/multiple_orgs_test.go index 1d140357d6..6326502c19 100644 --- a/test/integration/orgs/multiple_orgs_test.go +++ b/test/integration/orgs/multiple_orgs_test.go @@ -63,6 +63,11 @@ func TestOrgsEndToEnd(t *testing.T) { } defer sdk.Close() + // Delete all private keys from the crypto suite store + // and users from the user store at the end + integration.CleanupUserData(t, sdk) + defer integration.CleanupUserData(t, sdk) + expectedValue := testWithOrg1(t, sdk) expectedValue = testWithOrg2(t, expectedValue) verifyWithOrg1(t, sdk, expectedValue) diff --git a/test/integration/revoked/revoked_peer_test.go b/test/integration/revoked/revoked_peer_test.go index e03fddecf9..2a8615ab45 100644 --- a/test/integration/revoked/revoked_peer_test.go +++ b/test/integration/revoked/revoked_peer_test.go @@ -53,6 +53,11 @@ func TestRevokedPeer(t *testing.T) { } defer sdk.Close() + // Delete all private keys from the crypto suite store + // and users from the user store at the end + integration.CleanupUserData(t, sdk) + defer integration.CleanupUserData(t, sdk) + //prepare contexts ordererClientContext := sdk.Context(fabsdk.WithUser(ordererAdminUser), fabsdk.WithOrg(ordererOrgName)) org1AdminClientContext := sdk.Context(fabsdk.WithUser(org1AdminUser), fabsdk.WithOrg(org1)) diff --git a/test/integration/sdk/main_test.go b/test/integration/sdk/main_test.go index 66671a73cd..35bace69c0 100644 --- a/test/integration/sdk/main_test.go +++ b/test/integration/sdk/main_test.go @@ -42,6 +42,10 @@ func setup() { panic(fmt.Sprintf("Failed to create new SDK: %s", err)) } + // Delete all private keys from the crypto suite store + // and users from the user store + integration.CleanupUserData(nil, sdk) + if err := testSetup.Initialize(sdk); err != nil { panic(err.Error()) } @@ -57,5 +61,6 @@ func setup() { } func teardown() { + integration.CleanupUserData(nil, mainSDK) mainSDK.Close() } diff --git a/test/integration/utils.go b/test/integration/utils.go index c9b0cbfa1c..ed4460d883 100644 --- a/test/integration/utils.go +++ b/test/integration/utils.go @@ -12,6 +12,8 @@ import ( "testing" "time" + "fmt" + "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" @@ -159,6 +161,17 @@ func HasPeerJoinedChannel(client *resmgmt.Client, target string, channel string) func CleanupTestPath(t *testing.T, storePath string) { err := os.RemoveAll(storePath) if err != nil { + if t == nil { + panic(fmt.Sprintf("Cleaning up directory '%s' failed: %v", storePath, err)) + } t.Fatalf("Cleaning up directory '%s' failed: %v", storePath, err) } } + +func CleanupUserData(t *testing.T, sdk *fabsdk.FabricSDK) { + netConfig := sdk.Config() + keyStorePath := netConfig.KeyStorePath() + credentialStorePath := netConfig.CredentialStorePath() + CleanupTestPath(t, keyStorePath) + CleanupTestPath(t, credentialStorePath) +}