bson 4.5.0-java → 4.6.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Driver BSON Corpus spec tests' do
4
4
 
5
- specs = BSON_CORPUS_TESTS.map { |file| BSON::Corpus::Spec.new(file) }
5
+ BSON_CORPUS_TESTS.each do |path|
6
+ basename = File.basename(path)
7
+ # All of the tests in the failures subdir are failing apparently
8
+ #basename = path.sub(/.*corpus-tests\//, '')
6
9
 
7
- specs.each do |spec|
10
+ spec = BSON::Corpus::Spec.new(path)
8
11
 
9
- context(spec.description) do
12
+ context("(#{basename}): #{spec.description}") do
10
13
 
11
14
  spec.valid_tests.each do |test|
12
15
 
@@ -57,9 +60,9 @@ describe 'Driver BSON Corpus spec tests' do
57
60
 
58
61
  it 'raises an error' do
59
62
  skip 'This test case does not raise and error but should' unless error
60
- expect {
63
+ expect do
61
64
  test.reencoded_bson
62
- }.to raise_error
65
+ end.to raise_error(error.class)
63
66
  end
64
67
  end
65
68
  end
@@ -163,6 +163,26 @@ describe BSON::Document do
163
163
  it "sets the value" do
164
164
  expect(doc[key]).to eq(val)
165
165
  end
166
+
167
+ context 'when value is a hash' do
168
+ let(:val) do
169
+ {'foo' => {'bar' => 'baz'}}
170
+ end
171
+
172
+ it 'converts value to indifferent access' do
173
+ expect(doc[key][:foo][:bar]).to eq('baz')
174
+ end
175
+ end
176
+
177
+ context 'when value is an array with hash element' do
178
+ let(:val) do
179
+ [42, {'foo' => {'bar' => 'baz'}}]
180
+ end
181
+
182
+ it 'converts hash element to indifferent access' do
183
+ expect(doc[key][1][:foo][:bar]).to eq('baz')
184
+ end
185
+ end
166
186
  end
167
187
 
168
188
  if described_class.instance_methods.include?(:dig)
@@ -998,51 +1018,31 @@ describe BSON::Document do
998
1018
  it_behaves_like "a document able to handle utf-8"
999
1019
  end
1000
1020
 
1001
- context "when utf-8 values exist in wrong encoding" do
1021
+ context "given a utf-8-encodable string in another encoding" do
1002
1022
 
1003
1023
  let(:string) { "gültig" }
1004
1024
  let(:document) do
1005
1025
  described_class["type", string.encode("iso-8859-1")]
1006
1026
  end
1007
1027
 
1008
- it "raises an exception", unless: BSON::Environment.jruby? do
1009
- expect {
1010
- document.to_bson
1011
- }.to raise_error(ArgumentError)
1012
- end
1013
-
1014
- it 'converts the values', if: BSON::Environment.jruby? do
1015
- expect(
1016
- BSON::Document.from_bson(BSON::ByteBuffer.new(document.to_bson.to_s))
1017
- ).to eq({ "type" => string })
1018
- end
1019
- end
1020
-
1021
- context "when binary strings with utf-8 values exist", if: BSON::Environment.jruby? && (JRUBY_VERSION < '9') do
1022
-
1023
- let(:string) { "europäisch" }
1024
- let(:document) do
1025
- described_class["type", string.encode("binary")]
1026
- end
1027
-
1028
- it "encodes and decodes the document properly" do
1028
+ it 'converts the values to utf-8' do
1029
1029
  expect(
1030
1030
  BSON::Document.from_bson(BSON::ByteBuffer.new(document.to_bson.to_s))
1031
1031
  ).to eq({ "type" => string })
1032
1032
  end
1033
1033
  end
1034
1034
 
1035
- context "when binary strings with utf-8 values exist", unless: BSON::Environment.jruby? do
1035
+ context "given a binary string with utf-8 values" do
1036
1036
 
1037
- let(:string) { "europäisch" }
1037
+ let(:string) { "europäisch".force_encoding('binary') }
1038
1038
  let(:document) do
1039
- described_class["type", string.encode("binary", "binary")]
1039
+ described_class["type", string]
1040
1040
  end
1041
1041
 
1042
- it "encodes and decodes the document properly" do
1043
- expect(
1044
- BSON::Document.from_bson(BSON::ByteBuffer.new(document.to_bson.to_s))
1045
- ).to eq({ "type" => string })
1042
+ it "raises encoding error" do
1043
+ expect do
1044
+ document.to_bson
1045
+ end.to raise_error(Encoding::UndefinedConversionError, /from ASCII-8BIT to UTF-8/)
1046
1046
  end
1047
1047
  end
1048
1048
  end
@@ -158,4 +158,69 @@ describe Hash do
158
158
  it_behaves_like "a deserializable bson element"
159
159
  end
160
160
  end
161
+
162
+ describe '#to_bson' do
163
+ context 'when a key is not valid utf-8' do
164
+ let(:key) { Utils.make_byte_string([254, 253, 255]) }
165
+ let(:hash) do
166
+ {key => 'foo'}
167
+ end
168
+
169
+ let(:expected_message) do
170
+ if BSON::Environment.jruby?
171
+ # Uses JRE conversion to another encoding
172
+ /Error serializing key.*Encoding::UndefinedConversionError/
173
+ else
174
+ # Uses our validator
175
+ /Key.*is not valid UTF-8/
176
+ end
177
+ end
178
+
179
+ it 'raises EncodingError' do
180
+ expect do
181
+ hash.to_bson
182
+ end.to raise_error(EncodingError, expected_message)
183
+ end
184
+ end
185
+
186
+ context 'when a key contains null bytes' do
187
+ let(:hash) do
188
+ {"\x00".force_encoding('BINARY') => 'foo'}
189
+ end
190
+
191
+ it 'raises ArgumentError' do
192
+ expect do
193
+ hash.to_bson
194
+ end.to raise_error(ArgumentError, /[Kk]ey.*contains null bytes/)
195
+ end
196
+ end
197
+
198
+ context 'when a value is not valid utf-8' do
199
+ let(:hash) do
200
+ {'foo' => [254, 253, 255].map(&:chr).join.force_encoding('BINARY')}
201
+ end
202
+
203
+ let(:expected_message) do
204
+ /from ASCII-8BIT to UTF-8/
205
+ end
206
+
207
+ it 'raises EncodingError' do
208
+ expect do
209
+ hash.to_bson
210
+ end.to raise_error(EncodingError, expected_message)
211
+ end
212
+ end
213
+
214
+ context 'when a value contains null bytes' do
215
+ let(:hash) do
216
+ {'foo' => "\x00".force_encoding('BINARY')}
217
+ end
218
+
219
+ it 'works' do
220
+ expect do
221
+ hash.to_bson
222
+ end.not_to raise_error
223
+ end
224
+ end
225
+ end
161
226
  end
@@ -25,7 +25,7 @@ describe BSON::Int32 do
25
25
  let(:integer) { Integer::MAX_32BIT }
26
26
 
27
27
  it "wraps the integer" do
28
- expect(obj.instance_variable_get(:@integer)).to be(integer)
28
+ expect(obj.value).to be(integer)
29
29
  end
30
30
  end
31
31
 
@@ -34,9 +34,9 @@ describe BSON::Int32 do
34
34
  let(:integer) { Integer::MAX_32BIT + 1 }
35
35
 
36
36
  it "raises an out of range error" do
37
- expect {
37
+ expect do
38
38
  obj
39
- }.to raise_error(RangeError)
39
+ end.to raise_error(RangeError, /#{integer} cannot be stored in 32 bits/)
40
40
  end
41
41
  end
42
42
 
@@ -50,6 +50,16 @@ describe BSON::Int32 do
50
50
  }.to raise_error(RangeError)
51
51
  end
52
52
  end
53
+
54
+ context 'when argument is an Int32' do
55
+ let(:integer) do
56
+ described_class.new(described_class.new(50))
57
+ end
58
+
59
+ it 'works' do
60
+ expect(integer.value).to be 50
61
+ end
62
+ end
53
63
  end
54
64
 
55
65
  describe "#from_bson" do
@@ -235,4 +245,12 @@ describe BSON::Int32 do
235
245
  end
236
246
  end
237
247
  end
248
+
249
+ describe '#value' do
250
+ let(:obj) { described_class.new(12345) }
251
+
252
+ it 'returns value passed to initializer' do
253
+ expect(obj.value).to eq(12345)
254
+ end
255
+ end
238
256
  end
@@ -25,7 +25,7 @@ describe BSON::Int64 do
25
25
  let(:integer) { Integer::MAX_64BIT - 1 }
26
26
 
27
27
  it "wraps the integer" do
28
- expect(obj.instance_variable_get(:@integer)).to be(integer)
28
+ expect(obj.value).to be(integer)
29
29
  end
30
30
  end
31
31
 
@@ -34,9 +34,9 @@ describe BSON::Int64 do
34
34
  let(:integer) { Integer::MAX_64BIT + 1 }
35
35
 
36
36
  it "raises an out of range error" do
37
- expect {
37
+ expect do
38
38
  obj
39
- }.to raise_error(RangeError)
39
+ end.to raise_error(RangeError, /#{integer} cannot be stored in 64 bits/)
40
40
  end
41
41
  end
42
42
 
@@ -50,6 +50,16 @@ describe BSON::Int64 do
50
50
  }.to raise_error(RangeError)
51
51
  end
52
52
  end
53
+
54
+ context 'when argument is an Int64' do
55
+ let(:integer) do
56
+ described_class.new(described_class.new(50))
57
+ end
58
+
59
+ it 'works' do
60
+ expect(integer.value).to be 50
61
+ end
62
+ end
53
63
  end
54
64
 
55
65
  describe "#from_bson" do
@@ -280,4 +290,13 @@ describe BSON::Int64 do
280
290
  end
281
291
  end
282
292
  end
293
+
294
+ describe '#value' do
295
+ let(:obj) { described_class.new(12345) }
296
+
297
+ it 'returns value passed to initializer' do
298
+ expect(obj.value).to eq(12345)
299
+ end
300
+ end
301
+
283
302
  end
@@ -130,4 +130,22 @@ describe String do
130
130
  end
131
131
  end
132
132
  end
133
+
134
+ describe '#to_bson' do
135
+ context 'when string is not valid utf-8' do
136
+ let(:string) do
137
+ "\xfe\x00\xff".force_encoding('BINARY')
138
+ end
139
+
140
+ let(:expected_message) do
141
+ /from ASCII-8BIT to UTF-8/
142
+ end
143
+
144
+ it 'raises EncodingError' do
145
+ expect do
146
+ string.to_bson
147
+ end.to raise_error(EncodingError, expected_message)
148
+ end
149
+ end
150
+ end
133
151
  end
@@ -14,16 +14,22 @@
14
14
  "extjson": "{\"a\" : [10]}"
15
15
  },
16
16
  {
17
- "description": "Single Element Array with index set incorrectly",
17
+ "description": "Single Element Array with index set incorrectly to empty string",
18
18
  "bson": "130000000461000B00000010000A0000000000",
19
19
  "canonical_bson": "140000000461000C0000001030000A0000000000",
20
20
  "extjson": "{\"a\" : [10]}"
21
21
  },
22
22
  {
23
- "description": "Single Element Array with index set incorrectly",
23
+ "description": "Single Element Array with index set incorrectly to ab",
24
24
  "bson": "150000000461000D000000106162000A0000000000",
25
25
  "canonical_bson": "140000000461000C0000001030000A0000000000",
26
26
  "extjson": "{\"a\" : [10]}"
27
+ },
28
+ {
29
+ "description": "Multi Element Array with duplicate indexes",
30
+ "bson": "1b000000046100130000001030000a000000103000140000000000",
31
+ "canonical_bson": "1b000000046100130000001030000a000000103100140000000000",
32
+ "extjson": "{\"a\" : [10, 20]}"
27
33
  }
28
34
  ],
29
35
  "decodeErrors": [
@@ -18,10 +18,8 @@ shared_examples_for "a binary encoded string" do
18
18
  Encoding.find(BSON::BINARY)
19
19
  end
20
20
 
21
- unless RUBY_VERSION < "1.9"
22
- it "returns the string with binary encoding" do
23
- expect(encoded.encoding).to eq(binary_encoding)
24
- end
21
+ it "returns the string with binary encoding" do
22
+ expect(encoded.encoding).to eq(binary_encoding)
25
23
  end
26
24
  end
27
25
 
@@ -0,0 +1,10 @@
1
+ module Utils
2
+ # JRuby chokes when strings like "\xfe\x00\xff", which are not valid UTF-8,
3
+ # appear in the source. Use this method to build such strings.
4
+ # char_array is an array of byte values to use for the string.
5
+ module_function def make_byte_string(char_array, encoding = 'BINARY')
6
+ char_array.map do |char|
7
+ char.chr.force_encoding('BINARY')
8
+ end.join.force_encoding(encoding)
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.6.0
5
5
  platform: java
6
6
  authors:
7
7
  - Tyler Brock
@@ -33,9 +33,9 @@ cert_chain:
33
33
  bMYVwXXhV8czdzgkQB/ZPWHSbEWXnmkze1mzvqWBCPOVXYrcnL9cnEl/RoxtS1hr
34
34
  Db6Ac6mCUSYfYHBWpWqxjc45n70i5Xi1
35
35
  -----END CERTIFICATE-----
36
- date: 2019-05-23 00:00:00.000000000 Z
36
+ date: 2019-10-30 00:00:00.000000000 Z
37
37
  dependencies: []
38
- description: A full featured BSON specification implementation, in Ruby
38
+ description: A fully featured BSON specification implementation in Ruby
39
39
  email:
40
40
  - mongodb-dev@googlegroups.com
41
41
  executables: []
@@ -90,7 +90,9 @@ files:
90
90
  - spec/bson/array_spec.rb
91
91
  - spec/bson/binary_spec.rb
92
92
  - spec/bson/boolean_spec.rb
93
+ - spec/bson/byte_buffer_read_spec.rb
93
94
  - spec/bson/byte_buffer_spec.rb
95
+ - spec/bson/byte_buffer_write_spec.rb
94
96
  - spec/bson/code_spec.rb
95
97
  - spec/bson/code_with_scope_spec.rb
96
98
  - spec/bson/config_spec.rb
@@ -157,10 +159,17 @@ files:
157
159
  - spec/support/driver-spec-tests/decimal128/decimal128-7.json
158
160
  - spec/support/shared_examples.rb
159
161
  - spec/support/spec_config.rb
160
- homepage: http://bsonspec.org
162
+ - spec/support/utils.rb
163
+ homepage: https://docs.mongodb.com/ruby-driver/current/tutorials/bson-v4/
161
164
  licenses:
162
165
  - Apache-2.0
163
- metadata: {}
166
+ metadata:
167
+ bug_tracker_uri: https://jira.mongodb.org/projects/RUBY
168
+ changelog_uri: https://github.com/mongodb/bson-ruby/releases
169
+ documentation_uri: https://docs.mongodb.com/ruby-driver/current/tutorials/bson-v4/
170
+ homepage_uri: https://docs.mongodb.com/ruby-driver/current/tutorials/bson-v4/
171
+ mailing_list_uri: https://groups.google.com/group/mongodb-user
172
+ source_code_uri: https://github.com/mongodb/bson-ruby
164
173
  post_install_message:
165
174
  rdoc_options: []
166
175
  require_paths:
@@ -169,86 +178,89 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
178
  requirements:
170
179
  - - ">="
171
180
  - !ruby/object:Gem::Version
172
- version: 1.9.3
181
+ version: '2.3'
173
182
  required_rubygems_version: !ruby/object:Gem::Requirement
174
183
  requirements:
175
184
  - - ">="
176
185
  - !ruby/object:Gem::Version
177
186
  version: 1.3.6
178
187
  requirements: []
179
- rubyforge_project: bson
188
+ rubyforge_project:
180
189
  rubygems_version: 2.7.6
181
190
  signing_key:
182
191
  specification_version: 4
183
- summary: Ruby Implementation of the BSON specification
192
+ summary: Ruby implementation of the BSON specification
184
193
  test_files:
185
- - spec/spec_helper.rb
186
194
  - spec/bson_spec.rb
187
- - spec/bson/date_spec.rb
188
- - spec/bson/config_spec.rb
189
- - spec/bson/int64_spec.rb
195
+ - spec/spec_helper.rb
196
+ - spec/bson/min_key_spec.rb
190
197
  - spec/bson/undefined_spec.rb
191
- - spec/bson/corpus_spec.rb
198
+ - spec/bson/regexp_spec.rb
199
+ - spec/bson/decimal128_spec.rb
192
200
  - spec/bson/code_spec.rb
193
- - spec/bson/driver_bson_spec.rb
194
- - spec/bson/object_spec.rb
195
- - spec/bson/date_time_spec.rb
196
- - spec/bson/raw_spec.rb
197
- - spec/bson/min_key_spec.rb
198
- - spec/bson/time_with_zone_spec.rb
199
201
  - spec/bson/time_spec.rb
200
- - spec/bson/hash_spec.rb
201
- - spec/bson/timestamp_spec.rb
202
- - spec/bson/int32_spec.rb
203
- - spec/bson/byte_buffer_spec.rb
204
- - spec/bson/registry_spec.rb
205
- - spec/bson/regexp_spec.rb
206
- - spec/bson/symbol_spec.rb
202
+ - spec/bson/object_spec.rb
203
+ - spec/bson/integer_spec.rb
207
204
  - spec/bson/string_spec.rb
205
+ - spec/bson/byte_buffer_read_spec.rb
206
+ - spec/bson/config_spec.rb
207
+ - spec/bson/json_spec.rb
208
208
  - spec/bson/boolean_spec.rb
209
+ - spec/bson/corpus_spec.rb
210
+ - spec/bson/hash_spec.rb
209
211
  - spec/bson/open_struct_spec.rb
210
- - spec/bson/decimal128_spec.rb
211
- - spec/bson/json_spec.rb
212
+ - spec/bson/nil_class_spec.rb
212
213
  - spec/bson/array_spec.rb
213
214
  - spec/bson/false_class_spec.rb
214
215
  - spec/bson/true_class_spec.rb
215
- - spec/bson/binary_spec.rb
216
- - spec/bson/object_id_spec.rb
217
- - spec/bson/code_with_scope_spec.rb
218
- - spec/bson/nil_class_spec.rb
219
- - spec/bson/integer_spec.rb
220
- - spec/bson/document_spec.rb
216
+ - spec/bson/date_spec.rb
217
+ - spec/bson/byte_buffer_write_spec.rb
218
+ - spec/bson/int64_spec.rb
219
+ - spec/bson/timestamp_spec.rb
221
220
  - spec/bson/max_key_spec.rb
221
+ - spec/bson/raw_spec.rb
222
+ - spec/bson/byte_buffer_spec.rb
223
+ - spec/bson/document_spec.rb
224
+ - spec/bson/code_with_scope_spec.rb
222
225
  - spec/bson/float_spec.rb
223
- - spec/support/corpus.rb
226
+ - spec/bson/time_with_zone_spec.rb
227
+ - spec/bson/binary_spec.rb
228
+ - spec/bson/registry_spec.rb
229
+ - spec/bson/symbol_spec.rb
230
+ - spec/bson/driver_bson_spec.rb
231
+ - spec/bson/date_time_spec.rb
232
+ - spec/bson/object_id_spec.rb
233
+ - spec/bson/int32_spec.rb
234
+ - spec/support/utils.rb
235
+ - spec/support/common_driver.rb
224
236
  - spec/support/shared_examples.rb
225
237
  - spec/support/spec_config.rb
226
- - spec/support/common_driver.rb
238
+ - spec/support/corpus.rb
239
+ - spec/support/corpus-tests/code_w_scope.json
240
+ - spec/support/corpus-tests/code.json
241
+ - spec/support/corpus-tests/oid.json
242
+ - spec/support/corpus-tests/timestamp.json
227
243
  - spec/support/corpus-tests/string.json
228
244
  - spec/support/corpus-tests/null.json
229
245
  - spec/support/corpus-tests/int32.json
230
246
  - spec/support/corpus-tests/maxkey.json
231
- - spec/support/corpus-tests/timestamp.json
232
- - spec/support/corpus-tests/code.json
233
- - spec/support/corpus-tests/document.json
234
- - spec/support/corpus-tests/double.json
247
+ - spec/support/corpus-tests/array.json
235
248
  - spec/support/corpus-tests/regex.json
236
- - spec/support/corpus-tests/oid.json
249
+ - spec/support/corpus-tests/minkey.json
237
250
  - spec/support/corpus-tests/top.json
238
251
  - spec/support/corpus-tests/boolean.json
239
- - spec/support/corpus-tests/array.json
240
- - spec/support/corpus-tests/code_w_scope.json
241
- - spec/support/corpus-tests/minkey.json
252
+ - spec/support/corpus-tests/double.json
253
+ - spec/support/corpus-tests/document.json
254
+ - spec/support/corpus-tests/failures/undefined.json
242
255
  - spec/support/corpus-tests/failures/binary.json
243
- - spec/support/corpus-tests/failures/dbpointer.json
244
256
  - spec/support/corpus-tests/failures/symbol.json
245
- - spec/support/corpus-tests/failures/undefined.json
246
- - spec/support/corpus-tests/failures/datetime.json
247
257
  - spec/support/corpus-tests/failures/int64.json
248
- - spec/support/driver-spec-tests/decimal128/decimal128-4.json
249
- - spec/support/driver-spec-tests/decimal128/decimal128-2.json
250
- - spec/support/driver-spec-tests/decimal128/decimal128-5.json
251
- - spec/support/driver-spec-tests/decimal128/decimal128-3.json
258
+ - spec/support/corpus-tests/failures/dbpointer.json
259
+ - spec/support/corpus-tests/failures/datetime.json
252
260
  - spec/support/driver-spec-tests/decimal128/decimal128-6.json
261
+ - spec/support/driver-spec-tests/decimal128/decimal128-3.json
253
262
  - spec/support/driver-spec-tests/decimal128/decimal128-1.json
263
+ - spec/support/driver-spec-tests/decimal128/decimal128-4.json
254
264
  - spec/support/driver-spec-tests/decimal128/decimal128-7.json
265
+ - spec/support/driver-spec-tests/decimal128/decimal128-5.json
266
+ - spec/support/driver-spec-tests/decimal128/decimal128-2.json