Skip to content

Commit

Permalink
Add prose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
comandeo-mongo committed Aug 20, 2024
1 parent da0583c commit 43ab836
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mongo/crypt/explicit_encryption_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ def set_algorithm_opts(options)

def convert_range_opts(range_opts)
range_opts.dup.tap do |opts|
opts[:sparsity] = BSON::Int64.new(opts[:sparsity]) unless opts[:sparsity].is_a?(BSON::Int64)
if opts[:sparsity] && !opts[:sparsity].is_a?(BSON::Int64)
opts[:sparsity] = BSON::Int64.new(opts[:sparsity])
end
if opts[:trim_factor]
opts[:trimFactor] = opts.delete(:trim_factor)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,51 @@

include_examples 'common cases'
end

describe 'Range Explicit Encryption applies defaults' do
let(:payload_defaults) do
client_encryption.encrypt(
123,
key_id: key1_id,
algorithm: 'Range',
contention_factor: 0,
range_opts: {
min: 0,
max: 1000
}
)
end

it 'uses libmongocrypt default' do
payload = client_encryption.encrypt(
123,
key_id: key1_id,
algorithm: 'Range',
contention_factor: 0,
range_opts: {
min: 0,
max: 1000,
sparsity: 2,
trim_factor: 6
}
)
expect(payload.to_s.size).to eq(payload_defaults.to_s.size)
end

it 'accepts trim_factor 0' do
payload = client_encryption.encrypt(
123,
key_id: key1_id,
algorithm: 'Range',
contention_factor: 0,
range_opts: {
min: 0,
max: 1000,
trim_factor: 0
}
)
expect(payload.to_s.size).to eq(payload_defaults.to_s.size)
end
end
end
# rubocop:enable RSpec/ExampleLength

0 comments on commit 43ab836

Please sign in to comment.