diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index fe11905109a..a98ae85427f 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -757,7 +757,7 @@ NAN_METHOD(Call::SetCredentials) { Call *call = ObjectWrap::Unwrap(info.This()); CallCredentials *creds_object = ObjectWrap::Unwrap( Nan::To(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); diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index ff16a1f1221..9c5d9d291b7 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -64,11 +64,11 @@ using v8::Value; Nan::Callback *CallCredentials::constructor; Persistent 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 exports) { @@ -91,7 +91,7 @@ bool CallCredentials::HasInstance(Local val) { return Nan::New(fun_tpl)->HasInstance(val); } -Local CallCredentials::WrapStruct(grpc_credentials *credentials) { +Local CallCredentials::WrapStruct(grpc_call_credentials *credentials) { EscapableHandleScope scope; const int argc = 1; if (credentials == NULL) { @@ -108,7 +108,7 @@ Local 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 ext = info[0].As(); - grpc_credentials *creds_value = - reinterpret_cast(ext->Value()); + grpc_call_credentials *creds_value = + reinterpret_cast(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(info.This()); CallCredentials *other = ObjectWrap::Unwrap( Nan::To(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(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)); } diff --git a/src/node/ext/call_credentials.h b/src/node/ext/call_credentials.h index 618292d19e8..1cd8d8dd5d5 100644 --- a/src/node/ext/call_credentials.h +++ b/src/node/ext/call_credentials.h @@ -45,14 +45,14 @@ class CallCredentials : public Nan::ObjectWrap { public: static void Init(v8::Local exports); static bool HasInstance(v8::Local val); - /* Wrap a grpc_credentials struct in a javascript object */ - static v8::Local WrapStruct(grpc_credentials *credentials); + /* Wrap a grpc_call_credentials struct in a javascript object */ + static v8::Local 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 fun_tpl; - grpc_credentials *wrapped_credentials; + grpc_call_credentials *wrapped_credentials; }; /* Auth metadata plugin functionality */ diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc index 584a0cf8abf..6748cbfc54e 100644 --- a/src/node/ext/channel.cc +++ b/src/node/ext/channel.cc @@ -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"); diff --git a/src/node/ext/channel_credentials.cc b/src/node/ext/channel_credentials.cc index 7ca3b9816cf..b77ff80af27 100644 --- a/src/node/ext/channel_credentials.cc +++ b/src/node/ext/channel_credentials.cc @@ -65,11 +65,11 @@ using v8::Value; Nan::Callback *ChannelCredentials::constructor; Persistent 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 exports) { @@ -95,7 +95,8 @@ bool ChannelCredentials::HasInstance(Local val) { return Nan::New(fun_tpl)->HasInstance(val); } -Local ChannelCredentials::WrapStruct(grpc_credentials *credentials) { +Local ChannelCredentials::WrapStruct( + grpc_channel_credentials *credentials) { EscapableHandleScope scope; const int argc = 1; Local argv[argc] = { @@ -109,7 +110,7 @@ Local 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 ext = info[0].As(); - grpc_credentials *creds_value = - reinterpret_cast(ext->Value()); + grpc_channel_credentials *creds_value = + reinterpret_cast(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( Nan::To(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(); diff --git a/src/node/ext/channel_credentials.h b/src/node/ext/channel_credentials.h index 31ea0987bc6..89b115267f3 100644 --- a/src/node/ext/channel_credentials.h +++ b/src/node/ext/channel_credentials.h @@ -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 exports); static bool HasInstance(v8::Local val); - /* Wrap a grpc_credentials struct in a javascript object */ - static v8::Local WrapStruct(grpc_credentials *credentials); + /* Wrap a grpc_channel_credentials struct in a javascript object */ + static v8::Local 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 fun_tpl; - grpc_credentials *wrapped_credentials; + grpc_channel_credentials *wrapped_credentials; }; } // namespace node diff --git a/src/node/test/credentials_test.js b/src/node/test/credentials_test.js index 3d0b38fd52d..647f648ca93 100644 --- a/src/node/test/credentials_test.js +++ b/src/node/test/credentials_test.js @@ -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(); }); });