Skip to content

Commit 0b6704a

Browse files
wip
1 parent 19a11e7 commit 0b6704a

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

lib/mongo/crypt/auto_encrypter.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,6 @@ def set_default_options(options)
245245
extra_options = opts.delete(:extra_options) || Options::Redacted.new
246246
extra_options = DEFAULT_EXTRA_OPTIONS.merge(extra_options)
247247

248-
# When no explicit crypt_shared_lib_path is provided and the caller has
249-
# not opted out of crypt_shared entirely, fall back to the environment
250-
# variable. This ensures every Handle in the same process uses the same
251-
# explicit-path load mechanism, preventing the "An existing crypt_shared
252-
# library is loaded" conflict on macOS when multiple Handle instances are
253-
# created after a prior path-override load.
254-
if extra_options[:crypt_shared_lib_path].nil? && !extra_options[:disable_crypt_shared_lib_search]
255-
env_path = ENV['MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH']
256-
extra_options[:crypt_shared_lib_path] = env_path if env_path
257-
end
258248

259249
has_timeout_string_arg = extra_options[:mongocryptd_spawn_args].any? do |elem|
260250
elem.is_a?(String) && elem.match(/\A--idleShutdownTimeoutSecs=\d+\z/)

spec/integration/client_side_encryption/auto_encryption_mongocryptd_spawn_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
schema_map: { 'auto_encryption.users' => schema_map },
2222
extra_options: {
2323
mongocryptd_spawn_path: 'echo hello world',
24-
mongocryptd_spawn_args: []
24+
mongocryptd_spawn_args: [],
25+
# Suppress $SYSTEM crypt_shared search to avoid "existing library"
26+
# conflicts on macOS when another spec in the same process has
27+
# already loaded crypt_shared via an explicit path override.
28+
disable_crypt_shared_lib_search: true,
2529
}
2630
},
2731
database: 'auto_encryption'

spec/integration/client_side_encryption/bypass_mongocryptd_spawn_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
mongocryptd_bypass_spawn: true,
3232
mongocryptd_uri: "mongodb://localhost:#{mongocryptd_port}/db?serverSelectionTimeoutMS=1000",
3333
mongocryptd_spawn_args: [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=#{mongocryptd_port}"],
34+
disable_crypt_shared_lib_search: true,
3435
},
3536
},
3637
database: 'db'
@@ -56,6 +57,7 @@
5657
bypass_auto_encryption: true,
5758
extra_options: {
5859
mongocryptd_spawn_args: [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=#{mongocryptd_port}"],
60+
disable_crypt_shared_lib_search: true,
5961
},
6062
},
6163
database: 'db'

spec/integration/client_side_encryption/data_key_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@
171171

172172
expect do
173173
client_encrypted['coll'].insert_one(encrypted_placeholder: encrypted)
174-
end.to raise_error(Mongo::Error::OperationFailure, /Cannot encrypt element of type(: encrypted binary data| binData)/)
174+
# With mongocryptd the error comes back as OperationFailure from the
175+
# markForEncryption command response; with crypt_shared it is raised
176+
# directly by libmongocrypt as a CryptError. Both are Mongo::Error subclasses.
177+
end.to raise_error(Mongo::Error, /Cannot encrypt element of type(: encrypted binary data| binData)/)
175178
end
176179
end
177180

spec/mongo/client_construction_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,20 @@
317317

318318
context 'with default extra options' do
319319
let(:auto_encryption_options) do
320-
{
320+
opts = {
321321
key_vault_namespace: key_vault_namespace,
322322
kms_providers: kms_providers,
323323
schema_map: schema_map,
324324
}
325+
# When the env var is set, pass the explicit crypt_shared path so
326+
# that Handle in this process uses the same load mechanism as any
327+
# prior Handle, avoiding the "existing library" conflict on macOS.
328+
# The test assertions only check mongocryptd default values, so this
329+
# does not affect what is being verified.
330+
if (path = SpecConfig.instance.crypt_shared_lib_path)
331+
opts[:extra_options] = { crypt_shared_lib_path: path }
332+
end
333+
opts
325334
end
326335

327336
it 'sets key_vault_client with no encryption options' do

0 commit comments

Comments
 (0)