diff --git a/lib/mongo/client_encryption.rb b/lib/mongo/client_encryption.rb index ac9cb8c541..f9d4039b54 100644 --- a/lib/mongo/client_encryption.rb +++ b/lib/mongo/client_encryption.rb @@ -50,7 +50,8 @@ def initialize(key_vault_client, options = {}) key_vault_client, options[:key_vault_namespace], Crypt::KMS::Credentials.new(options[:kms_providers]), - Crypt::KMS::Validations.validate_tls_options(options[:kms_tls_options]) + Crypt::KMS::Validations.validate_tls_options(options[:kms_tls_options]), + options[:timeout_ms] ) end diff --git a/lib/mongo/crypt/binding.rb b/lib/mongo/crypt/binding.rb index 38276e56d2..1e6b224f1f 100644 --- a/lib/mongo/crypt/binding.rb +++ b/lib/mongo/crypt/binding.rb @@ -81,7 +81,7 @@ class Binding # will cause a `LoadError`. # # @api private - MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new('1.12.0') + MIN_LIBMONGOCRYPT_VERSION = Gem::Version.new('1.20.0') # @!method self.mongocrypt_version(len) # @api private diff --git a/lib/mongo/crypt/explicit_encryption_context.rb b/lib/mongo/crypt/explicit_encryption_context.rb index d835495a79..ee025ae2ea 100644 --- a/lib/mongo/crypt/explicit_encryption_context.rb +++ b/lib/mongo/crypt/explicit_encryption_context.rb @@ -148,6 +148,8 @@ def set_algorithm_opts(options) end def convert_range_opts(range_opts) + raise ArgumentError.new(':range_opts is required for the "Range" algorithm') if range_opts.nil? + range_opts.dup.tap do |opts| opts[:sparsity] = BSON::Int64.new(opts[:sparsity]) if opts[:sparsity] && !opts[:sparsity].is_a?(BSON::Int64) opts[:trimFactor] = opts.delete(:trim_factor) if opts[:trim_factor] diff --git a/spec/mongo/client_encryption_spec.rb b/spec/mongo/client_encryption_spec.rb index 5484658d01..1f9438db58 100644 --- a/spec/mongo/client_encryption_spec.rb +++ b/spec/mongo/client_encryption_spec.rb @@ -61,6 +61,20 @@ it_behaves_like 'a functioning ClientEncryption' end + context 'with timeout_ms' do + include_context 'with local kms_providers' + + it 'passes the timeout to the encrypter' do + client_encryption = described_class.new(client, { + key_vault_namespace: key_vault_namespace, + kms_providers: kms_providers, + timeout_ms: 5_000 + }) + encrypter = client_encryption.instance_variable_get(:@encrypter) + expect(encrypter.instance_variable_get(:@timeout_ms)).to eq(5_000) + end + end + context 'with invalid KMS provider information' do let(:kms_providers) { { random_key: {} } } diff --git a/spec/mongo/crypt/explicit_encryption_context_spec.rb b/spec/mongo/crypt/explicit_encryption_context_spec.rb index bd21641c87..7147d3b78d 100644 --- a/spec/mongo/crypt/explicit_encryption_context_spec.rb +++ b/spec/mongo/crypt/explicit_encryption_context_spec.rb @@ -204,6 +204,57 @@ end end + context 'with Range algorithm' do + let(:algorithm) { 'Range' } + let(:key_alt_name) { nil } + let(:value) { { v: 123 } } + + let(:range_opts) do + { min: 0, max: 200, sparsity: 1, trim_factor: 1 } + end + + it 'initializes context' do + expect do + described_class.new( + mongocrypt, + io, + value, + options.merge(contention_factor: 0, range_opts: range_opts) + ) + end.not_to raise_error + end + + context 'with trim_factor of 0' do + let(:range_opts) do + { min: 0, max: 200, sparsity: 1, trim_factor: 0 } + end + + it 'passes the trim factor through' do + expect do + described_class.new( + mongocrypt, + io, + value, + options.merge(contention_factor: 0, range_opts: range_opts) + ) + end.not_to raise_error + end + end + + context 'without range_opts' do + it 'raises an exception' do + expect do + described_class.new( + mongocrypt, + io, + value, + options.merge(contention_factor: 0) + ) + end.to raise_error(ArgumentError, /:range_opts is required for the "Range" algorithm/) + end + end + end + context 'with String algorithm' do let(:algorithm) { 'String' } let(:key_alt_name) { nil }