Skip to content

Commit fab5ce1

Browse files
RUBY-3073 RUBY-3077 Fix LMC version check (#2571)
1 parent 6b1c149 commit fab5ce1

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

docs/reference/client-side-encryption.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Queryable Encryption
361361
====================
362362

363363
Queryable encryption is a new feature in MongoDB 6.0. It also requires
364-
libmongocrypt version 1.5.0 or above.
364+
libmongocrypt version 1.5.2 or above.
365365

366366
You can find more information about queryable encryption in `MongoDB Manual
367367
<https://www.mongodb.com/docs/upcoming/core/queryable-encryption/queryable-encryption/>`_

gemfiles/standard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ def standard_dependencies
6060
end
6161

6262
if ENV['FLE'] == 'helper'
63-
gem 'libmongocrypt-helper', '~> 1.5.0'
63+
gem 'libmongocrypt-helper', '~> 1.5.2'
6464
end
6565
end

lib/mongo/crypt/binding.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Binding
8383
# will cause a `LoadError`.
8484
#
8585
# @api private
86-
MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new("1.5.0.alpha")
86+
MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new("1.5.2")
8787

8888
# @!method self.mongocrypt_version(len)
8989
# @api private
@@ -107,6 +107,24 @@ def self.validate_version(lmc_version)
107107
raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " +
108108
"but version #{actual_version} was found."
109109
end
110+
rescue ArgumentError => e
111+
# Some lmc versions cannot be parsed with Gem::Version class,
112+
# so we fall back to regex.
113+
match = lmc_version.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)?(-[A-Za-z\+\d]+)?\z/)
114+
if match.nil?
115+
raise ArgumentError.new("Malformed version number string #{lmc_version}")
116+
end
117+
actual_version = Gem::Version.new(
118+
[
119+
match[:major],
120+
match[:minor],
121+
match[:patch]
122+
].join('.')
123+
)
124+
if actual_version < MIN_LIBMONGOCRYPT_VERSION
125+
raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " +
126+
"but version #{actual_version} was found."
127+
end
110128
end
111129

112130
validate_version(mongocrypt_version(nil))

spec/mongo/crypt/binding/version_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,13 @@
4141
end.not_to raise_error(LoadError, /libmongocrypt version .* or above is required, but version .* was found./)
4242
end
4343
end
44+
45+
context 'when in a non-parsable format' do
46+
it 'does not raise ArgumentError' do
47+
expect do
48+
Mongo::Crypt::Binding.validate_version("1.5.3-dev+20220730git8f8675fa11")
49+
end.not_to raise_error(ArgumentError, /Malformed version number string/)
50+
end
51+
end
4452
end
4553
end

spec/spec_tests/data/client_side_encryption/unified/rewrapManyDataKey.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# commands sort the resulting documents in ascending order by the single-element
33
# keyAltNames array to ensure alphabetic order by original KMS provider as
44
# defined in initialData.
5-
description: rewrapManyDataKey-kms_providers
5+
description: rewrapManyDataKey
66

77
schemaVersion: "1.8"
88

@@ -50,7 +50,7 @@ initialData:
5050
region: us-east-1
5151
- _id: &azure_key_id { $binary: { base64: YXp1cmVhenVyZWF6dXJlYQ==, subType: "04" } }
5252
keyAltNames: ["azure_key"]
53-
keyMaterial: { $binary: { base64: AQICAHhQNmWG2CzOm1dq3kWLM+iDUZhEqnhJwH9wZVpuZ94A8gEGkNTybTc7Eyif0f+qqE0lAAAAwjCBvwYJKoZIhvcNAQcGoIGxMIGuAgEAMIGoBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDB2j78AeuIQxcRh8cQIBEIB7vj9buHEaT7XHFIsKBJiyzZRmNnjvqMK5LSdzonKdx97jlqauvPvTDXSsdQDcspUs5oLrGmAXpbFResscxmbwZoKgUtWiuIOpeAcYuszCiMKt15s1WIMLDXUhYtfCmhRhekvgHnRAaK4HJMlGE+lKJXYI84E0b86Cd/g+, subType: "00" } }
53+
keyMaterial: { $binary: { base64: pr01l7qDygUkFE/0peFwpnNlv3iIy8zrQK38Q9i12UCN2jwZHDmfyx8wokiIKMb9kAleeY+vnt3Cf1MKu9kcDmI+KxbNDd+V3ytAAGzOVLDJr77CiWjF9f8ntkXRHrAY9WwnVDANYkDwXlyU0Y2GQFTiW65jiQhUtYLYH63Tk48SsJuQvnWw1Q+PzY8ga+QeVec8wbcThwtm+r2IHsCFnc72Gv73qq7weISw+O4mN08z3wOp5FOS2ZM3MK7tBGmPdBcktW7F8ODGsOQ1FU53OrWUnyX2aTi2ftFFFMWVHqQo7EYuBZHru8RRODNKMyQk0BFfKovAeTAVRv9WH9QU7g==, subType: "00" } }
5454
creationDate: { $date: { $numberLong: "1641024000000" } }
5555
updateDate: { $date: { $numberLong: "1641024000000" } }
5656
status: 1
@@ -72,7 +72,7 @@ initialData:
7272
keyName: key-name-csfle
7373
- _id: &kmip_key_id { $binary: { base64: a21pcGttaXBrbWlwa21pcA==, subType: "04" } }
7474
keyAltNames: ["kmip_key"]
75-
keyMaterial: { $binary: { base64: VoI9J8HusQ3u2gT9i8Awgg/6W4/igvLwRzn3SRDGx0Dl/1ayDMubphOw0ONPVKfuvS6HL3e4gAoCJ/uEz2KLFTVsEqYCpMhfAhgXxm8Ena8vDcOkCzFX+euvN/N2ES3wpzAD18b3qIH0MbBwKJP82d5GQ4pVfGnPW8Ujp9aO1qC/s0EqNqYyzJ1SyzhV9lAjHHGIENYJx+bBrekg2EeZBA==, subType: "00" } }
75+
keyMaterial: { $binary: { base64: CklVctHzke4mcytd0TxGqvepkdkQN8NUF4+jV7aZQITAKdz6WjdDpq3lMt9nSzWGG2vAEfvRb3mFEVjV57qqGqxjq2751gmiMRHXz0btStbIK3mQ5xbY9kdye4tsixlCryEwQONr96gwlwKKI9Nubl9/8+uRF6tgYjje7Q7OjauEf1SrJwKcoQ3WwnjZmEqAug0kImCpJ/irhdqPzivRiA==, subType: "00" } }
7676
creationDate: { $date: { $numberLong: "1641024000000" } }
7777
updateDate: { $date: { $numberLong: "1641024000000" } }
7878
status: 1

0 commit comments

Comments
 (0)