grpc 1.58.3-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32-msvcrt.ruby +0 -0
  4. data/grpc_c.64-msvcrt.ruby +0 -0
  5. data/grpc_c.64-ucrt.ruby +0 -0
  6. data/src/ruby/bin/math_client.rb +140 -0
  7. data/src/ruby/bin/math_pb.rb +40 -0
  8. data/src/ruby/bin/math_server.rb +191 -0
  9. data/src/ruby/bin/math_services_pb.rb +51 -0
  10. data/src/ruby/bin/noproto_client.rb +93 -0
  11. data/src/ruby/bin/noproto_server.rb +97 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
  13. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
  14. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
  15. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
  16. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  17. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  18. data/src/ruby/ext/grpc/extconf.rb +208 -0
  19. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  20. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  21. data/src/ruby/ext/grpc/rb_call.c +1075 -0
  22. data/src/ruby/ext/grpc/rb_call.h +57 -0
  23. data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
  24. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  25. data/src/ruby/ext/grpc/rb_channel.c +875 -0
  26. data/src/ruby/ext/grpc/rb_channel.h +35 -0
  27. data/src/ruby/ext/grpc/rb_channel_args.c +170 -0
  28. data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
  29. data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
  30. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  31. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  32. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  33. data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
  34. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  35. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  36. data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
  37. data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
  38. data/src/ruby/ext/grpc/rb_grpc.c +496 -0
  39. data/src/ruby/ext/grpc/rb_grpc.h +83 -0
  40. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +599 -0
  41. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +904 -0
  42. data/src/ruby/ext/grpc/rb_loader.c +61 -0
  43. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  44. data/src/ruby/ext/grpc/rb_server.c +405 -0
  45. data/src/ruby/ext/grpc/rb_server.h +32 -0
  46. data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
  47. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  48. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
  49. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  50. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  51. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  52. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  53. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  54. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  55. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  56. data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
  57. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  58. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  59. data/src/ruby/lib/grpc/errors.rb +277 -0
  60. data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
  61. data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
  62. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  63. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  64. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  65. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  66. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  67. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  68. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  69. data/src/ruby/lib/grpc/grpc.rb +24 -0
  70. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  71. data/src/ruby/lib/grpc/notifier.rb +45 -0
  72. data/src/ruby/lib/grpc/structs.rb +15 -0
  73. data/src/ruby/lib/grpc/version.rb +18 -0
  74. data/src/ruby/lib/grpc.rb +37 -0
  75. data/src/ruby/pb/README.md +42 -0
  76. data/src/ruby/pb/generate_proto_ruby.sh +46 -0
  77. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  78. data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
  79. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  80. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  81. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  82. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  83. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
  84. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +63 -0
  85. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
  86. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  87. data/src/ruby/pb/test/client.rb +785 -0
  88. data/src/ruby/pb/test/server.rb +252 -0
  89. data/src/ruby/pb/test/xds_client.rb +415 -0
  90. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  91. data/src/ruby/spec/call_spec.rb +180 -0
  92. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  93. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  94. data/src/ruby/spec/channel_spec.rb +207 -0
  95. data/src/ruby/spec/client_auth_spec.rb +152 -0
  96. data/src/ruby/spec/client_server_spec.rb +676 -0
  97. data/src/ruby/spec/compression_options_spec.rb +149 -0
  98. data/src/ruby/spec/debug_message_spec.rb +134 -0
  99. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  100. data/src/ruby/spec/errors_spec.rb +142 -0
  101. data/src/ruby/spec/generic/active_call_spec.rb +692 -0
  102. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  103. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  104. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  105. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  106. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  107. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  108. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  109. data/src/ruby/spec/generic/service_spec.rb +263 -0
  110. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  112. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  113. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  114. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  115. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  116. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  117. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  118. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  119. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  120. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  121. data/src/ruby/spec/server_spec.rb +231 -0
  122. data/src/ruby/spec/spec_helper.rb +61 -0
  123. data/src/ruby/spec/support/helpers.rb +107 -0
  124. data/src/ruby/spec/support/services.rb +160 -0
  125. data/src/ruby/spec/testdata/README +1 -0
  126. data/src/ruby/spec/testdata/ca.pem +20 -0
  127. data/src/ruby/spec/testdata/client.key +28 -0
  128. data/src/ruby/spec/testdata/client.pem +20 -0
  129. data/src/ruby/spec/testdata/server1.key +28 -0
  130. data/src/ruby/spec/testdata/server1.pem +22 -0
  131. data/src/ruby/spec/time_consts_spec.rb +74 -0
  132. data/src/ruby/spec/user_agent_spec.rb +74 -0
  133. metadata +406 -0
@@ -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,134 @@
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
+ TEST_DEBUG_MESSAGE = 'raised by test server'.freeze
18
+
19
+ # a test service that checks the cert of its peer
20
+ class DebugMessageTestService
21
+ include GRPC::GenericService
22
+ rpc :an_rpc_raises_abort, EchoMsg, EchoMsg
23
+ rpc :an_rpc_raises_standarderror, EchoMsg, EchoMsg
24
+
25
+ def an_rpc_raises_abort(_req, _call)
26
+ fail GRPC::Aborted.new(
27
+ 'aborted',
28
+ {},
29
+ TEST_DEBUG_MESSAGE)
30
+ end
31
+
32
+ def an_rpc_raises_standarderror(_req, _call)
33
+ fail(StandardError, TEST_DEBUG_MESSAGE)
34
+ end
35
+ end
36
+
37
+ DebugMessageTestServiceStub = DebugMessageTestService.rpc_stub_class
38
+
39
+ describe 'surfacing and transmitting of debug messages' do
40
+ RpcServer = GRPC::RpcServer
41
+
42
+ before(:all) do
43
+ server_opts = {
44
+ poll_period: 1
45
+ }
46
+ @srv = new_rpc_server_for_testing(**server_opts)
47
+ @port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
48
+ @srv.handle(DebugMessageTestService)
49
+ @srv_thd = Thread.new { @srv.run }
50
+ @srv.wait_till_running
51
+ end
52
+
53
+ after(:all) do
54
+ expect(@srv.stopped?).to be(false)
55
+ @srv.stop
56
+ @srv_thd.join
57
+ end
58
+
59
+ it 'debug error message is not present BadStatus exceptions that dont set it' do
60
+ exception_message = ''
61
+ begin
62
+ fail GRPC::Unavailable('unavailable', {})
63
+ rescue StandardError => e
64
+ p "Got exception: #{e.message}"
65
+ exception_message = e.message
66
+ end
67
+ expect(exception_message.empty?).to be(false)
68
+ expect(exception_message.include?('debug_error_string')).to be(false)
69
+ end
70
+
71
+ it 'debug error message is present in locally generated errors' do
72
+ # Create a secure channel. This is just one way to force a
73
+ # connection handshake error, which shoud result in C-core
74
+ # generating a status and error message and surfacing them up.
75
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
76
+ files = ['ca.pem', 'client.key', 'client.pem']
77
+ creds = files.map { |f| File.open(File.join(test_root, f)).read }
78
+ creds = GRPC::Core::ChannelCredentials.new(creds[0], creds[1], creds[2])
79
+ stub = DebugMessageTestServiceStub.new(
80
+ "localhost:#{@port}", creds)
81
+ begin
82
+ stub.an_rpc_raises_abort(EchoMsg.new)
83
+ rescue StandardError => e
84
+ p "Got exception: #{e.message}"
85
+ exception_message = e.message
86
+ # check that the RPC did actually result in a BadStatus exception
87
+ expect(e.is_a?(GRPC::BadStatus)).to be(true)
88
+ end
89
+ # just check that the debug_error_string is non-empty (we know that
90
+ # it's a JSON object, so the first character is '{').
91
+ expect(exception_message.include?('. debug_error_string:{')).to be(true)
92
+ end
93
+
94
+ it 'debug message is not transmitted from server to client' do
95
+ # in order to not accidentally leak internal details about a
96
+ # server to untrusted clients, avoid including the debug_error_string
97
+ # field of a BadStatusException raised at a server in the
98
+ # RPC status that it sends to clients.
99
+ stub = DebugMessageTestServiceStub.new(
100
+ "localhost:#{@port}", :this_channel_is_insecure)
101
+ exception_message = ''
102
+ begin
103
+ stub.an_rpc_raises_abort(EchoMsg.new)
104
+ rescue StandardError => e
105
+ p "Got exception: #{e.message}"
106
+ exception_message = e.message
107
+ # check that the status was aborted is an indirect way to
108
+ # tell that the RPC did actually get handled by the server
109
+ expect(e.is_a?(GRPC::Aborted)).to be(true)
110
+ end
111
+ # just assert that the contents of the server-side BadStatus
112
+ # debug_error_string field were *not* propagated to the client.
113
+ expect(exception_message.include?('. debug_error_string:{')).to be(true)
114
+ expect(exception_message.include?(TEST_DEBUG_MESSAGE)).to be(false)
115
+ end
116
+
117
+ it 'standard_error messages are transmitted from server to client' do
118
+ # this test exists mostly in order to understand the test case
119
+ # above, by comparison.
120
+ stub = DebugMessageTestServiceStub.new(
121
+ "localhost:#{@port}", :this_channel_is_insecure)
122
+ exception_message = ''
123
+ begin
124
+ stub.an_rpc_raises_standarderror(EchoMsg.new)
125
+ rescue StandardError => e
126
+ p "Got exception: #{e.message}"
127
+ exception_message = e.message
128
+ expect(e.is_a?(GRPC::BadStatus)).to be(true)
129
+ end
130
+ # assert that the contents of the StandardError exception message
131
+ # are propagated to the client.
132
+ expect(exception_message.include?(TEST_DEBUG_MESSAGE)).to be(true)
133
+ end
134
+ end
@@ -0,0 +1,49 @@
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
+ StatusCodes = GRPC::Core::StatusCodes
18
+
19
+ describe StatusCodes do
20
+ # convert upper snake-case to camel case.
21
+ # e.g., DEADLINE_EXCEEDED -> DeadlineExceeded
22
+ def upper_snake_to_camel(name)
23
+ name.to_s.split('_').map(&:downcase).map(&:capitalize).join('')
24
+ end
25
+
26
+ StatusCodes.constants.each do |status_name|
27
+ it 'there is a subclass of BadStatus corresponding to StatusCode: ' \
28
+ "#{status_name} that has code: #{StatusCodes.const_get(status_name)}" do
29
+ camel_case = upper_snake_to_camel(status_name)
30
+ error_class = GRPC.const_get(camel_case)
31
+ # expect the error class to be a subclass of BadStatus
32
+ expect(error_class < GRPC::BadStatus)
33
+
34
+ error_object = error_class.new
35
+ # check that the code matches the int value of the error's constant
36
+ status_code = StatusCodes.const_get(status_name)
37
+ expect(error_object.code).to eq(status_code)
38
+
39
+ # check default parameters
40
+ expect(error_object.details).to eq('unknown cause')
41
+ expect(error_object.metadata).to eq({})
42
+
43
+ # check that the BadStatus factory for creates the correct
44
+ # exception too
45
+ from_factory = GRPC::BadStatus.new_status_exception(status_code)
46
+ expect(from_factory.is_a?(error_class)).to be(true)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,142 @@
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
+ require 'google/protobuf/well_known_types'
17
+ require 'google/rpc/status_pb'
18
+ require_relative '../pb/src/proto/grpc/testing/messages_pb'
19
+
20
+ describe GRPC::BadStatus do
21
+ describe :attributes do
22
+ it 'has attributes' do
23
+ code = 1
24
+ details = 'details'
25
+ metadata = { 'key' => 'val' }
26
+
27
+ exception = GRPC::BadStatus.new(code, details, metadata)
28
+
29
+ expect(exception.code).to eq code
30
+ expect(exception.details).to eq details
31
+ expect(exception.metadata).to eq metadata
32
+ end
33
+ end
34
+
35
+ describe :new_status_exception do
36
+ let(:codes_and_classes) do
37
+ [
38
+ [GRPC::Core::StatusCodes::OK, GRPC::Ok],
39
+ [GRPC::Core::StatusCodes::CANCELLED, GRPC::Cancelled],
40
+ [GRPC::Core::StatusCodes::UNKNOWN, GRPC::Unknown],
41
+ [GRPC::Core::StatusCodes::INVALID_ARGUMENT, GRPC::InvalidArgument],
42
+ [GRPC::Core::StatusCodes::DEADLINE_EXCEEDED, GRPC::DeadlineExceeded],
43
+ [GRPC::Core::StatusCodes::NOT_FOUND, GRPC::NotFound],
44
+ [GRPC::Core::StatusCodes::ALREADY_EXISTS, GRPC::AlreadyExists],
45
+ [GRPC::Core::StatusCodes::PERMISSION_DENIED, GRPC::PermissionDenied],
46
+ [GRPC::Core::StatusCodes::UNAUTHENTICATED, GRPC::Unauthenticated],
47
+ [GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, GRPC::ResourceExhausted],
48
+ [GRPC::Core::StatusCodes::FAILED_PRECONDITION, GRPC::FailedPrecondition],
49
+ [GRPC::Core::StatusCodes::ABORTED, GRPC::Aborted],
50
+ [GRPC::Core::StatusCodes::OUT_OF_RANGE, GRPC::OutOfRange],
51
+ [GRPC::Core::StatusCodes::UNIMPLEMENTED, GRPC::Unimplemented],
52
+ [GRPC::Core::StatusCodes::INTERNAL, GRPC::Internal],
53
+ [GRPC::Core::StatusCodes::UNAVAILABLE, GRPC::Unavailable],
54
+ [GRPC::Core::StatusCodes::DATA_LOSS, GRPC::DataLoss],
55
+ [99, GRPC::BadStatus] # Unknown codes default to BadStatus
56
+ ]
57
+ end
58
+
59
+ it 'maps codes to the correct error class' do
60
+ codes_and_classes.each do |code, grpc_error_class|
61
+ exception = GRPC::BadStatus.new_status_exception(code)
62
+
63
+ expect(exception).to be_a grpc_error_class
64
+ end
65
+ end
66
+ end
67
+
68
+ describe :to_status do
69
+ it 'gets status' do
70
+ code = 1
71
+ details = 'details'
72
+ metadata = { 'key' => 'val' }
73
+
74
+ exception = GRPC::BadStatus.new(code, details, metadata)
75
+ status = Struct::Status.new(code, details, metadata)
76
+
77
+ expect(exception.to_status).to eq status
78
+ end
79
+ end
80
+
81
+ describe :to_rpc_status do
82
+ let(:simple_request_any) do
83
+ Google::Protobuf::Any.new.tap do |any|
84
+ any.pack(
85
+ Grpc::Testing::SimpleRequest.new(
86
+ payload: Grpc::Testing::Payload.new(body: 'request')
87
+ )
88
+ )
89
+ end
90
+ end
91
+ let(:simple_response_any) do
92
+ Google::Protobuf::Any.new.tap do |any|
93
+ any.pack(
94
+ Grpc::Testing::SimpleResponse.new(
95
+ payload: Grpc::Testing::Payload.new(body: 'response')
96
+ )
97
+ )
98
+ end
99
+ end
100
+ let(:payload_any) do
101
+ Google::Protobuf::Any.new.tap do |any|
102
+ any.pack(Grpc::Testing::Payload.new(body: 'payload'))
103
+ end
104
+ end
105
+
106
+ it 'decodes proto values' do
107
+ rpc_status = Google::Rpc::Status.new(
108
+ code: 1,
109
+ message: 'matching message',
110
+ details: [simple_request_any, simple_response_any, payload_any]
111
+ )
112
+ rpc_status_proto = Google::Rpc::Status.encode(rpc_status)
113
+
114
+ code = 1
115
+ details = 'details'
116
+ metadata = { 'grpc-status-details-bin' => rpc_status_proto }
117
+
118
+ exception = GRPC::BadStatus.new(code, details, metadata)
119
+
120
+ expect(exception.to_rpc_status).to eq rpc_status
121
+ end
122
+
123
+ it 'does not raise when decoding a bad proto' do
124
+ code = 1
125
+ details = 'details'
126
+ metadata = { 'grpc-status-details-bin' => 'notavalidprotostream' }
127
+
128
+ exception = GRPC::BadStatus.new(code, details, metadata)
129
+
130
+ expect(exception.to_rpc_status).to be nil
131
+
132
+ error_msg = 'parse error: to_rpc_status failed'
133
+ error_desc = '<Google::Protobuf::ParseError> ' \
134
+ 'Error occurred during parsing'
135
+
136
+ # Check that the parse error was logged correctly
137
+ log_contents = @log_output.read
138
+ expect(log_contents).to include "WARN GRPC : #{error_msg}"
139
+ expect(log_contents).to include "WARN GRPC : #{error_desc}"
140
+ end
141
+ end
142
+ end