Merge pull request #3 from murgatroid99/node_core_creds_api_change

Node wrapping of core credentials API change
reviewable/pr3765/r1
jboeuf 9 years ago
commit 276266d0b0
  1. 2
      src/node/ext/call.cc
  2. 18
      src/node/ext/call_credentials.cc
  3. 12
      src/node/ext/call_credentials.h
  4. 2
      src/node/ext/channel.cc
  5. 17
      src/node/ext/channel_credentials.cc
  6. 14
      src/node/ext/channel_credentials.h
  7. 23
      src/node/test/credentials_test.js

@ -757,7 +757,7 @@ NAN_METHOD(Call::SetCredentials) {
Call *call = ObjectWrap::Unwrap<Call>(info.This());
CallCredentials *creds_object = ObjectWrap::Unwrap<CallCredentials>(
Nan::To<Object>(info[0]).ToLocalChecked());
grpc_credentials *creds = creds_object->GetWrappedCredentials();
grpc_call_credentials *creds = creds_object->GetWrappedCredentials();
grpc_call_error error = GRPC_CALL_ERROR;
if (creds) {
error = grpc_call_set_credentials(call->wrapped_call, creds);

@ -64,11 +64,11 @@ using v8::Value;
Nan::Callback *CallCredentials::constructor;
Persistent<FunctionTemplate> CallCredentials::fun_tpl;
CallCredentials::CallCredentials(grpc_credentials *credentials)
CallCredentials::CallCredentials(grpc_call_credentials *credentials)
: wrapped_credentials(credentials) {}
CallCredentials::~CallCredentials() {
grpc_credentials_release(wrapped_credentials);
grpc_call_credentials_release(wrapped_credentials);
}
void CallCredentials::Init(Local<Object> exports) {
@ -91,7 +91,7 @@ bool CallCredentials::HasInstance(Local<Value> val) {
return Nan::New(fun_tpl)->HasInstance(val);
}
Local<Value> CallCredentials::WrapStruct(grpc_credentials *credentials) {
Local<Value> CallCredentials::WrapStruct(grpc_call_credentials *credentials) {
EscapableHandleScope scope;
const int argc = 1;
if (credentials == NULL) {
@ -108,7 +108,7 @@ Local<Value> CallCredentials::WrapStruct(grpc_credentials *credentials) {
}
}
grpc_credentials *CallCredentials::GetWrappedCredentials() {
grpc_call_credentials *CallCredentials::GetWrappedCredentials() {
return wrapped_credentials;
}
@ -119,8 +119,8 @@ NAN_METHOD(CallCredentials::New) {
"CallCredentials can only be created with the provided functions");
}
Local<External> ext = info[0].As<External>();
grpc_credentials *creds_value =
reinterpret_cast<grpc_credentials *>(ext->Value());
grpc_call_credentials *creds_value =
reinterpret_cast<grpc_call_credentials *>(ext->Value());
CallCredentials *credentials = new CallCredentials(creds_value);
credentials->Wrap(info.This());
info.GetReturnValue().Set(info.This());
@ -144,7 +144,7 @@ NAN_METHOD(CallCredentials::Compose) {
CallCredentials *self = ObjectWrap::Unwrap<CallCredentials>(info.This());
CallCredentials *other = ObjectWrap::Unwrap<CallCredentials>(
Nan::To<Object>(info[0]).ToLocalChecked());
grpc_credentials *creds = grpc_composite_credentials_create(
grpc_call_credentials *creds = grpc_composite_call_credentials_create(
self->wrapped_credentials, other->wrapped_credentials, NULL);
info.GetReturnValue().Set(WrapStruct(creds));
}
@ -162,8 +162,8 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) {
plugin.get_metadata = plugin_get_metadata;
plugin.destroy = plugin_destroy_state;
plugin.state = reinterpret_cast<void*>(state);
grpc_credentials *creds = grpc_metadata_credentials_create_from_plugin(plugin,
NULL);
grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(
plugin, NULL);
info.GetReturnValue().Set(WrapStruct(creds));
}

@ -45,14 +45,14 @@ class CallCredentials : public Nan::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
static bool HasInstance(v8::Local<v8::Value> val);
/* Wrap a grpc_credentials struct in a javascript object */
static v8::Local<v8::Value> WrapStruct(grpc_credentials *credentials);
/* Wrap a grpc_call_credentials struct in a javascript object */
static v8::Local<v8::Value> WrapStruct(grpc_call_credentials *credentials);
/* Returns the grpc_credentials struct that this object wraps */
grpc_credentials *GetWrappedCredentials();
/* Returns the grpc_call_credentials struct that this object wraps */
grpc_call_credentials *GetWrappedCredentials();
private:
explicit CallCredentials(grpc_credentials *credentials);
explicit CallCredentials(grpc_call_credentials *credentials);
~CallCredentials();
// Prevent copying
@ -68,7 +68,7 @@ class CallCredentials : public Nan::ObjectWrap {
// Used for typechecking instances of this javascript class
static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_credentials *wrapped_credentials;
grpc_call_credentials *wrapped_credentials;
};
/* Auth metadata plugin functionality */

@ -177,7 +177,7 @@ NAN_METHOD(Channel::New) {
grpc_channel *wrapped_channel;
// Owned by the Channel object
Utf8String host(info[0]);
grpc_credentials *creds;
grpc_channel_credentials *creds;
if (!ChannelCredentials::HasInstance(info[1])) {
return Nan::ThrowTypeError(
"Channel's second argument must be a ChannelCredentials");

@ -65,11 +65,11 @@ using v8::Value;
Nan::Callback *ChannelCredentials::constructor;
Persistent<FunctionTemplate> ChannelCredentials::fun_tpl;
ChannelCredentials::ChannelCredentials(grpc_credentials *credentials)
ChannelCredentials::ChannelCredentials(grpc_channel_credentials *credentials)
: wrapped_credentials(credentials) {}
ChannelCredentials::~ChannelCredentials() {
grpc_credentials_release(wrapped_credentials);
grpc_channel_credentials_release(wrapped_credentials);
}
void ChannelCredentials::Init(Local<Object> exports) {
@ -95,7 +95,8 @@ bool ChannelCredentials::HasInstance(Local<Value> val) {
return Nan::New(fun_tpl)->HasInstance(val);
}
Local<Value> ChannelCredentials::WrapStruct(grpc_credentials *credentials) {
Local<Value> ChannelCredentials::WrapStruct(
grpc_channel_credentials *credentials) {
EscapableHandleScope scope;
const int argc = 1;
Local<Value> argv[argc] = {
@ -109,7 +110,7 @@ Local<Value> ChannelCredentials::WrapStruct(grpc_credentials *credentials) {
}
}
grpc_credentials *ChannelCredentials::GetWrappedCredentials() {
grpc_channel_credentials *ChannelCredentials::GetWrappedCredentials() {
return wrapped_credentials;
}
@ -120,8 +121,8 @@ NAN_METHOD(ChannelCredentials::New) {
"ChannelCredentials can only be created with the provided functions");
}
Local<External> ext = info[0].As<External>();
grpc_credentials *creds_value =
reinterpret_cast<grpc_credentials *>(ext->Value());
grpc_channel_credentials *creds_value =
reinterpret_cast<grpc_channel_credentials *>(ext->Value());
ChannelCredentials *credentials = new ChannelCredentials(creds_value);
credentials->Wrap(info.This());
info.GetReturnValue().Set(info.This());
@ -153,7 +154,7 @@ NAN_METHOD(ChannelCredentials::CreateSsl) {
return Nan::ThrowTypeError(
"createSSl's third argument must be a Buffer if provided");
}
grpc_credentials *creds = grpc_ssl_credentials_create(
grpc_channel_credentials *creds = grpc_ssl_credentials_create(
root_certs, key_cert_pair.private_key == NULL ? NULL : &key_cert_pair,
NULL);
if (creds == NULL) {
@ -180,7 +181,7 @@ NAN_METHOD(ChannelCredentials::Compose) {
}
CallCredentials *other = ObjectWrap::Unwrap<CallCredentials>(
Nan::To<Object>(info[0]).ToLocalChecked());
grpc_credentials *creds = grpc_composite_credentials_create(
grpc_channel_credentials *creds = grpc_composite_channel_credentials_create(
self->wrapped_credentials, other->GetWrappedCredentials(), NULL);
if (creds == NULL) {
info.GetReturnValue().SetNull();

@ -42,19 +42,19 @@
namespace grpc {
namespace node {
/* Wrapper class for grpc_credentials structs */
/* Wrapper class for grpc_channel_credentials structs */
class ChannelCredentials : public Nan::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
static bool HasInstance(v8::Local<v8::Value> val);
/* Wrap a grpc_credentials struct in a javascript object */
static v8::Local<v8::Value> WrapStruct(grpc_credentials *credentials);
/* Wrap a grpc_channel_credentials struct in a javascript object */
static v8::Local<v8::Value> WrapStruct(grpc_channel_credentials *credentials);
/* Returns the grpc_credentials struct that this object wraps */
grpc_credentials *GetWrappedCredentials();
/* Returns the grpc_channel_credentials struct that this object wraps */
grpc_channel_credentials *GetWrappedCredentials();
private:
explicit ChannelCredentials(grpc_credentials *credentials);
explicit ChannelCredentials(grpc_channel_credentials *credentials);
~ChannelCredentials();
// Prevent copying
@ -70,7 +70,7 @@ class ChannelCredentials : public Nan::ObjectWrap {
// Used for typechecking instances of this javascript class
static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
grpc_credentials *wrapped_credentials;
grpc_channel_credentials *wrapped_credentials;
};
} // namespace node

@ -71,7 +71,7 @@ var fakeSuccessfulGoogleCredentials = {
var fakeFailingGoogleCredentials = {
getRequestMetadata: function(service_url, callback) {
setTimeout(function() {
callback(new Error("Authorization failure"));
callback(new Error('Authentication failure'));
}, 0);
}
};
@ -218,6 +218,25 @@ describe('client credentials', function() {
done();
});
});
it('Should not add metadata with just SSL credentials', function(done) {
// Tests idempotency of credentials composition
var metadataUpdater = function(service_url, callback) {
var metadata = new grpc.Metadata();
metadata.set('plugin_key', 'plugin_value');
callback(null, metadata);
};
var creds = grpc.credentials.createFromMetadataGenerator(metadataUpdater);
grpc.credentials.combineChannelCredentials(client_ssl_creds, creds);
var client = new Client('localhost:' + port, client_ssl_creds,
client_options);
var call = client.unary({}, function(err, data) {
assert.ifError(err);
});
call.on('metadata', function(metadata) {
assert.deepEqual(metadata.get('plugin_key'), []);
done();
});
});
it.skip('should get an error from a Google credential', function(done) {
var creds = grpc.credentials.createFromGoogleCredential(
fakeFailingGoogleCredentials);
@ -227,7 +246,7 @@ describe('client credentials', function() {
client_options);
client.unary({}, function(err, data) {
assert(err);
assert.strictEqual(err.message, 'Authorization failure');
assert.strictEqual(err.message, 'Authentication failure');
done();
});
});

Loading…
Cancel
Save