Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 32bd578

Browse files
committed
[FAB-11040] Organize PKCS11 integration tests
This change seperates the PKCS11 tests into its own script. The folder is also moved below e2e as it is simply running the e2e test. Change-Id: Ibec4366cb58c21899100dded864d935583804f04 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent 7a65fa4 commit 32bd578

File tree

8 files changed

+128
-60
lines changed

8 files changed

+128
-60
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You're good to go, happy coding! Check out the examples for usage demonstrations
2626
- [Ledger Query Test](test/integration/sdk/ledger_queries_test.go): Basic example that uses SDK to query a channel's underlying ledger
2727
- [Multi Org Test](test/integration/orgs/multiple_orgs_test.go): An example that has multiple organisations involved in transaction
2828
- [Dynamic Endorser Selection](test/integration/sdk/sdk_provider_test.go): An example that uses dynamic endorser selection (based on chaincode policy)
29-
- [E2E PKCS11 Test](test/integration/pkcs11/e2e_test.go): E2E Test using a PKCS11 crypto suite and configuration
29+
- [E2E PKCS11 Test](test/integration/e2e/pkcs11/e2e_test.go): E2E Test using a PKCS11 crypto suite and configuration
3030
- [CLI](https://github.com/securekey/fabric-examples/tree/master/fabric-cli/): An example CLI for Fabric built with the Go SDK.
3131
- More examples needed!
3232

test/fixtures/dockerenv/docker-compose-pkcs11-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
- TEST_CHANGED_ONLY
2121
volumes:
2222
- ../../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
23-
command: bash -c "/opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/unit-pkcs11.sh && /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration.sh"
23+
command: bash -c "/opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/unit-pkcs11.sh && /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration-pkcs11.sh"
2424
depends_on:
2525
- org1ca1
2626
- org2ca1

test/integration/e2e/end_to_end.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package e2e
88

99
import (
10-
"path"
1110
"strconv"
11+
"strings"
1212
"testing"
1313
"time"
1414

@@ -18,16 +18,13 @@ import (
1818
"github.com/stretchr/testify/require"
1919

2020
"github.com/hyperledger/fabric-sdk-go/test/integration"
21-
"github.com/hyperledger/fabric-sdk-go/test/metadata"
2221
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
2322

2423
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
2524
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
2625

2726
mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
2827

29-
"strings"
30-
3128
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
3229
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
3330
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
@@ -189,7 +186,7 @@ func queryCC(client *channel.Client, t *testing.T, targetEndpoints ...string) []
189186
}
190187

191188
func createCC(t *testing.T, orgResMgmt *resmgmt.Client) {
192-
ccPkg, err := packager.NewCCPackage("github.com/example_cc", "../../fixtures/testdata")
189+
ccPkg, err := packager.NewCCPackage("github.com/example_cc", integration.GetDeployPath())
193190
if err != nil {
194191
t.Fatal(err)
195192
}
@@ -221,7 +218,7 @@ func createChannel(sdk *fabsdk.FabricSDK, t *testing.T, resMgmtClient *resmgmt.C
221218
t.Fatal(err)
222219
}
223220
req := resmgmt.SaveChannelRequest{ChannelID: channelID,
224-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
221+
ChannelConfigPath: integration.GetChannelConfigPath("mychannel.tx"),
225222
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
226223
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
227224
require.Nil(t, err, "error should be nil")

test/integration/e2e/end_to_end_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
"testing"
1111

1212
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
13+
"github.com/hyperledger/fabric-sdk-go/test/integration"
1314
)
1415

1516
func TestE2E(t *testing.T) {
16-
configPath := "../../fixtures/config/config_test.yaml"
17+
configPath := integration.GetConfigPath("config_test.yaml")
1718
//End to End testing
1819
Run(t, config.FromFile(configPath))
1920

2021
//Using setup done set above by end to end test, run below test with new config which has no orderer config inside
21-
runWithNoOrdererConfig(t, config.FromFile("../../fixtures/config/config_test_no_orderer.yaml"))
22+
runWithNoOrdererConfig(t, config.FromFile(integration.GetConfigPath("config_test_no_orderer.yaml")))
2223
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
13+
"github.com/hyperledger/fabric-sdk-go/test/integration"
1314

1415
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
1516
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
@@ -18,10 +19,15 @@ import (
1819
"github.com/hyperledger/fabric-sdk-go/test/integration/e2e"
1920
)
2021

22+
const (
23+
// ConfigTestFile contains the path and filename of the config for integration tests
24+
ConfigTestFilename = "config_pkcs11_test.yaml"
25+
)
26+
2127
func TestE2E(t *testing.T) {
2228
// Create SDK setup for the integration tests
2329
e2e.Run(t,
24-
config.FromFile("../"+ConfigTestFile),
30+
config.FromFile(integration.GetConfigPath(ConfigTestFilename)),
2531
fabsdk.WithCorePkg(&CustomCryptoSuiteProviderFactory{}))
2632
}
2733

test/integration/pkcs11/env.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/scripts/integration-pkcs11.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
#
3+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Environment variables that affect this script:
8+
# GO_TESTFLAGS: Flags are added to the go test command.
9+
# GO_LDFLAGS: Flags are added to the go test command (example: -s).
10+
# TEST_CHANGED_ONLY: Boolean on whether to only run tests on changed packages.
11+
# TEST_RACE_CONDITIONS: Boolean on whether to test for race conditions.
12+
# FABRIC_SDKGO_CODELEVEL_TAG: Go tag that represents the fabric code target
13+
# FABRIC_SDKGO_CODELEVEL_VER: Version that represents the fabric code target
14+
# FABRIC_FIXTURE_VERSION: Version of fabric fixtures
15+
# FABRIC_CRYPTOCONFIG_VERSION: Version of cryptoconfig fixture to use
16+
# CONFIG_FILE: config file to use
17+
18+
set -e
19+
20+
GO_CMD="${GO_CMD:-go}"
21+
GOPATH="${GOPATH:-$HOME/go}"
22+
FABRIC_SDKGO_CODELEVEL_TAG="${FABRIC_SDKGO_CODELEVEL_TAG:-stable}"
23+
FABRIC_CRYPTOCONFIG_VERSION="${FABRIC_CRYPTOCONFIG_VERSION:-v1}"
24+
FABRIC_FIXTURE_VERSION="${FABRIC_FIXTURE_VERSION:-v1.2}"
25+
CONFIG_FILE="${CONFIG_FILE:-config_test.yaml}"
26+
TEST_LOCAL="${TEST_LOCAL:-false}"
27+
TEST_CHANGED_ONLY="${TEST_CHANGED_ONLY:-false}"
28+
TEST_RACE_CONDITIONS="${TEST_RACE_CONDITIONS:-true}"
29+
SCRIPT_DIR="$(dirname "$0")"
30+
# TODO: better default handling for FABRIC_CRYPTOCONFIG_VERSION
31+
32+
REPO="github.com/hyperledger/fabric-sdk-go"
33+
34+
source ${SCRIPT_DIR}/lib/find_packages.sh
35+
36+
echo "Running" $(basename "$0")
37+
38+
# Packages to include in test run
39+
PKGS=($(${GO_CMD} list ${REPO}/test/integration/... 2> /dev/null | \
40+
grep ^${REPO}/test/integration/e2e/pkcs11 | \
41+
tr '\n' ' '))
42+
43+
# Reduce tests to changed packages.
44+
if [ "${TEST_CHANGED_ONLY}" = true ]; then
45+
# findChangedFiles assumes that the working directory contains the repo; so change to the repo directory.
46+
PWD=$(pwd)
47+
cd "${GOPATH}/src/${REPO}"
48+
findChangedFiles
49+
cd ${PWD}
50+
51+
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)|ci.properties( |$)) ]]; then
52+
echo "Test scripts, fixtures or metadata changed - running all tests"
53+
else
54+
findChangedPackages
55+
filterExcludedPackages
56+
appendDepPackages
57+
PKGS=(${DEP_PKGS[@]})
58+
fi
59+
fi
60+
61+
RACEFLAG=""
62+
if [ "${TEST_RACE_CONDITIONS}" = true ]; then
63+
ARCH=$(uname -m)
64+
65+
if [ "${ARCH}" = "x86_64" ]; then
66+
echo "Enabling data race detection"
67+
RACEFLAG="-race"
68+
else
69+
echo "Data race detection not supported on ${ARCH}"
70+
fi
71+
fi
72+
73+
if [ ${#PKGS[@]} -eq 0 ]; then
74+
echo "Skipping integration tests since no packages were changed"
75+
exit 0
76+
fi
77+
78+
#Add entry here below for your key to be imported into softhsm
79+
declare -a PRIVATE_KEYS=(
80+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/config/mutual_tls/client_sdk_go-key.pem"
81+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore/f4aa194b12d13d7c2b7b275a7115af5e6f728e11710716f2c754df4587891511_sk"
82+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/ce142124e13093a3e13bc4708b0f2b26e1d4d2ea4d4cc59942790bfc0f3bcc6d_sk"
83+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/abbe8ee0f86c227b1917d208921497603d2ff28f4ba8e902d703744c4a6fa7b7_sk"
84+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/371ea01078b18f3b92c1fc8233dfa8d209d882ae40aeff4defd118ba9d572a15_sk"
85+
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/7777a174c9fe40ab5abe33199a4fe82f1e0a7c45715e395e73a78cc3480d0021_sk"
86+
)
87+
88+
GO_SRC=/opt/gopath/src
89+
for i in "${PRIVATE_KEYS[@]}"
90+
do
91+
echo "Importing key : ${GO_SRC}/${i}"
92+
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in ${GO_SRC}/${i} -out private.p8
93+
pkcs11helper -action import -keyFile private.p8
94+
rm -rf private.p8
95+
done
96+
97+
echo "Code level ${FABRIC_SDKGO_CODELEVEL_TAG} (Fabric ${FABRIC_FIXTURE_VERSION})"
98+
echo "Running integration tests ..."
99+
100+
GO_TAGS="$GO_TAGS ${FABRIC_SDKGO_CODELEVEL_TAG}"
101+
GO_LDFLAGS="${GO_LDFLAGS} -X github.com/hyperledger/fabric-sdk-go/test/metadata.ChannelConfigPath=test/fixtures/fabric/${FABRIC_FIXTURE_VERSION}/channel -X github.com/hyperledger/fabric-sdk-go/test/metadata.CryptoConfigPath=test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config"
102+
$GO_CMD test ${RACEFLAG} -tags "${GO_TAGS}" ${GO_TESTFLAGS} -ldflags="${GO_LDFLAGS}" ${PKGS[@]} -p 1 -timeout=40m configFile=${CONFIG_FILE} testLocal=${TEST_LOCAL}

test/scripts/integration.sh

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,19 @@ source ${SCRIPT_DIR}/lib/find_packages.sh
3636
echo "Running" $(basename "$0")
3737

3838
# Packages to include in test run
39-
PKGS=($($GO_CMD list $REPO/test/integration/... 2> /dev/null | \
40-
grep -v ^$REPO/test/integration/pkcs11 | \
41-
grep -v ^$REPO/test/integration/negative | \
42-
grep -v ^$REPO/test/integration\$ | \
39+
PKGS=($(${GO_CMD} list ${REPO}/test/integration/... 2> /dev/null | \
40+
grep -v ^${REPO}/test/integration/e2e/pkcs11 | \
41+
grep -v ^${REPO}/test/integration/negative | \
42+
grep -v ^${REPO}/test/integration\$ | \
4343
tr '\n' ' '))
4444

4545
if [ "$E2E_ONLY" == "true" ]; then
4646
echo "Including E2E tests only"
47-
PKGS=(`$GO_CMD list $REPO/test/integration/e2e/... 2> /dev/null`)
48-
fi
49-
50-
if [ "$FABRIC_SDK_CLIENT_BCCSP_SECURITY_DEFAULT_PROVIDER" == "PKCS11" ]; then
51-
echo "Including PKCS11 tests only"
52-
PKGS=("${REPO}/test/integration/pkcs11")
47+
PKGS=($(echo ${PKGS[@]} | tr ' ' '\n' | grep ^${REPO}/test/integration/e2e | tr '\n' ' '))
5348
fi
5449

5550
# Reduce tests to changed packages.
56-
if [ "$TEST_CHANGED_ONLY" = true ]; then
51+
if [ "${TEST_CHANGED_ONLY}" = true ]; then
5752
# findChangedFiles assumes that the working directory contains the repo; so change to the repo directory.
5853
PWD=$(pwd)
5954
cd "${GOPATH}/src/${REPO}"
@@ -71,7 +66,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
7166
fi
7267

7368
RACEFLAG=""
74-
if [ "$TEST_RACE_CONDITIONS" = true ]; then
69+
if [ "${TEST_RACE_CONDITIONS}" = true ]; then
7570
ARCH=$(uname -m)
7671

7772
if [ "${ARCH}" = "x86_64" ]; then
@@ -87,30 +82,9 @@ if [ ${#PKGS[@]} -eq 0 ]; then
8782
exit 0
8883
fi
8984

90-
#Add entry here below for your key to be imported into softhsm
91-
declare -a PRIVATE_KEYS=(
92-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/config/mutual_tls/client_sdk_go-key.pem"
93-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore/f4aa194b12d13d7c2b7b275a7115af5e6f728e11710716f2c754df4587891511_sk"
94-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/ce142124e13093a3e13bc4708b0f2b26e1d4d2ea4d4cc59942790bfc0f3bcc6d_sk"
95-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/abbe8ee0f86c227b1917d208921497603d2ff28f4ba8e902d703744c4a6fa7b7_sk"
96-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/371ea01078b18f3b92c1fc8233dfa8d209d882ae40aeff4defd118ba9d572a15_sk"
97-
"github.com/hyperledger/fabric-sdk-go/test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/7777a174c9fe40ab5abe33199a4fe82f1e0a7c45715e395e73a78cc3480d0021_sk"
98-
)
99-
100-
GO_SRC=/opt/gopath/src
101-
if [ "$FABRIC_SDK_CLIENT_BCCSP_SECURITY_DEFAULT_PROVIDER" == "PKCS11" ]; then
102-
for i in "${PRIVATE_KEYS[@]}"
103-
do
104-
echo "Importing key : ${GO_SRC}/${i}"
105-
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in ${GO_SRC}/${i} -out private.p8
106-
pkcs11helper -action import -keyFile private.p8
107-
rm -rf private.p8
108-
done
109-
fi
110-
111-
echo "Code level $FABRIC_SDKGO_CODELEVEL_TAG (Fabric ${FABRIC_FIXTURE_VERSION})"
85+
echo "Code level ${FABRIC_SDKGO_CODELEVEL_TAG} (Fabric ${FABRIC_FIXTURE_VERSION})"
11286
echo "Running integration tests ..."
11387

114-
GO_TAGS="$GO_TAGS $FABRIC_SDKGO_CODELEVEL_TAG"
115-
GO_LDFLAGS="$GO_LDFLAGS -X github.com/hyperledger/fabric-sdk-go/test/metadata.ChannelConfigPath=test/fixtures/fabric/${FABRIC_FIXTURE_VERSION}/channel -X github.com/hyperledger/fabric-sdk-go/test/metadata.CryptoConfigPath=test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config"
116-
$GO_CMD test $RACEFLAG -tags "$GO_TAGS" $GO_TESTFLAGS -ldflags="$GO_LDFLAGS" ${PKGS[@]} -p 1 -timeout=40m configFile=${CONFIG_FILE} testLocal=${TEST_LOCAL}
88+
GO_TAGS="${GO_TAGS} ${FABRIC_SDKGO_CODELEVEL_TAG}"
89+
GO_LDFLAGS="${GO_LDFLAGS} -X github.com/hyperledger/fabric-sdk-go/test/metadata.ChannelConfigPath=test/fixtures/fabric/${FABRIC_FIXTURE_VERSION}/channel -X github.com/hyperledger/fabric-sdk-go/test/metadata.CryptoConfigPath=test/fixtures/fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config"
90+
${GO_CMD} test ${RACEFLAG} -tags "${GO_TAGS}" ${GO_TESTFLAGS} -ldflags="${GO_LDFLAGS}" ${PKGS[@]} -p 1 -timeout=40m configFile=${CONFIG_FILE} testLocal=${TEST_LOCAL}

0 commit comments

Comments
 (0)