Skip to content

Commit 6ace236

Browse files
sync tests and fixes?
1 parent 698f6ac commit 6ace236

File tree

7 files changed

+70
-10
lines changed

7 files changed

+70
-10
lines changed

src/client-side-encryption/auto_encrypter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ export class AutoEncrypter {
403403
}
404404

405405
const commandBuffer = Buffer.isBuffer(cmd) ? cmd : serialize(cmd, options);
406-
407406
const context = this._mongocrypt.makeEncryptionContext(
408407
MongoDBCollectionNamespace.fromString(ns).db,
409408
commandBuffer

test/spec/client-side-encryption/tests/unified/localSchema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@
333333
}
334334
},
335335
"expectError": {
336-
"isClientError": true
336+
"isError": true,
337+
"errorContains": "JSON schema keyword 'required' is only allowed with a remote schema"
337338
}
338339
}
339340
]

test/spec/client-side-encryption/tests/unified/localSchema.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ tests:
9999
arguments:
100100
document: &doc0 { _id: 1, encrypted_string: "string0" }
101101
expectError:
102-
isClientError: true
102+
isError: true
103+
errorContains: "JSON schema keyword 'required' is only allowed with a remote schema"

test/tools/unified-spec-runner/entities.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ import {
4545
type TopologyOpeningEvent,
4646
WriteConcern
4747
} from '../../mongodb';
48-
import { getEnvironmentalOptions } from '../../tools/utils';
48+
import { getEncryptExtraOptions, getEnvironmentalOptions } from '../../tools/utils';
4949
import type { TestConfiguration } from '../runner/config';
5050
import { EntityEventRegistry } from './entity_event_registry';
5151
import { trace } from './runner';
5252
import type { ClientEntity, EntityDescription, ExpectedLogMessage } from './schema';
5353
import {
5454
createClientEncryption,
55+
getCSFLETestDataFromEnvironment,
5556
makeConnectionString,
57+
mergeKMSProviders,
5658
patchCollectionOptions,
5759
patchDbOptions
5860
} from './unified-utils';
@@ -236,6 +238,29 @@ export class UnifiedMongoClient extends MongoClient {
236238
config.setupLogging?.(options, description.id);
237239
}
238240

241+
if (description.autoEncryptOpts) {
242+
const { kmsProviders: kmsProvidersFromEnvironment } = getCSFLETestDataFromEnvironment(
243+
process.env
244+
);
245+
246+
const extraOptions =
247+
getEncryptExtraOptions().cryptSharedLibPath != null
248+
? {
249+
cryptSharedLibPath: getEncryptExtraOptions().cryptSharedLibPath,
250+
...description.autoEncryptOpts.extraOptions
251+
}
252+
: {};
253+
254+
options.autoEncryption = {
255+
...description.autoEncryptOpts,
256+
kmsProviders: mergeKMSProviders(
257+
description.autoEncryptOpts.kmsProviders,
258+
kmsProvidersFromEnvironment
259+
),
260+
extraOptions
261+
};
262+
}
263+
239264
super(uri, options);
240265
this.observedEventEmitter.on('error', () => null);
241266
this.logCollector = logCollector;

test/tools/unified-spec-runner/match.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,14 @@ function isMongoCryptError(err): boolean {
758758
if (err.constructor.name === 'MongoCryptError') {
759759
return true;
760760
}
761+
if (
762+
err instanceof TypeError &&
763+
err.message.includes(
764+
`csfle "analyze_query" failed: JSON schema keyword 'required' is only allowed with a remote schema`
765+
)
766+
) {
767+
return true;
768+
}
761769
return err.stack.includes('at ClientEncryption');
762770
}
763771

test/tools/unified-spec-runner/runner.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function runUnifiedTest(
8181
ctx.skip();
8282
}
8383

84-
let utilClient;
84+
let utilClient: MongoClient;
8585
if (ctx.configuration.isLoadBalanced) {
8686
// The util client can always point at the single mongos LB frontend.
8787
utilClient = ctx.configuration.newClient(ctx.configuration.singleMongosLoadBalancerUri);
@@ -143,13 +143,26 @@ async function runUnifiedTest(
143143
trace('initialData');
144144
for (const { databaseName, collectionName } of unifiedSuite.initialData) {
145145
const db = utilClient.db(databaseName);
146-
const collection = db.collection(collectionName, {
147-
writeConcern: { w: 'majority' }
148-
});
149146

150147
trace('listCollections');
151-
const collectionList = await db.listCollections({ name: collectionName }).toArray();
152-
if (collectionList.length !== 0) {
148+
const allCollections = new Set(
149+
await db
150+
.listCollections()
151+
.map(({ name }) => name)
152+
.toArray()
153+
);
154+
155+
const collections = [
156+
collectionName,
157+
`enxcol_.${collectionName}.esc`,
158+
`enxcol_.${collectionName}.ecoc`
159+
].filter(allCollections.has.bind(allCollections));
160+
161+
for (const name of collections) {
162+
const collection = db.collection(name, {
163+
writeConcern: { w: 'majority' }
164+
});
165+
153166
trace('drop');
154167
expect(await collection.drop()).to.be.true;
155168
}

test/tools/unified-spec-runner/schema.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
Document,
3+
MongoClientOptions,
34
MongoLoggableComponent,
45
ObjectId,
56
ReadConcernLevel,
@@ -152,7 +153,19 @@ export interface ClientEntity {
152153
observeSensitiveCommands?: boolean;
153154
// Was optionally scheduled for removal in NODE-6783, but opted to keep it for potential future use.
154155
storeEventsAsEntities?: StoreEventsAsEntity[];
156+
autoEncryptOpts?: Pick<
157+
MongoClientOptions['autoEncryption'],
158+
| 'keyVaultNamespace'
159+
| 'bypassAutoEncryption'
160+
| 'schemaMap'
161+
| 'encryptedFieldsMap'
162+
| 'extraOptions'
163+
| 'bypassQueryAnalysis'
164+
| 'keyExpirationMS'
165+
> &
166+
Pick<ClientEncryptionEntity['clientEncryptionOpts'], 'kmsProviders'>;
155167
}
168+
156169
export interface DatabaseEntity {
157170
id: string;
158171
client: string;

0 commit comments

Comments
 (0)