Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', (t) => {
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
const keyValStorePath = 'tmp/keyValStore1';
const config = {path: keyValStorePath};
let cs = utils.newCryptoKeyStore(config);
t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');
const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
cs = utils.newCryptoKeyStore();
t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');
let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
cs = utils.newCryptoKeyStore(kvsImplClass);
t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');
test('Use FabricCAServices with a File KeyValueStore', (t) => {
testUtil.resetDefaults();
Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
ORGS = Client.getConfigSetting('test-network');
const fabricCAEndpoint = ORGS[userOrg].ca.url;
// Set the relevant configuration values
utils.setConfigSetting('crypto-keysize', 256);
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
// var keyValueStore = Client.getConfigSetting('key-value-store');
const keyValStorePath = path.join(testUtil.getTempDir(), 'customKeyValStorePath');
const client = new Client();
let cryptoSuite, member;
// clean up
if (testUtil.existsSync(keyValStorePath)) {
fs.removeSync(keyValStorePath);
}
const tlsOptions = {
trustedRoots: [],
verify: false
test('\n\n** TEST ** orderer via member missing orderer', async (t) => {
testUtil.resetDefaults();
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for npm test
Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
ORGS = Client.getConfigSetting('test-network');
const orgName = ORGS[org].name;
//
// Create and configure the test channel
//
const channel = client.newChannel('testchannel-orderer-member2');
const cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
client.setCryptoSuite(cryptoSuite);
const store = await Client.newDefaultKeyValueStore({
path: testUtil.KVS
});
test('\n\n** CryptoKeyStore tests - couchdb based store tests - use configSetting **\n\n', (t) => {
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/CouchDBKeyValueStore.js');
const couchdb = CouchdbMock.createServer();
couchdb.listen(5985);
// override t.end function so it'll always disconnect the event hub
t.end = ((context, mockdb, f) => {
return function() {
if (mockdb) {
t.comment('Disconnecting the mock couchdb server');
mockdb.close();
}
f.apply(context, arguments);
};
})(t, couchdb, t.end);
test('\n\n ** createUser happy path - file store **\n\n', (t) => {
testUtil.resetDefaults();
Client.addConfigFile(path.join(__dirname, '../fixtures/profiles/caimport.json'));
caImport = utils.getConfigSetting('ca-import', 'notfound');
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
utils.setConfigSetting('crypto-keysize', 256);
const userOrg = 'org1';
const prvKey = path.join(__dirname, caImport.orgs[userOrg].cryptoContent.privateKey);
const sgnCert = path.join(__dirname, caImport.orgs[userOrg].cryptoContent.signedCert);
const keyStoreOpts = {path: path.join(testUtil.getTempDir(), caImport.orgs[userOrg].storePath)};
const client = new Client();
const cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore(keyStoreOpts));
client.setCryptoSuite(cryptoSuite);
logger.debug('try to cleanup kvs Path: ' + keyStoreOpts.path);
// clean up
if (testUtil.existsSync(keyStoreOpts.path)) {
fs.removeSync(keyStoreOpts.path);
let cs = utils.newCryptoSuite({keysize: 384, algorithm: 'EC'});
t.equal(cs instanceof CryptoSuite_ECDSA_AES, true, 'Should return an instance of CryptoSuite_ECDSA_AES');
t.equal(cs._keySize, 384, 'Returned instance should have keysize of 384');
cs = utils.newCryptoSuite({keysize: 384});
t.equal(cs instanceof CryptoSuite_ECDSA_AES, true, 'Default test: should return an instance of CryptoSuite_ECDSA_AES');
t.equal(cs._keySize, 384, 'Returned instance should have keysize of 384');
cs = utils.newCryptoSuite({algorithm: 'EC'});
t.equal(cs instanceof CryptoSuite_ECDSA_AES, true, 'Should return an instance of CryptoSuite_ECDSA_AES');
t.equal(cs._keySize, 256, 'Returned instance should have keysize of 256');
// each app instance is expected to use either HSM or software-based key management, as such this question
// is answered with a config setting rather than controlled on a case-by-case basis
utils.setConfigSetting('crypto-hsm', true);
/* eslint-disable-next-line */
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'});
},
expectedError,
'Should attempt to load the bccsp_pkcs11 module and fail because of the dummy library path'
);
// Control crypto-hsm settings via env variable
process.env.CRYPTO_HSM = false;
testutil.resetDefaults();
t.end = ((context, f) => {
return function() {
if (global && global.hfc) {
global.hfc.config = undefined;
}
require('nconf').reset();
f.apply(context, arguments);
};
})(t, t.end);
// var user = new User();
const client = new Client();
// Set the relevant configuration values
utils.setConfigSetting('crypto-keysize', 256);
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/CouchDBKeyValueStore.js');
// Clean up the cloudant couchdb test database
const dbname = 'member_db';
let cryptoSuite, member, options;
couchdbUtil.destroy(dbname, cloudantUrl)
.then(() => {
options = {name: dbname, url: cloudantUrl};
utils.newKeyValueStore(options)
.then(
(kvs) => {
member = new User('admin2');
cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore(options));
client.setCryptoSuite(cryptoSuite);
t.end = ((context, f) => {
return function() {
if (global && global.hfc) {
global.hfc.config = undefined;
}
require('nconf').reset();
f.apply(context, arguments);
};
})(t, t.end);
const client = new Client();
// Set the relevant configuration values
utils.setConfigSetting('crypto-keysize', 256);
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/CouchDBKeyValueStore.js');
// Clean up the couchdb test database
const dbname = 'my_member_db';
let cryptoSuite, member;
couchdbUtil.destroy(dbname, keyValStorePath)
.then(() => {
const options = {name: dbname, url: keyValStorePath};
utils.newKeyValueStore(options)
.then(
(kvs) => {
member = new User('admin2');
cryptoSuite = Client.newCryptoSuite(options);
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore(options));
client.setCryptoSuite(cryptoSuite);
testUtil.resetDefaults();
Client.addConfigFile(path.join(__dirname, './config.json'));
const ORGS = Client.getConfigSetting('test-network');
const client = new Client();
const caRootsPath = ORGS.orderer.tls_cacerts;
const data = fs.readFileSync(path.join(__dirname, caRootsPath));
const caroots = Buffer.from(data).toString();
const signatures = [];
// Acting as a client in org1 when creating the channel
const org = ORGS.org1.name;
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
const tlsInfo = await e2eUtils.tlsEnroll('org1');
t.pass('Successfully retrieved TLS certificate');
client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(org)});
client.setStateStore(store);
const cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(org)}));
client.setCryptoSuite(cryptoSuite);
// use the config update created by the configtx tool
const channeltx_subdir = process.env.channeltx_subdir ? process.env.channeltx_subdir : 'channel-config';
const envelope_bytes = fs.readFileSync(path.join(__dirname, '../../fixtures/crypto-material', channeltx_subdir, channel_name + '.tx'));
const config = client.extractChannelConfig(envelope_bytes);
t.pass('Successfully extracted the config update from the configtx envelope');
test(' ---->>>>> Query channel working <<<<<-----', (t) => {
Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
ORGS = Client.getConfigSetting('test-network');
orgName = ORGS[org].name;
const caRootsPath = ORGS.orderer.tls_cacerts;
data = fs.readFileSync(path.join(__dirname, 'e2e', caRootsPath));
const caroots = Buffer.from(data).toString();
let tlsInfo = null;
let bcInfo = null;
let tx_block = null;
utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
const cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
client.setCryptoSuite(cryptoSuite);
return e2eUtils.tlsEnroll(org).then((enrollment) => {
t.pass('Successfully retrieved TLS certificate');
tlsInfo = enrollment;
client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);
return Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)});
}).then((store) => {
client.setStateStore(store);
return testUtil.getSubmitter(client, t, org);
}).then(() => {
t.pass('Successfully enrolled user \'admin\'');
channel.addOrderer(