grpc 1.74.0.pre2-x86-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +19 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +269 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +347 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_channel.c +391 -0
- data/src/ruby/ext/grpc/rb_channel.h +32 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +174 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +95 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +469 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +167 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +500 -0
- data/src/ruby/ext/grpc/rb_grpc.h +88 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +902 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +406 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +679 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +57 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +21 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +19 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +50 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +19 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +193 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +209 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +317 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/core_spec.rb +22 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +670 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1079 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +773 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/logconfig_spec.rb +30 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +163 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +411 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
def create_channel_creds
|
18
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
19
|
+
files = ['ca.pem', 'client.key', 'client.pem']
|
20
|
+
creds = files.map { |f| File.open(File.join(test_root, f)).read }
|
21
|
+
GRPC::Core::ChannelCredentials.new(creds[0], creds[1], creds[2])
|
22
|
+
end
|
23
|
+
|
24
|
+
def client_cert
|
25
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
26
|
+
cert = File.open(File.join(test_root, 'client.pem')).read
|
27
|
+
fail unless cert.is_a?(String)
|
28
|
+
cert
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_server_creds
|
32
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
33
|
+
GRPC.logger.info("test root: #{test_root}")
|
34
|
+
files = ['ca.pem', 'server1.key', 'server1.pem']
|
35
|
+
creds = files.map { |f| File.open(File.join(test_root, f)).read }
|
36
|
+
GRPC::Core::ServerCredentials.new(
|
37
|
+
creds[0],
|
38
|
+
[{ private_key: creds[1], cert_chain: creds[2] }],
|
39
|
+
true) # force client auth
|
40
|
+
end
|
41
|
+
|
42
|
+
# a test service that checks the cert of its peer
|
43
|
+
class SslTestService
|
44
|
+
include GRPC::GenericService
|
45
|
+
rpc :an_rpc, EchoMsg, EchoMsg
|
46
|
+
rpc :a_client_streaming_rpc, stream(EchoMsg), EchoMsg
|
47
|
+
rpc :a_server_streaming_rpc, EchoMsg, stream(EchoMsg)
|
48
|
+
rpc :a_bidi_rpc, stream(EchoMsg), stream(EchoMsg)
|
49
|
+
|
50
|
+
def check_peer_cert(call)
|
51
|
+
error_msg = "want:\n#{client_cert}\n\ngot:\n#{call.peer_cert}"
|
52
|
+
fail(error_msg) unless call.peer_cert == client_cert
|
53
|
+
end
|
54
|
+
|
55
|
+
def an_rpc(req, call)
|
56
|
+
check_peer_cert(call)
|
57
|
+
req
|
58
|
+
end
|
59
|
+
|
60
|
+
def a_client_streaming_rpc(call)
|
61
|
+
check_peer_cert(call)
|
62
|
+
call.each_remote_read.each { |r| GRPC.logger.info(r) }
|
63
|
+
EchoMsg.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def a_server_streaming_rpc(_, call)
|
67
|
+
check_peer_cert(call)
|
68
|
+
[EchoMsg.new, EchoMsg.new]
|
69
|
+
end
|
70
|
+
|
71
|
+
def a_bidi_rpc(requests, call)
|
72
|
+
check_peer_cert(call)
|
73
|
+
requests.each { |r| GRPC.logger.info(r) }
|
74
|
+
[EchoMsg.new, EchoMsg.new]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
SslTestServiceStub = SslTestService.rpc_stub_class
|
79
|
+
|
80
|
+
describe 'client-server auth' do
|
81
|
+
RpcServer = GRPC::RpcServer
|
82
|
+
|
83
|
+
before(:all) do
|
84
|
+
server_opts = {
|
85
|
+
poll_period: 1
|
86
|
+
}
|
87
|
+
@srv = new_rpc_server_for_testing(**server_opts)
|
88
|
+
ssl_creds = create_server_creds
|
89
|
+
xds_creds = GRPC::Core::XdsServerCredentials.new(ssl_creds)
|
90
|
+
port = @srv.add_http2_port('0.0.0.0:0', ssl_creds)
|
91
|
+
xds_port = @srv.add_http2_port('0.0.0.0:0', xds_creds)
|
92
|
+
@srv.handle(SslTestService)
|
93
|
+
@srv_thd = Thread.new { @srv.run }
|
94
|
+
@srv.wait_till_running
|
95
|
+
|
96
|
+
client_opts = {
|
97
|
+
channel_args: {
|
98
|
+
GRPC::Core::Channel::SSL_TARGET => 'foo.test.google.fr'
|
99
|
+
}
|
100
|
+
}
|
101
|
+
@stub = SslTestServiceStub.new("localhost:#{port}",
|
102
|
+
create_channel_creds,
|
103
|
+
**client_opts)
|
104
|
+
# auth should success as the fallback creds wil be used
|
105
|
+
xds_channel_creds = GRPC::Core::XdsChannelCredentials.new(create_channel_creds)
|
106
|
+
@xds_stub = SslTestServiceStub.new("localhost:#{xds_port}",
|
107
|
+
xds_channel_creds,
|
108
|
+
**client_opts)
|
109
|
+
end
|
110
|
+
|
111
|
+
after(:all) do
|
112
|
+
expect(@srv.stopped?).to be(false)
|
113
|
+
@srv.stop
|
114
|
+
@srv_thd.join
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'client-server auth with unary RPCs' do
|
118
|
+
@stub.an_rpc(EchoMsg.new)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'client-server auth with client streaming RPCs' do
|
122
|
+
@stub.a_client_streaming_rpc([EchoMsg.new, EchoMsg.new])
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'client-server auth with server streaming RPCs' do
|
126
|
+
responses = @stub.a_server_streaming_rpc(EchoMsg.new)
|
127
|
+
responses.each { |r| GRPC.logger.info(r) }
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'client-server auth with bidi RPCs' do
|
131
|
+
responses = @stub.a_bidi_rpc([EchoMsg.new, EchoMsg.new])
|
132
|
+
responses.each { |r| GRPC.logger.info(r) }
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'xds_client-xds_server ssl fallback auth with unary RPCs' do
|
136
|
+
@xds_stub.an_rpc(EchoMsg.new)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'xds_client-xds_server ssl fallback auth with client streaming RPCs' do
|
140
|
+
@xds_stub.a_client_streaming_rpc([EchoMsg.new, EchoMsg.new])
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'xds_client-xds_server ssl fallback auth with server streaming RPCs' do
|
144
|
+
responses = @xds_stub.a_server_streaming_rpc(EchoMsg.new)
|
145
|
+
responses.each { |r| GRPC.logger.info(r) }
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'xds_client-xds_server ssl fallback auth with bidi RPCs' do
|
149
|
+
responses = @xds_stub.a_bidi_rpc([EchoMsg.new, EchoMsg.new])
|
150
|
+
responses.each { |r| GRPC.logger.info(r) }
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
include GRPC::Core
|
18
|
+
|
19
|
+
shared_examples 'basic GRPC message delivery is OK' do
|
20
|
+
include GRPC::Core
|
21
|
+
|
22
|
+
context 'the test channel' do
|
23
|
+
it 'should have a target' do
|
24
|
+
expect(@ch.target).to be_a(String)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'unary calls work' do
|
29
|
+
run_services_on_server(@server, services: [EchoService]) do
|
30
|
+
call = @stub.an_rpc(EchoMsg.new, return_op: true)
|
31
|
+
expect(call.execute).to be_a(EchoMsg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'unary calls work when enabling compression' do
|
36
|
+
run_services_on_server(@server, services: [EchoService]) do
|
37
|
+
long_request_str = '0' * 2000
|
38
|
+
md = { 'grpc-internal-encoding-request' => 'gzip' }
|
39
|
+
call = @stub.an_rpc(EchoMsg.new(msg: long_request_str),
|
40
|
+
return_op: true,
|
41
|
+
metadata: md)
|
42
|
+
response = call.execute
|
43
|
+
expect(response).to be_a(EchoMsg)
|
44
|
+
expect(response.msg).to eq(long_request_str)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def client_cancel_test(cancel_proc, expected_code,
|
49
|
+
expected_details)
|
50
|
+
call = @stub.an_rpc(EchoMsg.new, return_op: true)
|
51
|
+
run_services_on_server(@server, services: [EchoService]) do
|
52
|
+
# start the call, but don't send a message yet
|
53
|
+
call.start_call
|
54
|
+
# cancel the call
|
55
|
+
cancel_proc.call(call)
|
56
|
+
# check the client's status
|
57
|
+
failed = false
|
58
|
+
begin
|
59
|
+
call.execute
|
60
|
+
rescue GRPC::BadStatus => e
|
61
|
+
failed = true
|
62
|
+
expect(e.code).to be expected_code
|
63
|
+
expect(e.details).to eq expected_details
|
64
|
+
end
|
65
|
+
expect(failed).to be(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'clients can cancel a call on the server' do
|
70
|
+
expected_code = StatusCodes::CANCELLED
|
71
|
+
expected_details = 'CANCELLED'
|
72
|
+
cancel_proc = proc { |call| call.cancel }
|
73
|
+
client_cancel_test(cancel_proc, expected_code, expected_details)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'cancel_with_status unknown status' do
|
77
|
+
code = StatusCodes::UNKNOWN
|
78
|
+
details = 'test unknown reason'
|
79
|
+
cancel_proc = proc { |call| call.cancel_with_status(code, details) }
|
80
|
+
client_cancel_test(cancel_proc, code, details)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'cancel_with_status unknown status' do
|
84
|
+
code = StatusCodes::FAILED_PRECONDITION
|
85
|
+
details = 'test failed precondition reason'
|
86
|
+
cancel_proc = proc { |call| call.cancel_with_status(code, details) }
|
87
|
+
client_cancel_test(cancel_proc, code, details)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
shared_examples 'GRPC metadata delivery works OK' do
|
92
|
+
describe 'from client => server' do
|
93
|
+
before(:example) do
|
94
|
+
n = 7 # arbitrary number of metadata
|
95
|
+
diff_keys_fn = proc { |i| [format('k%d', i), format('v%d', i)] }
|
96
|
+
diff_keys = Hash[n.times.collect { |x| diff_keys_fn.call x }]
|
97
|
+
null_vals_fn = proc { |i| [format('k%d', i), format('v\0%d', i)] }
|
98
|
+
null_vals = Hash[n.times.collect { |x| null_vals_fn.call x }]
|
99
|
+
same_keys_fn = proc { |i| [format('k%d', i), [format('v%d', i)] * n] }
|
100
|
+
same_keys = Hash[n.times.collect { |x| same_keys_fn.call x }]
|
101
|
+
symbol_key = { a_key: 'a val' }
|
102
|
+
@valid_metadata = [diff_keys, same_keys, null_vals, symbol_key]
|
103
|
+
@bad_keys = []
|
104
|
+
@bad_keys << { Object.new => 'a value' }
|
105
|
+
@bad_keys << { 1 => 'a value' }
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'raises an exception if a metadata key is invalid' do
|
109
|
+
@bad_keys.each do |md|
|
110
|
+
# NOTE: no need to run a server in this test b/c the failure
|
111
|
+
# happens while validating metadata to send.
|
112
|
+
failed = false
|
113
|
+
begin
|
114
|
+
@stub.an_rpc(EchoMsg.new, metadata: md)
|
115
|
+
rescue TypeError => e
|
116
|
+
failed = true
|
117
|
+
expect(e.message).to eq('grpc_rb_md_ary_fill_hash_cb: bad type for key parameter')
|
118
|
+
end
|
119
|
+
expect(failed).to be(true)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'sends all the metadata pairs when keys and values are valid' do
|
124
|
+
service = EchoService.new
|
125
|
+
run_services_on_server(@server, services: [service]) do
|
126
|
+
@valid_metadata.each_with_index do |md, i|
|
127
|
+
expect(@stub.an_rpc(EchoMsg.new, metadata: md)).to be_a(EchoMsg)
|
128
|
+
# confirm the server can receive the client metadata
|
129
|
+
# finish the call
|
130
|
+
expect(service.received_md.length).to eq(i + 1)
|
131
|
+
md.each do |k, v|
|
132
|
+
expect(service.received_md[i][k.to_s]).to eq(v)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'from server => client' do
|
140
|
+
before(:example) do
|
141
|
+
n = 7 # arbitrary number of metadata
|
142
|
+
diff_keys_fn = proc { |i| [format('k%d', i), format('v%d', i)] }
|
143
|
+
diff_keys = Hash[n.times.collect { |x| diff_keys_fn.call x }]
|
144
|
+
null_vals_fn = proc { |i| [format('k%d', i), format('v\0%d', i)] }
|
145
|
+
null_vals = Hash[n.times.collect { |x| null_vals_fn.call x }]
|
146
|
+
same_keys_fn = proc { |i| [format('k%d', i), [format('v%d', i)] * n] }
|
147
|
+
same_keys = Hash[n.times.collect { |x| same_keys_fn.call x }]
|
148
|
+
symbol_key = { a_key: 'a val' }
|
149
|
+
@valid_metadata = [diff_keys, same_keys, null_vals, symbol_key]
|
150
|
+
@bad_keys = []
|
151
|
+
@bad_keys << { Object.new => 'a value' }
|
152
|
+
@bad_keys << { 1 => 'a value' }
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'raises an exception if a metadata key is invalid' do
|
156
|
+
service = EchoService.new
|
157
|
+
run_services_on_server(@server, services: [service]) do
|
158
|
+
@bad_keys.each do |md|
|
159
|
+
proceed = Queue.new
|
160
|
+
server_exception = nil
|
161
|
+
service.on_call_started = proc do |call|
|
162
|
+
call.send_initial_metadata(md)
|
163
|
+
rescue TypeError => e
|
164
|
+
server_exception = e
|
165
|
+
ensure
|
166
|
+
proceed.push(1)
|
167
|
+
end
|
168
|
+
client_exception = nil
|
169
|
+
client_call = @stub.an_rpc(EchoMsg.new, return_op: true)
|
170
|
+
thr = Thread.new do
|
171
|
+
client_call.execute
|
172
|
+
rescue GRPC::BadStatus => e
|
173
|
+
client_exception = e
|
174
|
+
end
|
175
|
+
proceed.pop
|
176
|
+
# TODO(apolcyn): we shouldn't need this cancel here. It's
|
177
|
+
# only currently needed b/c the server does not seem to properly
|
178
|
+
# terminate the RPC if it fails to send initial metadata. That
|
179
|
+
# should be fixed, in which case this cancellation can be removed.
|
180
|
+
client_call.cancel
|
181
|
+
thr.join
|
182
|
+
p client_exception
|
183
|
+
expect(client_exception.nil?).to be(false)
|
184
|
+
expect(server_exception.nil?).to be(false)
|
185
|
+
expect(server_exception.message).to eq(
|
186
|
+
'grpc_rb_md_ary_fill_hash_cb: bad type for key parameter')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'sends an empty hash if no metadata is added' do
|
192
|
+
run_services_on_server(@server, services: [EchoService]) do
|
193
|
+
call = @stub.an_rpc(EchoMsg.new, return_op: true)
|
194
|
+
expect(call.execute).to be_a(EchoMsg)
|
195
|
+
expect(call.metadata).to eq({})
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'sends all the pairs when keys and values are valid' do
|
200
|
+
service = EchoService.new
|
201
|
+
run_services_on_server(@server, services: [service]) do
|
202
|
+
@valid_metadata.each do |md|
|
203
|
+
service.on_call_started = proc do |call|
|
204
|
+
call.send_initial_metadata(md)
|
205
|
+
end
|
206
|
+
call = @stub.an_rpc(EchoMsg.new, return_op: true)
|
207
|
+
call.execute
|
208
|
+
replace_symbols = Hash[md.each_pair.collect { |x, y| [x.to_s, y] }]
|
209
|
+
expect(call.metadata).to eq(replace_symbols)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'the http client/server' do
|
217
|
+
before(:example) do
|
218
|
+
server_host = '0.0.0.0:0'
|
219
|
+
@server = new_rpc_server_for_testing
|
220
|
+
server_port = @server.add_http2_port(server_host, :this_port_is_insecure)
|
221
|
+
@ch = Channel.new("0.0.0.0:#{server_port}", nil, :this_channel_is_insecure)
|
222
|
+
@stub = EchoStub.new(
|
223
|
+
"0.0.0.0:#{server_port}", nil, channel_override: @ch)
|
224
|
+
end
|
225
|
+
|
226
|
+
it_behaves_like 'basic GRPC message delivery is OK' do
|
227
|
+
end
|
228
|
+
|
229
|
+
it_behaves_like 'GRPC metadata delivery works OK' do
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe 'the secure http client/server' do
|
234
|
+
def load_test_certs
|
235
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
236
|
+
files = ['ca.pem', 'server1.key', 'server1.pem']
|
237
|
+
files.map { |f| File.open(File.join(test_root, f)).read }
|
238
|
+
end
|
239
|
+
|
240
|
+
before(:example) do
|
241
|
+
certs = load_test_certs
|
242
|
+
server_host = '0.0.0.0:0'
|
243
|
+
server_creds = GRPC::Core::ServerCredentials.new(
|
244
|
+
nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
|
245
|
+
@server = new_rpc_server_for_testing
|
246
|
+
server_port = @server.add_http2_port(server_host, server_creds)
|
247
|
+
args = { Channel::SSL_TARGET => 'foo.test.google.fr' }
|
248
|
+
@ch = Channel.new(
|
249
|
+
"0.0.0.0:#{server_port}", args,
|
250
|
+
GRPC::Core::ChannelCredentials.new(certs[0], nil, nil))
|
251
|
+
@stub = EchoStub.new(
|
252
|
+
"0.0.0.0:#{server_port}", nil, channel_override: @ch)
|
253
|
+
end
|
254
|
+
|
255
|
+
it_behaves_like 'basic GRPC message delivery is OK' do
|
256
|
+
end
|
257
|
+
|
258
|
+
it_behaves_like 'GRPC metadata delivery works OK' do
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'modifies metadata with CallCredentials' do
|
262
|
+
# create call creds
|
263
|
+
auth_proc = proc { { 'k1' => 'v1' } }
|
264
|
+
call_creds = GRPC::Core::CallCredentials.new(auth_proc)
|
265
|
+
# create arbitrary custom metadata
|
266
|
+
custom_md = { 'k2' => 'v2' }
|
267
|
+
# perform an RPC
|
268
|
+
echo_service = EchoService.new
|
269
|
+
run_services_on_server(@server, services: [echo_service]) do
|
270
|
+
expect(@stub.an_rpc(EchoMsg.new,
|
271
|
+
credentials: call_creds,
|
272
|
+
metadata: custom_md)).to be_a(EchoMsg)
|
273
|
+
end
|
274
|
+
# call creds metadata should be merged with custom MD
|
275
|
+
expect(echo_service.received_md.length).to eq(1)
|
276
|
+
expected_md = { 'k1' => 'v1', 'k2' => 'v2' }
|
277
|
+
expected_md.each do |k, v|
|
278
|
+
expect(echo_service.received_md[0][k]).to eq(v)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'modifies large metadata with CallCredentials' do
|
283
|
+
val_array = %w(
|
284
|
+
'00000000000000000000000000000000000000000000000000000000000000',
|
285
|
+
'11111111111111111111111111111111111111111111111111111111111111',
|
286
|
+
)
|
287
|
+
# create call creds
|
288
|
+
auth_proc = proc do
|
289
|
+
{
|
290
|
+
k2: val_array,
|
291
|
+
k3: '0000000000000000000000000000000000000000000000000000000000',
|
292
|
+
keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey4: 'v4'
|
293
|
+
}
|
294
|
+
end
|
295
|
+
call_creds = GRPC::Core::CallCredentials.new(auth_proc)
|
296
|
+
# create arbitrary custom metadata
|
297
|
+
custom_md = { k1: 'v1' }
|
298
|
+
# perform an RPC
|
299
|
+
echo_service = EchoService.new
|
300
|
+
run_services_on_server(@server, services: [echo_service]) do
|
301
|
+
expect(@stub.an_rpc(EchoMsg.new,
|
302
|
+
credentials: call_creds,
|
303
|
+
metadata: custom_md)).to be_a(EchoMsg)
|
304
|
+
end
|
305
|
+
# call creds metadata should be merged with custom MD
|
306
|
+
expect(echo_service.received_md.length).to eq(1)
|
307
|
+
expected_md = {
|
308
|
+
k1: 'v1',
|
309
|
+
k2: val_array,
|
310
|
+
k3: '0000000000000000000000000000000000000000000000000000000000',
|
311
|
+
keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey4: 'v4'
|
312
|
+
}
|
313
|
+
expected_md.each do |k, v|
|
314
|
+
expect(echo_service.received_md[0][k.to_s]).to eq(v)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
describe GRPC::Core::CompressionOptions do
|
18
|
+
# Note these constants should be updated
|
19
|
+
# according to what the core lib provides.
|
20
|
+
|
21
|
+
# Names of supported compression algorithms
|
22
|
+
ALGORITHMS = [:identity, :deflate, :gzip]
|
23
|
+
|
24
|
+
# Names of valid supported compression levels
|
25
|
+
COMPRESS_LEVELS = [:none, :low, :medium, :high]
|
26
|
+
|
27
|
+
it 'implements to_s' do
|
28
|
+
expect { GRPC::Core::CompressionOptions.new.to_s }.to_not raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#to_channel_arg_hash gives the same result as #to_hash' do
|
32
|
+
options = GRPC::Core::CompressionOptions.new
|
33
|
+
expect(options.to_channel_arg_hash).to eq(options.to_hash)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Test the normal call sequence of creating an instance
|
37
|
+
# and then obtaining the resulting channel-arg hash that
|
38
|
+
# corresponds to the compression settings of the instance
|
39
|
+
describe 'creating, reading, and converting to channel args hash' do
|
40
|
+
it 'works when no optional args were provided' do
|
41
|
+
options = GRPC::Core::CompressionOptions.new
|
42
|
+
|
43
|
+
ALGORITHMS.each do |algorithm|
|
44
|
+
expect(options.algorithm_enabled?(algorithm)).to be true
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(options.disabled_algorithms).to be_empty
|
48
|
+
expect(options.default_algorithm).to be nil
|
49
|
+
expect(options.default_level).to be nil
|
50
|
+
expect(options.to_hash).to be_instance_of(Hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'works when disabling multiple algorithms' do
|
54
|
+
options = GRPC::Core::CompressionOptions.new(
|
55
|
+
default_algorithm: :identity,
|
56
|
+
default_level: :none,
|
57
|
+
disabled_algorithms: [:gzip, :deflate]
|
58
|
+
)
|
59
|
+
|
60
|
+
[:gzip, :deflate].each do |algorithm|
|
61
|
+
expect(options.algorithm_enabled?(algorithm)).to be false
|
62
|
+
expect(options.disabled_algorithms.include?(algorithm)).to be true
|
63
|
+
end
|
64
|
+
|
65
|
+
expect(options.default_algorithm).to be(:identity)
|
66
|
+
expect(options.default_level).to be(:none)
|
67
|
+
expect(options.to_hash).to be_instance_of(Hash)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'works when all optional args have been set' do
|
71
|
+
options = GRPC::Core::CompressionOptions.new(
|
72
|
+
default_algorithm: :gzip,
|
73
|
+
default_level: :low,
|
74
|
+
disabled_algorithms: [:deflate]
|
75
|
+
)
|
76
|
+
|
77
|
+
expect(options.algorithm_enabled?(:deflate)).to be false
|
78
|
+
expect(options.algorithm_enabled?(:gzip)).to be true
|
79
|
+
expect(options.disabled_algorithms).to eq([:deflate])
|
80
|
+
|
81
|
+
expect(options.default_algorithm).to be(:gzip)
|
82
|
+
expect(options.default_level).to be(:low)
|
83
|
+
expect(options.to_hash).to be_instance_of(Hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'doesnt fail when no algorithms are disabled' do
|
87
|
+
options = GRPC::Core::CompressionOptions.new(
|
88
|
+
default_algorithm: :identity,
|
89
|
+
default_level: :high
|
90
|
+
)
|
91
|
+
|
92
|
+
ALGORITHMS.each do |algorithm|
|
93
|
+
expect(options.algorithm_enabled?(algorithm)).to be(true)
|
94
|
+
end
|
95
|
+
|
96
|
+
expect(options.disabled_algorithms).to be_empty
|
97
|
+
expect(options.default_algorithm).to be(:identity)
|
98
|
+
expect(options.default_level).to be(:high)
|
99
|
+
expect(options.to_hash).to be_instance_of(Hash)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#new with bad parameters' do
|
104
|
+
it 'should fail with more than one parameter' do
|
105
|
+
blk = proc { GRPC::Core::CompressionOptions.new(:gzip, :none) }
|
106
|
+
expect { blk.call }.to raise_error
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should fail with a non-hash parameter' do
|
110
|
+
blk = proc { GRPC::Core::CompressionOptions.new(:gzip) }
|
111
|
+
expect { blk.call }.to raise_error
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#default_algorithm' do
|
116
|
+
it 'returns nil if unset' do
|
117
|
+
options = GRPC::Core::CompressionOptions.new
|
118
|
+
expect(options.default_algorithm).to be(nil)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#default_level' do
|
123
|
+
it 'returns nil if unset' do
|
124
|
+
options = GRPC::Core::CompressionOptions.new
|
125
|
+
expect(options.default_level).to be(nil)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#disabled_algorithms' do
|
130
|
+
it 'returns an empty list if no algorithms were disabled' do
|
131
|
+
options = GRPC::Core::CompressionOptions.new
|
132
|
+
expect(options.disabled_algorithms).to be_empty
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#algorithm_enabled?' do
|
137
|
+
[:none, :any, 'gzip', Object.new, 1].each do |name|
|
138
|
+
it "should fail for parameter ${name} of class #{name.class}" do
|
139
|
+
options = GRPC::Core::CompressionOptions.new(
|
140
|
+
disabled_algorithms: [:gzip])
|
141
|
+
|
142
|
+
blk = proc do
|
143
|
+
options.algorithm_enabled?(name)
|
144
|
+
end
|
145
|
+
expect { blk.call }.to raise_error
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
describe GRPC::Core do
|
18
|
+
it 'returns valid VALUEs from C functions' do
|
19
|
+
expect(GRPC::Core.fork_unsafe_begin).to be_nil
|
20
|
+
expect(GRPC::Core.fork_unsafe_end).to be_nil
|
21
|
+
end
|
22
|
+
end
|