Skip to content

Commit

Permalink
FABN-1532 NodeSDK allow for non-TLS networks (#198)
Browse files Browse the repository at this point in the history
Update the fabric-network parsing of a common connection
profile to handle a non-TLS network. Provide testing.

Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob authored Mar 27, 2020
1 parent e415c40 commit 9ba41f8
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 58 deletions.
8 changes: 5 additions & 3 deletions fabric-network/src/impl/ccp/networkconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ function findPeerMspid(name, config) {
function buildOptions(endpoint_config) {
const method = 'buildOptions';
logger.debug(`${method} - start`);
const pem = getPEMfromConfig(endpoint_config.tlsCACerts);
const options = {
url: endpoint_config.url,
pem: pem
url: endpoint_config.url
};
const pem = getPEMfromConfig(endpoint_config.tlsCACerts);
if (pem) {
options.pem = pem;
}
Object.assign(options, endpoint_config.grpcOptions);

if (options['request-timeout'] && !options.requestTimeout) {
Expand Down
11 changes: 11 additions & 0 deletions test/ts-fixtures/chaincode/node/fabcar/metadata/collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"name": "collectionFabcar",
"policy": "OR('Org1MSP.member', 'Org2MSP.member')",
"requiredPeerCount": 0,
"maxPeerCount": 3,
"blockToLive":1000000,
"memberOnlyRead": true,
"memberOnlyWrite": true
}
]
2 changes: 1 addition & 1 deletion test/ts-fixtures/crypto-material/config-base/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channe
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/deprecatedchannel.tx" -channelID deprecatedchannel # scenario test deprecated sdk
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/discoverychannel.tx" -channelID discoverychannel # sceanrio test discovery feature
#configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/eventschannel.tx" -channelID eventschannel # sceanrio test discovery feature
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/gatewaychannel.tx" -channelID gatewaychannel # sceanrio test gateway feature
#configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/gatewaychannel.tx" -channelID gatewaychannel # sceanrio test gateway feature

echo 'Generating crypto-material complete, now renaming keys...'
# Rename the key files we use to be key.pem instead of a uuid
Expand Down
2 changes: 2 additions & 0 deletions test/ts-fixtures/crypto-material/config-v2/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export FABRIC_CFG_PATH="$BASEDIR"

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/channelopschannelvtwo.tx" -channelID channelopschannelvtwo # V2 channel
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/lifecyclechannel.tx" -channelID lifecyclechannel # V2 lifecycle
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/gatewaychannel.tx" -channelID gatewaychannel # V2 lifecycle
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx "${BASEDIR}/../channel-config/eventschannel.tx" -channelID eventschannel # V2 lifecycle

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate "${BASEDIR}/../channel-config/channelopschannelvtwo-anchor.tx" -channelID channelopschannelvtwo -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate "${BASEDIR}/../channel-config/gatewaychannel-anchor.tx" -channelID gatewaychannel -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate "${BASEDIR}/../channel-config/eventschannel-anchor.tx" -channelID eventschannel -asOrg Org1MSP
36 changes: 23 additions & 13 deletions test/ts-scenario/features/base_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@
Feature: Use base API to perform core operations

Background:
Given I place a scenario start message BASE API FEATURE
Given I deploy a tls Fabric network at 2.0 version
And I use the cli to create and join the channel named baseapichannel on the deployed network
And I use the cli to deploy a node smart contract named fabcar at version 1.0.0 for all organizations on channel baseapichannel with endorsement policy 1of and arguments ["initLedger"]
Given I place a scenario start message BASE API FEATURE
Given I deploy a tls Fabric network at 2.0 version
And I use the cli to create and join the channel named eventschannel on the deployed network
And I use the cli to update the channel with name eventschannel with config file eventschannel-anchor.tx on the deployed network
And I use the cli to lifecycle deploy a node smart contract named fabcar at version 1.0.0 as fabcar for all organizations on channel eventschannel with default endorsement policy and init-required true

Scenario: Using only fabric-base I can propose, endorse and commit a transaction on instantiated node chaincode
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named baseapichannel
When I build a new endorsement request named myFirstRequest for smart contract named fabcar with arguments [createCar, 2000, GMC, Savana, grey, Jones] as client leon on channel baseapichannel
And I commit the endorsement request named myFirstRequest as client leon on channel baseapichannel
Scenario: Using only fabric-base I can initialize node chaincode
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named eventschannel
When I build a new endorsement request named initRequest for smart contract named fabcar with arguments [initLedger] as client leon on channel eventschannel
And I commit the endorsement request named initRequest as client leon on channel eventschannel
Then the request named initRequest for client leon has a general result matching {"result":"SUCCESS"}
And the request named initRequest for client leon has a event result matching {"result":"Commit success"}
And the request named initRequest for client leon has a commit result matching {"status":"SUCCESS"}

Scenario: Using only fabric-base I can propose, endorse and commit a transaction on approved/committed node chaincode
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named eventschannel
When I build a new endorsement request named myFirstRequest for smart contract named fabcar with arguments [createCar, 2000, GMC, Savana, grey, Jones] as client leon on channel eventschannel
And I commit the endorsement request named myFirstRequest as client leon on channel eventschannel
Then the request named myFirstRequest for client leon has a general result matching {"result":"SUCCESS"}
And the request named myFirstRequest for client leon has a event result matching {"result":"Commit success"}
And the request named myFirstRequest for client leon has a commit result matching {"status":"SUCCESS"}

Scenario: Using only fabric-base I can send a query request to peers and recieve a valid result
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named baseapichannel
When I submit a query named myFirstQuery with args [queryCar,CAR0] for contract fabcar as client leon on channel baseapichannel
Then the query named myFirstQuery for client leon has a general result matching {"result":"SUCCESS"}
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named eventschannel
When I submit a query named myFirstQuery with args [queryCar,CAR0] for contract fabcar as client leon on channel eventschannel
Then the query named myFirstQuery for client leon has a general result matching {"result":"SUCCESS"}
And the query named myFirstQuery for client leon has a peer0 result matching {"color":"blue","docType":"car","make":"Toyota","model":"Prius","owner":"Tomoko"}
2 changes: 1 addition & 1 deletion test/ts-scenario/features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Node SDK Events
Given I deploy a tls Fabric network at 2.0 version
And I use the cli to create and join the channel named eventschannel on the deployed network
And I use the cli to update the channel with name eventschannel with config file eventschannel-anchor.tx on the deployed network
And I use the cli to lifecycle deploy a node smart contract named events at version 1.0.0 as events for all organizations on channel eventschannel with default endorsement policy and arguments ["initLedger"]
And I use the cli to lifecycle deploy a node smart contract named events at version 1.0.0 as events for all organizations on channel eventschannel with default endorsement policy and init-required false
And I have a memory backed gateway named event_gateway with discovery set to true for user User1 using the connection profile named ccp-tls.json

Scenario: Using a Contract I can listen to full contract create events emitted by instantiated chaincodes
Expand Down
5 changes: 3 additions & 2 deletions test/ts-scenario/features/gateway.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Feature: Configure Fabric using CLI and submit/evaluate using a network Gateway
Background:
Given I place a scenario start message GATEWAY FEATURE
Given I deploy a tls Fabric network at 2.0 version
And I use the cli to create and join the channel named gatewaychannel on the deployed network
And I use the cli to deploy a node smart contract named fabcar at version 1.0.0 for all organizations on channel gatewaychannel with endorsement policy 1ofAny and arguments ["initLedger"]
And I use the cli to create and join the channel named gatewaychannel on the deployed network
And I use the cli to update the channel with name gatewaychannel with config file gatewaychannel-anchor.tx on the deployed network
And I use the cli to lifecycle deploy a node smart contract named fabcar at version 1.0.0 as fabcar for all organizations on channel gatewaychannel with default endorsement policy and init-required false
And I have a couchDB backed gateway named mycouchgateway with discovery set to false for user User1 using the connection profile named ccp-tls.json

Scenario: Using a Gateway I can submit and evaluate transactions on instantiated node smart contract
Expand Down
62 changes: 62 additions & 0 deletions test/ts-scenario/features/nontls-gateway.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# SPDX-License-Identifier: Apache-2.0
#

@gateway_nontls
@gateway
@fabric_merge
Feature: Configure Fabric using CLI and submit/evaluate using a network Gateway without discovery

Background:
Given I place a scenario start message GATEWAY NON TLS FEATURE
Given I deploy a non-tls Fabric network at 2.0 version
And I use the cli to create and join the channel named gatewaychannel on the deployed network
And I use the cli to update the channel with name gatewaychannel with config file gatewaychannel-anchor.tx on the deployed network
And I use the cli to lifecycle deploy a node smart contract named fabcar at version 1.0.0 as fabcar for all organizations on channel gatewaychannel with default endorsement policy and init-required false
And I have a couchDB backed gateway named mynontlsgateway with discovery set to false for user User1 using the connection profile named ccp.json

Scenario: Using a Gateway I can submit and evaluate transactions on instantiated node smart contract
When I use the gateway named mynontlsgateway to submit a transaction with args [createCar,1001,Trabant,601 Estate,brown,Simon] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a submit type response
When I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,1001] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"brown","docType":"car","make":"Trabant","model":"601 Estate","owner":"Simon"}

Scenario: Using a Gateway I recieve useful error messages when I submit or evaulate invalid transactions
When I use the gateway named mynontlsgateway to submit a transaction with args [noSuchSubmitTransaction,1001,Trabant,601 Estate,brown,Simon] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a error type response containing Error: You've asked to invoke a function that does not exist: noSuchSubmitTransaction
When I use the gateway named mynontlsgateway to submit a transaction with args [createCar,9,Ford] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a error type response containing Error: Expected 5 parameters, but 2 have been supplied
When I use the gateway named mynontlsgateway to evaluate a transaction with args [noSuchEvaluateTransaction,1001] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a error type response containing Error: You've asked to invoke a function that does not exist: noSuchEvaluateTransaction
When I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,because,I,said,so] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a error type response containing Error: Expected 1 parameters, but 4 have been supplied

Scenario: Using a Gateway to submit transactions I can use different event handler strategies
When I modify mynontlsgateway to submit a transaction with args [createCar,1002,Ford,Mustang,Silver,Andy] for contract fabcar instantiated on channel gatewaychannel using handler option MSPID_SCOPE_ALLFORTX
And I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,1002] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"Silver","docType":"car","make":"Ford","model":"Mustang","owner":"Andy"}
When I modify mynontlsgateway to submit a transaction with args [createCar,1003,Ford,Fiesta,Blue,Heather] for contract fabcar instantiated on channel gatewaychannel using handler option MSPID_SCOPE_ANYFORTX
And I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,1003] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"Blue","docType":"car","make":"Ford","model":"Fiesta","owner":"Heather"}
When I modify mynontlsgateway to submit a transaction with args [createCar,1004,Vauxhall,Corsa,White,Mark] for contract fabcar instantiated on channel gatewaychannel using handler option NETWORK_SCOPE_ALLFORTX
And I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,1004] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"White","docType":"car","make":"Vauxhall","model":"Corsa","owner":"Mark"}
When I modify mynontlsgateway to submit a transaction with args [createCar,1005,Bugatti,Veyron,Black,Bret] for contract fabcar instantiated on channel gatewaychannel using handler option NETWORK_SCOPE_ANYFORTX
Then The gateway named mynontlsgateway has a submit type response
When I modify mynontlsgateway to submit a transaction with args [createCar,1006,Lotus,Elise,Pink,Nick] for contract fabcar instantiated on channel gatewaychannel using handler option custom
And I use the gateway named mynontlsgateway to evaluate a transaction with args [queryCar,1006] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"Pink","docType":"car","make":"Lotus","model":"Elise","owner":"Nick"}

Scenario: Using a Gateway I can use transient data
When I modify mynontlsgateway to submit a transaction with transient data using args [getTransient,value1,value2] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a submit type response matching {"key0":"value1","key1":"value2"}
When I modify mynontlsgateway to evaluate a transaction with transient data using args [getTransient,valueA,valueB] for contract fabcar instantiated on channel gatewaychannel
Then The gateway named mynontlsgateway has a evaluate type response matching {"key0":"valueA","key1":"valueB"}

Scenario: Using a Gateway to evaluate transactions I can use different query handler strategies
When I modify mynontlsgateway to evaluate a transaction with args [queryCar,1001] for contract fabcar instantiated on channel gatewaychannel using handler option MSPID_SCOPE_SINGLE
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"brown","docType":"car","make":"Trabant","model":"601 Estate","owner":"Simon"}
When I modify mynontlsgateway to evaluate a transaction with args [queryCar,1001] for contract fabcar instantiated on channel gatewaychannel using handler option MSPID_SCOPE_ROUND_ROBIN
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"brown","docType":"car","make":"Trabant","model":"601 Estate","owner":"Simon"}
When I modify mynontlsgateway to evaluate a transaction with args [queryCar,1001] for contract fabcar instantiated on channel gatewaychannel using handler option custom
Then The gateway named mynontlsgateway has a evaluate type response matching {"color":"brown","docType":"car","make":"Trabant","model":"601 Estate","owner":"Simon"}
Loading

0 comments on commit 9ba41f8

Please sign in to comment.