Skip to content
Draft
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 packages/service-provider-node-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"optionalDependencies": {
"kerberos": "2.1.0",
"mongodb-client-encryption": "^6.1.1"
"mongodb-client-encryption": "^6.3.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like mongodb-client-encryption was previously bumped but this package was left at the old version; was this intentional?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think that's just an oversight (or maybe a bad merge conflict resolve?) 👍

},
"devDependencies": {
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
Expand Down
93 changes: 92 additions & 1 deletion packages/shell-api/src/field-level-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ srDVjIT3LsvTqw==`,
return;
}
expect.fail('missed exception');
break;
// eslint-disable-next-line no-fallthrough
default:
throw new Error(`unreachable ${kmsName}`);
}
Expand Down Expand Up @@ -1058,6 +1058,97 @@ srDVjIT3LsvTqw==`,
expect(printedOutput).to.deep.equal([]);
});

it('allows $lookup with a collection with automatic encryption', async function () {
const keyMongo = new Mongo(
instanceState,
uri,
{
keyVaultNamespace: `${dbname}.__keyVault`,
kmsProviders: { local: { key: 'A'.repeat(128) } },
},
{},
serviceProvider
);

await keyMongo.connect();
instanceState.mongos.push(keyMongo);

const keyVault = await keyMongo.getKeyVault();

const dataKey1 = await keyVault.createKey('local');
const dataKey2 = await keyVault.createKey('local');

const schemaMap = {
[`${dbname}.coll1`]: {
bsonType: 'object',
properties: {
phoneNumber: {
encrypt: {
bsonType: 'string',
keyId: [dataKey1],
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic',
},
},
key: {
bsonType: 'string',
},
},
},
[`${dbname}.coll2`]: {
bsonType: 'object',
properties: {
phoneNumber: {
encrypt: {
bsonType: 'string',
keyId: [dataKey2],
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic',
},
},
key: {
bsonType: 'string',
},
},
},
};

const autoMongo = new Mongo(instanceState, uri, {
keyVaultNamespace: `${dbname}.__keyVault`,
kmsProviders: { local: { key: 'A'.repeat(128) } },
schemaMap,
});

const coll1 = autoMongo.getDB(dbname).getCollection('coll1');
await coll1.insertMany([
{ phoneNumber: '123-456-7890', key: 'foo' },
{ phoneNumber: '123-456-7891', key: 'bar' },
]);

const coll2 = autoMongo.getDB(dbname).getCollection('coll2');
await coll2.insertMany([
{ phoneNumber: '123-456-7892', key: 'baz' },
{ phoneNumber: '123-456-7893', key: 'foo' },
]);
const result = await (
await coll1.aggregate([
{
$lookup: {
from: 'coll2',
localField: 'key',
foreignField: 'key',
as: 'lookupMatch',
},
},
])
)
.map(({ key, lookupMatch }) => ({ key, size: lookupMatch.length }))
.toArray();

expect(result).deep.equals([
{ key: 'foo', size: 1 },
{ key: 'bar', size: 0 },
]);
});

it('prints a warning when creating the keyAltNames index fails', async function () {
const mongo = new Mongo(
instanceState,
Expand Down