Skip to content

Commit

Permalink
fix(node-runtime-worker-thread): properly pass through FLE2 options C…
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored May 17, 2022
1 parent 6d3d912 commit 7daf54d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
40 changes: 38 additions & 2 deletions packages/node-runtime-worker-thread/src/serializer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DevtoolsConnectOptions } from '@mongosh/service-provider-server/lib/cli-service-provider';
import { expect } from 'chai';
import { UUID } from 'bson';
import { UUID, Long } from 'bson';
import {
serializeError,
deserializeError,
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('serializer', () => {
});

describe('connection options', () => {
it('should serialize and deserialize connection options', () => {
it('should serialize and deserialize FLE1 connection options', () => {
const options: DevtoolsConnectOptions = {
autoEncryption: {
schemaMap: {
Expand Down Expand Up @@ -184,5 +184,41 @@ describe('serializer', () => {

expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
});

it('should serialize and deserialize FLE2 connection options', () => {
const options: DevtoolsConnectOptions = {
autoEncryption: {
encryptedFieldsMap: {
'hr.employees': {
fields: [{
path: 'phoneNumber',
keyId: new UUID('fd6275d7-9260-4e6c-a86b-68ec5240814a').toBinary(),
bsonType: 'string',
queries: { queryType: 'equality', contention: new Long(0) }
}]
}
}
}
};

const serialized = serializeConnectOptions(options);

expect(serialized).to.deep.equal({
autoEncryption: {
encryptedFieldsMap: {
'hr.employees': {
fields: [{
path: 'phoneNumber',
keyId: { $binary: { base64: '/WJ115JgTmyoa2jsUkCBSg==', subType: '04' } },
bsonType: 'string',
queries: { queryType: 'equality', contention: { $numberLong: '0' } }
}]
}
}
}
});

expect(deserializeConnectOptions(serialized)).to.deep.equal(options);
});
});
});
8 changes: 3 additions & 5 deletions packages/node-runtime-worker-thread/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ export function deserializeEvaluationResult({

const autoEncryptionBSONOptions = [
'schemaMap',
// Note: This is an educated guess for what the name of this option will be.
// This may need to be adjusted later.
'encryptedFieldConfigMap'
'encryptedFieldsMap'
] as const;

export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions> = {}): DevtoolsConnectOptions {
Expand All @@ -125,7 +123,7 @@ export function serializeConnectOptions(options: Readonly<DevtoolsConnectOptions
if (serializedOptions.autoEncryption?.[autoEncryptionOption]) {
serializedOptions.autoEncryption = {
...serializedOptions.autoEncryption,
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption])
[autoEncryptionOption]: EJSON.serialize(serializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
};
}
}
Expand All @@ -138,7 +136,7 @@ export function deserializeConnectOptions(options: Readonly<DevtoolsConnectOptio
if (deserializedOptions.autoEncryption?.[autoEncryptionOption]) {
deserializedOptions.autoEncryption = {
...deserializedOptions.autoEncryption,
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption])
[autoEncryptionOption]: EJSON.deserialize(deserializedOptions.autoEncryption[autoEncryptionOption], { relaxed: false })
};
}
}
Expand Down

0 comments on commit 7daf54d

Please sign in to comment.