Skip to content

Commit 7daf54d

Browse files
authored
fix(node-runtime-worker-thread): properly pass through FLE2 options COMPASS-5647 (#1288)
1 parent 6d3d912 commit 7daf54d

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

packages/node-runtime-worker-thread/src/serializer.spec.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
22
import { expect } from 'chai';
3-
import { UUID } from 'bson';
3+
import { UUID, Long } from 'bson';
44
import {
55
serializeError,
66
deserializeError,
@@ -141,7 +141,7 @@ describe('serializer', () => {
141141
});
142142

143143
describe('connection options', () => {
144-
it('should serialize and deserialize connection options', () => {
144+
it('should serialize and deserialize FLE1 connection options', () => {
145145
const options: DevtoolsConnectOptions = {
146146
autoEncryption: {
147147
schemaMap: {
@@ -184,5 +184,41 @@ describe('serializer', () => {
184184

185185
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
186186
});
187+
188+
it('should serialize and deserialize FLE2 connection options', () => {
189+
const options: DevtoolsConnectOptions = {
190+
autoEncryption: {
191+
encryptedFieldsMap: {
192+
'hr.employees': {
193+
fields: [{
194+
path: 'phoneNumber',
195+
keyId: new UUID('fd6275d7-9260-4e6c-a86b-68ec5240814a').toBinary(),
196+
bsonType: 'string',
197+
queries: { queryType: 'equality', contention: new Long(0) }
198+
}]
199+
}
200+
}
201+
}
202+
};
203+
204+
const serialized = serializeConnectOptions(options);
205+
206+
expect(serialized).to.deep.equal({
207+
autoEncryption: {
208+
encryptedFieldsMap: {
209+
'hr.employees': {
210+
fields: [{
211+
path: 'phoneNumber',
212+
keyId: { $binary: { base64: '/WJ115JgTmyoa2jsUkCBSg==', subType: '04' } },
213+
bsonType: 'string',
214+
queries: { queryType: 'equality', contention: { $numberLong: '0' } }
215+
}]
216+
}
217+
}
218+
}
219+
});
220+
221+
expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
222+
});
187223
});
188224
});

packages/node-runtime-worker-thread/src/serializer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ export function deserializeEvaluationResult({
114114

115115
const autoEncryptionBSONOptions = [
116116
'schemaMap',
117-
// Note: This is an educated guess for what the name of this option will be.
118-
// This may need to be adjusted later.
119-
'encryptedFieldConfigMap'
117+
'encryptedFieldsMap'
120118
] as const;
121119

122120
export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions> = {}): DevtoolsConnectOptions {
@@ -125,7 +123,7 @@ export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions
125123
if (serializedOptions.autoEncryption?.[autoEncryptionOption]) {
126124
serializedOptions.autoEncryption = {
127125
...serializedOptions.autoEncryption,
128-
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption])
126+
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
129127
};
130128
}
131129
}
@@ -138,7 +136,7 @@ export function deserializeConnectOptions(options: Readonly<DevtoolsConnectOptio
138136
if (deserializedOptions.autoEncryption?.[autoEncryptionOption]) {
139137
deserializedOptions.autoEncryption = {
140138
...deserializedOptions.autoEncryption,
141-
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption])
139+
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
142140
};
143141
}
144142
}

0 commit comments

Comments
 (0)