diff options
author | jboeuf <jboeuf@users.noreply.github.com> | 2015-10-27 13:39:59 -0700 |
---|---|---|
committer | jboeuf <jboeuf@users.noreply.github.com> | 2015-10-27 13:39:59 -0700 |
commit | 276266d0b02a752ccbe980239b624ca3036c382f (patch) | |
tree | 5c5d218418d65d444dc7d84b7e8d453b8526cd28 /src | |
parent | ea41264a7193e56568aaaa21edfaaae87931277e (diff) | |
parent | c90b1099cc59bcaed55f1f8b26d4c76201fa16fa (diff) |
Merge pull request #3 from murgatroid99/node_core_creds_api_change
Node wrapping of core credentials API change
Diffstat (limited to 'src')
-rw-r--r-- | src/node/ext/call.cc | 2 | ||||
-rw-r--r-- | src/node/ext/call_credentials.cc | 18 | ||||
-rw-r--r-- | src/node/ext/call_credentials.h | 12 | ||||
-rw-r--r-- | src/node/ext/channel.cc | 2 | ||||
-rw-r--r-- | src/node/ext/channel_credentials.cc | 17 | ||||
-rw-r--r-- | src/node/ext/channel_credentials.h | 14 | ||||
-rw-r--r-- | src/node/test/credentials_test.js | 23 |
7 files changed, 54 insertions, 34 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index fe11905109..a98ae85427 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<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); diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index ff16a1f122..9c5d9d291b 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<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)); } diff --git a/src/node/ext/call_credentials.h b/src/node/ext/call_credentials.h index 618292d19e..1cd8d8dd5d 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<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 */ diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc index 584a0cf8ab..6748cbfc54 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 7ca3b9816c..b77ff80af2 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<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(); diff --git a/src/node/ext/channel_credentials.h b/src/node/ext/channel_credentials.h index 31ea0987bc..89b115267f 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<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 diff --git a/src/node/test/credentials_test.js b/src/node/test/credentials_test.js index 3d0b38fd52..647f648ca9 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(); }); }); |