Skip to content

Commit

Permalink
nodeSDK Fix gulp test
Browse files Browse the repository at this point in the history
'gulp test' gets errors because the couchdb
and cloudant tests are picking up incorrect values for
the key-value-store config environment variables set while the
headless tests are running.  This change sets
the correct values into the config env rather
than loading from the file store.

Change-Id: I77c80498c4494bc44cdf6125d027a78d580065db
Signed-off-by: cdaughtr <cdaughtr@us.ibm.com>
  • Loading branch information
cdaughtr committed Mar 3, 2017
1 parent 4702e5b commit 0303e44
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Configurable settings are encapsulated in test/fixtures/couchdb.json and can be

Run the associated unit test with the following command:

node test/unit/couchdb-fabriccop-test.js
node test/unit/couchdb-fabricca-tests.js

### Contributor Check-list
The following check-list is for code contributors to make sure their changesets are compliant to the coding standards and avoid time wasted in rejected changesets:
Expand Down
5 changes: 3 additions & 2 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ gulp.task('test', ['lint', 'test-headless'], function() {
// saved the user certificates so they can interact with the
// network
return gulp.src([
// 'test/integration/ca-tests.js',
'test/integration/chain-fabric-ca-tests.js',
'test/integration/endorser-tests.js',
'test/integration/orderer-chain-tests.js',
'test/integration/install.js'
'test/integration/cloudant-fabricca-tests.js',
'test/integration/install.js',
'test/integration/end-to-end.js'
])
.pipe(tape({
reporter: tapColorize()
Expand Down
2 changes: 1 addition & 1 deletion fabric-ca-client/lib/FabricCAClientImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var FabricCAServices = class {
* - keysize {number}: The key size to use for the crypto suite instance. default is value of the setting 'crypto-keysize'
* - algorithm {string}: Digital signature algorithm, currently supporting ECDSA only with value "EC"
*
* @param {string} KVSImplClass Optional. The built-in key store saves private keys. The key store may be backed by different
* @param {function} KVSImplClass Optional. The built-in key store saves private keys. The key store may be backed by different
* {@link KeyValueStore} implementations. If specified, the value of the argument must point to a module implementing the
* KeyValueStore interface.
* @param {object} opts Implementation-specific options object for the {@link KeyValueStore} class to instantiate an instance
Expand Down
6 changes: 3 additions & 3 deletions fabric-client/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ module.exports.getCryptoSuite = function(setting, KVSImplClass, opts) {
// - getCryptoSuite()

// step 1: what's the cryptosuite impl to use, key size and algo
if (typeof setting === 'object' && typeof setting.keysize === 'number') {
if (setting && setting.keysize && typeof setting === 'object' && typeof setting.keysize === 'number') {
keysize = setting.keysize;
haveSettings = true;
} else
keysize = this.getConfigSetting('crypto-keysize');

if (typeof setting === 'object' && typeof setting.algorithm === 'string') {
if (setting && setting.algorithm && typeof setting === 'object' && typeof setting.algorithm === 'string') {
algorithm = setting.algorithm.toUpperCase();
haveSettings = true;
} else
algorithm = 'EC';

if (typeof setting === 'object' && typeof setting.hash === 'string') {
if (setting && setting.hash && typeof setting === 'object' && typeof setting.hash === 'string') {
hashAlgo = setting.hash.toUpperCase();
haveSettings = true;
} else
Expand Down
87 changes: 0 additions & 87 deletions test/integration/chain-fabric-ca-tests.js

This file was deleted.

10 changes: 7 additions & 3 deletions test/integration/cloudant-fabricca-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ var _test = require('tape-promise');
var test = _test(tape);

var hfc = require('fabric-client');

var Client = hfc;
var User = require('fabric-client/lib/User.js');
var FabricCAServices = require('fabric-ca-client/lib/FabricCAClientImpl');
var CouchDBKeyValueStore = require('fabric-client/lib/impl/CouchDBKeyValueStore');

var utils = require('fabric-client/lib/utils.js');
var couchdbUtil = require('./couchdb-util.js');
var logger = utils.getLogger('cloudant-fabricca');
hfc.setConfigSetting('hfc-logging', '{"debug":"console"}');

require('../unit/util.js').resetDefaults();

hfc.addConfigFile('test/fixtures/cloudant.json');
var keyValueStore = hfc.getConfigSetting('key-value-store');
logger.info('cloudant Key Value Store = ' + keyValueStore);

var cloudantUrl = 'https://1421acc7-6faa-491a-8e10-951e2e190684-bluemix:7179ef7a72602189243deeabe207889bde1c2fada173ae1022b5592e5a79dacc@1421acc7-6faa-491a-8e10-951e2e190684-bluemix.cloudant.com';

Expand All @@ -40,13 +44,13 @@ var cloudantUrl = 'https://1421acc7-6faa-491a-8e10-951e2e190684-bluemix:7179ef7a
// CouchDB KeyValueStore. Then the test uses the Chain class to load the member
// from the key value store.
test('Use FabricCAServices wih a Cloudant CouchDB KeyValueStore', function(t) {
t.equal(keyValueStore, 'fabric-client/lib/impl/CouchDBKeyValueStore.js', 'Check key value store override for CouchDBKeyValueStore');

//var user = new User();
var client = new Client();

// Set the relevant configuration values
utils.setConfigSetting('crypto-keysize', 256);
utils.setConfigSetting('key-value-store','fabric-client/lib/impl/CouchDBKeyValueStore.js');

// Clean up the cloudant couchdb test database
var dbname = 'member_db';
Expand All @@ -72,14 +76,14 @@ test('Use FabricCAServices wih a Cloudant CouchDB KeyValueStore', function(t) {
return new FabricCAServices('http://localhost:7054', {name: dbname, url: cloudantUrl});
},
function(err) {
console.log(err);
logger.error(err);
t.fail('Error initializing Cloudant KeyValueStore. Exiting.');
t.end();
process.exit(1);
})
.then(
function(caService) {
console.log('ADD: caService - ' + caService);
logger.info('ADD: caService - ' + caService);
t.pass('Successfully initialized the Fabric CA service.');

client.setCryptoSuite(caService.getCrypto());
Expand Down
14 changes: 10 additions & 4 deletions test/integration/couchdb-fabricca-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ var _test = require('tape-promise');
var test = _test(tape);

var hfc = require('fabric-client');

var Client = hfc;
var User = require('fabric-client/lib/User.js');
var FabricCAServices = require('fabric-ca-client/lib/FabricCAClientImpl');

var utils = require('fabric-client/lib/utils.js');
var couchdbUtil = require('./couchdb-util.js');
var logger = utils.getLogger('couchdb-fabricca');
hfc.setConfigSetting('hfc-logging', '{"debug":"console"}');

// Use the CouchDB specific config file
hfc.addConfigFile('test/fixtures/couchdb.json');

var keyValueStore = hfc.getConfigSetting('key-value-store');
console.log('Key Value Store = ' + keyValueStore);
logger.info('couchdb Key Value Store = ' + keyValueStore);

var couchdbIPAddr = hfc.getConfigSetting('couchdb-ip-addr', 'notfound');
var couchdbPort = hfc.getConfigSetting('couchdb-port', 'notfound');
var keyValStorePath = couchdbIPAddr + ':' + couchdbPort;
logger.info('couch keyValStorePath: '+keyValStorePath);

// This test first checks to see if a user has already been enrolled. If so,
// the test terminates. If the user is not yet enrolled, the test uses the
Expand All @@ -48,6 +52,7 @@ test('Use FabricCAServices with a CouchDB KeyValueStore', function(t) {

// Set the relevant configuration values
utils.setConfigSetting('crypto-keysize', 256);
utils.setConfigSetting('key-value-store','fabric-client/lib/impl/CouchDBKeyValueStore.js');

// Clean up the couchdb test database
var dbname = 'member_db';
Expand All @@ -70,17 +75,18 @@ test('Use FabricCAServices with a CouchDB KeyValueStore', function(t) {
process.exit(1);
}
t.comment('Initialize the CA server connection and KeyValueStore');
return new FabricCAServices('http://localhost:7054', {name: dbname, url: keyValStorePath});
t.comment('Test optional parameters passed into FabricCAServices of cryptoSettings and KVSImplClass');
return new FabricCAServices('http://localhost:7054', null/*cryptoSettings*/, kvs/*KVSImplClass*/, {name: dbname, url: keyValStorePath});
},
function(err) {
console.log(err);
logger.error(err);
t.fail('Error initializing CouchDB KeyValueStore. Exiting.');
t.end();
process.exit(1);
})
.then(
function(caService) {
console.log('ADD: caService - ' + caService);
logger.info('ADD: caService - ' + caService);
t.pass('Successfully initialized the Fabric CA service.');

client.setCryptoSuite(caService.getCrypto());
Expand Down

0 comments on commit 0303e44

Please sign in to comment.