Skip to content

Commit

Permalink
Fix issue where init flow errors when not using mutual TLS (#1183)
Browse files Browse the repository at this point in the history
fixes the issue where on the init flow you get

TypeError:
this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(...).isTLSEnabled
is not a function

closes #1160
Signed-off-by: D <d_kelsey@uk.ibm.com>

Co-authored-by: D <d_kelsey@uk.ibm.com>
  • Loading branch information
davidkel and davidkel committed Dec 9, 2021
1 parent cc19cd6 commit 595942a
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -68,4 +68,4 @@
}
},
"license": "Apache-2.0"
}
}
Expand Up @@ -133,7 +133,7 @@ class V1FabricGateway extends ConnectorBase {
async init() {
const defaultOrganization = this.connectorConfiguration.getOrganizations()[0];
const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual'
: (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none');
: ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none');
logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`);

const fabricChannelOperations = new FabricChannelOperations(this.connectorConfiguration);
Expand Down
Expand Up @@ -128,7 +128,7 @@ class V1Fabric extends ConnectorBase {
await this._validateConnectionProfilesAreStatic();
const defaultOrganization = this.connectorConfiguration.getOrganizations()[0];
const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual'
: (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none');
: ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none');
logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`);

const fabricChannelOperations = new FabricChannelOperations(this.connectorConfiguration);
Expand Down
Expand Up @@ -129,7 +129,7 @@ class V2FabricGateway extends ConnectorBase {
// will call it
const defaultOrganization = this.connectorConfiguration.getOrganizations()[0];
const tlsInfo = this.connectorConfiguration.isMutualTLS() ? 'mutual'
: (this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization).isTLSEnabled() ? 'server' : 'none');
: ((await this.connectorConfiguration.getConnectionProfileDefinitionForOrganization(defaultOrganization)).isTLSEnabled() ? 'server' : 'none');
logger.info(`Fabric SDK version: ${this.fabricNetworkVersion.toString()}; TLS based on ${defaultOrganization}: ${tlsInfo}`);
}

Expand Down
Expand Up @@ -25,6 +25,7 @@ const DefaultEventHandlerStrategies = {};
const DefaultQueryHandlerStrategies = {};

const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfig.yaml';
const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutual.yaml';

const { Client, Constants } = require('./ClientStubs');
const { Gateway, Transaction, InMemoryWallet, FileSystemWallet, X509WalletMixin, Network } = require('./V1GatewayStubs');
Expand Down Expand Up @@ -90,6 +91,12 @@ describe('A Node-SDK V1 Fabric Gateway', () => {
await fabricGateway.init().should.not.be.rejected;
});

it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), walletFacadeFactory);
const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric');
await fabricGateway.init().should.not.be.rejected;
});

it('should do nothing when attempting to install a smart contract', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWallet), walletFacadeFactory);
const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric');
Expand Down
Expand Up @@ -23,6 +23,7 @@ const path = require('path');

const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfigWithStaticCCP.yaml';
const configWith2Orgs1AdminInWalletWithDiscover = '../../sample-configs/BasicConfig.yaml';
const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutualWithStaticCCP.yaml';

const { Client, Channel, ChannelEventHub, Constants } = require('./ClientStubs');
const GenerateConfiguration = require('../../utils/GenerateConfiguration');
Expand Down Expand Up @@ -78,6 +79,12 @@ describe('A Node-SDK V1 Fabric Non Gateway', () => {
await fabricNonGateway.init().should.not.be.rejected;
});

it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), stubWalletFacadeFactory);
const fabricGateway = new FabricNonGateway(connectorConfiguration, 1, 'fabric');
await fabricGateway.init().should.not.be.rejected;
});

it('should throw an error if the connection profile is defined with discover when initalizing for use by caliper master', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletWithDiscover), stubWalletFacadeFactory);
const fabricNonGateway = new FabricNonGateway(connectorConfiguration, 1, 'fabric');
Expand Down
Expand Up @@ -25,6 +25,7 @@ const DefaultEventHandlerStrategies = {};
const DefaultQueryHandlerStrategies = {};

const configWith2Orgs1AdminInWallet = '../../sample-configs/BasicConfig.yaml';
const configWith2Orgs1AdminInWalletNotMutual = '../../sample-configs/BasicConfigNotMutual.yaml';

const { Gateway, Transaction, Network, Wallets } = require('./V2GatewayStubs');
const GenerateConfiguration = require('../../utils/GenerateConfiguration');
Expand Down Expand Up @@ -78,6 +79,12 @@ describe('A Node-SDK V2 Fabric Gateway', () => {
await fabricGateway.init().should.not.be.rejected;
});

it('should be able to initialise in preperation for use by a caliper master when mutual tls is false', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWalletNotMutual), walletFacadeFactory);
const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric');
await fabricGateway.init().should.not.be.rejected;
});

it('should do nothing when attempting to install a smart contract', async () => {
const connectorConfiguration = await new ConnectorConfigurationFactory().create(path.resolve(__dirname, configWith2Orgs1AdminInWallet), walletFacadeFactory);
const fabricGateway = new FabricGateway(connectorConfiguration, 1, 'fabric');
Expand Down
118 changes: 118 additions & 0 deletions packages/caliper-fabric/test/sample-configs/BasicConfigNotMutual.yaml
@@ -0,0 +1,118 @@
---
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The name of the benchmark
name: BasicConfig
# The caliper semantic version
version: "2.0.0"

# Global properties that define the SUT, and options that are specific to the target SUT
caliper:
blockchain: fabric
sutOptions :
mutualTls: false

# Array of fabric channels for creation or use
channels:
- channelName: mychannel
# [Optional] create the channel
create:
buildTransaction:
capabilities: []
consortium: 'SampleConsortium2'
msps: ['Org1MSP', 'Org2MSP']
version: 0
# Array of contracts to be installed/instantiated on the named channel and available for use by the workload module
contracts:
- id: marbles
contractID: myMarbles
# define the install requirements to install chaincode if chaincode is to be installed
install:
version: v0
language: golang
path: marbles/go
metadataPath: src/marbles/go/metadata
# define the instantiate requirements to instantiate chaincode all of this section is optional depending on chaincode requirements
instantiate:
initFunction: init
initArguments: []
initTransientMap:
key1: value1
key2: value2
endorsementPolicy: ''
collectionsConfig: ''

- channelName: somechannel
create:
prebuiltTransaction: 'channel.tx'
contracts:
- id: marbles
contractID: foundMyMarbles
version: v0

- channelName: yourchannel
contracts:
- id: marbles
contractID: lostMyMarbles
version: v0

# [Minimum 1] Array of organizations that are to be used within the benchmarking, containing one of more identities to be used by the connector
organizations:
- mspid: Org1MSP
# One or more identity specification types that may provide a unique identity for the use by the connector.
identities:
# [NOT CURRENTLY SUPPORTED] [Optional] only for use by non gateway fabric connector (could also be defined in connection profile)
credentialStore:
path: /tmp/hfc-kvs/org1
cryptoStore:
path: /tmp/hfc-cvs/org1
# [Optional] File path to a FileWallet, within which all entries are all for the same org. Only for use by gateway
wallet:
path: './test/sample-configs'
adminNames:
- admin
# [Optional] certificates for the client
certificates:
- name: 'User1'
clientPrivateKey:
# pem or path can be specified here can be specified here
pem: |-
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
clientSignedCert:
pem: |-
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
# Connection profile to be used by the connector for the organization
# - could validate this connection profile matches declared mspid
connectionProfile:
path: './test/sample-configs/Org1ConnectionProfile.yaml'
discover: true
- mspid: Org2MSP
identities:
certificates:
- name: 'User1'
clientPrivateKey:
# pem or path can be specified here can be specified here
pem: |-
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
clientSignedCert:
pem: |-
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
connectionProfile:
path: './test/sample-configs/StaticOrg2ConnectionProfile.json'
discover: false
@@ -0,0 +1,89 @@
---
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: BasicConfigWithStaticCCP
version: "2.0.0"

caliper:
blockchain: fabric,
sutOptions :
mutualTls: false

channels:
- channelName: mychannel
create:
buildTransaction:
capabilities: []
consortium: 'SampleConsortium2'
msps: ['Org1MSP', 'Org2MSP']
version: 0
contracts:
- id: marbles
contractID: myMarbles
install:
version: v0
language: golang
path: marbles/go
metadataPath: src/marbles/go/metadata
instantiate:
initFunction: init
initArguments: []
initTransientMap:
key1: value1
key2: value2
endorsementPolicy: ''
collectionsConfig: ''

- channelName: yourchannel
contracts:
- id: marbles
contractID: lostMyMarbles
version: v0

organizations:
- mspid: Org1MSP
identities:
wallet:
path: './test/sample-configs'
adminNames:
- admin
certificates:
- name: 'User1'
clientPrivateKey:
pem: |-
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
clientSignedCert:
pem: |-
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
connectionProfile:
path: './test/sample-configs/StaticOrg1ConnectionProfile.json'
discover: false
- mspid: Org2MSP
identities:
certificates:
- name: 'User1'
clientPrivateKey:
pem: |-
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
clientSignedCert:
pem: |-
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
connectionProfile:
path: './test/sample-configs/StaticOrg2ConnectionProfile.json'
discover: false

0 comments on commit 595942a

Please sign in to comment.