Skip to content
Merged
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
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
30 changes: 28 additions & 2 deletions test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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/);
});
});