Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .evergreen/install-mongodb-client-encryption.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ -z ${PROJECT_DIRECTORY+omitted} ]; then echo "PROJECT_DIRECTORY is unset" &
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh

rm -rf mongodb-client-encryption
git clone https://github.com/mongodb-js/mongodb-client-encryption.git
git clone https://github.com/baileympearson/mongodb-client-encryption.git -b NODE-7043
pushd mongodb-client-encryption

node --version
Expand Down
14 changes: 5 additions & 9 deletions src/client-side-encryption/auto_encrypter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
type MongoCrypt,
type MongoCryptConstructor,
type MongoCryptOptions
} from 'mongodb-client-encryption';
import { type MongoCrypt, type MongoCryptOptions } from 'mongodb-client-encryption';
import * as net from 'net';

import { deserialize, type Document, serialize } from '../bson';
Expand All @@ -15,7 +11,7 @@
import { MongoDBCollectionNamespace } from '../utils';
import { autoSelectSocketOptions } from './client_encryption';
import * as cryptoCallbacks from './crypto_callbacks';
import { MongoCryptInvalidArgumentError } from './errors';
import { defaultErrorWrapper, MongoCryptInvalidArgumentError } from './errors';
import { MongocryptdManager } from './mongocryptd_manager';
import {
type CredentialProviders,
Expand Down Expand Up @@ -183,7 +179,7 @@
[kDecorateResult] = false;

/** @internal */
static getMongoCrypt(): MongoCryptConstructor {
static getMongoCrypt(): typeof MongoCrypt {
const encryption = getMongoDBClientEncryption();
if ('kModuleError' in encryption) {
throw encryption.kModuleError;
Expand Down Expand Up @@ -258,8 +254,8 @@
}

const mongoCryptOptions: MongoCryptOptions = {
enableMultipleCollinfo: true,
cryptoCallbacks
cryptoCallbacks,
errorWrapper: defaultErrorWrapper

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 258 in src/client-side-encryption/auto_encrypter.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.
};
if (options.schemaMap) {
mongoCryptOptions.schemaMap = Buffer.isBuffer(options.schemaMap)
Expand Down
7 changes: 4 additions & 3 deletions src/client-side-encryption/client_encryption.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
ExplicitEncryptionContextOptions,
MongoCrypt,
MongoCryptConstructor,
MongoCryptOptions
} from 'mongodb-client-encryption';

Expand All @@ -28,6 +27,7 @@
import { MongoDBCollectionNamespace, resolveTimeoutOptions } from '../utils';
import * as cryptoCallbacks from './crypto_callbacks';
import {
defaultErrorWrapper,
MongoCryptCreateDataKeyError,
MongoCryptCreateEncryptedCollectionError,
MongoCryptInvalidArgumentError
Expand Down Expand Up @@ -87,7 +87,7 @@
_credentialProviders?: CredentialProviders;

/** @internal */
static getMongoCrypt(): MongoCryptConstructor {
static getMongoCrypt(): typeof MongoCrypt {
const encryption = getMongoDBClientEncryption();
if ('kModuleError' in encryption) {
throw encryption.kModuleError;
Expand Down Expand Up @@ -147,7 +147,8 @@
cryptoCallbacks,
kmsProviders: !Buffer.isBuffer(this._kmsProviders)
? (serialize(this._kmsProviders) as Buffer)
: this._kmsProviders
: this._kmsProviders,
errorWrapper: defaultErrorWrapper

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.

Check failure on line 151 in src/client-side-encryption/client_encryption.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'errorWrapper' does not exist in type 'MongoCryptConstructorOptions'.
};

this._keyVaultNamespace = options.keyVaultNamespace;
Expand Down
3 changes: 3 additions & 0 deletions src/client-side-encryption/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class MongoCryptError extends MongoError {
}
}

export const defaultErrorWrapper = (error: Error) =>
new MongoCryptError(error.message, { cause: error });

/**
* @public
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ describe('Range Explicit Encryption', function () {
})
.catch(e => e);

expect(resultOrError).to.be.instanceOf(TypeError);
expect(resultOrError).to.be.instanceOf(MongoCryptError);
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { type MongoCryptOptions } from 'mongodb-client-encryption';
import * as sinon from 'sinon';

import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
import { AutoEncrypter, BSON, type Document, type MongoClient } from '../../mongodb';
import {
AutoEncrypter,
BSON,
type Document,
type MongoClient,
MongoCryptError
} from '../../mongodb';
import { type TestConfiguration } from '../../tools/runner/config';
import { getEncryptExtraOptions } from '../../tools/utils';

Expand Down Expand Up @@ -362,71 +368,4 @@ describe('$lookup support', defaultMetadata, function () {
/Upgrade/i,
{ requires: { ...defaultMetadata.requires, mongodb: '>=7.0.0 <8.1.0' } }
);

describe('Node.js custom test', function () {
describe('when enableMultipleCollinfo is off and a $lookup is run', function () {
let client: MongoClient;

beforeEach(async function () {
const mochaTest = { metadata: defaultMetadata };

if (!this.configuration.filters.MongoDBVersionFilter.filter(mochaTest)) {
return;
}

if (!this.configuration.filters.MongoDBTopologyFilter.filter(mochaTest)) {
return;
}

if (!this.configuration.filters.ClientSideEncryptionFilter.filter(mochaTest)) {
return;
}

const getMongoCrypt = sinon.stub(AutoEncrypter, 'getMongoCrypt').callsFake(function () {
const MongoCrypt = getMongoCrypt.wrappedMethod.call(this);
return class extends MongoCrypt {
constructor(options: MongoCryptOptions) {
expect(options).to.have.property('enableMultipleCollinfo', true); // assert invariant
options.enableMultipleCollinfo = false;
super(options);
}
};
});

client = newEncryptedClient(this);
});

afterEach(async function () {
sinon.restore();
await client?.close();
});

it(
'throws a TypeError about libmongocrypt not enabled to support multiple collections',
defaultMetadata,
async () => {
const collection = client.db('db').collection('csfle');
const actual = await collection
.aggregate([
{ $match: { csfle: 'csfle' } },
{
$lookup: {
from: 'csfle2',
as: 'matched',
pipeline: [{ $match: { csfle2: 'csfle2' } }, { $project: { _id: 0 } }]
}
},
{ $project: { _id: 0 } }
])
.toArray()
.catch(error => error);

expect(actual).to.be.instanceOf(TypeError);
expect(actual.message).to.match(
/libmongocrypt is not configured to support encrypting a command with multiple collections/i
);
}
);
});
});
});
Loading