Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mongo/client_encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/crypt/binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/mongo/crypt/explicit_encryption_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions spec/mongo/client_encryption_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} } }

Expand Down
51 changes: 51 additions & 0 deletions spec/mongo/crypt/explicit_encryption_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading