thrift 0.23.0 → 0.25.0
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 +4 -4
- data/README.md +203 -40
- data/ext/binary_protocol_accelerated.c +130 -40
- data/ext/bytes.c +14 -0
- data/ext/compact_protocol.c +184 -91
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +12 -4
- data/ext/macros.h +11 -0
- data/ext/memory_buffer.c +67 -12
- data/ext/struct.c +192 -71
- data/ext/thrift_native.c +7 -0
- data/lib/thrift/bytes.rb +6 -3
- data/lib/thrift/client.rb +31 -33
- data/lib/thrift/exceptions.rb +11 -8
- data/lib/thrift/multiplexed_processor.rb +17 -8
- data/lib/thrift/processor.rb +25 -3
- data/lib/thrift/protocol/base_protocol.rb +66 -31
- data/lib/thrift/protocol/binary_protocol.rb +80 -37
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
- data/lib/thrift/protocol/compact_protocol.rb +204 -88
- data/lib/thrift/protocol/header_protocol.rb +15 -3
- data/lib/thrift/protocol/json_protocol.rb +158 -109
- data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
- data/lib/thrift/protocol/protocol_decorator.rb +6 -2
- data/lib/thrift/serializer/deserializer.rb +1 -0
- data/lib/thrift/serializer/serializer.rb +7 -0
- data/lib/thrift/server/base_server.rb +11 -2
- data/lib/thrift/server/nonblocking_server.rb +69 -20
- data/lib/thrift/server/rack_application.rb +69 -0
- data/lib/thrift/server/simple_server.rb +27 -15
- data/lib/thrift/server/thin_http_server.rb +21 -44
- data/lib/thrift/server/thread_pool_server.rb +21 -17
- data/lib/thrift/server/threaded_server.rb +22 -18
- data/lib/thrift/struct.rb +34 -18
- data/lib/thrift/struct_union.rb +37 -36
- data/lib/thrift/thrift_native.rb +2 -1
- data/lib/thrift/transport/base_server_transport.rb +3 -0
- data/lib/thrift/transport/base_transport.rb +26 -4
- data/lib/thrift/transport/buffered_transport.rb +5 -4
- data/lib/thrift/transport/framed_transport.rb +33 -7
- data/lib/thrift/transport/header_transport.rb +159 -33
- data/lib/thrift/transport/http_client_transport.rb +28 -14
- data/lib/thrift/transport/io_stream_transport.rb +3 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
- data/lib/thrift/transport/server_socket.rb +10 -8
- data/lib/thrift/transport/socket.rb +85 -48
- data/lib/thrift/transport/ssl_server_socket.rb +67 -6
- data/lib/thrift/transport/ssl_socket.rb +73 -14
- data/lib/thrift/transport/unix_server_socket.rb +6 -2
- data/lib/thrift/transport/unix_socket.rb +5 -6
- data/lib/thrift/types.rb +23 -22
- data/lib/thrift/union.rb +21 -11
- data/lib/thrift/uuid.rb +9 -8
- data/lib/thrift.rb +40 -39
- metadata +7 -266
- data/benchmark/Benchmark.thrift +0 -24
- data/benchmark/benchmark.rb +0 -285
- data/benchmark/client.rb +0 -117
- data/benchmark/server.rb +0 -120
- data/benchmark/thin_server.rb +0 -45
- data/lib/thrift/server/mongrel_http_server.rb +0 -60
- data/spec/BaseService.thrift +0 -27
- data/spec/ExtendedService.thrift +0 -25
- data/spec/Referenced.thrift +0 -44
- data/spec/ThriftNamespacedSpec.thrift +0 -53
- data/spec/ThriftSpec.thrift +0 -187
- data/spec/base_protocol_spec.rb +0 -224
- data/spec/base_transport_spec.rb +0 -387
- data/spec/binary_protocol_accelerated_spec.rb +0 -46
- data/spec/binary_protocol_spec.rb +0 -72
- data/spec/binary_protocol_spec_shared.rb +0 -445
- data/spec/bytes_spec.rb +0 -99
- data/spec/client_spec.rb +0 -166
- data/spec/compact_protocol_spec.rb +0 -196
- data/spec/constants_demo_spec.rb +0 -101
- data/spec/exception_spec.rb +0 -140
- data/spec/flat_spec.rb +0 -62
- data/spec/header_protocol_spec.rb +0 -475
- data/spec/header_transport_spec.rb +0 -386
- data/spec/http_client_spec.rb +0 -159
- data/spec/json_protocol_spec.rb +0 -552
- data/spec/namespaced_spec.rb +0 -66
- data/spec/nonblocking_server_spec.rb +0 -361
- data/spec/processor_spec.rb +0 -79
- data/spec/serializer_spec.rb +0 -66
- data/spec/server_socket_spec.rb +0 -84
- data/spec/server_spec.rb +0 -186
- data/spec/socket_spec.rb +0 -67
- data/spec/socket_spec_shared.rb +0 -167
- data/spec/spec_helper.rb +0 -69
- data/spec/ssl_server_socket_spec.rb +0 -45
- data/spec/ssl_socket_spec.rb +0 -87
- data/spec/struct_nested_containers_spec.rb +0 -190
- data/spec/struct_spec.rb +0 -397
- data/spec/support/header_protocol_helper.rb +0 -54
- data/spec/thin_http_server_spec.rb +0 -126
- data/spec/types_spec.rb +0 -117
- data/spec/union_spec.rb +0 -272
- data/spec/unix_socket_spec.rb +0 -115
- data/spec/uuid_validation_spec.rb +0 -238
- data/test/fuzz/Makefile.am +0 -173
- data/test/fuzz/README.md +0 -149
- data/test/fuzz/fuzz_common.rb +0 -95
- data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
- data/test/fuzz/fuzz_tracer.rb +0 -28
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
# or more contributor license agreements. See the NOTICE file
|
|
4
|
-
# distributed with this work for additional information
|
|
5
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
# to you under the Apache License, Version 2.0 (the
|
|
7
|
-
# "License"); you may not use this file except in compliance
|
|
8
|
-
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing,
|
|
13
|
-
# software distributed under the License is distributed on an
|
|
14
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
# KIND, either express or implied. See the License for the
|
|
16
|
-
# specific language governing permissions and limitations
|
|
17
|
-
# under the License.
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
require 'spec_helper'
|
|
21
|
-
require_relative 'support/header_protocol_helper'
|
|
22
|
-
|
|
23
|
-
describe 'HeaderTransport' do
|
|
24
|
-
include HeaderProtocolHelper
|
|
25
|
-
|
|
26
|
-
describe Thrift::HeaderClientType do
|
|
27
|
-
it "should define client type constants" do
|
|
28
|
-
expect(Thrift::HeaderClientType::HEADERS).to eq(0x00)
|
|
29
|
-
expect(Thrift::HeaderClientType::FRAMED_BINARY).to eq(0x01)
|
|
30
|
-
expect(Thrift::HeaderClientType::UNFRAMED_BINARY).to eq(0x02)
|
|
31
|
-
expect(Thrift::HeaderClientType::FRAMED_COMPACT).to eq(0x03)
|
|
32
|
-
expect(Thrift::HeaderClientType::UNFRAMED_COMPACT).to eq(0x04)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe Thrift::HeaderSubprotocolID do
|
|
37
|
-
it "should define protocol ID constants" do
|
|
38
|
-
expect(Thrift::HeaderSubprotocolID::BINARY).to eq(0x00)
|
|
39
|
-
expect(Thrift::HeaderSubprotocolID::COMPACT).to eq(0x02)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe Thrift::HeaderTransformID do
|
|
44
|
-
it "should define transform ID constants" do
|
|
45
|
-
expect(Thrift::HeaderTransformID::ZLIB).to eq(0x01)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe Thrift::HeaderTransport do
|
|
50
|
-
before(:each) do
|
|
51
|
-
@underlying = Thrift::MemoryBufferTransport.new
|
|
52
|
-
@trans = Thrift::HeaderTransport.new(@underlying)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "should provide a to_s that describes the encapsulation" do
|
|
56
|
-
expect(@trans.to_s).to eq("header(memory)")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should pass through open?/open/close" do
|
|
60
|
-
mock_transport = double("Transport")
|
|
61
|
-
expect(mock_transport).to receive(:open?).and_return(true)
|
|
62
|
-
expect(mock_transport).to receive(:open).and_return(nil)
|
|
63
|
-
expect(mock_transport).to receive(:close).and_return(nil)
|
|
64
|
-
|
|
65
|
-
trans = Thrift::HeaderTransport.new(mock_transport)
|
|
66
|
-
expect(trans.open?).to be true
|
|
67
|
-
trans.open
|
|
68
|
-
trans.close
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "header management" do
|
|
72
|
-
it "should allow setting and getting headers" do
|
|
73
|
-
@trans.set_header("key1", "value1")
|
|
74
|
-
@trans.set_header("key2", "value2")
|
|
75
|
-
# Headers aren't read until we receive data, so write and read back
|
|
76
|
-
expect(@trans.get_headers).to eq({})
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "should clear headers" do
|
|
80
|
-
@trans.set_header("key1", "value1")
|
|
81
|
-
@trans.clear_headers
|
|
82
|
-
# Write and flush to verify headers were cleared
|
|
83
|
-
@trans.write("test")
|
|
84
|
-
@trans.flush
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "should add transforms" do
|
|
88
|
-
expect { @trans.add_transform(Thrift::HeaderTransformID::ZLIB) }.not_to raise_error
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "should reject unknown transforms" do
|
|
92
|
-
expect { @trans.add_transform(999) }.to raise_error(Thrift::TransportException)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
describe "write and flush" do
|
|
97
|
-
it "should buffer writes" do
|
|
98
|
-
@trans.write("hello")
|
|
99
|
-
@trans.write(" world")
|
|
100
|
-
expect(@underlying.available).to eq(0)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "should write Header format on flush" do
|
|
104
|
-
@trans.write("test payload")
|
|
105
|
-
@trans.flush
|
|
106
|
-
|
|
107
|
-
# Read back the frame
|
|
108
|
-
data = @underlying.read(@underlying.available)
|
|
109
|
-
|
|
110
|
-
# Should have frame length (4 bytes) + header + payload
|
|
111
|
-
expect(data.bytesize).to be > 16
|
|
112
|
-
|
|
113
|
-
# First 4 bytes are frame length
|
|
114
|
-
frame_size = data[0, 4].unpack('N').first
|
|
115
|
-
expect(frame_size).to eq(data.bytesize - 4)
|
|
116
|
-
|
|
117
|
-
# Next 2 bytes should be header magic
|
|
118
|
-
magic = data[4, 2].unpack('n').first
|
|
119
|
-
expect(magic).to eq(Thrift::HeaderTransport::HEADER_MAGIC)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "should include headers in frame" do
|
|
123
|
-
@trans.set_header("test-key", "test-value")
|
|
124
|
-
@trans.write("payload")
|
|
125
|
-
@trans.flush
|
|
126
|
-
|
|
127
|
-
# Read back and verify it's larger due to headers
|
|
128
|
-
data = @underlying.read(@underlying.available)
|
|
129
|
-
expect(data.bytesize).to be > 30 # Should include header key-value
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "should write the configured sequence id into the frame header" do
|
|
133
|
-
@trans.sequence_id = 456
|
|
134
|
-
@trans.write("payload")
|
|
135
|
-
@trans.flush
|
|
136
|
-
|
|
137
|
-
data = @underlying.read(@underlying.available)
|
|
138
|
-
expect(data[8, 4].unpack('N').first).to eq(456)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it "should apply ZLIB transform" do
|
|
142
|
-
@trans.add_transform(Thrift::HeaderTransformID::ZLIB)
|
|
143
|
-
original_payload = "a" * 1000 # Compressible data
|
|
144
|
-
@trans.write(original_payload)
|
|
145
|
-
@trans.flush
|
|
146
|
-
|
|
147
|
-
data = @underlying.read(@underlying.available)
|
|
148
|
-
# Compressed frame should be smaller than uncompressed
|
|
149
|
-
expect(data.bytesize).to be < original_payload.bytesize
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe "frame size limits" do
|
|
154
|
-
it "should reject payloads larger than max frame size" do
|
|
155
|
-
@trans.set_max_frame_size(4)
|
|
156
|
-
@trans.write("12345")
|
|
157
|
-
expect { @trans.flush }.to raise_error(Thrift::TransportException, /frame that is too large/)
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
describe "read and frame detection" do
|
|
162
|
-
it "should detect Header format" do
|
|
163
|
-
# Write a Header frame
|
|
164
|
-
@trans.write("test data")
|
|
165
|
-
@trans.flush
|
|
166
|
-
|
|
167
|
-
# Reset for reading
|
|
168
|
-
written_data = @underlying.read(@underlying.available)
|
|
169
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
170
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
171
|
-
|
|
172
|
-
result = read_trans.read(9)
|
|
173
|
-
expect(result).to eq("test data")
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it "should detect framed binary protocol" do
|
|
177
|
-
# Create a framed binary message
|
|
178
|
-
payload = [Thrift::BinaryProtocol::VERSION_1 | Thrift::MessageTypes::CALL].pack('N')
|
|
179
|
-
payload << "test"
|
|
180
|
-
frame = [payload.bytesize].pack('N') + payload
|
|
181
|
-
|
|
182
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
183
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
184
|
-
|
|
185
|
-
result = read_trans.read(payload.bytesize)
|
|
186
|
-
expect(result).to eq(payload)
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
it "should detect unframed binary protocol" do
|
|
190
|
-
# Create an unframed binary message (version word first)
|
|
191
|
-
message = [Thrift::BinaryProtocol::VERSION_1 | Thrift::MessageTypes::CALL].pack('N')
|
|
192
|
-
message << "test"
|
|
193
|
-
|
|
194
|
-
read_transport = Thrift::MemoryBufferTransport.new(message)
|
|
195
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
196
|
-
|
|
197
|
-
result = read_trans.read(message.bytesize)
|
|
198
|
-
expect(result).to eq(message)
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it "should read headers from Header frame" do
|
|
202
|
-
# Write with headers
|
|
203
|
-
@trans.set_header("request-id", "12345")
|
|
204
|
-
@trans.write("payload")
|
|
205
|
-
@trans.flush
|
|
206
|
-
|
|
207
|
-
# Read back
|
|
208
|
-
written_data = @underlying.read(@underlying.available)
|
|
209
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
210
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
211
|
-
|
|
212
|
-
read_trans.read(7)
|
|
213
|
-
headers = read_trans.get_headers
|
|
214
|
-
expect(headers["request-id"]).to eq("12345")
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it "should decode signed sequence ids from Header frames" do
|
|
218
|
-
@trans.sequence_id = -2147483648
|
|
219
|
-
@trans.write("payload")
|
|
220
|
-
@trans.flush
|
|
221
|
-
|
|
222
|
-
written_data = @underlying.read(@underlying.available)
|
|
223
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
224
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
225
|
-
|
|
226
|
-
expect(read_trans.read(7)).to eq("payload")
|
|
227
|
-
expect(read_trans.sequence_id).to eq(-2147483648)
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
it "should decompress ZLIB payload" do
|
|
231
|
-
# Write with ZLIB
|
|
232
|
-
@trans.add_transform(Thrift::HeaderTransformID::ZLIB)
|
|
233
|
-
original = "hello world this is a test"
|
|
234
|
-
@trans.write(original)
|
|
235
|
-
@trans.flush
|
|
236
|
-
|
|
237
|
-
# Read back
|
|
238
|
-
written_data = @underlying.read(@underlying.available)
|
|
239
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
240
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
241
|
-
|
|
242
|
-
result = read_trans.read(original.bytesize)
|
|
243
|
-
expect(result).to eq(original)
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
describe "header parsing protections" do
|
|
248
|
-
it "should reject unreasonable header sizes" do
|
|
249
|
-
frame = build_header_frame("", Thrift::Bytes.empty_byte_buffer, header_words: 16_384)
|
|
250
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
251
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
252
|
-
|
|
253
|
-
expect { read_trans.read(1) }.to raise_error(Thrift::TransportException, /Header size is unreasonable/)
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
it "should reject header frames that are too small" do
|
|
257
|
-
frame = Thrift::Bytes.empty_byte_buffer
|
|
258
|
-
frame << [9].pack('N')
|
|
259
|
-
frame << [Thrift::HeaderTransport::HEADER_MAGIC].pack('n')
|
|
260
|
-
frame << [0].pack('n')
|
|
261
|
-
frame << [0].pack('N')
|
|
262
|
-
frame << [0].pack('n')
|
|
263
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
264
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
265
|
-
|
|
266
|
-
expect { read_trans.read(1) }.to raise_error(Thrift::TransportException, /frame is too small/)
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
it "should reject varints that cross header boundary" do
|
|
270
|
-
header_data = [0x80, 0x80, 0x80, 0x80].pack('C*')
|
|
271
|
-
frame = build_header_frame(header_data)
|
|
272
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
273
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
274
|
-
|
|
275
|
-
expect { read_trans.read(1) }.to raise_error(Thrift::TransportException, /header boundary/)
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
it "should reject strings that exceed header boundary" do
|
|
279
|
-
header_data = +""
|
|
280
|
-
header_data << varint32(Thrift::HeaderSubprotocolID::BINARY)
|
|
281
|
-
header_data << varint32(0)
|
|
282
|
-
header_data << varint32(Thrift::HeaderInfoType::KEY_VALUE)
|
|
283
|
-
header_data << varint32(1)
|
|
284
|
-
header_data << varint32(10)
|
|
285
|
-
header_data << "a"
|
|
286
|
-
|
|
287
|
-
frame = build_header_frame(header_data)
|
|
288
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
289
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
290
|
-
|
|
291
|
-
expect { read_trans.read(1) }.to raise_error(Thrift::TransportException, /Info header length exceeds header size/)
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
describe "round-trip" do
|
|
296
|
-
it "should handle complete write-read cycle" do
|
|
297
|
-
# Write
|
|
298
|
-
@trans.set_header("trace-id", "abc123")
|
|
299
|
-
@trans.write("hello world")
|
|
300
|
-
@trans.flush
|
|
301
|
-
|
|
302
|
-
# Read
|
|
303
|
-
written_data = @underlying.read(@underlying.available)
|
|
304
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
305
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
306
|
-
|
|
307
|
-
result = read_trans.read(11)
|
|
308
|
-
expect(result).to eq("hello world")
|
|
309
|
-
expect(read_trans.get_headers["trace-id"]).to eq("abc123")
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
it "should handle multiple headers" do
|
|
313
|
-
@trans.set_header("header1", "value1")
|
|
314
|
-
@trans.set_header("header2", "value2")
|
|
315
|
-
@trans.set_header("header3", "value3")
|
|
316
|
-
@trans.write("data")
|
|
317
|
-
@trans.flush
|
|
318
|
-
|
|
319
|
-
written_data = @underlying.read(@underlying.available)
|
|
320
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
321
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
322
|
-
|
|
323
|
-
read_trans.read(4)
|
|
324
|
-
headers = read_trans.get_headers
|
|
325
|
-
expect(headers["header1"]).to eq("value1")
|
|
326
|
-
expect(headers["header2"]).to eq("value2")
|
|
327
|
-
expect(headers["header3"]).to eq("value3")
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it "should handle ZLIB compression round-trip" do
|
|
331
|
-
@trans.add_transform(Thrift::HeaderTransformID::ZLIB)
|
|
332
|
-
@trans.set_header("compressed", "true")
|
|
333
|
-
original = "x" * 500
|
|
334
|
-
@trans.write(original)
|
|
335
|
-
@trans.flush
|
|
336
|
-
|
|
337
|
-
written_data = @underlying.read(@underlying.available)
|
|
338
|
-
read_transport = Thrift::MemoryBufferTransport.new(written_data)
|
|
339
|
-
read_trans = Thrift::HeaderTransport.new(read_transport)
|
|
340
|
-
|
|
341
|
-
result = read_trans.read(500)
|
|
342
|
-
expect(result).to eq(original)
|
|
343
|
-
expect(read_trans.get_headers["compressed"]).to eq("true")
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
describe "client type restrictions" do
|
|
348
|
-
it "should reject disallowed client types" do
|
|
349
|
-
# Only allow HEADERS
|
|
350
|
-
allowed = [Thrift::HeaderClientType::HEADERS]
|
|
351
|
-
|
|
352
|
-
# Create framed binary message
|
|
353
|
-
payload = [Thrift::BinaryProtocol::VERSION_1 | Thrift::MessageTypes::CALL].pack('N')
|
|
354
|
-
frame = [payload.bytesize].pack('N') + payload
|
|
355
|
-
|
|
356
|
-
read_transport = Thrift::MemoryBufferTransport.new(frame)
|
|
357
|
-
read_trans = Thrift::HeaderTransport.new(read_transport, allowed)
|
|
358
|
-
|
|
359
|
-
expect { read_trans.read(4) }.to raise_error(Thrift::TransportException)
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
describe Thrift::HeaderTransportFactory do
|
|
365
|
-
it "should wrap transport in HeaderTransport" do
|
|
366
|
-
mock_transport = double("Transport")
|
|
367
|
-
factory = Thrift::HeaderTransportFactory.new
|
|
368
|
-
result = factory.get_transport(mock_transport)
|
|
369
|
-
expect(result).to be_a(Thrift::HeaderTransport)
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
it "should provide a reasonable to_s" do
|
|
373
|
-
expect(Thrift::HeaderTransportFactory.new.to_s).to eq("header")
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
it "should pass allowed_client_types to transport" do
|
|
377
|
-
allowed = [Thrift::HeaderClientType::HEADERS]
|
|
378
|
-
factory = Thrift::HeaderTransportFactory.new(allowed)
|
|
379
|
-
|
|
380
|
-
mock_transport = Thrift::MemoryBufferTransport.new
|
|
381
|
-
result = factory.get_transport(mock_transport)
|
|
382
|
-
|
|
383
|
-
expect(result).to be_a(Thrift::HeaderTransport)
|
|
384
|
-
end
|
|
385
|
-
end
|
|
386
|
-
end
|
data/spec/http_client_spec.rb
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
# or more contributor license agreements. See the NOTICE file
|
|
4
|
-
# distributed with this work for additional information
|
|
5
|
-
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
# to you under the Apache License, Version 2.0 (the
|
|
7
|
-
# "License"); you may not use this file except in compliance
|
|
8
|
-
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing,
|
|
13
|
-
# software distributed under the License is distributed on an
|
|
14
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
# KIND, either express or implied. See the License for the
|
|
16
|
-
# specific language governing permissions and limitations
|
|
17
|
-
# under the License.
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
require 'spec_helper'
|
|
21
|
-
|
|
22
|
-
describe 'Thrift::HTTPClientTransport' do
|
|
23
|
-
describe Thrift::HTTPClientTransport do
|
|
24
|
-
before(:each) do
|
|
25
|
-
@client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should provide a reasonable to_s" do
|
|
29
|
-
@client.to_s == "http://my.domain.com/path/to/service?param=value"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should always be open" do
|
|
33
|
-
expect(@client).to be_open
|
|
34
|
-
@client.close
|
|
35
|
-
expect(@client).to be_open
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should post via HTTP and return the results" do
|
|
39
|
-
@client.write "a test"
|
|
40
|
-
@client.write " frame"
|
|
41
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
|
42
|
-
double("Net::HTTP").tap do |http|
|
|
43
|
-
expect(http).to receive(:use_ssl=).with(false)
|
|
44
|
-
expect(http).to receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}) do
|
|
45
|
-
double("Net::HTTPOK").tap do |response|
|
|
46
|
-
expect(response).to receive(:body).and_return "data"
|
|
47
|
-
expect(response).to receive(:code).and_return "200"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
@client.flush
|
|
53
|
-
expect(@client.read(10)).to eq("data")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "should send custom headers if defined" do
|
|
57
|
-
@client.write "test"
|
|
58
|
-
custom_headers = {"Cookie" => "Foo"}
|
|
59
|
-
headers = {"Content-Type"=>"application/x-thrift"}.merge(custom_headers)
|
|
60
|
-
|
|
61
|
-
@client.add_headers(custom_headers)
|
|
62
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
|
63
|
-
double("Net::HTTP").tap do |http|
|
|
64
|
-
expect(http).to receive(:use_ssl=).with(false)
|
|
65
|
-
expect(http).to receive(:post).with("/path/to/service?param=value", "test", headers) do
|
|
66
|
-
double("Net::HTTPOK").tap do |response|
|
|
67
|
-
expect(response).to receive(:body).and_return "data"
|
|
68
|
-
expect(response).to receive(:code).and_return "200"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
@client.flush
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'should reset the outbuf on HTTP failures' do
|
|
77
|
-
@client.write "test"
|
|
78
|
-
|
|
79
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
|
80
|
-
double("Net::HTTP").tap do |http|
|
|
81
|
-
expect(http).to receive(:use_ssl=).with(false)
|
|
82
|
-
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout }
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
@client.flush rescue
|
|
87
|
-
expect(@client.instance_variable_get(:@outbuf)).to eq(Thrift::Bytes.empty_byte_buffer)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'should raise TransportError on HTTP failures' do
|
|
91
|
-
@client.write "test"
|
|
92
|
-
|
|
93
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 80) do
|
|
94
|
-
double("Net::HTTP").tap do |http|
|
|
95
|
-
expect(http).to receive(:use_ssl=).with(false)
|
|
96
|
-
expect(http).to receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) do
|
|
97
|
-
double("Net::HTTPOK").tap do |response|
|
|
98
|
-
expect(response).not_to receive(:body)
|
|
99
|
-
expect(response).to receive(:code).at_least(:once).and_return "503"
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
expect { @client.flush }.to raise_error(Thrift::TransportException)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe 'ssl enabled' do
|
|
110
|
-
before(:each) do
|
|
111
|
-
@service_path = "/path/to/service?param=value"
|
|
112
|
-
@server_uri = "https://my.domain.com"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "should use SSL for https" do
|
|
116
|
-
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}")
|
|
117
|
-
|
|
118
|
-
client.write "test"
|
|
119
|
-
|
|
120
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
|
121
|
-
double("Net::HTTP").tap do |http|
|
|
122
|
-
expect(http).to receive(:use_ssl=).with(true)
|
|
123
|
-
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
|
|
124
|
-
expect(http).to receive(:post).with(@service_path, "test",
|
|
125
|
-
{"Content-Type" => "application/x-thrift"}) do
|
|
126
|
-
double("Net::HTTPOK").tap do |response|
|
|
127
|
-
expect(response).to receive(:body).and_return "data"
|
|
128
|
-
expect(response).to receive(:code).and_return "200"
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
client.flush
|
|
134
|
-
expect(client.read(4)).to eq("data")
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "should set SSL verify mode when specified" do
|
|
138
|
-
client = Thrift::HTTPClientTransport.new("#{@server_uri}#{@service_path}",
|
|
139
|
-
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
|
140
|
-
|
|
141
|
-
client.write "test"
|
|
142
|
-
expect(Net::HTTP).to receive(:new).with("my.domain.com", 443) do
|
|
143
|
-
double("Net::HTTP").tap do |http|
|
|
144
|
-
expect(http).to receive(:use_ssl=).with(true)
|
|
145
|
-
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
|
146
|
-
expect(http).to receive(:post).with(@service_path, "test",
|
|
147
|
-
{"Content-Type" => "application/x-thrift"}) do
|
|
148
|
-
double("Net::HTTPOK").tap do |response|
|
|
149
|
-
expect(response).to receive(:body).and_return "data"
|
|
150
|
-
expect(response).to receive(:code).and_return "200"
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
client.flush
|
|
156
|
-
expect(client.read(4)).to eq("data")
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|