From 9dad8aeef1cad811762f1c476eb6fdf459836471 Mon Sep 17 00:00:00 2001 From: Divyank Katira Date: Mon, 4 Dec 2017 12:13:17 -0500 Subject: [PATCH] [FAB-7292] Configure fabric-ca server correctly Change-Id: Ib0ba9eba3b14e2aeaaa78ec826ba2bfda87e865e Signed-off-by: Divyank Katira --- test/fixtures/docker-compose.yaml | 22 ++++++------- test/integration/fabric_ca_test.go | 51 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/test/fixtures/docker-compose.yaml b/test/fixtures/docker-compose.yaml index 79932d497c..9ba1ef177f 100644 --- a/test/fixtures/docker-compose.yaml +++ b/test/fixtures/docker-compose.yaml @@ -14,17 +14,17 @@ services: - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/8791d1363e89515f9afa042b0693a2c704bb8dd95d28f97d3549a2b9e3c4352d_sk - FABRIC_CA_SERVER_TLS_ENABLED=true - - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/server_wild_org1or2.example.com.pem - - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/server_wild_org1or2.example.com-key.pem + - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/tls/server_wild_org1or2.example.com.pem + - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/tls/server_wild_org1or2.example.com-key.pem #comment out logging.driver in order to render the debug logs logging: - driver: none + driver: none ports: - "7054:7054" command: sh -c 'fabric-ca-server start -b admin:adminpw -d' volumes: - - ./channel/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config - - ./tls/fabricca/certs/server:/etc/hyperledger/fabric-ca-server-config + - ./channel/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config/ + - ./tls/fabricca/certs/server/:/etc/hyperledger/fabric-ca-server-config/tls networks: default: aliases: @@ -38,17 +38,17 @@ services: - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a259204dbd6adb14c05a6e02de94567b2a9f7dbe9e6a063ba767d42bf0b544c1_sk - FABRIC_CA_SERVER_TLS_ENABLED=true - - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/server_wild_org1or2.example.com.pem - - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/server_wild_org1or2.example.com-key.pem - #comment out logging.driver in order to render the debug logs + - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/tls/server_wild_org1or2.example.com.pem + - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/tls/server_wild_org1or2.example.com-key.pem + #comment out logging.driver in order to render the debug logs logging: - driver: none + driver: none ports: - "8054:7054" command: sh -c 'fabric-ca-server start -b admin:adminpw -d' volumes: - - ./channel/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config - - ./tls/fabricca/certs/server:/etc/hyperledger/fabric-ca-server-config + - ./channel/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config/ + - ./tls/fabricca/certs/server:/etc/hyperledger/fabric-ca-server-config/tls networks: default: aliases: diff --git a/test/integration/fabric_ca_test.go b/test/integration/fabric_ca_test.go index 3c6032c45a..ab575ffe4d 100644 --- a/test/integration/fabric_ca_test.go +++ b/test/integration/fabric_ca_test.go @@ -15,11 +15,14 @@ import ( "testing" "time" + "github.com/hyperledger/fabric-sdk-go/api/apiconfig" ca "github.com/hyperledger/fabric-sdk-go/api/apifabca" client "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client" "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/identity" kvs "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/keyvaluestore" + "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/peer" + "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/signingmgr" cryptosuite "github.com/hyperledger/fabric-sdk-go/pkg/cryptosuite/bccsp" fabricCAClient "github.com/hyperledger/fabric-sdk-go/pkg/fabric-ca-client" @@ -172,6 +175,54 @@ func TestEnrollOrg2(t *testing.T) { } } +func TestEnrollAndTransact(t *testing.T) { + mspID, err := testFabricConfig.MspID(org1Name) + if err != nil { + t.Fatalf("GetMspId() returned error: %v", err) + } + peers, err := testFabricConfig.PeersConfig(org1Name) + if err != nil { + t.Fatalf("Failed to get peer config : %s", err) + } + networkPeer := &apiconfig.NetworkPeer{PeerConfig: peers[0], MspID: mspID} + testPeer, err := peer.NewPeerFromConfig(networkPeer, testFabricConfig) + if err != nil { + t.Fatalf("Failed to create peer from config : %s", err) + } + + cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(testFabricConfig) + if err != nil { + t.Fatalf("Failed getting cryptosuite from config : %s", err) + } + signingManager, err := signingmgr.NewSigningManager(cryptoSuiteProvider, testFabricConfig) + if err != nil { + t.Fatalf("Could not create signing manager: %s", err) + } + + caClient, err := fabricCAClient.NewFabricCAClient(org1Name, testFabricConfig, cryptoSuiteProvider) + if err != nil { + t.Fatalf("NewFabricCAClient returned error: %v", err) + } + + key, cert, err := caClient.Enroll("admin", "adminpw") + if err != nil { + t.Fatalf("Enroll returned error: %v", err) + } + + myUser := identity.NewUser("myUser", mspID) + myUser.SetEnrollmentCertificate(cert) + myUser.SetPrivateKey(key) + + testClient := client.NewClient(testFabricConfig) + testClient.SetUserContext(myUser) + testClient.SetSigningManager(signingManager) + + _, err = testClient.QueryChannels(testPeer) + if err != nil { + t.Fatalf("Failed to query with enrolled user : %s", err) + } +} + func createRandomName() string { rand.Seed(time.Now().UnixNano()) return "user" + strconv.Itoa(rand.Intn(500000))