From af3ebcec860513843c49c84d8e2351dc08d52b43 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 18 Oct 2024 16:03:02 -0400 Subject: [PATCH] chore: rm only --- .../client-side-encryption/driver.test.ts | 358 +++++++++--------- 1 file changed, 172 insertions(+), 186 deletions(-) diff --git a/test/integration/client-side-encryption/driver.test.ts b/test/integration/client-side-encryption/driver.test.ts index 291d43326a..c410004623 100644 --- a/test/integration/client-side-encryption/driver.test.ts +++ b/test/integration/client-side-encryption/driver.test.ts @@ -411,236 +411,222 @@ describe('Client Side Encryption Functional', function () { } ); - describe.only( - 'CSOT on ClientEncryption', - { requires: { clientSideEncryption: true } }, - function () { - const metadata: MongoDBMetadataUI = { - requires: { clientSideEncryption: true, mongodb: '>=4.4' } - }; - - const LOCAL_KEY = Buffer.from( - 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', - 'base64' - ); - - function makeBlockingFailFor(command: string, blockTimeMS: number) { - beforeEach(async function () { - await configureFailPoint(this.configuration, { - configureFailPoint: 'failCommand', - mode: { times: 2 }, - data: { - failCommands: [command], - blockConnection: true, - blockTimeMS, - appName: 'clientEncryption' - } - }); - }); - - afterEach(async function () { - sinon.restore(); - await clearFailPoint(this.configuration); - }); - } - - function runAndCheckForCSOTTimeout(fn: () => Promise) { - return async () => { - const start = performance.now(); - const error = await fn().then( - () => 'API did not reject', - error => error - ); - const end = performance.now(); - if (error?.name === 'MongoBulkWriteError') { - expect(error) - .to.have.property('errorResponse') - .that.is.instanceOf(MongoOperationTimeoutError); - } else { - expect(error).to.be.instanceOf(MongoOperationTimeoutError); - } - expect(end - start).to.be.within(498, 1000); - }; - } + describe('CSOT on ClientEncryption', { requires: { clientSideEncryption: true } }, function () { + const metadata: MongoDBMetadataUI = { + requires: { clientSideEncryption: true, mongodb: '>=4.4' } + }; - let client: MongoClient; - let clientEncryption: ClientEncryption; - let key1Id; - - const data = path.join( - __dirname, - '..', - '..', - 'spec', - 'client-side-encryption', - 'etc', - 'data' - ); + const LOCAL_KEY = Buffer.from( + 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', + 'base64' + ); + function makeBlockingFailFor(command: string, blockTimeMS: number) { beforeEach(async function () { - // Load the file encryptedFields.json as encryptedFields. - const encryptedFields = EJSON.parse( - await fs.promises.readFile(path.join(data, 'encryptedFields.json'), 'utf8'), - { relaxed: false } - ); - // Load the file key1-document.json as key1Document. - const key1Document = EJSON.parse( - await fs.promises.readFile(path.join(data, 'keys', 'key1-document.json'), 'utf8'), - { relaxed: false } - ); - // Read the "_id" field of key1Document as key1ID. - key1Id = key1Document._id; - const setupClient = this.configuration.newClient(); - // Drop and create the collection db.explicit_encryption using encryptedFields as an option. - const db = setupClient.db('db'); - await db - .collection('explicit_encryption') - .drop() - .catch(() => null); - await db.createCollection('explicit_encryption', { encryptedFields }); - // Drop and create the collection keyvault.datakeys. - const kdb = setupClient.db('keyvault'); - await kdb - .collection('datakeys') - .drop() - .catch(() => null); - await kdb.createCollection('datakeys'); - // Insert key1Document in keyvault.datakeys with majority write concern. - await kdb - .collection('datakeys') - .insertOne(key1Document, { writeConcern: { w: 'majority' } }); - - client = this.configuration.newClient({}, { appName: 'clientEncryption' }); - await client.connect(); - clientEncryption = new ClientEncryption(client, { - kmsProviders: { local: { key: LOCAL_KEY } }, - keyVaultNamespace, - keyVaultClient: null, - timeoutMS: 500, - ...getEncryptExtraOptions() + await configureFailPoint(this.configuration, { + configureFailPoint: 'failCommand', + mode: { times: 2 }, + data: { + failCommands: [command], + blockConnection: true, + blockTimeMS, + appName: 'clientEncryption' + } }); - - await setupClient.close(); }); afterEach(async function () { - await client?.close(); + sinon.restore(); + await clearFailPoint(this.configuration); }); + } - describe('rewrapManyDataKey', function () { - describe('when the bulk operation takes too long', function () { - makeBlockingFailFor('update', 2000); - - it( - 'throws a timeout error', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); - }) - ); - }); + function runAndCheckForCSOTTimeout(fn: () => Promise) { + return async () => { + const start = performance.now(); + const error = await fn().then( + () => 'API did not reject', + error => error + ); + const end = performance.now(); + if (error?.name === 'MongoBulkWriteError') { + expect(error) + .to.have.property('errorResponse') + .that.is.instanceOf(MongoOperationTimeoutError); + } else { + expect(error).to.be.instanceOf(MongoOperationTimeoutError); + } + expect(end - start).to.be.within(498, 1000); + }; + } - describe('when the find operation for fetchKeys takes too long', function () { - makeBlockingFailFor('find', 2000); + let client: MongoClient; + let clientEncryption: ClientEncryption; + let key1Id; - it( - 'throws a timeout error', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); - }) - ); - }); + const data = path.join(__dirname, '..', '..', 'spec', 'client-side-encryption', 'etc', 'data'); - // TOOD, does not make rewriteManyDataKey fail - describe.skip('when the find and bulk operation takes too long', function () { - // together they add up to 600, exceeding the timeout of 500 - makeBlockingFailFor('update', 400); - makeBlockingFailFor('listCollections', 400); - - it( - 'throws a timeout error', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); - }) - ); - }); + beforeEach(async function () { + // Load the file encryptedFields.json as encryptedFields. + const encryptedFields = EJSON.parse( + await fs.promises.readFile(path.join(data, 'encryptedFields.json'), 'utf8'), + { relaxed: false } + ); + // Load the file key1-document.json as key1Document. + const key1Document = EJSON.parse( + await fs.promises.readFile(path.join(data, 'keys', 'key1-document.json'), 'utf8'), + { relaxed: false } + ); + // Read the "_id" field of key1Document as key1ID. + key1Id = key1Document._id; + const setupClient = this.configuration.newClient(); + // Drop and create the collection db.explicit_encryption using encryptedFields as an option. + const db = setupClient.db('db'); + await db + .collection('explicit_encryption') + .drop() + .catch(() => null); + await db.createCollection('explicit_encryption', { encryptedFields }); + // Drop and create the collection keyvault.datakeys. + const kdb = setupClient.db('keyvault'); + await kdb + .collection('datakeys') + .drop() + .catch(() => null); + await kdb.createCollection('datakeys'); + // Insert key1Document in keyvault.datakeys with majority write concern. + await kdb.collection('datakeys').insertOne(key1Document, { writeConcern: { w: 'majority' } }); + + client = this.configuration.newClient({}, { appName: 'clientEncryption' }); + await client.connect(); + clientEncryption = new ClientEncryption(client, { + kmsProviders: { local: { key: LOCAL_KEY } }, + keyVaultNamespace, + keyVaultClient: null, + timeoutMS: 500, + ...getEncryptExtraOptions() }); - describe('deleteKey', function () { - makeBlockingFailFor('delete', 2000); + await setupClient.close(); + }); - it( - 'throws a timeout error if the delete operation takes too long', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.deleteKey(new UUID()); - }) - ); - }); + afterEach(async function () { + await client?.close(); + }); - describe('getKey', function () { - makeBlockingFailFor('find', 2000); + describe('rewrapManyDataKey', function () { + describe('when the bulk operation takes too long', function () { + makeBlockingFailFor('update', 2000); it( - 'throws a timeout error if the bulk operation takes too long', + 'throws a timeout error', metadata, runAndCheckForCSOTTimeout(async () => { - await clientEncryption.getKey(new UUID()); + await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); }) ); }); - describe('getKeys', function () { + describe('when the find operation for fetchKeys takes too long', function () { makeBlockingFailFor('find', 2000); it( - 'throws a timeout error if the find operation takes too long', + 'throws a timeout error', metadata, runAndCheckForCSOTTimeout(async () => { - await clientEncryption.getKeys().toArray(); + await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); }) ); }); - describe('removeKeyAltName', function () { - makeBlockingFailFor('findAndModify', 2000); + // TOOD, does not make rewriteManyDataKey fail + describe.skip('when the find and bulk operation takes too long', function () { + // together they add up to 600, exceeding the timeout of 500 + makeBlockingFailFor('update', 400); + makeBlockingFailFor('listCollections', 400); it( - 'throws a timeout error if the findAndModify operation takes too long', + 'throws a timeout error', metadata, runAndCheckForCSOTTimeout(async () => { - await clientEncryption.removeKeyAltName(new UUID(), 'blah'); + await clientEncryption.rewrapManyDataKey({ _id: key1Id }, { provider: 'local' }); }) ); }); + }); - describe('addKeyAltName', function () { - makeBlockingFailFor('findAndModify', 2000); + describe('deleteKey', function () { + makeBlockingFailFor('delete', 2000); - it( - 'throws a timeout error if the findAndModify operation takes too long', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.addKeyAltName(new UUID(), 'blah'); - }) - ); - }); + it( + 'throws a timeout error if the delete operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.deleteKey(new UUID()); + }) + ); + }); - describe('getKeyByAltName', function () { - makeBlockingFailFor('find', 2000); + describe('getKey', function () { + makeBlockingFailFor('find', 2000); - it( - 'throws a timeout error if the find operation takes too long', - metadata, - runAndCheckForCSOTTimeout(async () => { - await clientEncryption.getKeyByAltName('blah'); - }) - ); - }); - } - ); + it( + 'throws a timeout error if the bulk operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.getKey(new UUID()); + }) + ); + }); + + describe('getKeys', function () { + makeBlockingFailFor('find', 2000); + + it( + 'throws a timeout error if the find operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.getKeys().toArray(); + }) + ); + }); + + describe('removeKeyAltName', function () { + makeBlockingFailFor('findAndModify', 2000); + + it( + 'throws a timeout error if the findAndModify operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.removeKeyAltName(new UUID(), 'blah'); + }) + ); + }); + + describe('addKeyAltName', function () { + makeBlockingFailFor('findAndModify', 2000); + + it( + 'throws a timeout error if the findAndModify operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.addKeyAltName(new UUID(), 'blah'); + }) + ); + }); + + describe('getKeyByAltName', function () { + makeBlockingFailFor('find', 2000); + + it( + 'throws a timeout error if the find operation takes too long', + metadata, + runAndCheckForCSOTTimeout(async () => { + await clientEncryption.getKeyByAltName('blah'); + }) + ); + }); + }); }); describe('Range Explicit Encryption with JS native types', function () {