Skip to content

Commit

Permalink
[FAB-7292] Configure fabric-ca server correctly
Browse files Browse the repository at this point in the history
Change-Id: Ib0ba9eba3b14e2aeaaa78ec826ba2bfda87e865e
Signed-off-by: Divyank Katira <[email protected]>
  • Loading branch information
d1vyank committed Dec 4, 2017
1 parent d3c36d4 commit 9dad8ae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/fixtures/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
51 changes: 51 additions & 0 deletions test/integration/fabric_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 9dad8ae

Please sign in to comment.