mirror of https://github.com/grpc/grpc-node.git
Added failing tests for server bad argument handling
This commit is contained in:
parent
b0390c4af8
commit
06ddb92e9c
|
@ -47,6 +47,8 @@ var mathService = math_proto.lookup('math.Math');
|
||||||
|
|
||||||
var capitalize = require('underscore.string/capitalize');
|
var capitalize = require('underscore.string/capitalize');
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
|
||||||
describe('File loader', function() {
|
describe('File loader', function() {
|
||||||
it('Should load a proto file by default', function() {
|
it('Should load a proto file by default', function() {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
|
@ -178,9 +180,10 @@ describe('Generic client and server', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Trailing metadata', function() {
|
describe('Other conditions', function() {
|
||||||
var client;
|
var client;
|
||||||
var server;
|
var server;
|
||||||
|
var port;
|
||||||
before(function() {
|
before(function() {
|
||||||
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
|
var test_proto = ProtoBuf.loadProtoFile(__dirname + '/test_service.proto');
|
||||||
var test_service = test_proto.lookup('TestService');
|
var test_service = test_proto.lookup('TestService');
|
||||||
|
@ -189,6 +192,7 @@ describe('Trailing metadata', function() {
|
||||||
TestService: {
|
TestService: {
|
||||||
unary: function(call, cb) {
|
unary: function(call, cb) {
|
||||||
var req = call.request;
|
var req = call.request;
|
||||||
|
debugger;
|
||||||
if (req.error) {
|
if (req.error) {
|
||||||
cb(new Error('Requested error'), null, {metadata: ['yes']});
|
cb(new Error('Requested error'), null, {metadata: ['yes']});
|
||||||
} else {
|
} else {
|
||||||
|
@ -246,7 +250,7 @@ describe('Trailing metadata', function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var port = server.bind('localhost:0');
|
port = server.bind('localhost:0');
|
||||||
var Client = surface_client.makeProtobufClientConstructor(test_service);
|
var Client = surface_client.makeProtobufClientConstructor(test_service);
|
||||||
client = new Client('localhost:' + port);
|
client = new Client('localhost:' + port);
|
||||||
server.listen();
|
server.listen();
|
||||||
|
@ -254,86 +258,163 @@ describe('Trailing metadata', function() {
|
||||||
after(function() {
|
after(function() {
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
});
|
});
|
||||||
it('should be present when a unary call succeeds', function(done) {
|
describe('Server recieving bad input', function() {
|
||||||
var call = client.unary({error: false}, function(err, data) {
|
var misbehavingClient;
|
||||||
assert.ifError(err);
|
var badArg = new Buffer([0xFF]);
|
||||||
|
before(function() {
|
||||||
|
var test_service_attrs = {
|
||||||
|
unary: {
|
||||||
|
path: '/TestService/Unary',
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: _.identity,
|
||||||
|
responseDeserialize: _.identity
|
||||||
|
},
|
||||||
|
clientStream: {
|
||||||
|
path: '/TestService/ClientStream',
|
||||||
|
requestStream: true,
|
||||||
|
responseStream: false,
|
||||||
|
requestSerialize: _.identity,
|
||||||
|
responseDeserialize: _.identity
|
||||||
|
},
|
||||||
|
serverStream: {
|
||||||
|
path: '/TestService/ServerStream',
|
||||||
|
requestStream: false,
|
||||||
|
responseStream: true,
|
||||||
|
requestSerialize: _.identity,
|
||||||
|
responseDeserialize: _.identity
|
||||||
|
},
|
||||||
|
bidiStream: {
|
||||||
|
path: '/TestService/BidiStream',
|
||||||
|
requestStream: true,
|
||||||
|
responseStream: true,
|
||||||
|
requestSerialize: _.identity,
|
||||||
|
responseDeserialize: _.identity
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var Client = surface_client.makeClientConstructor(test_service_attrs,
|
||||||
|
'TestService');
|
||||||
|
misbehavingClient = new Client('localhost:' + port);
|
||||||
});
|
});
|
||||||
call.on('status', function(status) {
|
it('should respond correctly to a unary call', function(done) {
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
var call = misbehavingClient.unary(badArg, function(err, data) {
|
||||||
done();
|
assert(err);
|
||||||
|
assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should respond correctly to a client stream', function(done) {
|
||||||
|
var call = misbehavingClient.clientStream(function(err, data) {
|
||||||
|
assert(err);
|
||||||
|
assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call.write(badArg);
|
||||||
|
});
|
||||||
|
it('should respond correctly to a server stream', function(done) {
|
||||||
|
var call = misbehavingClient.serverStream(badArg);
|
||||||
|
call.on('data', function(data) {
|
||||||
|
assert.fail(data, null, 'Unexpected data', '!=');
|
||||||
|
});
|
||||||
|
call.on('error', function(err) {
|
||||||
|
assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should respond correctly to a bidi stream', function(done) {
|
||||||
|
var call = misbehavingClient.bidiStream();
|
||||||
|
call.on('data', function(data) {
|
||||||
|
assert.fail(data, null, 'Unexpected data', '!=');
|
||||||
|
});
|
||||||
|
call.on('error', function(err) {
|
||||||
|
assert.strictEqual(err.code, grpc.status.INVALID_ARGUMENT);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
call.write(badArg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should be present when a unary call fails', function(done) {
|
describe('Trailing metadata', function() {
|
||||||
var call = client.unary({error: true}, function(err, data) {
|
it('should be present when a unary call succeeds', function(done) {
|
||||||
assert(err);
|
var call = client.unary({error: false}, function(err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
});
|
||||||
|
call.on('status', function(status) {
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
call.on('status', function(status) {
|
it('should be present when a unary call fails', function(done) {
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
var call = client.unary({error: true}, function(err, data) {
|
||||||
done();
|
assert(err);
|
||||||
|
});
|
||||||
|
call.on('status', function(status) {
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
it('should be present when a client stream call succeeds', function(done) {
|
||||||
it('should be present when a client stream call succeeds', function(done) {
|
var call = client.clientStream(function(err, data) {
|
||||||
var call = client.clientStream(function(err, data) {
|
assert.ifError(err);
|
||||||
assert.ifError(err);
|
});
|
||||||
|
call.write({error: false});
|
||||||
|
call.write({error: false});
|
||||||
|
call.end();
|
||||||
|
call.on('status', function(status) {
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
call.write({error: false});
|
it('should be present when a client stream call fails', function(done) {
|
||||||
call.write({error: false});
|
var call = client.clientStream(function(err, data) {
|
||||||
call.end();
|
assert(err);
|
||||||
call.on('status', function(status) {
|
});
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
call.write({error: false});
|
||||||
done();
|
call.write({error: true});
|
||||||
|
call.end();
|
||||||
|
call.on('status', function(status) {
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
it('should be present when a server stream call succeeds', function(done) {
|
||||||
it('should be present when a client stream call fails', function(done) {
|
var call = client.serverStream({error: false});
|
||||||
var call = client.clientStream(function(err, data) {
|
call.on('data', function(){});
|
||||||
assert(err);
|
call.on('status', function(status) {
|
||||||
|
assert.strictEqual(status.code, grpc.status.OK);
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
call.write({error: false});
|
it('should be present when a server stream call fails', function(done) {
|
||||||
call.write({error: true});
|
var call = client.serverStream({error: true});
|
||||||
call.end();
|
call.on('data', function(){});
|
||||||
call.on('status', function(status) {
|
call.on('error', function(error) {
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
assert.deepEqual(error.metadata.metadata, ['yes']);
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
it('should be present when a bidi stream succeeds', function(done) {
|
||||||
it('should be present when a server stream call succeeds', function(done) {
|
var call = client.bidiStream();
|
||||||
var call = client.serverStream({error: false});
|
call.write({error: false});
|
||||||
call.on('data', function(){});
|
call.write({error: false});
|
||||||
call.on('status', function(status) {
|
call.end();
|
||||||
assert.strictEqual(status.code, grpc.status.OK);
|
call.on('data', function(){});
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
call.on('status', function(status) {
|
||||||
done();
|
assert.strictEqual(status.code, grpc.status.OK);
|
||||||
|
assert.deepEqual(status.metadata.metadata, ['yes']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
it('should be present when a bidi stream fails', function(done) {
|
||||||
it('should be present when a server stream call fails', function(done) {
|
var call = client.bidiStream();
|
||||||
var call = client.serverStream({error: true});
|
call.write({error: false});
|
||||||
call.on('data', function(){});
|
call.write({error: true});
|
||||||
call.on('error', function(error) {
|
call.end();
|
||||||
assert.deepEqual(error.metadata.metadata, ['yes']);
|
call.on('data', function(){});
|
||||||
done();
|
call.on('error', function(error) {
|
||||||
});
|
assert.deepEqual(error.metadata.metadata, ['yes']);
|
||||||
});
|
done();
|
||||||
it('should be present when a bidi stream succeeds', function(done) {
|
});
|
||||||
var call = client.bidiStream();
|
|
||||||
call.write({error: false});
|
|
||||||
call.write({error: false});
|
|
||||||
call.end();
|
|
||||||
call.on('data', function(){});
|
|
||||||
call.on('status', function(status) {
|
|
||||||
assert.strictEqual(status.code, grpc.status.OK);
|
|
||||||
assert.deepEqual(status.metadata.metadata, ['yes']);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should be present when a bidi stream fails', function(done) {
|
|
||||||
var call = client.bidiStream();
|
|
||||||
call.write({error: false});
|
|
||||||
call.write({error: true});
|
|
||||||
call.end();
|
|
||||||
call.on('data', function(){});
|
|
||||||
call.on('error', function(error) {
|
|
||||||
assert.deepEqual(error.metadata.metadata, ['yes']);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue