Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runTest(address, host_override, test_case, tls, test_ca, done, extra) {
// TODO(mlumish): enable TLS functionality
var options = {};
var creds;
if (tls) {
var ca_path;
if (test_ca) {
ca_path = path.join(__dirname, '../data/ca.pem');
var ca_data = fs.readFileSync(ca_path);
creds = grpc.credentials.createSsl(ca_data);
} else {
creds = grpc.credentials.createSsl();
}
if (host_override) {
options['grpc.ssl_target_name_override'] = host_override;
options['grpc.default_authority'] = host_override;
}
} else {
creds = grpc.credentials.createInsecure();
}
var test = test_cases[test_case];
var execute = function(err, creds) {
assert.ifError(err);
var client = new test.Client(address, creds, options);
test.run(client, done, extra);
};
if (test.getCreds) {
test.getCreds(extra.oauth_scope, function(err, new_creds) {
assert.ifError(err);
execute(err, grpc.credentials.combineChannelCredentials(
function runTest(address, host_override, test_case, tls, test_ca, done, extra) {
// TODO(mlumish): enable TLS functionality
var options = {};
var creds;
if (tls) {
var ca_path;
if (test_ca) {
ca_path = path.join(__dirname, '../data/ca.pem');
var ca_data = fs.readFileSync(ca_path);
creds = grpc.credentials.createSsl(ca_data);
} else {
creds = grpc.credentials.createSsl();
}
if (host_override) {
options['grpc.ssl_target_name_override'] = host_override;
options['grpc.default_authority'] = host_override;
}
} else {
creds = grpc.credentials.createInsecure();
}
var test = test_cases[test_case];
var execute = function(err, creds) {
assert.ifError(err);
var client = new test.Client(address, creds, options);
test.run(client, done, extra);
};
if (test.getCreds) {
test.getCreds(extra.oauth_scope, function(err, new_creds) {
assert.ifError(err);
execute(err, grpc.credentials.combineChannelCredentials(
'ssl-target-name-override': 'dummyHost',
'request-timeout': 12345,
'another-property': 'dummyValue7',
'key':'dummyKeyString',
'cert':'dummyCertString',
'grpc.max_send_message_length': 1,
'grpc.max_receive_message_length': 2,
'grpc.keepalive_time_ms': 3,
'grpc.http2.min_time_between_pings_ms': 5,
'grpc.keepalive_timeout_ms': 8,
'grpc.http2.max_pings_without_data': 13,
'grpc.keepalive_permit_without_calls': 21
});
t.equal(handler._options['grpc.ssl_target_name_override'], 'dummyHost', 'Test converting opts.ssl-target-name-override to grpc.ssl_target_name_override');
t.equal(handler._options['grpc.default_authority'], 'dummyHost', 'Test converting opts.ssl-target-name-override to grpc.default_authority');
t.equal(handler._options['request-timeout'], 12345, 'Test processing request-time option');
t.equal(handler._options['another-property'], 'dummyValue7', 'Test processing another-property option');
t.equal(handler._options['grpc.max_send_message_length'], 1, 'Test grpc.max_send_message_length set to 1');
t.equal(handler._options['grpc.max_receive_message_length'], 2, 'Test grpc.max_receive_message_length set to 2');
t.equal(handler._options['grpc.keepalive_time_ms'], 3, 'Test grpc.keepalive_time_ms set to 3');
t.equal(handler._options['grpc.http2.min_time_between_pings_ms'], 5, 'Test grpc.http2.min_time_between_pings_ms set to 5');
t.equal(handler._options['grpc.keepalive_timeout_ms'], 8, 'Test grpc.keepalive_timeout_ms set to 8');
t.equal(handler._options['grpc.http2.max_pings_without_data'], 13, 'Test grpc.http2.max_pings_without_data set to 13');
t.equal(handler._options['grpc.keepalive_permit_without_calls'], 21, 'Test grpc.keepalive_permit_without_calls set to 21');
// The DNS can be case sensitive in some cases (eg Docker DNS)
handler = new Handler(chaincodeObj, 'grpc://Peer.Example.com:7051');
t.equal(handler._endpoint.addr, 'Peer.Example.com:7051', 'Test handler.addr value preserves casing');
t.end();
});
if (typeof chaincode.Init !== 'function') {
throw new Error('The chaincode argument must implement the mandatory "Init()" method');
}
if (typeof chaincode.Invoke !== 'function') {
throw new Error('The chaincode argument must implement the mandatory "Invoke()" method');
}
this.chaincode = chaincode;
// connection options
this._options = {};
if (opts && opts['ssl-target-name-override'] && opts['ssl-target-name-override'] !== '') {
this._options['grpc.ssl_target_name_override'] = opts['ssl-target-name-override'];
this._options['grpc.default_authority'] = opts['ssl-target-name-override'];
}
for (const key in opts ? opts : {}) {
if (key !== 'pem' && key !== 'ssl-target-name-override') {
this._options[key] = opts[key];
}
}
// service connection
this._url = url;
this._endpoint = new Endpoint(url, opts);
// node.js based timeout
this._request_timeout = 30000;
if (opts && opts['request-timeout']) {
this._request_timeout = opts['request-timeout'];
if (options.hasOwnProperty(option)) {
if (!recognizedOptions.hasOwnProperty(option)) {
console.warn(
`Unrecognized channel argument '${option}' will be ignored.`
);
}
}
}
if (credentials._isSecure()) {
this.target = new url.URL(`https://${address}`);
} else {
this.target = new url.URL(`http://${address}`);
}
// TODO(murgatroid99): Add more centralized handling of channel options
if (this.options['grpc.default_authority']) {
this.defaultAuthority = this.options['grpc.default_authority'] as string;
} else {
this.defaultAuthority = this.target.host;
}
this.filterStackFactory = new FilterStackFactory([
new CallCredentialsFilterFactory(this),
new DeadlineFilterFactory(this),
new MetadataStatusFilterFactory(this),
new CompressionFilterFactory(this),
]);
this.currentBackoffDeadline = new Date();
/* The only purpose of these lines is to ensure that this.backoffTimerId has
* a value of type NodeJS.Timer. */
this.backoffTimerId = setTimeout(() => {}, 0);
// Build user-agent string.
this.userAgent = [
ssl_target_name_override = opts['ssl-target-name-override'];
}
else {
ssl_target_name_override = utils.getConfigSetting('ssl-target-name-override','tlsca');
}
if(opts && opts['default-authority']) {
default_authority = opts['default-authority'];
}
else {
default_authority = utils.getConfigSetting('default-authority','tlsca');
}
// connection options
this._options = {};
if(ssl_target_name_override) this._options['grpc.ssl_target_name_override'] = ssl_target_name_override;
if(default_authority) this._options['grpc.default_authority'] = default_authority;
// service connection
this._url = url;
this._endpoint = new utils.Endpoint(url, pem);
}
let defaultServiceConfig = {
loadBalancingConfig: [],
methodConfig: [],
};
if (options['grpc.service_config']) {
defaultServiceConfig = service_config_1.validateServiceConfig(JSON.parse(options['grpc.service_config']));
}
this.resolvingLoadBalancer = new resolving_load_balancer_1.ResolvingLoadBalancer(target, channelControlHelper, defaultServiceConfig);
this.filterStackFactory = new filter_stack_1.FilterStackFactory([
new call_credentials_filter_1.CallCredentialsFilterFactory(this),
new deadline_filter_1.DeadlineFilterFactory(this),
new metadata_status_filter_1.MetadataStatusFilterFactory(this),
new compression_filter_1.CompressionFilterFactory(this),
]);
// TODO(murgatroid99): Add more centralized handling of channel options
if (this.options['grpc.default_authority']) {
this.defaultAuthority = this.options['grpc.default_authority'];
}
else {
this.defaultAuthority = resolver_1.getDefaultAuthority(target);
}
}
/**
stream.sendMetadata(stream.metadata);
stream.end();
});
}
});
const keyCertPairs = [{ private_key: key, cert_chain: cert }];
const creds = ServerCredentials.createSsl(null, keyCertPairs);
port = await server.bind('localhost:0', creds);
server.start();
Client = proto.TestService;
clientSslCreds = Grpc.credentials.createSsl(ca);
const hostOverride = 'foo.test.google.fr';
clientOptions['grpc.ssl_target_name_override'] = hostOverride;
clientOptions['grpc.default_authority'] = hostOverride;
});
"grpc.max_send_message_length": -1
};
var creds;
if (security_params) {
var ca_path;
if (security_params.use_test_ca) {
ca_path = path.join(__dirname, '../data/ca.pem');
var ca_data = fs.readFileSync(ca_path);
creds = grpc.credentials.createSsl(ca_data);
} else {
creds = grpc.credentials.createSsl();
}
if (security_params.server_host_override) {
var host_override = security_params.server_host_override;
options['grpc.ssl_target_name_override'] = host_override;
options['grpc.default_authority'] = host_override;
}
} else {
creds = grpc.credentials.createInsecure();
}
this.clients = [];
var GenericClient = grpc.makeGenericClientConstructor(genericService);
this.genericClients = [];
for (var i = 0; i < channels; i++) {
this.clients[i] = new serviceProto.BenchmarkService(
server_targets[i % server_targets.length], creds, options);
this.genericClients[i] = new GenericClient(
server_targets[i % server_targets.length], creds, options);
}
targets.map(t => {
let text = t._url
if (t._options['grpc.default_authority'] !== undefined) {
text += " " + t._options['grpc.default_authority']
}
return text
}).join(', '),
'...'