Skip to content

Commit 30bcf22

Browse files
authored
RUBY-3154 Test crypt_shared with older server versions (#2705)
* RUBY-3154 run all encryption tests against both mongocryptd and crypt_shared * allow fork_reconnect_spec to run on a mac * let's try disabling these tests on jruby... * no need to overcomplicate the without_crypt_shared_lib_path helper * lock older server versions to recent crypt_shared
1 parent aa0813e commit 30bcf22

File tree

9 files changed

+89
-18
lines changed

9 files changed

+89
-18
lines changed

.evergreen/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ functions:
106106
export COMPRESSOR=${COMPRESSOR}
107107
export RVM_RUBY="${RVM_RUBY}"
108108
export MONGODB_VERSION=${MONGODB_VERSION}
109+
export CRYPT_SHARED_VERSION=${CRYPT_SHARED_VERSION}
109110
export FCV=${FCV}
110111
export MONGO_RUBY_DRIVER_LINT=${LINT}
111112
export RETRY_READS=${RETRY_READS}
@@ -616,18 +617,22 @@ axes:
616617
display_name: "5.3"
617618
variables:
618619
MONGODB_VERSION: "5.3"
620+
CRYPT_SHARED_VERSION: "6.0.5"
619621
- id: "5.0"
620622
display_name: "5.0"
621623
variables:
622624
MONGODB_VERSION: "5.0"
625+
CRYPT_SHARED_VERSION: "6.0.5"
623626
- id: "4.4"
624627
display_name: "4.4"
625628
variables:
626629
MONGODB_VERSION: "4.4"
630+
CRYPT_SHARED_VERSION: "6.0.5"
627631
- id: "4.2"
628632
display_name: "4.2"
629633
variables:
630634
MONGODB_VERSION: "4.2"
635+
CRYPT_SHARED_VERSION: "6.0.5"
631636
- id: "4.0"
632637
display_name: "4.0"
633638
variables:

.evergreen/config/axes.yml.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ axes:
2525
display_name: "5.3"
2626
variables:
2727
MONGODB_VERSION: "5.3"
28+
CRYPT_SHARED_VERSION: "6.0.5"
2829
- id: "5.0"
2930
display_name: "5.0"
3031
variables:
3132
MONGODB_VERSION: "5.0"
33+
CRYPT_SHARED_VERSION: "6.0.5"
3234
- id: "4.4"
3335
display_name: "4.4"
3436
variables:
3537
MONGODB_VERSION: "4.4"
38+
CRYPT_SHARED_VERSION: "6.0.5"
3639
- id: "4.2"
3740
display_name: "4.2"
3841
variables:
3942
MONGODB_VERSION: "4.2"
43+
CRYPT_SHARED_VERSION: "6.0.5"
4044
- id: "4.0"
4145
display_name: "4.0"
4246
variables:

.evergreen/config/common.yml.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ functions:
104104
export COMPRESSOR=${COMPRESSOR}
105105
export RVM_RUBY="${RVM_RUBY}"
106106
export MONGODB_VERSION=${MONGODB_VERSION}
107+
export CRYPT_SHARED_VERSION=${CRYPT_SHARED_VERSION}
107108
export FCV=${FCV}
108109
export MONGO_RUBY_DRIVER_LINT=${LINT}
109110
export RETRY_READS=${RETRY_READS}

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fi
165165
if test -n "$FLE"; then
166166
# Downloading crypt shared lib
167167
if [ -z "$MONGO_CRYPT_SHARED_DOWNLOAD_URL" ]; then
168-
crypt_shared_version=$("${BINDIR}"/mongod --version | grep -oP 'db version v\K.*')
168+
crypt_shared_version=${CRYPT_SHARED_VERSION:-$("${BINDIR}"/mongod --version | grep -oP 'db version v\K.*')}
169169
python3 -u .evergreen/mongodl.py --component crypt_shared -V ${crypt_shared_version} --out $(pwd)/csfle_lib --target $(host_distro) || true
170170
if test -f $(pwd)/csfle_lib/lib/mongo_crypt_v1.so
171171
then

spec/integration/fork_reconnect_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
child_socket.object_id.should_not == socket.object_id
4343

4444
# Exec so that we do not close any clients etc. in the child.
45-
exec('/bin/true')
45+
exec(Utils::BIN_TRUE)
4646
end
4747

4848
# Connection should remain serviceable in the parent.

spec/spec_tests/client_side_encryption_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,21 @@
1010
require_libmongocrypt
1111
require_enterprise
1212

13-
define_transactions_spec_tests(CLIENT_SIDE_ENCRYPTION_TESTS, expectations_bson_types: true)
13+
context 'with mongocryptd' do
14+
SpecConfig.instance.without_crypt_shared_lib_path do
15+
define_transactions_spec_tests(CLIENT_SIDE_ENCRYPTION_TESTS, expectations_bson_types: true)
16+
end
17+
end
18+
19+
context 'with crypt_shared' do
20+
# Under JRuby+Evergreen, these specs complain about the crypt_shared
21+
# library not loading; however, crypt_shared appears to load for other
22+
# specs that require it (see the client_side_encryption_unified_spec and
23+
# mongocryptd_prose_spec tests).
24+
fails_on_jruby
25+
26+
SpecConfig.instance.require_crypt_shared do
27+
define_transactions_spec_tests(CLIENT_SIDE_ENCRYPTION_TESTS, expectations_bson_types: true)
28+
end
29+
end
1430
end

spec/spec_tests/client_side_encryption_unified_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,15 @@
1212
require_libmongocrypt
1313
require_enterprise
1414

15-
define_unified_spec_tests(base, CLIENT_SIDE_ENCRYPTION_UNIFIED_TESTS)
15+
context 'with mongocryptd' do
16+
SpecConfig.instance.without_crypt_shared_lib_path do
17+
define_unified_spec_tests(base, CLIENT_SIDE_ENCRYPTION_UNIFIED_TESTS)
18+
end
19+
end
20+
21+
context 'with crypt_shared' do
22+
SpecConfig.instance.require_crypt_shared do
23+
define_unified_spec_tests(base, CLIENT_SIDE_ENCRYPTION_UNIFIED_TESTS)
24+
end
25+
end
1626
end

spec/support/spec_config.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,27 @@ def mongocryptd_port
489489
end
490490

491491
def crypt_shared_lib_path
492-
ENV['MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH']
492+
if @without_crypt_shared_lib_path
493+
nil
494+
else
495+
ENV['MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH']
496+
end
497+
end
498+
499+
def without_crypt_shared_lib_path
500+
saved, @without_crypt_shared_lib_path = @without_crypt_shared_lib_path, true
501+
yield
502+
ensure
503+
@without_crypt_shared_lib_path = saved
504+
end
505+
506+
attr_accessor :crypt_shared_lib_required
507+
508+
def require_crypt_shared
509+
saved, self.crypt_shared_lib_required = crypt_shared_lib_required, true
510+
yield
511+
ensure
512+
self.crypt_shared_lib_required = saved
493513
end
494514

495515
def auth?

spec/support/utils.rb

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,8 @@ def convert_client_options(spec_test_options)
138138
mapper = Mongo::URI::OptionsMapper.new
139139
spec_test_options.reduce({}) do |opts, (name, value)|
140140
if name == 'autoEncryptOpts'
141-
opts.merge!(
142-
auto_encryption_options: convert_auto_encryption_client_options(value)
143-
.merge(
144-
# Spawn mongocryptd on non-default port for sharded cluster tests
145-
extra_options: {
146-
mongocryptd_spawn_args: ["--port=#{SpecConfig.instance.mongocryptd_port}"],
147-
mongocryptd_uri: "mongodb://localhost:#{SpecConfig.instance.mongocryptd_port}",
148-
}
149-
)
150-
)
141+
auto_encryption_options = convert_auto_encryption_client_options(value)
142+
opts.merge!(auto_encryption_options: auto_encryption_options)
151143
else
152144
mapper.add_uri_option(name, value.to_s, opts)
153145
end
@@ -206,10 +198,30 @@ def convert_client_options(spec_test_options)
206198
auto_encrypt_opts[:encrypted_fields_map] = BSON::ExtJSON.parse_obj(opts['encryptedFieldsMap'])
207199
end
208200

209-
auto_encrypt_opts
201+
auto_encrypt_opts.merge!(extra_options: convert_auto_encryption_extra_options(auto_encrypt_opts))
210202
end
211203
module_function :convert_auto_encryption_client_options
212204

205+
private def convert_auto_encryption_extra_options(opts)
206+
# Spawn mongocryptd on non-default port for sharded cluster tests
207+
extra_options = {
208+
mongocryptd_spawn_args: [ "--port=#{SpecConfig.instance.mongocryptd_port}" ],
209+
mongocryptd_uri: "mongodb://localhost:#{SpecConfig.instance.mongocryptd_port}"
210+
}.merge(opts[:extra_options] || {})
211+
212+
# if bypass_query_analysis has been explicitly specified, then we ignore
213+
# any requirement to use the shared library, as the two are not
214+
# compatible.
215+
if SpecConfig.instance.crypt_shared_lib_required && !opts[:bypass_query_analysis]
216+
extra_options[:crypt_shared_lib_required] = SpecConfig.instance.crypt_shared_lib_required
217+
extra_options[:crypt_shared_lib_path] = SpecConfig.instance.crypt_shared_lib_path
218+
extra_options[:mongocryptd_uri] = "mongodb://localhost:27777"
219+
end
220+
221+
extra_options
222+
end
223+
module_function :convert_auto_encryption_extra_options
224+
213225
def order_hash(hash)
214226
Hash[hash.to_a.sort]
215227
end
@@ -539,15 +551,18 @@ def match_with_type?(expected, actual)
539551
end
540552
end
541553

554+
BIN_FALSE = File.executable?("/bin/false") ? "/bin/false" : "false"
555+
BIN_TRUE = File.executable?("/bin/true") ? "/bin/true" : "true"
556+
542557
module_function def wrap_forked_child
543558
begin
544559
yield
545560
rescue => e
546561
STDERR.puts "Failing process #{Process.pid} due to #{e.class}: #{e}"
547-
exec('/bin/false')
562+
exec(BIN_FALSE)
548563
else
549564
# Exec so that we do not close any clients etc. in the child.
550-
exec('/bin/true')
565+
exec(BIN_TRUE)
551566
end
552567
end
553568

0 commit comments

Comments
 (0)