Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
088416df
Commit
088416df
authored
8 years ago
by
Alexander Polcyn
Browse files
Options
Downloads
Patches
Plain Diff
surface more exception info for call creds errors
parent
7a209ace
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ruby/ext/grpc/rb_call_credentials.c
+5
-8
5 additions, 8 deletions
src/ruby/ext/grpc/rb_call_credentials.c
src/ruby/spec/generic/client_stub_spec.rb
+52
-4
52 additions, 4 deletions
src/ruby/spec/generic/client_stub_spec.rb
with
57 additions
and
12 deletions
src/ruby/ext/grpc/rb_call_credentials.c
+
5
−
8
View file @
088416df
...
@@ -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\t
from "
));
1
,
rb_str_new2
(
"
\n\t
from "
));
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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ruby/spec/generic/client_stub_spec.rb
+
52
−
4
View file @
088416df
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment