Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 1 addition & 6 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import {
MongoCompatibilityError,
MONGODB_ERROR_CODES,
MongoMissingDependencyError,
MongoNetworkError,
MongoNetworkTimeoutError,
MongoOperationTimeoutError,
Expand Down Expand Up @@ -868,11 +867,7 @@ export class CryptoConnection extends Connection {
): Promise<Document> {
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);
Expand Down
16 changes: 15 additions & 1 deletion test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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';
Expand Down Expand Up @@ -401,4 +401,18 @@ describe('new Connection()', function () {
expect(error).to.be.instanceOf(MongoRuntimeError);
});
});

it('CryptoConnection.command() throws if no autoEncrypter is configured', async function () {
const error = await connect({
...connectionOptionsDefaults,
hostAddress: server.hostAddress(),
authProviders: new MongoClientAuthProviders(),
connectionType: CryptoConnection,
extendedMetadata: Promise.resolve({})
}).catch(e => e);

expect(error)
.to.be.instanceOf(MongoRuntimeError)
.to.match(/No AutoEncrypter available for encryption/);
});
});