thrift 0.24.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.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -4
  3. data/ext/binary_protocol_accelerated.c +52 -17
  4. data/ext/compact_protocol.c +135 -70
  5. data/ext/constants.h +3 -0
  6. data/ext/extconf.rb +4 -4
  7. data/ext/macros.h +11 -0
  8. data/ext/memory_buffer.c +35 -17
  9. data/ext/struct.c +185 -64
  10. data/ext/thrift_native.c +6 -0
  11. data/lib/thrift/bytes.rb +2 -2
  12. data/lib/thrift/client.rb +31 -22
  13. data/lib/thrift/exceptions.rb +10 -8
  14. data/lib/thrift/multiplexed_processor.rb +5 -6
  15. data/lib/thrift/processor.rb +24 -3
  16. data/lib/thrift/protocol/base_protocol.rb +53 -27
  17. data/lib/thrift/protocol/binary_protocol.rb +54 -40
  18. data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
  19. data/lib/thrift/protocol/compact_protocol.rb +193 -88
  20. data/lib/thrift/protocol/header_protocol.rb +14 -3
  21. data/lib/thrift/protocol/json_protocol.rb +146 -104
  22. data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
  23. data/lib/thrift/protocol/protocol_decorator.rb +5 -2
  24. data/lib/thrift/serializer/serializer.rb +6 -0
  25. data/lib/thrift/server/base_server.rb +10 -2
  26. data/lib/thrift/server/nonblocking_server.rb +49 -26
  27. data/lib/thrift/server/rack_application.rb +69 -0
  28. data/lib/thrift/server/simple_server.rb +27 -23
  29. data/lib/thrift/server/thin_http_server.rb +20 -44
  30. data/lib/thrift/server/thread_pool_server.rb +20 -17
  31. data/lib/thrift/server/threaded_server.rb +22 -26
  32. data/lib/thrift/struct.rb +33 -18
  33. data/lib/thrift/struct_union.rb +36 -30
  34. data/lib/thrift/transport/base_transport.rb +23 -5
  35. data/lib/thrift/transport/buffered_transport.rb +4 -4
  36. data/lib/thrift/transport/framed_transport.rb +32 -7
  37. data/lib/thrift/transport/header_transport.rb +130 -50
  38. data/lib/thrift/transport/http_client_transport.rb +27 -14
  39. data/lib/thrift/transport/io_stream_transport.rb +2 -1
  40. data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
  41. data/lib/thrift/transport/server_socket.rb +4 -5
  42. data/lib/thrift/transport/socket.rb +20 -22
  43. data/lib/thrift/transport/ssl_server_socket.rb +64 -4
  44. data/lib/thrift/transport/ssl_socket.rb +32 -5
  45. data/lib/thrift/transport/unix_server_socket.rb +1 -1
  46. data/lib/thrift/transport/unix_socket.rb +4 -6
  47. data/lib/thrift/types.rb +22 -22
  48. data/lib/thrift/union.rb +20 -11
  49. data/lib/thrift/uuid.rb +8 -8
  50. data/lib/thrift.rb +39 -39
  51. metadata +5 -230
  52. data/benchmark/Benchmark.thrift +0 -24
  53. data/benchmark/benchmark.rb +0 -286
  54. data/benchmark/client.rb +0 -118
  55. data/benchmark/server.rb +0 -121
  56. data/benchmark/thin_server.rb +0 -46
  57. data/lib/thrift/server/mongrel_http_server.rb +0 -61
  58. data/spec/BaseService.thrift +0 -27
  59. data/spec/ExtendedService.thrift +0 -25
  60. data/spec/Referenced.thrift +0 -44
  61. data/spec/ThriftNamespacedSpec.thrift +0 -53
  62. data/spec/ThriftSpec.thrift +0 -203
  63. data/spec/base_protocol_spec.rb +0 -244
  64. data/spec/base_transport_spec.rb +0 -428
  65. data/spec/binary_protocol_accelerated_spec.rb +0 -47
  66. data/spec/binary_protocol_spec.rb +0 -73
  67. data/spec/binary_protocol_spec_shared.rb +0 -509
  68. data/spec/bytes_spec.rb +0 -117
  69. data/spec/client_spec.rb +0 -167
  70. data/spec/compact_protocol_spec.rb +0 -295
  71. data/spec/constants_demo_spec.rb +0 -102
  72. data/spec/exception_spec.rb +0 -141
  73. data/spec/flat_spec.rb +0 -63
  74. data/spec/header_protocol_spec.rb +0 -476
  75. data/spec/header_transport_spec.rb +0 -431
  76. data/spec/http_client_spec.rb +0 -160
  77. data/spec/json_protocol_spec.rb +0 -574
  78. data/spec/multiplexed_processor_spec.rb +0 -75
  79. data/spec/namespaced_spec.rb +0 -67
  80. data/spec/nonblocking_server_spec.rb +0 -429
  81. data/spec/processor_spec.rb +0 -80
  82. data/spec/recursion_depth_spec.rb +0 -223
  83. data/spec/serializer_spec.rb +0 -67
  84. data/spec/server_socket_spec.rb +0 -121
  85. data/spec/server_spec.rb +0 -238
  86. data/spec/socket_spec.rb +0 -174
  87. data/spec/socket_spec_shared.rb +0 -168
  88. data/spec/spec_helper.rb +0 -70
  89. data/spec/ssl_server_socket_spec.rb +0 -85
  90. data/spec/ssl_socket_spec.rb +0 -248
  91. data/spec/struct_nested_containers_spec.rb +0 -191
  92. data/spec/struct_spec.rb +0 -398
  93. data/spec/support/header_protocol_helper.rb +0 -55
  94. data/spec/thin_http_server_spec.rb +0 -127
  95. data/spec/types_spec.rb +0 -118
  96. data/spec/union_spec.rb +0 -273
  97. data/spec/unix_socket_spec.rb +0 -131
  98. data/spec/uuid_validation_spec.rb +0 -239
  99. data/test/fuzz/Makefile +0 -779
  100. data/test/fuzz/Makefile.am +0 -173
  101. data/test/fuzz/Makefile.in +0 -775
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -96
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
  120. data/test/fuzz/fuzz_tracer.rb +0 -29
@@ -1,239 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'spec_helper'
22
-
23
- describe 'UUID Validation' do
24
- protocols = [
25
- ['BinaryProtocol', Thrift::BinaryProtocol],
26
- ]
27
-
28
- if defined?(Thrift::BinaryProtocolAccelerated)
29
- protocols << ['BinaryProtocolAccelerated', Thrift::BinaryProtocolAccelerated]
30
- end
31
-
32
- protocols << ['CompactProtocol', Thrift::CompactProtocol]
33
- protocols << ['JsonProtocol', Thrift::JsonProtocol]
34
-
35
- protocols.each do |protocol_name, protocol_class|
36
- describe protocol_name do
37
- before(:each) do
38
- @trans = Thrift::MemoryBufferTransport.new
39
- @prot = protocol_class.new(@trans)
40
- end
41
-
42
- context 'valid UUIDs' do
43
- it 'should accept lowercase UUIDs' do
44
- uuid = '550e8400-e29b-41d4-a716-446655440000'
45
- expect { @prot.write_uuid(uuid) }.not_to raise_error
46
- result = @prot.read_uuid
47
- expect(result).to eq(uuid)
48
- end
49
-
50
- it 'should accept uppercase UUIDs' do
51
- uuid = '550E8400-E29B-41D4-A716-446655440000'
52
- expect { @prot.write_uuid(uuid) }.not_to raise_error
53
- result = @prot.read_uuid
54
- # Result should be lowercase
55
- expect(result).to eq('550e8400-e29b-41d4-a716-446655440000')
56
- end
57
-
58
- it 'should accept mixed case UUIDs' do
59
- uuid = '550e8400-E29B-41d4-A716-446655440000'
60
- expect { @prot.write_uuid(uuid) }.not_to raise_error
61
- result = @prot.read_uuid
62
- expect(result).to eq('550e8400-e29b-41d4-a716-446655440000')
63
- end
64
-
65
- it 'should accept all zeros' do
66
- uuid = '00000000-0000-0000-0000-000000000000'
67
- expect { @prot.write_uuid(uuid) }.not_to raise_error
68
- result = @prot.read_uuid
69
- expect(result).to eq(uuid)
70
- end
71
-
72
- it 'should accept all fs' do
73
- uuid = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
74
- expect { @prot.write_uuid(uuid) }.not_to raise_error
75
- result = @prot.read_uuid
76
- expect(result).to eq(uuid)
77
- end
78
- end
79
-
80
- context 'invalid UUIDs' do
81
- def expect_invalid_uuid(value, message)
82
- expect { @prot.write_uuid(value) }.to raise_error(Thrift::ProtocolException) do |error|
83
- expect(error.type).to eq(Thrift::ProtocolException::INVALID_DATA)
84
- expect(error.message).to eq(message)
85
- end
86
- end
87
-
88
- it 'should reject nil' do
89
- expect_invalid_uuid(nil, 'UUID must be a string')
90
- end
91
-
92
- it 'should reject non-string' do
93
- expect_invalid_uuid(12345, 'UUID must be a string')
94
- end
95
-
96
- it 'should reject wrong length' do
97
- expect_invalid_uuid('550e8400-e29b-41d4-a716', 'Invalid UUID format')
98
- end
99
-
100
- it 'should reject missing hyphens' do
101
- expect_invalid_uuid('550e8400e29b41d4a716446655440000', 'Invalid UUID format')
102
- end
103
-
104
- it 'should reject hyphens in wrong positions' do
105
- expect_invalid_uuid('550e840-0e29b-41d4-a716-446655440000', 'Invalid UUID format')
106
- end
107
-
108
- it 'should reject invalid hex characters (g)' do
109
- expect_invalid_uuid('550e8400-e29b-41d4-a716-44665544000g', 'Invalid UUID format')
110
- end
111
-
112
- it 'should reject invalid hex characters (z)' do
113
- expect_invalid_uuid('z50e8400-e29b-41d4-a716-446655440000', 'Invalid UUID format')
114
- end
115
-
116
- it 'should reject invalid hex characters (space)' do
117
- expect_invalid_uuid('550e8400-e29b-41d4-a716-44665544000 ', 'Invalid UUID format')
118
- end
119
-
120
- it 'should reject empty string' do
121
- expect_invalid_uuid('', 'Invalid UUID format')
122
- end
123
-
124
- it 'should reject UUID with extra characters' do
125
- expect_invalid_uuid('550e8400-e29b-41d4-a716-446655440000x', 'Invalid UUID format')
126
- end
127
-
128
- it 'should reject trailing hyphen' do
129
- expect_invalid_uuid('550e8400-e29b-41d4-a716-44665544000-', 'Invalid UUID format')
130
- end
131
-
132
- it 'should reject hyphen inside hex pair' do
133
- expect_invalid_uuid('550e8400-e29b-41d4-a716-4466-5544000', 'Invalid UUID format')
134
- end
135
- end
136
-
137
- context 'malformed binary data on read' do
138
- it 'should raise error on truncated data' do
139
- @trans = Thrift::MemoryBufferTransport.new
140
- @prot = protocol_class.new(@trans)
141
-
142
- # Write only 10 bytes instead of 16
143
- if protocol_class == Thrift::JsonProtocol
144
- @trans.write('"00000000-0000-0000-0000"')
145
- else
146
- @trans.write("\x00" * 10)
147
- end
148
-
149
- expect { @prot.read_uuid }.to raise_error(EOFError)
150
- end
151
-
152
- it 'should raise error on 15 bytes (one byte short)' do
153
- @trans = Thrift::MemoryBufferTransport.new
154
- @prot = protocol_class.new(@trans)
155
-
156
- if protocol_class == Thrift::JsonProtocol
157
- @trans.write('"00000000-0000-0000-0000-000000000"')
158
- else
159
- @trans.write("\x00" * 15)
160
- end
161
-
162
- expect { @prot.read_uuid }.to raise_error(EOFError)
163
- end
164
-
165
- it 'should raise error on empty buffer' do
166
- @trans = Thrift::MemoryBufferTransport.new
167
- @prot = protocol_class.new(@trans)
168
-
169
- expect { @prot.read_uuid }.to raise_error(EOFError)
170
- end
171
- end
172
-
173
- context 'multiple UUIDs in sequence' do
174
- it 'should handle 10 UUIDs in sequence' do
175
- uuids = 10.times.map { |i| sprintf('%08x-0000-0000-0000-000000000000', i) }
176
-
177
- @trans = Thrift::MemoryBufferTransport.new
178
- @prot = protocol_class.new(@trans)
179
-
180
- uuids.each { |uuid| @prot.write_uuid(uuid) }
181
-
182
- results = 10.times.map { @prot.read_uuid }
183
- expect(results).to eq(uuids)
184
- end
185
-
186
- it 'should handle UUIDs interleaved with other types' do
187
- @trans = Thrift::MemoryBufferTransport.new
188
- @prot = protocol_class.new(@trans)
189
-
190
- @prot.write_message_begin('testMessage', Thrift::MessageTypes::CALL, 0)
191
- @prot.write_i32(42)
192
- @prot.write_uuid('550e8400-e29b-41d4-a716-446655440000')
193
- @prot.write_string('test')
194
- @prot.write_uuid('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
195
- @prot.write_i64(123456789)
196
- @prot.write_message_end
197
-
198
- @prot.read_message_begin
199
- expect(@prot.read_i32).to eq(42)
200
- expect(@prot.read_uuid).to eq('550e8400-e29b-41d4-a716-446655440000')
201
- expect(@prot.read_string).to eq('test')
202
- expect(@prot.read_uuid).to eq('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
203
- expect(@prot.read_i64).to eq(123456789)
204
- @prot.read_message_end
205
- end
206
-
207
- it 'should handle UUIDs in struct fields context' do
208
- @trans = Thrift::MemoryBufferTransport.new
209
- @prot = protocol_class.new(@trans)
210
-
211
- # Simulate struct field headers
212
- @prot.write_struct_begin('test')
213
- @prot.write_field_begin('uuid1', Thrift::Types::UUID, 1)
214
- @prot.write_uuid('550e8400-e29b-41d4-a716-446655440000')
215
- @prot.write_field_end
216
- @prot.write_field_begin('uuid2', Thrift::Types::UUID, 2)
217
- @prot.write_uuid('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
218
- @prot.write_field_end
219
- @prot.write_field_stop
220
- @prot.write_struct_end
221
-
222
- @prot.read_struct_begin
223
- name, type, id = @prot.read_field_begin
224
- expect(type).to eq(Thrift::Types::UUID)
225
- expect(@prot.read_uuid).to eq('550e8400-e29b-41d4-a716-446655440000')
226
- @prot.read_field_end
227
-
228
- name, type, id = @prot.read_field_begin
229
- expect(type).to eq(Thrift::Types::UUID)
230
- expect(@prot.read_uuid).to eq('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
231
- @prot.read_field_end
232
-
233
- name, type, id = @prot.read_field_begin
234
- expect(type).to eq(Thrift::Types::STOP)
235
- end
236
- end
237
- end
238
- end
239
- end