Skip to content

Commit

Permalink
[FAB-6423] Go SDK config reused issue
Browse files Browse the repository at this point in the history
Change-Id: I89bc8a91532e8b1ebd4bb79bcf82c27bc405adeb
Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
  • Loading branch information
sandrask committed Oct 5, 2017
1 parent 171e0c6 commit f048f16
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 108 deletions.
85 changes: 84 additions & 1 deletion def/fabapi/fabapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,103 @@ import (
func TestNewDefaultSDK(t *testing.T) {

setup := Options{
ConfigFile: "../../test/fixtures/config/config_test.yaml",
ConfigFile: "../../test/fixtures/config/invalid.yaml",
StateStoreOpts: opt.StateStoreOpts{
Path: "/tmp/state",
},
}

// Test new SDK with invalid config file
_, err := NewSDK(setup)
if err == nil {
t.Fatalf("Should have failed for invalid config file")
}

// Test New SDK with valid config file
setup.ConfigFile = "../../test/fixtures/config/config_test.yaml"
sdk, err := NewSDK(setup)
if err != nil {
t.Fatalf("Error initializing SDK: %s", err)
}

// Default channel client (uses organisation from client configuration)
_, err = sdk.NewChannelClient("mychannel", "User1")
if err != nil {
t.Fatalf("Failed to create new channel client: %s", err)
}

// Test configuration failure for channel client (mychannel does't have event source configured for Org2)
_, err = sdk.NewChannelClientWithOpts("mychannel", "User1", &ChannelClientOpts{OrgName: "Org2"})
if err == nil {
t.Fatalf("Should have failed to create channel client since event source not configured for Org2")
}

// Test new channel client with options
_, err = sdk.NewChannelClientWithOpts("orgchannel", "User1", &ChannelClientOpts{OrgName: "Org2"})
if err != nil {
t.Fatalf("Failed to create new channel client: %s", err)
}

}

func TestNewDefaultTwoValidSDK(t *testing.T) {
setup := Options{
ConfigFile: "../../test/fixtures/config/config_test.yaml",
StateStoreOpts: opt.StateStoreOpts{
Path: "/tmp/state",
},
}

sdk1, err := NewSDK(setup)
if err != nil {
t.Fatalf("Error initializing SDK: %s", err)
}

setup.ConfigFile = "./testdata/test.yaml"
sdk2, err := NewSDK(setup)
if err != nil {
t.Fatalf("Error initializing SDK: %s", err)
}

// Default sdk with two channels
client1, err := sdk1.configProvider.Client()
if err != nil {
t.Fatalf("Error getting client from config: %s", err)
}

if client1.Organization != "Org1" {
t.Fatalf("Unexpected org in config: %s", client1.Organization)
}

client2, err := sdk2.configProvider.Client()
if err != nil {
t.Fatalf("Error getting client from config: %s", err)
}

if client2.Organization != "Org2" {
t.Fatalf("Unexpected org in config: %s", client1.Organization)
}

// Test SDK1 channel clients ('mychannel', 'orgchannel')
_, err = sdk1.NewChannelClient("mychannel", "User1")
if err != nil {
t.Fatalf("Failed to create new channel client: %s", err)
}

_, err = sdk1.NewChannelClient("orgchannel", "User1")
if err != nil {
t.Fatalf("Failed to create new channel client: %s", err)
}

// SDK 2 doesn't have 'mychannel' configured
_, err = sdk2.NewChannelClient("mychannel", "User1")
if err == nil {
t.Fatalf("Should have failed to create channel that is not configured")
}

// SDK 2 has 'orgchannel' configured
_, err = sdk2.NewChannelClient("orgchannel", "User1")
if err != nil {
t.Fatalf("Failed to create new 'orgchannel' channel client: %s", err)
}
}
129 changes: 129 additions & 0 deletions def/fabapi/testdata/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

name: "global-trade-network"

x-type: "hlfv1"
x-loggingLevel: info

description: "The network to be in if you want to stay in the global trade business"
version: 1.0.0

client:
organization: Org2

logging:
level: info

# Global configuration for peer, event service and orderer timeouts
peer:
timeout:
connection: 3s
queryResponse: 20s
executeTxResponse: 30s
eventService:
timeout:
connection: 3s
registrationResponse: 3s
orderer:
timeout:
connection: 3s
response: 5s

cryptoconfig:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config

credentialStore:
path: "/tmp/hfc-kvs"

cryptoStore:
# Specific to the underlying KeyValueStore that backs the crypto key store.
path: /tmp/msp

# BCCSP config for the client. Used by GO SDK.
BCCSP:
security:
enabled: true
default:
provider: "SW"
hashAlgorithm: "SHA2"
softVerify: true
ephemeral: false
level: 256

channels:

orgchannel:

orderers:
- orderer.example.com

peers:
peer0.org2.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true

organizations:

Org2:
mspid: Org2MSP

# Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode)
cryptoPath: peerOrganizations/org2.example.com/users/{userName}@org2.example.com/msp

peers:
- peer0.org2.example.com

certificateAuthorities:
- ca-org2

ordererorg:
mspID: "OrdererOrg"

# Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode)
cryptoPath: ordererOrganizations/example.com/users/{userName}@example.com/msp


orderers:
orderer.example.com:
url: grpcs://orderer.example.com:7050

grpcOptions:
ssl-target-name-override: orderer.example.com
grpc-max-send-message-length: 15

tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem

peers:
peer0.org2.example.com:
url: grpcs://peer0.org2.example.com:7051
eventUrl: grpcs://peer0.org2.example.com:7053
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem

certificateAuthorities:
ca-org2:
url: https://ca_peerOrg2:7054

httpOptions:
verify: true

tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/ca_root.pem
client:
keyfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client-key.pem
certfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client.pem

registrar:
enrollId: admin
enrollSecret: adminpw

caName: ca-org2
Loading

0 comments on commit f048f16

Please sign in to comment.