Skip to content
Snippets Groups Projects
Commit 088416df authored by Alexander Polcyn's avatar Alexander Polcyn
Browse files

surface more exception info for call creds errors

parent 7a209ace
No related branches found
No related tags found
No related merge requests found
...@@ -86,19 +86,16 @@ static VALUE grpc_rb_call_credentials_callback_rescue(VALUE args, ...@@ -86,19 +86,16 @@ static VALUE grpc_rb_call_credentials_callback_rescue(VALUE args,
rb_funcall(exception_object, rb_intern("backtrace"), 0), rb_funcall(exception_object, rb_intern("backtrace"), 0),
rb_intern("join"), rb_intern("join"),
1, rb_str_new2("\n\tfrom ")); 1, rb_str_new2("\n\tfrom "));
VALUE rb_exception_info = rb_funcall(exception_object, rb_intern("to_s"), 0); VALUE rb_exception_info = rb_funcall(exception_object, rb_intern("inspect"), 0);
const char *exception_classname = rb_obj_classname(exception_object);
(void)args; (void)args;
gpr_log(GPR_INFO, "Call credentials callback failed: %s: %s\n%s", gpr_log(GPR_INFO, "Call credentials callback failed: %s\n%s",
exception_classname, StringValueCStr(rb_exception_info), StringValueCStr(rb_exception_info),
StringValueCStr(backtrace)); StringValueCStr(backtrace));
rb_hash_aset(result, rb_str_new2("metadata"), Qnil); rb_hash_aset(result, rb_str_new2("metadata"), Qnil);
/* Currently only gives the exception class name. It should be possible get
more details */
rb_hash_aset(result, rb_str_new2("status"), rb_hash_aset(result, rb_str_new2("status"),
INT2NUM(GRPC_STATUS_PERMISSION_DENIED)); INT2NUM(GRPC_STATUS_UNAVAILABLE));
rb_hash_aset(result, rb_str_new2("details"), rb_hash_aset(result, rb_str_new2("details"),
rb_str_new2(exception_classname)); rb_exception_info);
return result; return result;
} }
......
...@@ -168,23 +168,62 @@ describe 'ClientStub' do ...@@ -168,23 +168,62 @@ describe 'ClientStub' do
expect(&blk).to raise_error(GRPC::BadStatus) expect(&blk).to raise_error(GRPC::BadStatus)
th.join th.join
end end
it 'should receive UNAUTHENTICATED if call credentials plugin fails' do
server_port = create_secure_test_server
th = run_request_response(@sent_msg, @resp, @pass)
certs = load_test_certs
secure_channel_creds = GRPC::Core::ChannelCredentials.new(
certs[0], nil, nil)
secure_stub_opts = {
channel_args: {
GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr'
}
}
stub = GRPC::ClientStub.new("localhost:#{server_port}",
secure_channel_creds, **secure_stub_opts)
error_message = 'Failing call credentials callback'
failing_auth = proc do
fail error_message
end
creds = GRPC::Core::CallCredentials.new(failing_auth)
error_occured = false
begin
get_response(stub, credentials: creds)
rescue GRPC::BadStatus => e
error_occured = true
expect(e.code).to eq(GRPC::Core::StatusCodes::UNAUTHENTICATED)
# Expecting the error message from the exception to also be included
expect(e.details.include?(error_message)).to be true
end
expect(error_occured).to eq(true)
# Kill the server thread so tests can complete
th.kill
end
end end
describe 'without a call operation' do describe 'without a call operation' do
def get_response(stub) def get_response(stub, credentials: nil)
puts credentials.inspect
stub.request_response(@method, @sent_msg, noop, noop, stub.request_response(@method, @sent_msg, noop, noop,
metadata: { k1: 'v1', k2: 'v2' }) metadata: { k1: 'v1', k2: 'v2' },
credentials: credentials)
end end
it_behaves_like 'request response' it_behaves_like 'request response'
end end
describe 'via a call operation' do describe 'via a call operation' do
def get_response(stub) def get_response(stub, credentials: nil)
op = stub.request_response(@method, @sent_msg, noop, noop, op = stub.request_response(@method, @sent_msg, noop, noop,
return_op: true, return_op: true,
metadata: { k1: 'v1', k2: 'v2' }, metadata: { k1: 'v1', k2: 'v2' },
deadline: from_relative_time(2)) deadline: from_relative_time(2),
credentials: credentials)
expect(op).to be_a(GRPC::ActiveCall::Operation) expect(op).to be_a(GRPC::ActiveCall::Operation)
op.execute op.execute
end end
...@@ -441,6 +480,15 @@ describe 'ClientStub' do ...@@ -441,6 +480,15 @@ describe 'ClientStub' do
end end
end end
def create_secure_test_server
certs = load_test_certs
secure_credentials = GRPC::Core::ServerCredentials.new(
nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
@server = GRPC::Core::Server.new(nil)
@server.add_http2_port('0.0.0.0:0', secure_credentials)
end
def create_test_server def create_test_server
@server = GRPC::Core::Server.new(nil) @server = GRPC::Core::Server.new(nil)
@server.add_http2_port('0.0.0.0:0', :this_port_is_insecure) @server.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment