aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/interop
diff options
context:
space:
mode:
authorGravatar murgatroid99 <michael.lumish@gmail.com>2015-01-21 10:30:36 -0800
committerGravatar murgatroid99 <michael.lumish@gmail.com>2015-01-21 10:30:36 -0800
commitb6ab1b477f2c0df860acafd91047da2de288e9fe (patch)
tree17da6d2a2dd95501d91d737acf38c4949333a0aa /src/node/interop
parent6d10bda989f41d88746aa1b7e760707d71a49407 (diff)
Added TLS support to interop tests
Diffstat (limited to 'src/node/interop')
-rw-r--r--src/node/interop/interop_client.js60
-rw-r--r--src/node/interop/interop_server.js62
2 files changed, 118 insertions, 4 deletions
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 7cacf83cb9..cf75b9a77a 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -31,17 +31,30 @@
*
*/
+var fs = require('fs');
+var path = require('path');
var grpc = require('..');
var testProto = grpc.load(__dirname + '/test.proto').grpc.testing;
var assert = require('assert');
+/**
+ * Create a buffer filled with size zeroes
+ * @param {number} size The length of the buffer
+ * @return {Buffer} The new buffer
+ */
function zeroBuffer(size) {
var zeros = new Buffer(size);
zeros.fill(0);
return zeros;
}
+/**
+ * Run the empty_unary test
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function emptyUnary(client, done) {
var call = client.emptyCall({}, function(err, resp) {
assert.ifError(err);
@@ -54,6 +67,12 @@ function emptyUnary(client, done) {
});
}
+/**
+ * Run the large_unary test
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function largeUnary(client, done) {
var arg = {
response_type: testProto.PayloadType.COMPRESSABLE,
@@ -76,6 +95,12 @@ function largeUnary(client, done) {
});
}
+/**
+ * Run the client_streaming test
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function clientStreaming(client, done) {
var call = client.streamingInputCall(function(err, resp) {
assert.ifError(err);
@@ -94,6 +119,12 @@ function clientStreaming(client, done) {
call.end();
}
+/**
+ * Run the server_streaming test
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function serverStreaming(client, done) {
var arg = {
response_type: testProto.PayloadType.COMPRESSABLE,
@@ -122,6 +153,12 @@ function serverStreaming(client, done) {
});
}
+/**
+ * Run the ping_pong test
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function pingPong(client, done) {
var payload_sizes = [27182, 8, 1828, 45904];
var response_sizes = [31415, 9, 2653, 58979];
@@ -160,6 +197,13 @@ function pingPong(client, done) {
});
}
+/**
+ * Run the empty_stream test.
+ * NOTE: This does not work, but should with the new invoke API
+ * @param {Client} client The client to test against
+ * @param {function} done Callback to call when the test is completed. Included
+ * primarily for use with mocha
+ */
function emptyStream(client, done) {
var call = client.fullDuplexCall();
call.on('status', function(status) {
@@ -174,6 +218,9 @@ function emptyStream(client, done) {
call.end();
}
+/**
+ * Map from test case names to test functions
+ */
var test_cases = {
empty_unary: emptyUnary,
large_unary: largeUnary,
@@ -196,8 +243,17 @@ var test_cases = {
*/
function runTest(address, host_override, test_case, tls, done) {
// TODO(mlumish): enable TLS functionality
- // TODO(mlumish): fix namespaces and service name
- var client = new testProto.TestService(address);
+ var options = {};
+ if (tls) {
+ var ca_path = path.join(__dirname, '../test/data/ca.pem');
+ var ca_data = fs.readFileSync(ca_path);
+ var creds = grpc.Credentials.createSsl(ca_data);
+ options.credentials = creds;
+ if (host_override) {
+ options['grpc.ssl_target_name_override'] = host_override;
+ }
+ }
+ var client = new testProto.TestService(address, options);
test_cases[test_case](client, done);
}
diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js
index 3eb663c1d5..735b7a6d18 100644
--- a/src/node/interop/interop_server.js
+++ b/src/node/interop/interop_server.js
@@ -31,21 +31,41 @@
*
*/
+var fs = require('fs');
+var path = require('path');
var _ = require('underscore');
var grpc = require('..');
var testProto = grpc.load(__dirname + '/test.proto').grpc.testing;
var Server = grpc.buildServer([testProto.TestService.service]);
+/**
+ * Create a buffer filled with size zeroes
+ * @param {number} size The length of the buffer
+ * @return {Buffer} The new buffer
+ */
function zeroBuffer(size) {
var zeros = new Buffer(size);
zeros.fill(0);
return zeros;
}
+/**
+ * Respond to an empty parameter with an empty response.
+ * NOTE: this currently does not work due to issue #137
+ * @param {Call} call Call to handle
+ * @param {function(Error, Object)} callback Callback to call with result
+ * or error
+ */
function handleEmpty(call, callback) {
callback(null, {});
}
+/**
+ * Handle a unary request by sending the requested payload
+ * @param {Call} call Call to handle
+ * @param {function(Error, Object)} callback Callback to call with result or
+ * error
+ */
function handleUnary(call, callback) {
var req = call.request;
var zeros = zeroBuffer(req.response_size);
@@ -58,6 +78,12 @@ function handleUnary(call, callback) {
callback(null, {payload: {type: payload_type, body: zeros}});
}
+/**
+ * Respond to a streaming call with the total size of all payloads
+ * @param {Call} call Call to handle
+ * @param {function(Error, Object)} callback Callback to call with result or
+ * error
+ */
function handleStreamingInput(call, callback) {
var aggregate_size = 0;
call.on('data', function(value) {
@@ -68,6 +94,10 @@ function handleStreamingInput(call, callback) {
});
}
+/**
+ * Respond to a payload request with a stream of the requested payloads
+ * @param {Call} call Call to handle
+ */
function handleStreamingOutput(call) {
var req = call.request;
var payload_type = req.response_type;
@@ -87,6 +117,11 @@ function handleStreamingOutput(call) {
call.end();
}
+/**
+ * Respond to a stream of payload requests with a stream of payload responses as
+ * they arrive.
+ * @param {Call} call Call to handle
+ */
function handleFullDuplex(call) {
call.on('data', function(value) {
var payload_type = value.response_type;
@@ -109,12 +144,35 @@ function handleFullDuplex(call) {
});
}
+/**
+ * Respond to a stream of payload requests with a stream of payload responses
+ * after all requests have arrived
+ * @param {Call} call Call to handle
+ */
function handleHalfDuplex(call) {
throw new Error('HalfDuplexCall not yet implemented');
}
+/**
+ * Get a server object bound to the given port
+ * @param {string} port Port to which to bind
+ * @param {boolean} tls Indicates that the bound port should use TLS
+ * @return {Server} Server object bound to the support
+ */
function getServer(port, tls) {
// TODO(mlumish): enable TLS functionality
+ var options = {};
+ if (tls) {
+ var key_path = path.join(__dirname, '../test/data/server1.key');
+ var pem_path = path.join(__dirname, '../test/data/server1.pem');
+
+ var key_data = fs.readFileSync(key_path);
+ var pem_data = fs.readFileSync(pem_path);
+ var server_creds = grpc.ServerCredentials.createSsl(null,
+ key_data,
+ pem_data);
+ options.credentials = server_creds;
+ }
var server = new Server({
'grpc.testing.TestService' : {
emptyCall: handleEmpty,
@@ -124,8 +182,8 @@ function getServer(port, tls) {
fullDuplexCall: handleFullDuplex,
halfDuplexCall: handleHalfDuplex
}
- });
- server.bind('0.0.0.0:' + port);
+ }, options);
+ server.bind('0.0.0.0:' + port, tls);
return server;
}