Skip to content

Commit fa7f0b3

Browse files
RUBY-2832 Fix FLE problems on JRuby
1 parent 8faaee3 commit fa7f0b3

File tree

6 files changed

+196
-71
lines changed

6 files changed

+196
-71
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,7 @@ buildvariants:
12891289
- matrix_name: "fle-4.4"
12901290
matrix_spec:
12911291
auth-and-ssl: "noauth-and-nossl"
1292-
# https://jira.mongodb.org/browse/RUBY-2832
1293-
# ruby: [ruby-3.0, ruby-2.7, jruby-9.2]
1294-
ruby: [ruby-3.0, ruby-2.7]
1292+
ruby: [ruby-3.0, ruby-2.7, jruby-9.2]
12951293
topology: standalone
12961294
mongodb-version: ['4.4']
12971295
os: ubuntu1804

.evergreen/config/standard.yml.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ buildvariants:
437437
- matrix_name: "fle-4.4"
438438
matrix_spec:
439439
auth-and-ssl: "noauth-and-nossl"
440-
# https://jira.mongodb.org/browse/RUBY-2832
441-
# ruby: [ruby-3.0, ruby-2.7, jruby-9.2]
442-
ruby: [ruby-3.0, ruby-2.7]
440+
ruby: [ruby-3.0, ruby-2.7, jruby-9.2]
443441
topology: standalone
444442
mongodb-version: ['4.4']
445443
os: ubuntu1804

lib/mongo/crypt/binding.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,11 @@ def self.kms_ctx_get_kms_provider(kms_context)
798798
if len_ptr.nil?
799799
nil
800800
else
801-
len = len_ptr.read(:uint32)
801+
len = if BSON::Environment.jruby?
802+
len_ptr.get_uint32
803+
else
804+
len_ptr.get(:uint32, 0)
805+
end
802806
provider.read_string(len).to_sym
803807
end
804808
end

spec/integration/client_side_encryption/custom_endpoint_spec.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,28 @@
9393
}
9494
end
9595

96-
it 'throws an exception' do
97-
expect do
98-
data_key_id
99-
end.to raise_error(Mongo::Error::KmsError, /Connection refused/)
96+
context 'MRI' do
97+
require_mri
98+
99+
it 'throws an exception' do
100+
expect do
101+
data_key_id
102+
end.to raise_error(Mongo::Error::KmsError, /Connection refused/)
103+
end
104+
end
105+
106+
context 'JRuby' do
107+
require_jruby
108+
109+
it 'throws an exception' do
110+
expect do
111+
data_key_id
112+
end.to raise_error(Mongo::Error::KmsError)
113+
end
100114
end
101115
end
102116

117+
103118
context 'with region, key, and endpoint with invalid region' do
104119
let(:master_key) do
105120
{

spec/integration/client_side_encryption/kms_tls_options_spec.rb

Lines changed: 133 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -234,37 +234,83 @@
234234
end
235235
end
236236

237-
context 'with no expired server certificate' do
238-
it 'TLS handshake failed' do
239-
expect do
240-
client_encryption_expired.create_data_key(
241-
'aws',
242-
{
243-
master_key: {
244-
region: "us-east-1",
245-
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
246-
endpoint: "127.0.0.1:8000",
247-
}
248-
}
249-
)
250-
end.to raise_error(Mongo::Error::KmsError, /certificate has expired/)
237+
context 'with expired server certificate' do
238+
context "MRI" do
239+
require_mri
240+
241+
it 'TLS handshake failed' do
242+
expect do
243+
client_encryption_expired.create_data_key(
244+
'aws',
245+
{
246+
master_key: {
247+
region: "us-east-1",
248+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
249+
endpoint: "127.0.0.1:8000",
250+
}
251+
}
252+
)
253+
end.to raise_error(Mongo::Error::KmsError, /certificate has expired/)
254+
end
255+
end
256+
257+
context 'JRuby' do
258+
require_jruby
259+
260+
it 'TLS handshake failed' do
261+
expect do
262+
client_encryption_expired.create_data_key(
263+
'aws',
264+
{
265+
master_key: {
266+
region: "us-east-1",
267+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
268+
endpoint: "127.0.0.1:8000",
269+
}
270+
}
271+
)
272+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
273+
end
251274
end
252275
end
253276

254277
context 'with server certificate with invalid hostname' do
255-
it 'TLS handshake failed' do
256-
expect do
257-
client_encryption_invalid_hostname.create_data_key(
258-
'aws',
259-
{
260-
master_key: {
261-
region: "us-east-1",
262-
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
263-
endpoint: "127.0.0.1:8001",
264-
}
265-
}
266-
)
267-
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
278+
context 'MRI' do
279+
require_mri
280+
281+
it 'TLS handshake failed' do
282+
expect do
283+
client_encryption_invalid_hostname.create_data_key(
284+
'aws',
285+
{
286+
master_key: {
287+
region: "us-east-1",
288+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
289+
endpoint: "127.0.0.1:8001",
290+
}
291+
}
292+
)
293+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
294+
end
295+
end
296+
297+
context 'JRuby' do
298+
require_jruby
299+
300+
it 'TLS handshake failed' do
301+
expect do
302+
client_encryption_invalid_hostname.create_data_key(
303+
'aws',
304+
{
305+
master_key: {
306+
region: "us-east-1",
307+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
308+
endpoint: "127.0.0.1:8001",
309+
}
310+
}
311+
)
312+
end.to raise_error(Mongo::Error::KmsError, /TLS handshake failed due to a hostname mismatch/)
313+
end
268314
end
269315
end
270316
end
@@ -296,30 +342,71 @@
296342
end
297343
end
298344

299-
context 'with no expired server certificate' do
300-
it 'TLS handshake failed' do
301-
expect do
302-
client_encryption_expired.create_data_key(
303-
kms_provider,
304-
{
305-
master_key: master_key
306-
}
307-
)
308-
end.to raise_error(Mongo::Error::KmsError, /certificate has expired/)
345+
context 'MRI' do
346+
require_mri
347+
348+
context 'with expired server certificate' do
349+
it 'TLS handshake failed' do
350+
expect do
351+
client_encryption_expired.create_data_key(
352+
kms_provider,
353+
{
354+
master_key: master_key
355+
}
356+
)
357+
end.to raise_error(Mongo::Error::KmsError, /certificate has expired/)
358+
end
359+
end
360+
end
361+
362+
context 'JRuby' do
363+
require_jruby
364+
365+
context 'with expired server certificate' do
366+
it 'TLS handshake failed' do
367+
expect do
368+
client_encryption_expired.create_data_key(
369+
kms_provider,
370+
{
371+
master_key: master_key
372+
}
373+
)
374+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
375+
end
309376
end
310377
end
311378

312379
context 'with server certificate with invalid hostname' do
313-
it 'TLS handshake failed' do
314-
expect do
315-
client_encryption_invalid_hostname.create_data_key(
316-
kms_provider,
317-
{
318-
master_key: master_key
319-
}
320-
)
321-
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
380+
context 'MRI' do
381+
require_mri
382+
383+
it 'TLS handshake failed' do
384+
expect do
385+
client_encryption_invalid_hostname.create_data_key(
386+
kms_provider,
387+
{
388+
master_key: master_key
389+
}
390+
)
391+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
392+
end
393+
end
394+
395+
context 'JRuby' do
396+
require_jruby
397+
398+
it 'TLS handshake failed' do
399+
expect do
400+
client_encryption_invalid_hostname.create_data_key(
401+
kms_provider,
402+
{
403+
master_key: master_key
404+
}
405+
)
406+
end.to raise_error(Mongo::Error::KmsError, /TLS handshake failed due to a hostname mismatch/)
407+
end
322408
end
409+
323410
end
324411
end
325412

spec/integration/client_side_encryption/kms_tls_spec.rb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,47 @@
4444
}
4545
}
4646
)
47-
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed \(certificate has expired\)/)
47+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
4848
end
4949
end
5050

5151
context 'Invalid Hostname in KMS Certificate' do
52-
it 'raises an error when creating data key' do
53-
expect do
54-
client_encryption.create_data_key(
55-
'aws',
56-
{
57-
master_key: {
58-
region: "us-east-1",
59-
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
60-
endpoint: "127.0.0.1:8001",
61-
}
62-
}
63-
)
64-
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
52+
context 'MRI' do
53+
require_mri
54+
55+
it 'raises an error when creating data key' do
56+
expect do
57+
client_encryption.create_data_key(
58+
'aws',
59+
{
60+
master_key: {
61+
region: "us-east-1",
62+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
63+
endpoint: "127.0.0.1:8001",
64+
}
65+
}
66+
)
67+
end.to raise_error(Mongo::Error::KmsError, /certificate verify failed/)
68+
end
69+
end
70+
71+
context 'JRuby' do
72+
require_jruby
73+
74+
it 'raises an error when creating data key' do
75+
expect do
76+
client_encryption.create_data_key(
77+
'aws',
78+
{
79+
master_key: {
80+
region: "us-east-1",
81+
key: "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
82+
endpoint: "127.0.0.1:8001",
83+
}
84+
}
85+
)
86+
end.to raise_error(Mongo::Error::KmsError, /hostname mismatch/)
87+
end
6588
end
6689
end
6790

0 commit comments

Comments
 (0)