forked from mongodb/mongo-ruby-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_encryption_mongocryptd_spawn_spec.rb
More file actions
78 lines (68 loc) · 2.63 KB
/
auto_encryption_mongocryptd_spawn_spec.rb
File metadata and controls
78 lines (68 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'Auto Encryption' do
require_libmongocrypt
require_enterprise
include_context 'define shared FLE helpers'
include_context 'with local kms_providers'
context 'with an invalid mongocryptd spawn path' do
let(:client) do
new_local_client(
SpecConfig.instance.addresses,
SpecConfig.instance.test_options.merge(
auto_encryption_options: {
kms_providers: kms_providers,
key_vault_namespace: key_vault_namespace,
schema_map: { 'auto_encryption.users' => schema_map },
extra_options: {
mongocryptd_spawn_path: 'echo hello world',
mongocryptd_spawn_args: [],
# Suppress $SYSTEM crypt_shared search to avoid "existing library"
# conflicts on macOS when another spec in the same process has
# already loaded crypt_shared via an explicit path override.
disable_crypt_shared_lib_search: true,
}
},
database: 'auto_encryption'
),
)
end
let(:server_selector) { double("ServerSelector") }
let(:cluster) { double("Cluster") }
before do
key_vault_collection.drop
key_vault_collection.insert_one(data_key)
allow(server_selector).to receive(:name)
allow(server_selector).to receive(:server_selection_timeout)
allow(server_selector).to receive(:local_threshold)
allow(cluster).to receive(:summary)
# Raise a server selection error on intent-to-encrypt commands to mock
# what would happen if mongocryptd hadn't already been spawned. It is
# necessary to mock this behavior because it is likely that another test
# will have already spawned mongocryptd, causing this test to fail.
allow_any_instance_of(Mongo::Database)
.to receive(:command)
.with(
hash_including(
'insert' => 'users',
'ordered' => true,
'lsid' => kind_of(Hash),
'documents' => kind_of(Array),
'jsonSchema' => kind_of(Hash),
'isRemoteSchema' => false,
),
{ execution_options: { deserialize_as_bson: true }, timeout_ms: nil },
)
.and_raise(Mongo::Error::NoServerAvailable.new(server_selector, cluster))
end
it 'raises an exception when trying to perform auto encryption' do
expect do
client['users'].insert_one(ssn: ssn)
end.to raise_error(
Mongo::Error::MongocryptdSpawnError,
/Failed to spawn mongocryptd at the path "echo hello world" with arguments/
)
end
end
end