diff --git a/fabric-ca-client/lib/FabricCAClientImpl.js b/fabric-ca-client/lib/FabricCAClientImpl.js index 191e0715fc..a4f4c79095 100644 --- a/fabric-ca-client/lib/FabricCAClientImpl.js +++ b/fabric-ca-client/lib/FabricCAClientImpl.js @@ -752,7 +752,7 @@ var FabricCAClient = class { socket.setTimeout(CONNECTION_TIMEOUT); socket.on('timeout', () => { request.abort(); - reject(new Error(util.format('Calling %s endpoint failed, CONNECTION Timeout', api_method))); + reject(new Error(util.format('Calling %s endpoint failed, CONNECTION Timeout', api_method))); }); }); @@ -761,9 +761,9 @@ var FabricCAClient = class { request.setTimeout(SO_TIMEOUT, () => { reject(new Error(util.format('Calling %s endpoint failed, READ Timeout', api_method))); }); - } + } - request.on('error', function (err) { + request.on('error', function (err) { reject(new Error(util.format('Calling %s endpoint failed with error [%s]', api_method, err))); }); diff --git a/fabric-ca-client/lib/IdentityService.js b/fabric-ca-client/lib/IdentityService.js index a8744e13b3..def2bb44b6 100644 --- a/fabric-ca-client/lib/IdentityService.js +++ b/fabric-ca-client/lib/IdentityService.js @@ -163,7 +163,7 @@ class IdentityService { throw new Error('Can not get signingIdentity from registrar'); } - const url = 'identities/' + enrollmentID + '?ca='+this.client._caName;; + const url = 'identities/' + enrollmentID + '?ca='+this.client._caName; return this.client.get(url, signingIdentity); } diff --git a/fabric-client/lib/Channel.js b/fabric-client/lib/Channel.js index 941c65d1ee..929eb127f1 100755 --- a/fabric-client/lib/Channel.js +++ b/fabric-client/lib/Channel.js @@ -277,15 +277,15 @@ const Channel = class { * @param {string} name - The name of the peer assigned to this channel * @returns {ChannelPeer} The ChannelPeer instance */ - getChannelPeer(name) { - const channel_peer = this._channel_peers.get(name); + getChannelPeer(name) { + const channel_peer = this._channel_peers.get(name); - if(!channel_peer){ - throw new Error(util.format(PEER_NOT_ASSIGNED_MSG, name)); - } + if(!channel_peer){ + throw new Error(util.format(PEER_NOT_ASSIGNED_MSG, name)); + } - return channel_peer; - } + return channel_peer; + } /** * Returns a list of peers assigned to this channel instance. @@ -2273,8 +2273,6 @@ const Channel = class { return Promise.all(promises); } return Promise.reject('Failed to execute transaction: ' + errorMsg); - }).catch(error => { - return Promise.reject(error); }); } @@ -2878,9 +2876,9 @@ var ChannelPeer = class { * * @returns {string} The organization name. */ - getOrganizationName() { - return this._org_name; - } + getOrganizationName() { + return this._org_name; + } /** * Get the name. This is a client-side only identifier for this diff --git a/fabric-client/lib/impl/CryptoKeyStore.js b/fabric-client/lib/impl/CryptoKeyStore.js index 67a02ff8d9..d2e4056899 100644 --- a/fabric-client/lib/impl/CryptoKeyStore.js +++ b/fabric-client/lib/impl/CryptoKeyStore.js @@ -36,7 +36,7 @@ var CryptoKeyStoreMixin = (KeyValueStore) => class extends KeyValueStore { // next try the public key entry return self.getValue(_getKeyIndex(ski, false)); }).then((key) => { - if (ECDSAKey.isInstance(key)) + if (key instanceof ECDSAKey) return key; if (key !== null) { diff --git a/fabric-client/lib/impl/CryptoSuite_ECDSA_AES.js b/fabric-client/lib/impl/CryptoSuite_ECDSA_AES.js index c4355a8104..43ee675d9b 100755 --- a/fabric-client/lib/impl/CryptoSuite_ECDSA_AES.js +++ b/fabric-client/lib/impl/CryptoSuite_ECDSA_AES.js @@ -33,11 +33,11 @@ const logger = utils.getLogger('crypto_ecdsa_aes'); class CryptoSuite_ECDSA_AES extends api.CryptoSuite { /** - * constructor - * - * @param {number} keySize Key size for the ECDSA algorithm, can only be 256 or 384 - * @param {string} hash Optional. Hash algorithm, supported values are "SHA2" and "SHA3" - */ + * constructor + * + * @param {number} keySize Key size for the ECDSA algorithm, can only be 256 or 384 + * @param {string} hash Optional. Hash algorithm, supported values are "SHA2" and "SHA3" + */ constructor(keySize, hash) { if (!keySize) throw new Error('keySize must be specified'); if (keySize !== 256 && keySize !== 384) { @@ -77,24 +77,24 @@ class CryptoSuite_ECDSA_AES extends api.CryptoSuite { } /** - * Set the cryptoKeyStore. - * - * When the application needs to use a key store other than the default, - * it should use the {@link Client} newCryptoKeyStore to create an instance and - * use this function to set the instance on the CryptoSuite. - * - * @param {CryptoKeyStore} cryptoKeyStore The cryptoKeyStore. - */ + * Set the cryptoKeyStore. + * + * When the application needs to use a key store other than the default, + * it should use the {@link Client} newCryptoKeyStore to create an instance and + * use this function to set the instance on the CryptoSuite. + * + * @param {CryptoKeyStore} cryptoKeyStore The cryptoKeyStore. + */ setCryptoKeyStore(cryptoKeyStore) { this._cryptoKeyStore = cryptoKeyStore; } - generateKey(opts) { + async generateKey(opts) { const pair = KEYUTIL.generateKeypair('EC', this._curveName); if (typeof opts !== 'undefined' && typeof opts.ephemeral !== 'undefined' && opts.ephemeral === true) { logger.debug('generateKey, ephemeral true, Promise resolved'); - return Promise.resolve(new ECDSAKey(pair.prvKeyObj)); + return new ECDSAKey(pair.prvKeyObj); } else { if (!this._cryptoKeyStore) { throw new Error('generateKey opts.ephemeral is false, which requires CryptoKeyStore to be set.'); @@ -102,43 +102,32 @@ class CryptoSuite_ECDSA_AES extends api.CryptoSuite { // unless "opts.ephemeral" is explicitly set to "true", default to saving the key const key = new ECDSAKey(pair.prvKeyObj); - const self = this; - return new Promise((resolve, reject) => { - self._cryptoKeyStore._getKeyStore() - .then((store) => { - logger.debug('generateKey, store.setValue'); - return store.putKey(key) - .then(() => { - return resolve(key); - }).catch((err) => { - reject(err); - }); - }); - - }); + const store = await this._cryptoKeyStore._getKeyStore(); + logger.debug('generateKey, store.setValue'); + await store.putKey(key); + return key; } } /** - * This is an implementation of {@link module:api.CryptoSuite#deriveKey} - * To be implemented - */ + * This is an implementation of {@link module:api.CryptoSuite#deriveKey} + * To be implemented + */ deriveKey(key, opts) { if (key || opts) ; throw new Error('Not implemented yet'); } /** - * This is an implementation of {@link module:api.CryptoSuite#importKey} - * To be implemented - */ + * This is an implementation of {@link module:api.CryptoSuite#importKey} + */ importKey(pem, opts) { logger.debug('importKey - start'); let store_key = true; //default if (typeof opts !== 'undefined' && typeof opts.ephemeral !== 'undefined' && opts.ephemeral === true) { store_key = false; } - if (!!store_key && !this._cryptoKeyStore) { + if (store_key && !this._cryptoKeyStore) { throw new Error('importKey opts.ephemeral is false, which requires CryptoKeyStore to be set.'); } @@ -196,46 +185,35 @@ class CryptoSuite_ECDSA_AES extends api.CryptoSuite { } } - getKey(ski) { - const self = this; - let store; + async getKey(ski) { - if (!self._cryptoKeyStore) { + if (!this._cryptoKeyStore) { throw new Error('getKey requires CryptoKeyStore to be set.'); } - return new Promise((resolve, reject) => { - self._cryptoKeyStore._getKeyStore() - .then((st) => { - store = st; - return store.getKey(ski); - }).then((key) => { - if (ECDSAKey.isInstance(key)) - return resolve(key); - - if (key !== null) { - const pubKey = KEYUTIL.getKey(key); - return resolve(new ECDSAKey(pubKey)); - } - }).catch((err) => { - reject(err); - }); - - }); + const store = await this._cryptoKeyStore._getKeyStore(); + const key = await store.getKey(ski); + if (key instanceof ECDSAKey) + return key; + + if (key !== null) { + const pubKey = KEYUTIL.getKey(key); + return new ECDSAKey(pubKey); + } } /** - * This is an implementation of {@link module:api.CryptoSuite#hash} - * The opts argument is not supported. - */ + * This is an implementation of {@link module:api.CryptoSuite#hash} + * The opts argument is not supported. + */ hash(msg, opts) { if (opts) ; return this._hashFunction(msg); } /** - * This is an implementation of {@link module:api.CryptoSuite#sign} - * Signs digest using key k. - */ + * This is an implementation of {@link module:api.CryptoSuite#sign} + * Signs digest using key k. + */ sign(key, digest) { if (typeof key === 'undefined' || key === null) { throw new Error('A valid key is required to sign'); @@ -278,18 +256,18 @@ class CryptoSuite_ECDSA_AES extends api.CryptoSuite { } /** - * This is an implementation of {@link module:api.CryptoSuite#encrypt} - * To be implemented. - */ + * This is an implementation of {@link module:api.CryptoSuite#encrypt} + * To be implemented. + */ encrypt(key, plainText, opts) { if (key || plainText || opts) ; throw new Error('Not implemented yet'); } /** - * This is an implementation of {@link module:api.CryptoSuite#decrypt} - * To be implemented. - */ + * This is an implementation of {@link module:api.CryptoSuite#decrypt} + * To be implemented. + */ decrypt(key, cipherText, opts) { if (key || cipherText || opts) ; throw new Error('Not implemented yet'); diff --git a/fabric-client/lib/impl/NetworkConfig_1_0.js b/fabric-client/lib/impl/NetworkConfig_1_0.js index 8f898ee9ae..87776014df 100644 --- a/fabric-client/lib/impl/NetworkConfig_1_0.js +++ b/fabric-client/lib/impl/NetworkConfig_1_0.js @@ -376,7 +376,7 @@ var NetworkConfig_1_0 = class { /* * Internal utility method to get the organization the peer belongs */ - _getOrganizationForPeer(peer_name) { + _getOrganizationForPeer(peer_name) { if(this._network_config && this._network_config[ORGS_CONFIG]) { for(let organization_name in this._network_config[ORGS_CONFIG]) { let organization = this.getOrganization(organization_name); @@ -387,7 +387,7 @@ var NetworkConfig_1_0 = class { } } } - } + } }; function getTLSCACert(config) { diff --git a/fabric-client/lib/impl/ecdsa/key.js b/fabric-client/lib/impl/ecdsa/key.js index 66a1144ec4..1ee16e7315 100644 --- a/fabric-client/lib/impl/ecdsa/key.js +++ b/fabric-client/lib/impl/ecdsa/key.js @@ -13,7 +13,7 @@ const jsrsa = require('jsrsasign'); const asn1 = jsrsa.asn1; const KEYUTIL = jsrsa.KEYUTIL; const ECDSA = jsrsa.ECDSA; - +const api = require('../../api'); const logger = utils.getLogger('ecdsa/key.js'); /** @@ -21,14 +21,14 @@ const logger = utils.getLogger('ecdsa/key.js'); * @class ECDSA_KEY * @extends module:api.Key */ -module.exports = class ECDSA_KEY { +module.exports = class ECDSA_KEY extends api.Key{ /** * this class represents the private or public key of an ECDSA key pair. * * @param {Object} key This must be the "privKeyObj" or "pubKeyObj" part of the object generated by jsrsasign.KEYUTIL.generateKeypair() */ constructor(key) { - if (typeof key === 'undefined' || key === null) { + if (!key) { throw new Error('The key parameter is required by this key class implementation, whether this instance is for the public key or private key'); } @@ -36,16 +36,14 @@ module.exports = class ECDSA_KEY { throw new Error('This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "type" property of value "EC"'); } - // prvKeyHex value can be null for public keys, so need to check typeof here - if (typeof key.prvKeyHex === 'undefined') { - throw new Error('This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "prvKeyHex" property'); - } - // pubKeyHex must have a non-null value if (!key.pubKeyHex) { throw new Error('This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "pubKeyHex" property'); } + // prvKeyHex value can be null for public keys + + super(); this._key = (typeof key === 'undefined') ? null : key; } @@ -139,15 +137,4 @@ module.exports = class ECDSA_KEY { return KEYUTIL.getPEM(this._key); } } - - static isInstance(object) { - if (typeof object._key === 'undefined') { - return false; - } - - const key = object._key; - return (key.type && key.type === 'EC' && - typeof key.prvKeyHex !== 'undefined' && // prvKeyHex value can be null for public keys, so need to check typeof here - typeof key.pubKeyHex === 'string'); // pubKeyHex must have a non-null value - } }; diff --git a/test/integration/channel-event-hub.js b/test/integration/channel-event-hub.js index c2d65ddce7..64092c9fd1 100644 --- a/test/integration/channel-event-hub.js +++ b/test/integration/channel-event-hub.js @@ -378,7 +378,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco let event_monitor_1 = new Promise((resolve, reject) => { let handle = setTimeout(() => { t.fail('Timeout - Failed to receive the event for event1'); - eh.unregisterTxEvent(req1.txId.getTransactionID()); + event_hub.unregisterTxEvent(req1.txId.getTransactionID()); reject('timeout'); }, 200000); diff --git a/test/integration/configtxlator.js b/test/integration/configtxlator.js index 5b5426b873..3a22e422b0 100644 --- a/test/integration/configtxlator.js +++ b/test/integration/configtxlator.js @@ -15,64 +15,58 @@ * superagent * superagent-promise */ -var utils = require('fabric-client/lib/utils.js'); -var logger = utils.getLogger('configinator'); +const utils = require('fabric-client/lib/utils.js'); +const logger = utils.getLogger('configinator'); -var tape = require('tape'); -var _test = require('tape-promise').default; -var test = _test(tape); -var superagent = require('superagent'); -var agent = require('superagent-promise')(require('superagent'), Promise); -var requester = require('request'); +const tape = require('tape'); +const _test = require('tape-promise').default; +const test = _test(tape); +const superagent = require('superagent'); +const agent = require('superagent-promise')(require('superagent'), Promise); +const requester = require('request'); -var Client = require('fabric-client'); -var util = require('util'); -var fs = require('fs'); -var path = require('path'); +const Client = require('fabric-client'); +const util = require('util'); +const fs = require('fs'); +const path = require('path'); -var testUtil = require('../unit/util.js'); -var e2eUtils = require('./e2e/e2eUtils.js'); +const testUtil = require('../unit/util.js'); +const e2eUtils = require('./e2e/e2eUtils.js'); -var the_user = null; -var ORGS; -test('\n\n***** configtxlator flow for create and then update *****\n\n', function(t) { +test('\n\n***** configtxlator flow for create and then update *****\n\n', async (t) => { testUtil.resetDefaults(); Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json')); - ORGS = Client.getConfigSetting('test-network'); + const ORGS = Client.getConfigSetting('test-network'); - var channel_name = 'mychannelator'; - var channel = null; + const channel_name = 'mychannelator'; // // Create and configure the test channel // - var client = new Client(); + const client = new Client(); - var caRootsPath = ORGS.orderer.tls_cacerts; - let data = fs.readFileSync(path.join(__dirname, '/test', caRootsPath)); - let caroots = Buffer.from(data).toString(); + const caRootsPath = ORGS.orderer.tls_cacerts; + const data = fs.readFileSync(path.join(__dirname, '/test', caRootsPath)); + const caroots = Buffer.from(data).toString(); - var config_proto = null; - var original_config_proto = null; - var original_config_json = null; - var updated_config_proto = null; - var updated_config_json = null; - var signatures = []; - var request = null; - var tlsInfo = null; + let config_proto = null; + let original_config_proto = null; + let original_config_json = null; + let updated_config_proto = null; + let updated_config_json = null; + let signatures = []; + let request = null; // Acting as a client in org1 when creating the channel - var org = ORGS.org1.name; + const org = ORGS.org1.name; utils.setConfigSetting('key-value-store', 'fabric-client/lib/impl/FileKeyValueStore.js'); + try { - return e2eUtils.tlsEnroll(org) - .then((enrollment) => { + const tlsInfo = await e2eUtils.tlsEnroll(org); t.pass('Successfully retrieved TLS certificate'); - tlsInfo = enrollment; - return Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(org)}); - }).then((store) => { + let store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(org)}); client.setStateStore(store); /* @@ -94,12 +88,11 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct * the "ConfigUpdate" object. */ - return testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org1'); - }).then((admin) =>{ + let admin = await testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org1'); t.pass('Successfully enrolled user \'admin\' for org1'); - let config_json = fs.readFileSync(path.join(__dirname, '../fixtures/channel/' + channel_name + '.json')); + const config_json = fs.readFileSync(path.join(__dirname, '../fixtures/channel/' + channel_name + '.json')); - var orderer = client.newOrderer( + const orderer = client.newOrderer( ORGS.orderer.url, { 'pem': caroots, @@ -110,11 +103,11 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct ); // the following is an example of how to make the call without a promise - var response = superagent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate', + superagent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate', config_json.toString()) .buffer() .end((err, res) => { - if(err) { + if (err) { logger.error(err); return; } @@ -122,71 +115,59 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct //logger.info('config_proto %s',config_proto.toString()); }); // and here is an example of how to use it with a promise - return agent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate', config_json.toString()) + const config = await agent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate', config_json.toString()) .buffer(); - }).then((config) =>{ config_proto = config.body; t.pass('Successfully built the config create from the json input'); - // sign the config - var signature = client.signChannelConfig(config_proto); + // sign and collect signature + signatures.push(client.signChannelConfig(config_proto)); t.pass('Successfully signed config create by org1'); - // collect signature - signatures.push(signature); // make sure we do not reuse the user client._userContext = null; - return testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org2'); - }).then((admin) => { + admin = await testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org2'); t.pass('Successfully enrolled user \'admin\' for org2'); - // sign the config - var signature = client.signChannelConfig(config_proto); + // sign and collect signature + signatures.push(client.signChannelConfig(config_proto)); t.pass('Successfully signed config create by org2'); - // collect signature - signatures.push(signature); // make sure we do not reuse the user client._userContext = null; - return testUtil.getOrderAdminSubmitter(client, t); - }).then((admin) => { + admin = await testUtil.getOrderAdminSubmitter(client, t); t.pass('Successfully enrolled user \'admin\' for orderer (configtxlator 1)'); - the_user = admin; // sign the config - var signature = client.signChannelConfig(config_proto); t.pass('Successfully signed config create by orderer'); // collect signature - signatures.push(signature); + signatures.push(client.signChannelConfig(config_proto)); // build up the create request - let tx_id = client.newTransactionID(); request = { config: config_proto, - signatures : signatures, - name : channel_name, - orderer : orderer, - txId : tx_id + signatures: signatures, + name: channel_name, + orderer: orderer, + txId: client.newTransactionID() }; // this will send the create request to the orderer - return client.createChannel(request); - }).then((result) => { + let result = await client.createChannel(request); logger.debug('\n***\n completed the create \n***\n'); - logger.debug(' response ::%j',result); - if(result.status && result.status === 'SUCCESS') { + logger.debug(' response ::%j', result); + if (result.status && result.status === 'SUCCESS') { t.pass('Successfully created the channel.'); - return e2eUtils.sleep(5000); + await e2eUtils.sleep(5000); } else { t.fail('Failed to create the channel. '); - Promise.reject('Failed to create the channel'); + throw 'Failed to create the channel'; } - }).then((nothing) => { t.pass('Successfully waited to make sure new channel was created.'); /* @@ -216,11 +197,10 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct * the "ConfigUpdate" object. */ - var channel = client.newChannel(channel_name); + const channel = client.newChannel(channel_name); channel.addOrderer(orderer); - return channel.getChannelConfig(); - }).then((config_envelope) => { + const config_envelope = await channel.getChannelConfig(); t.pass('Successfully read the current channel configuration'); // we just need the config from the envelope and configtxlator // works with bytes @@ -228,30 +208,28 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct // lets get the config converted into JSON, so we can edit JSON to // make our changes - return agent.post('http://127.0.0.1:7059/protolator/decode/common.Config', + let response = await agent.post('http://127.0.0.1:7059/protolator/decode/common.Config', original_config_proto) .buffer(); - }).then((response) => { t.pass('Successfully decoded the current configuration config proto into JSON'); original_config_json = response.text.toString(); - logger.info(' original_config_json :: %s',original_config_json); + logger.info(' original_config_json :: %s', original_config_json); // make a copy of the original so we can edit it updated_config_json = original_config_json; - var updated_config = JSON.parse(updated_config_json); + const updated_config = JSON.parse(updated_config_json); // now edit the config -- remove one of the organizations delete updated_config.channel_group.groups.Application.groups.Org1MSP; updated_config_json = JSON.stringify(updated_config); - logger.info(' updated_config_json :: %s',updated_config_json); + logger.info(' updated_config_json :: %s', updated_config_json); // lets get the updated JSON encoded - return agent.post('http://127.0.0.1:7059/protolator/encode/common.Config', + response = await agent.post('http://127.0.0.1:7059/protolator/encode/common.Config', updated_config_json.toString()) .buffer(); - }).then((response) =>{ t.pass('Successfully encoded the updated config from the JSON input'); updated_config_proto = response.body; - var formData = { + const formData = { channel: channel_name, original: { value: original_config_proto, @@ -269,21 +247,20 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct } }; - return new Promise((resolve, reject) =>{ + response = await new Promise((resolve, reject) => { requester.post({ url: 'http://127.0.0.1:7059/configtxlator/compute/update-from-configs', formData: formData - }, function optionalCallback(err, res, body) { + }, (err, res, body) => { if (err) { - t.fail('Failed to get the updated configuration ::'+err); + t.fail('Failed to get the updated configuration ::' + err); reject(err); } else { - var proto = Buffer.from(body, 'binary'); + const proto = Buffer.from(body, 'binary'); resolve(proto); } }); }); - }).then((response) =>{ t.pass('Successfully had configtxlator compute the updated config object'); config_proto = response; @@ -292,69 +269,57 @@ test('\n\n***** configtxlator flow for create and then update *****\n\n', funct // make sure we do not reuse the user client._userContext = null; - return testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org1'); - }).then((admin) => { + admin = await testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org1'); t.pass('Successfully enrolled user \'admin\' for org1'); - // sign the config - var signature = client.signChannelConfig(config_proto); + // sign and collect signature + signatures.push(client.signChannelConfig(config_proto)); t.pass('Successfully signed config update by org1'); - // collect signature - signatures.push(signature); - // make sure we do not reuse the user client._userContext = null; - return testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org2'); - }).then((admin) => { + admin = await testUtil.getSubmitter(client, t, true /*get the org admin*/, 'org2'); t.pass('Successfully enrolled user \'admin\' for org2'); - // sign the config - var signature = client.signChannelConfig(config_proto); + // sign and collect signature + signatures.push(client.signChannelConfig(config_proto)); t.pass('Successfully signed config update by org2'); - // collect signature - signatures.push(signature); // make sure we do not reuse the user client._userContext = null; - return testUtil.getOrderAdminSubmitter(client, t); - }).then((admin) => { + admin = await testUtil.getOrderAdminSubmitter(client, t); t.pass('Successfully enrolled user \'admin\' for orderer (configtxlator 2)'); - the_user = admin; - // sign the config - var signature = client.signChannelConfig(config_proto); + // sign and collect signature + signatures.push(client.signChannelConfig(config_proto)); t.pass('Successfully signed config update by orderer'); - // collect signature - signatures.push(signature); // build up the create request - let tx_id = client.newTransactionID(); request = { config: config_proto, - signatures : signatures, - name : channel_name, - orderer : orderer, - txId : tx_id + signatures: signatures, + name: channel_name, + orderer: orderer, + txId: client.newTransactionID() }; // this will send the update request to the orderer - return client.updateChannel(request); - }).then((result) => { - if(result.status && result.status === 'SUCCESS') { + result = await client.updateChannel(request); + if (result.status && result.status === 'SUCCESS') { t.pass('Successfully updated the channel.'); - return e2eUtils.sleep(5000); + await e2eUtils.sleep(5000); } else { t.fail('Failed to update the channel. '); - Promise.reject('Failed to update the channel'); + throw 'Failed to update the channel'; } - }).then((nothing) => { t.pass('Successfully waited to make sure new channel was updated.'); t.end(); - }).catch((err) =>{ - t.fail('Unexpected error '+err); + + } catch (err) { + t.fail('Unexpected error ' + err); t.end(); - }); + } + }); diff --git a/test/unit/crypto-key-store.js b/test/unit/crypto-key-store.js index cf461c6fff..5567a32cfe 100644 --- a/test/unit/crypto-key-store.js +++ b/test/unit/crypto-key-store.js @@ -256,25 +256,14 @@ test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', function(t) t.end(); }); -test('\n\n** CryptoKeyStore tests - getKey error tests **\n\n', function(t) { +test('\n\n** CryptoKeyStore tests - getKey error tests **\n\n', function (t) { // override t.end function so it'll always clear the config settings - t.end = ((context, f) => { - return function() { - if (global && global.hfc) global.hfc.config = undefined; - require('nconf').reset(); - - f.apply(context, arguments); - }; - })(t, t.end); - + testutil.resetDefaults(); var cryptoSuite = utils.newCryptoSuite(); - t.throws( - () => { - cryptoSuite.getKey('blah'); - }, - /getKey requires CryptoKeyStore to be set./, - 'Test missing cryptoKeyStore: cryptoSuite.getKey' - ); - t.end(); + cryptoSuite.getKey('blah').catch(err => { + t.ok(err.toString().includes('getKey requires CryptoKeyStore to be set.'), + 'Test missing cryptoKeyStore: cryptoSuite.getKey'); + t.end(); + }); }); diff --git a/test/unit/cryptosuite-ecdsa-aes.js b/test/unit/cryptosuite-ecdsa-aes.js index 2e8375ee87..c502dd1b15 100644 --- a/test/unit/cryptosuite-ecdsa-aes.js +++ b/test/unit/cryptosuite-ecdsa-aes.js @@ -104,9 +104,9 @@ var TEST_KEY_PRIVATE_CERT_PEM = '-----BEGIN CERTIFICATE-----' + var TEST_USER_ENROLLMENT = { 'name': 'admin2', 'mspid': 'test', - 'roles':null, - 'affiliation':'', - 'enrollmentSecret':'', + 'roles': null, + 'affiliation': '', + 'enrollmentSecret': '', 'enrollment': { 'signingIdentity': '0e67f7fa577fd76e487ea3b660e1a3ff15320dbc95e396d8b0ff616c87f8c81a', 'identity': { @@ -120,8 +120,6 @@ const halfOrdersForCurve = { 'secp384r1': elliptic.curves['p384'].n.shrn(1) }; -var _client = new Client(); - test('\n\n** utils.newCryptoSuite tests **\n\n', (t) => { testutil.resetDefaults(); @@ -143,10 +141,10 @@ test('\n\n** utils.newCryptoSuite tests **\n\n', (t) => { let expectedError = '/Error:.*\/usr\/local\/lib/'; if (process.platform === 'win32') { expectedError = 'Error: Win32 error 126/'; - }; + } t.throws( () => { - cs = utils.newCryptoSuite({lib: '/usr/local/lib', slot: 0, pin: '1234' }); + cs = utils.newCryptoSuite({lib: '/usr/local/lib', slot: 0, pin: '1234'}); }, expectedError, 'Should attempt to load the bccsp_pkcs11 module and fail because of the dummy library path' @@ -154,7 +152,7 @@ test('\n\n** utils.newCryptoSuite tests **\n\n', (t) => { t.end(); }); -test('\n\n ** CryptoSuite_ECDSA_AES - error tests **\n\n', function (t) { +test('\n\n ** CryptoSuite_ECDSA_AES - error tests **\n\n', (t) => { testutil.resetDefaults(); var cryptoUtils = utils.newCryptoSuite(); t.throws( @@ -164,14 +162,14 @@ test('\n\n ** CryptoSuite_ECDSA_AES - error tests **\n\n', function (t) { /importKey opts.ephemeral is false, which requires CryptoKeyStore to be set./, 'Test missing cryptoKeyStore: cryptoSuite.importKey' ); - t.throws( - () => { - cryptoUtils.generateKey(); - }, - /generateKey opts.ephemeral is false, which requires CryptoKeyStore to be set./, - 'Test missing cryptoKeyStore: cryptoSuite.generateKey' - ); - t.end(); + cryptoUtils.generateKey().catch(err => { + t.ok(err.toString() + .includes('generateKey opts.ephemeral is false, which requires CryptoKeyStore to be set.'), + 'Test missing cryptoKeyStore: cryptoSuite.generateKey'); + + t.end(); + }); + }); test('\n\n ** CryptoSuite_ECDSA_AES - ephemeral true tests **\n\n', function (t) { @@ -220,9 +218,9 @@ test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) { t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA384, 'CryptoSuite_ECDSA_AES function tests: using "SHA2" hashing algorithm with default key size which should be 384'); - //reset to default key size + //reset to default key size utils.setConfigSetting('crypto-keysize', 256); - utils.setConfigSetting('key-value-store','fabric-client/lib/impl/FileKeyValueStore.js');//force for gulp test + utils.setConfigSetting('key-value-store', 'fabric-client/lib/impl/FileKeyValueStore.js');//force for gulp test cryptoUtils = utils.newCryptoSuite(); cryptoUtils.setCryptoKeyStore(utils.newCryptoKeyStore()); diff --git a/test/unit/ecdsa-key.js b/test/unit/ecdsa-key.js index 07d10445a4..89d952e79b 100644 --- a/test/unit/ecdsa-key.js +++ b/test/unit/ecdsa-key.js @@ -47,29 +47,12 @@ test('\n\n ** ECDSA Key Impl tests **\n\n', function (t) { t.throws( function () { - var k = new ecdsaKey({type: 'EC', pubKeyHex: 'some random value'}); - }, - /^Error: This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "prvKeyHex" property/, - 'ECDSA Impl test: catch missing "prvKeyHex"' - ); - - t.throws( - function () { - var k = new ecdsaKey({type: 'EC', prvKeyHex: null}); + var k = new ecdsaKey({type: 'EC', prvKeyHex: 'some key value'}); }, /^Error: This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "pubKeyHex" property/, 'ECDSA Impl test: catch missing "pubKeyHex" property' ); - t.throws( - function () { - var k = new ecdsaKey({type: 'EC', prvKeyHex: null, pubKeyHex: null}); - }, - /^Error: This key implementation only supports keys generated by jsrsasign.KEYUTIL. It must have a "pubKeyHex" property/, - 'ECDSA Impl test: catch "pubKeyHex" with null value' - ); - - t.doesNotThrow( function () { var k = new ecdsaKey({type: 'EC', prvKeyHex: null, pubKeyHex: 'some random value'}); diff --git a/test/unit/policy.js b/test/unit/policy.js index 89528fd1e6..990ded6236 100644 --- a/test/unit/policy.js +++ b/test/unit/policy.js @@ -50,17 +50,17 @@ test('Test Policy.checkPolicy()', async (t) => { policy = { identities: [{ role: { - name: 'member', - mspId: 'Org1MSP' + name: 'member', + mspId: 'Org1MSP' } - } + } ], policy: { - '1-of': [ - { - 'signed-by': 0 - } - ] + '1-of': [ + { + 'signed-by': 0 + } + ] } }; t.doesNotThrow(()=>{ diff --git a/test/unit/sidedb.js b/test/unit/sidedb.js index 16ab951a08..3a561a67ec 100644 --- a/test/unit/sidedb.js +++ b/test/unit/sidedb.js @@ -15,26 +15,26 @@ test('Test SideDB.checkCollectionConfig()', async (t) => { let policy = { identities: [{ role: { - name: 'member', - mspId: 'Org1MSP' + name: 'member', + mspId: 'Org1MSP' } - }, - { + }, + { role: { - name: 'member', - mspId: 'Org2MSP' + name: 'member', + mspId: 'Org2MSP' } - } + } ], policy: { - '1-of': [ - { - 'signed-by': 0 - }, - { - 'signed-by': 1 - } - ] + '1-of': [ + { + 'signed-by': 0 + }, + { + 'signed-by': 1 + } + ] } };