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 ** 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
} else {
const split = url.split('//');
this._name = split[1];
}
// node.js based timeout
if (utils.checkIntegerConfig(opts, 'request-timeout')) {
this._request_timeout = opts['request-timeout'];
} else {
this._request_timeout = utils.getConfigSetting('request-timeout', 30000); // default 30 seconds
}
if (utils.checkIntegerConfig(opts, 'grpc-wait-for-ready-timeout')) {
this._grpc_wait_for_ready_timeout = opts['grpc-wait-for-ready-timeout'];
} else {
this._grpc_wait_for_ready_timeout = utils.getConfigSetting('grpc-wait-for-ready-timeout', 3000); // default 3 seconds
}
super_logger.debug(' ** Remote instance url: %s, name: %s, options loaded are:: %j', this._url, this._name, this._options);
}
if (!params) {
errorMsg = 'Missing all required input parameters';
} else if (!params.request) {
errorMsg = 'Missing "request" input parameter';
} else if (!params.signed_envelope) {
errorMsg = 'Missing "signed_envelope" input parameter';
}
if (errorMsg) {
logger.error('Commit Handler error:' + errorMsg);
throw new Error(errorMsg);
}
const request = Object.assign({}, params.request);
let timeout = utils.getConfigSetting('request-timeout');
if (params.timeout) {
timeout = params.timeout;
}
if (!request.orderer) {
logger.debug('%s - using commit handler', method);
// this will check the age of the results and get new results if needed
try {
await this._channel.getDiscoveryResults(); // this will cause a refresh if using discovery and the results are old
} catch (error) {
// No problem, user may not be using discovery
logger.debug('%s - no discovery results %s', method, error);
}
// Orderers will be assigned to the channel by this point
return this._commit(params.signed_envelope, timeout);
if (typeof grpc_receive_max === 'undefined') {
grpc_receive_max = -1; // default is unlimited
}
// keep this for backward compatibility until remove probably deprecated code (lines 83-115)
this._options[MAX_RECEIVE] = (this._options[MAX_RECEIVE] && (this._options[MAX_RECEIVE] !== -1))
? this._options[MAX_RECEIVE] : grpc_receive_max;
let grpc_send_max;
if (opts[MAX_SEND_V10]) {
grpc_send_max = opts[MAX_SEND_V10];
} else if (opts[MAX_SEND]) {
grpc_send_max = opts[MAX_SEND];
} else {
grpc_send_max = utils.getConfigSetting(MAX_SEND_V10);
if (typeof grpc_send_max === 'undefined') {
grpc_send_max = utils.getConfigSetting(MAX_SEND);
}
}
if (typeof grpc_send_max === 'undefined') {
grpc_send_max = -1; // default is unlimited
}
this._options[MAX_SEND] = (this._options[MAX_SEND] && (this._options[MAX_SEND] !== -1)) ? this._options[MAX_SEND] : grpc_send_max;
// service connection
this._url = url;
this._endpoint = new Endpoint(url, pem, clientKey, this.clientCert);
// what shall we call this remote object
if (opts && opts.name) {
this._name = opts.name;
} else {
const split = url.split('//');
this._connect_running = true;
this._current_stream++;
const stream_id = this._current_stream;
logger.debug('_connect - start stream:', stream_id);
const self = this; // for callback context
const connection_setup_timeout = setTimeout(() => {
logger.error('_connect - timed out after:%s', self._peer._request_timeout);
self._connect_running = false;
self._disconnect(new Error('Unable to connect to the fabric peer service'));
}, self._peer._request_timeout);
// check on the keep alive options
// the keep alive interval
let options = utils.checkAndAddConfigSetting('grpc.keepalive_time_ms', 360000, this._peer._options);
// how long should we wait for the keep alive response
const request_timeout_ms = utils.getConfigSetting('request-timeout', 3000);
options = utils.checkAndAddConfigSetting('grpc.keepalive_timeout_ms', request_timeout_ms, options);
options = utils.checkAndAddConfigSetting('grpc.http2.min_time_between_pings_ms', five_minutes_ms, options);
logger.debug('_connect - options %j', options);
this._event_client = new fabprotos.protos.Deliver(this._peer._endpoint.addr, this._peer._endpoint.creds, options);
if (this._filtered_stream) {
this._stream = this._event_client.deliverFiltered();
} else {
if (this._stream_with_private_data) {
this._stream = this._event_client.deliverWithPrivateData();
} else {
this._stream = this._event_client.deliver();
}
}
this._stream.on('data', (deliverResponse) => {
this.clientCert = clientCert;
// connection options
if (ssl_target_name_override && typeof ssl_target_name_override === 'string') {
this._options['grpc.ssl_target_name_override'] = ssl_target_name_override;
this._options['grpc.default_authority'] = ssl_target_name_override;
}
let grpc_receive_max;
if (opts[MAX_RECEIVE_V10]) {
grpc_receive_max = opts[MAX_RECEIVE_V10];
} else if (opts[MAX_RECEIVE]) {
grpc_receive_max = opts[MAX_RECEIVE];
} else {
grpc_receive_max = utils.getConfigSetting(MAX_RECEIVE_V10);
if (typeof grpc_receive_max === 'undefined') {
grpc_receive_max = utils.getConfigSetting(MAX_RECEIVE);
}
}
if (typeof grpc_receive_max === 'undefined') {
grpc_receive_max = -1; // default is unlimited
}
// keep this for backward compatibility until remove probably deprecated code (lines 83-115)
this._options[MAX_RECEIVE] = (this._options[MAX_RECEIVE] && (this._options[MAX_RECEIVE] !== -1))
? this._options[MAX_RECEIVE] : grpc_receive_max;
let grpc_send_max;
if (opts[MAX_SEND_V10]) {
grpc_send_max = opts[MAX_SEND_V10];
} else if (opts[MAX_SEND]) {
grpc_send_max = opts[MAX_SEND];
function sentConnectionOptionsIfDefined(optionName, optionValue) {
if (optionValue !== null) {
let connectionOptions = utils.getConfigSetting('connection-options');
connectionOptions = Object.assign(connectionOptions, {[optionName]:optionValue});
utils.setConfigSetting('connection-options', connectionOptions);
}
}
_getLegacyOptions() {
const MAX_SEND = 'grpc.max_send_message_length';
const MAX_RECEIVE = 'grpc.max_receive_message_length';
const MAX_SEND_V10 = 'grpc-max-send-message-length';
const MAX_RECEIVE_V10 = 'grpc-max-receive-message-length';
const LEGACY_WARN_MESSAGE = 'Setting grpc options by utils.setConfigSetting() is deprecated. Use utils.g(s)etConfigSetting("connection-options")';
const result = {};
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE)});
}
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE_V10) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE_V10)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND_V10) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND_V10)});
}
if (Object.keys(result).length > 0) {
logger.warn(LEGACY_WARN_MESSAGE);
}
return result;
}
const MAX_RECEIVE = 'grpc.max_receive_message_length';
const MAX_SEND_V10 = 'grpc-max-send-message-length';
const MAX_RECEIVE_V10 = 'grpc-max-receive-message-length';
const LEGACY_WARN_MESSAGE = 'Setting grpc options by utils.setConfigSetting() is deprecated. Use utils.g(s)etConfigSetting("connection-options")';
const result = {};
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE)});
}
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE_V10) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE_V10)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND_V10) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND_V10)});
}
if (Object.keys(result).length > 0) {
logger.warn(LEGACY_WARN_MESSAGE);
}
return result;
}
_getLegacyOptions() {
const MAX_SEND = 'grpc.max_send_message_length';
const MAX_RECEIVE = 'grpc.max_receive_message_length';
const MAX_SEND_V10 = 'grpc-max-send-message-length';
const MAX_RECEIVE_V10 = 'grpc-max-receive-message-length';
const LEGACY_WARN_MESSAGE = 'Setting grpc options by utils.setConfigSetting() is deprecated. Use utils.g(s)etConfigSetting("connection-options")';
const result = {};
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE)});
}
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE_V10) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE_V10)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND_V10) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND_V10)});
}
if (Object.keys(result).length > 0) {
logger.warn(LEGACY_WARN_MESSAGE);
}
return result;
}