Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tcurl

Package Overview
Dependencies
Maintainers
6
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcurl - npm Package Compare versions

Comparing version 4.12.4 to 4.13.0

test/legacy.thrift

69

index.js

@@ -53,3 +53,3 @@ #!/usr/bin/env node

var minimistArgs = {
boolean: ['raw'],
boolean: ['raw', 'strict'],
alias: {

@@ -66,9 +66,8 @@ h: 'help',

head: '',
body: ''
body: '',
strict: true
}
};
var throwOnError = true;
if (require.main === module) {
throwOnError = false;
main(minimist(process.argv.slice(2), minimistArgs));

@@ -95,2 +94,3 @@ }

' -t [dir] directory containing Thrift files',
' --no-strict parse Thrift loosely',
' --http method',

@@ -136,2 +136,3 @@ ' --raw encode arg2 & arg3 raw',

thrift: argv.thrift,
strict: argv.strict,
http: argv.http,

@@ -154,4 +155,3 @@ json: argv.json,

var opts = parseArgs(argv);
opts.onResponse = onResponse;
tcurl(opts);
tcurl(opts, onResponse);
}

@@ -168,7 +168,2 @@

});
if (!throwOnError) {
process.exit(-1);
} else {
throw err;
}
}

@@ -187,8 +182,2 @@

});
if (!throwOnError) {
process.exit(-1);
} else {
throw err;
}
}

@@ -233,2 +222,3 @@

opts.thrift + '"', err);
return null;
}

@@ -257,2 +247,3 @@ }

reportError(opts.logger, err.message, err);
return null;
}

@@ -263,3 +254,4 @@

function tcurl(opts) {
function tcurl(opts, callback) {
callback = callback || defaultCallback;
var logger = opts.logger;

@@ -305,3 +297,3 @@

});
meta.health(request, opts.onResponse);
meta.health(request, callback);
} else if (opts.thrift) {

@@ -319,2 +311,4 @@ asThrift(opts, request, onResponse);

function onResponse(err, resp, arg2, arg3) {
client.quit();
if (arg2 !== undefined && resp) {

@@ -327,10 +321,14 @@ resp.head = arg2;

if (opts.onResponse) {
opts.onResponse(err, resp, arg2, arg3);
client.quit();
return;
callback(err, resp, arg2, arg3);
}
function defaultCallback(err, resp) {
if (err && err.type === 'thrift-parse-error') {
logger.display('error', err.message);
logger.display('error',
'Consider using --no-strict to bypass mandatory optional/required field assertions');
}
client.quit();
if (err && err.exitCode) {
process.exit(err.exitCode);
}
if (err) {

@@ -340,3 +338,4 @@ logger.displayResponse('error', 'Got an error response', err);

process.exit(1);
} else if (!resp.ok) {
}
if (!resp.ok) {
logger.displayResponse('error',

@@ -350,2 +349,3 @@ 'Got call response not ok', resp.body);

}
}

@@ -356,4 +356,16 @@

var sender = new TChannelAsThrift({source: spec});
if (spec === null) {
return onResponse({exitCode: 1});
}
var sender;
try {
sender = new TChannelAsThrift({source: spec, strict: opts.strict});
} catch (err) {
err.message = 'Error parsing Thrift IDL: ' + err.message;
err.type = 'thrift-parse-error';
err.exitCode = 1;
return onResponse(err);
}
// The following is a hack to produce a nice error message when

@@ -377,2 +389,3 @@ // the endpoint does not exist. It is a temporary solution based

+ msg, e);
return onResponse(e);
}

@@ -379,0 +392,0 @@ }

@@ -77,3 +77,5 @@ #!/usr/bin/env node

var self = this;
if (self.options.json) {
if (typeof value === 'string') {
self.log(level, value);
} else if (self.options.json) {
self.log(level, JSON.stringify(value, null, self.options.json));

@@ -80,0 +82,0 @@ } else if (self.options.raw) {

{
"name": "tcurl",
"version": "4.12.4",
"version": "4.13.0",
"description": "A command line utility to talk to a tchannel server",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -33,2 +33,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

var meta = fs.readFileSync(path.join(__dirname, '..', 'meta.thrift'), 'utf-8');
var legacy = fs.readFileSync(path.join(__dirname, 'legacy.thrift'), 'utf-8');

@@ -139,4 +140,82 @@ test('getting an ok response', function t(assert) {

function noop() {}
});
test('fails to run for invalid thrift', function t(assert) {
var serviceName = 'meta';
var server = new TChannel({
serviceName: serviceName
});
var hostname = '127.0.0.1';
var port = 4040;
server.listen(port, hostname, onListening);
function onListening() {
var cmd = [
'-p', '127.0.0.1:4040',
'no-service',
'no-endpoint',
'-t', path.join(__dirname, 'legacy.thrift')
];
tcurl.exec(cmd, afterExec);
}
function afterExec(err) {
if (!err) {
assert.fail('expected error');
return assert.end();
}
assert.equal(err.message,
'Error parsing Thrift IDL: every field must be marked optional, ' +
'required, or have a default value on Feckless including ' +
'"ambiguity" in strict mode', 'expected thrift IDL validation error');
server.close();
assert.end();
}
});
test('tolerates loose thrift with --no-strict', function t(assert) {
var serviceName = 'legacy';
var server = new TChannel({
serviceName: serviceName
});
var hostname = '127.0.0.1';
var port = 4040;
server.listen(port, hostname, onListening);
var tchannelAsThrift = TChannelAsThrift({source: legacy, strict: false});
tchannelAsThrift.register(server, 'Pinger::ping', {}, ping);
function onListening() {
var cmd = [
'-p', '127.0.0.1:4040',
'legacy',
'Pinger::ping',
'--no-strict',
'-t', path.join(__dirname, 'legacy.thrift')
];
tcurl.exec(cmd, afterExec);
}
function afterExec(err) {
server.close();
assert.end(err);
}
});
function ping(options, req, head, body, cb) {
cb(null, {ok: true, head: null, body: null});
}
function noop() {}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc