diff --git a/src/cmap/connection.ts b/src/cmap/connection.ts index ce62f9a7da..e235c6e239 100644 --- a/src/cmap/connection.ts +++ b/src/cmap/connection.ts @@ -22,7 +22,6 @@ import { import { MongoCompatibilityError, MONGODB_ERROR_CODES, - MongoMissingDependencyError, MongoNetworkError, MongoNetworkTimeoutError, MongoOperationTimeoutError, @@ -868,11 +867,7 @@ export class CryptoConnection extends Connection { ): Promise { const { autoEncrypter } = this; if (!autoEncrypter) { - // TODO(NODE-6065): throw a MongoRuntimeError in Node V7 - // @ts-expect-error No cause provided because there is no underlying error. - throw new MongoMissingDependencyError('No AutoEncrypter available for encryption', { - dependencyName: 'n/a' - }); + throw new MongoRuntimeError('No AutoEncrypter available for encryption'); } const serverWireVersion = maxWireVersion(this); diff --git a/test/unit/cmap/connection.test.ts b/test/unit/cmap/connection.test.ts index fcd15a5dd3..bab1422a89 100644 --- a/test/unit/cmap/connection.test.ts +++ b/test/unit/cmap/connection.test.ts @@ -6,10 +6,17 @@ import * as sinon from 'sinon'; import { setTimeout } from 'timers/promises'; import { connect } from '../../../src/cmap/connect'; -import { Connection, SizedMessageTransform } from '../../../src/cmap/connection'; +import { Connection, CryptoConnection, SizedMessageTransform } from '../../../src/cmap/connection'; import { MongoNetworkTimeoutError, MongoRuntimeError } from '../../../src/error'; import { MongoClientAuthProviders } from '../../../src/mongo_client_auth_providers'; -import { isHello, MongoDBCollectionNamespace, ns, promiseWithResolvers } from '../../../src/utils'; +import { + HostAddress, + isHello, + MongoDBCollectionNamespace, + MongoDBNamespace, + ns, + promiseWithResolvers +} from '../../../src/utils'; import * as mock from '../../tools/mongodb-mock/index'; const connectionOptionsDefaults = { @@ -402,3 +409,22 @@ describe('new Connection()', function () { }); }); }); + +describe('class CryptoConnection {}', function () { + it('CryptoConnection.command() throws if no autoEncrypter is configured', async function () { + const connection = new CryptoConnection(new Socket(), { + ...connectionOptionsDefaults, + hostAddress: HostAddress.fromString('localhost:27017'), + authProviders: new MongoClientAuthProviders(), + extendedMetadata: Promise.resolve({}) + }); + + const error = await connection + .command(MongoDBNamespace.fromString('foo.bar'), {}, {}) + .catch(e => e); + + expect(error) + .to.be.instanceOf(MongoRuntimeError) + .to.match(/No AutoEncrypter available for encryption/); + }); +});