Skip to content

Commit c1835c7

Browse files
RUBY-3262 enable QEv2 tests on Serverless (#2731)
* RUBY-3262 enable QEv2 tests on Serverless * also address RUBY-3270 this is just removing a bandaid I added a few weeks ago to work around this very issue * add CSE specs to serverless also some incidental cleanup of the version parsing code, which turned out to be unnecessary * bump spec/shared for better version parsing * Check wire version on connection --------- Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent bc9da14 commit c1835c7

File tree

65 files changed

+223
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+223
-243
lines changed

.evergreen/run-tests-serverless.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ cd -
7676
echo "Running specs"
7777

7878
bundle exec rspec \
79+
spec/spec_tests/client_side_encryption_spec.rb \
7980
spec/spec_tests/crud_spec.rb \
8081
spec/spec_tests/retryable_reads_spec.rb \
8182
spec/spec_tests/retryable_writes_spec.rb \
@@ -91,9 +92,6 @@ bundle exec rspec \
9192
spec/spec_tests/sessions_unified_spec.rb \
9293
spec/spec_tests/transactions_unified_spec.rb
9394

94-
# https://jira.mongodb.org/browse/RUBY-3249
95-
# Add when fixed: spec/spec_tests/client_side_encryption_spec.rb \
96-
9795
kill_jruby
9896
# Terminate all kmip servers... and whatever else happens to be running
9997
# that is a python script.

lib/mongo/collection/queryable_encryption.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ def maybe_create_qe_collections(encrypted_fields, client, session)
3636
encrypted_fields = encrypted_fields_from(encrypted_fields)
3737
return yield if encrypted_fields.empty?
3838

39-
check_wire_version!
40-
41-
emm_collections(encrypted_fields).each do |coll|
42-
context = Operation::Context.new(client: client, session: session)
43-
create_operation_for(coll)
44-
.execute(next_primary(nil, session), context: context)
39+
server = next_primary(nil, session)
40+
context = Operation::Context.new(client: client, session: session)
41+
server.with_connection do |connection|
42+
check_wire_version!(connection)
43+
emm_collections(encrypted_fields).each do |coll|
44+
create_operation_for(coll)
45+
.execute_with_connection(connection, context: context)
46+
end
4547
end
4648

4749
yield(encrypted_fields).tap do |result|
@@ -99,10 +101,13 @@ def emm_collections(encrypted_fields)
99101
# Creating encrypted collections is only supported on 7.0.0 and later
100102
# (wire version 21+).
101103
#
104+
# @param [ Mongo::Connection ] connection The connection to check
105+
# the wire version of.
106+
#
102107
# @raise [ Mongo::Error ] if the wire version is not
103108
# recent enough
104-
def check_wire_version!
105-
return unless next_primary.max_wire_version < QE2_MIN_WIRE_VERSION
109+
def check_wire_version!(connection)
110+
return unless connection.description.max_wire_version < QE2_MIN_WIRE_VERSION
106111

107112
raise Mongo::Error,
108113
'Driver support of Queryable Encryption is incompatible with server. ' \

lib/mongo/crypt/binding.rb

+26-18
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,42 @@ class Binding
9494
# @return [ String ] A version string for libmongocrypt.
9595
attach_function :mongocrypt_version, [:pointer], :string
9696

97-
# Validates if provided version of libmongocrypt is valid, i.e. equal or
98-
# greater than minimum required version. Raises a LoadError if not.
97+
# Given a string representing a version number, parses it into a
98+
# Gem::Version object. This handles the case where the string is not
99+
# in a format supported by Gem::Version by doing some custom parsing.
99100
#
100-
# @param [ String ] lmc_version String representing libmongocrypt version.
101+
# @param [ String ] version String representing a version number.
101102
#
102-
# @raise [ LoadError ] if given version is lesser than minimum required version.
103+
# @return [ Gem::Version ] the version number
104+
#
105+
# @raise [ ArgumentError ] if the string cannot be parsed.
103106
#
104107
# @api private
105-
def self.validate_version(lmc_version)
106-
if (actual_version = Gem::Version.new(lmc_version)) < MIN_LIBMONGOCRYPT_VERSION
107-
raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " +
108-
"but version #{actual_version} was found."
109-
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(
108+
def self.parse_version(version)
109+
Gem::Version.new(version)
110+
rescue ArgumentError
111+
match = version.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)?(-[A-Za-z\+\d]+)?\z/)
112+
raise ArgumentError.new("Malformed version number string #{version}") if match.nil?
113+
114+
Gem::Version.new(
118115
[
119116
match[:major],
120117
match[:minor],
121118
match[:patch]
122119
].join('.')
123120
)
124-
if actual_version < MIN_LIBMONGOCRYPT_VERSION
121+
end
122+
123+
# Validates if provided version of libmongocrypt is valid, i.e. equal or
124+
# greater than minimum required version. Raises a LoadError if not.
125+
#
126+
# @param [ String ] lmc_version String representing libmongocrypt version.
127+
#
128+
# @raise [ LoadError ] if given version is lesser than minimum required version.
129+
#
130+
# @api private
131+
def self.validate_version(lmc_version)
132+
if (actual_version = parse_version(lmc_version)) < MIN_LIBMONGOCRYPT_VERSION
125133
raise LoadError, "libmongocrypt version #{MIN_LIBMONGOCRYPT_VERSION} or above is required, " +
126134
"but version #{actual_version} was found."
127135
end

spec/mongo/crypt/binding/version_spec.rb

+18-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,24 @@
4343
end
4444

4545
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/)
46+
let(:base_version) { Mongo::Crypt::Binding::MIN_LIBMONGOCRYPT_VERSION.to_s }
47+
48+
shared_examples_for 'non-standard version format' do
49+
it 'does not raise an exception' do
50+
expect do
51+
Mongo::Crypt::Binding.validate_version(version)
52+
end.not_to raise_error
53+
end
54+
end
55+
56+
context 'when the version is MAJOR.MINOR.PATH-dev+datecommit' do
57+
let(:version) { "#{base_version}-dev+20220730git8f8675fa11" }
58+
include_examples 'non-standard version format'
59+
end
60+
61+
context 'when the version is MAJOR.MINOR.PATH-date+commit' do
62+
let(:version) { "#{base_version}-20230601+git9b07846bef" }
63+
include_examples 'non-standard version format'
5064
end
5165
end
5266
end

spec/spec_tests/data/client_side_encryption/fle2v2-BypassQueryAnalysis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Compact.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-CreateCollection-OldServer.yml

+22
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,25 @@ tests:
3737
collection: "encryptedCollection"
3838
result:
3939
errorContains: "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
40+
# Assert no collections were created.
41+
- name: assertCollectionNotExists
42+
object: testRunner
43+
arguments:
44+
database: *database_name
45+
collection: &esc_collection_name "enxcol_.encryptedCollection.esc"
46+
# ecc collection is no longer created for QEv2
47+
- name: assertCollectionNotExists
48+
object: testRunner
49+
arguments:
50+
database: *database_name
51+
collection: &ecc_collection_name "enxcol_.encryptedCollection.ecc"
52+
- name: assertCollectionNotExists
53+
object: testRunner
54+
arguments:
55+
database: *database_name
56+
collection: &ecoc_collection_name "enxcol_.encryptedCollection.ecoc"
57+
- name: assertCollectionNotExists
58+
object: testRunner
59+
arguments:
60+
database: *database_name
61+
collection: encryptedCollection

spec/spec_tests/data/client_side_encryption/fle2v2-CreateCollection.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]
@@ -101,10 +100,6 @@ tests:
101100
command:
102101
create: *encrypted_collection_name
103102
encryptedFields: &encrypted_fields_expectation {
104-
# Expect state collections are not included in the encryptedFields sent to the server.
105-
"escCollection": null,
106-
"ecocCollection": null,
107-
"eccCollection": null,
108103
"fields": [
109104
{
110105
"path": "firstName",
@@ -939,4 +934,4 @@ tests:
939934
collection: *encrypted_collection_name
940935
result:
941936
# Expect error due to server constraints added in SERVER-74069
942-
errorContains: "Encrypted State Collection name should follow"
937+
errorContains: "Encrypted State Collection name should follow"

spec/spec_tests/data/client_side_encryption/fle2v2-DecryptExistingData.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Delete.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFields-vs-EncryptedFieldsMap.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFields-vs-jsonSchema.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-EncryptedFieldsMap-defaults.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-FindOneAndUpdate.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-InsertFind-Indexed.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-InsertFind-Unindexed.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-MissingKey.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-NoEncryption.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requires libmongocrypt 1.8.0.
22
runOn:
33
- minServerVersion: "7.0.0"
4-
serverless: "forbid"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Aggregate.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Requires libmongocrypt 1.8.0.
33
runOn:
44
- minServerVersion: "7.0.0"
5-
serverless: "forbid"
65
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
76
# FLE 2 Encrypted collections are not supported on standalone.
87
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Correctness.yml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Requires libmongocrypt 1.8.0.
55
runOn:
66
- minServerVersion: "7.0.0"
7-
serverless: "forbid"
87
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
98
# FLE 2 Encrypted collections are not supported on standalone.
109
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Delete.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Requires libmongocrypt 1.8.0.
33
runOn:
44
- minServerVersion: "7.0.0"
5-
serverless: "forbid"
65
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
76
# FLE 2 Encrypted collections are not supported on standalone.
87
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-FindOneAndUpdate.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Requires libmongocrypt 1.8.0.
33
runOn:
44
- minServerVersion: "7.0.0"
5-
serverless: "forbid"
65
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
76
# FLE 2 Encrypted collections are not supported on standalone.
87
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-InsertFind.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Requires libmongocrypt 1.8.0.
33
runOn:
44
- minServerVersion: "7.0.0"
5-
serverless: "forbid"
65
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
76
# FLE 2 Encrypted collections are not supported on standalone.
87
topology: [ "replicaset", "sharded", "load-balanced" ]

spec/spec_tests/data/client_side_encryption/fle2v2-Range-Date-Update.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Requires libmongocrypt 1.8.0.
33
runOn:
44
- minServerVersion: "7.0.0"
5-
serverless: "forbid"
65
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
76
# FLE 2 Encrypted collections are not supported on standalone.
87
topology: [ "replicaset", "sharded", "load-balanced" ]

0 commit comments

Comments
 (0)