Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
};
utils.newKeyValueStore({path: keyValStorePath})
.then(
(kvs) => {
member = new User('admin2');
cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: keyValStorePath}));
member.setCryptoSuite(cryptoSuite);
client.setStateStore(kvs);
if (client.getStateStore() === kvs) {
t.pass('Successfully set File KeyValueStore for client');
} else {
t.fail('File KeyValStore is not set successfully on this client!');
t.end();
process.exit(1);
}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);
logger.debug('removed kvsPath: ' + keyStoreOpts.path);
}
return utils.newKeyValueStore(keyStoreOpts)
.then((store) => {
logger.debug('store: %s', store);
client.setStateStore(store);
return '';
}).then(() => {
return client.createUser(
{username: caImport.orgs[userOrg].username,
mspid: caImport.orgs[userOrg].mspid,
cryptoContent: {privateKey: prvKey, signedCert: sgnCert}
});
}, (err) => {
logger.error(err.stack ? err.stack : err);
throw new Error('Failed createUser.');
}).then((user) => {
if (user) {
t.pass(tag + ': got user');.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);
member.setCryptoSuite(cryptoSuite);
client.setStateStore(kvs);
if (client.getStateStore() === kvs) {
t.pass('Successfully set Cloudant CouchDB KeyValueStore for client');
} else {
t.pass('Cloudant CouchDB KeyValStore is not set successfully on this client!');
t.end();
process.exit(1);
}.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);
member.setCryptoSuite(cryptoSuite);
client.setStateStore(kvs);
if (client.getStateStore() === kvs) {
t.pass('Successfully set CouchDB KeyValueStore for client');
} else {
t.fail('CouchDB KeyValStore is not set successfully on this client!');
t.end();
process.exit(1);.then(() => {
return utils.newKeyValueStore(keyStoreOpts);
}).then((store) => {
logger.debug('store: %s', store);