@@ -6,10 +6,17 @@ import * as sinon from 'sinon';
66import { setTimeout } from 'timers/promises' ;
77
88import { connect } from '../../../src/cmap/connect' ;
9- import { Connection , SizedMessageTransform } from '../../../src/cmap/connection' ;
9+ import { Connection , CryptoConnection , SizedMessageTransform } from '../../../src/cmap/connection' ;
1010import { MongoNetworkTimeoutError , MongoRuntimeError } from '../../../src/error' ;
1111import { MongoClientAuthProviders } from '../../../src/mongo_client_auth_providers' ;
12- import { isHello , MongoDBCollectionNamespace , ns , promiseWithResolvers } from '../../../src/utils' ;
12+ import {
13+ HostAddress ,
14+ isHello ,
15+ MongoDBCollectionNamespace ,
16+ MongoDBNamespace ,
17+ ns ,
18+ promiseWithResolvers
19+ } from '../../../src/utils' ;
1320import * as mock from '../../tools/mongodb-mock/index' ;
1421
1522const connectionOptionsDefaults = {
@@ -402,3 +409,22 @@ describe('new Connection()', function () {
402409 } ) ;
403410 } ) ;
404411} ) ;
412+
413+ describe ( 'class CryptoConnection {}' , function ( ) {
414+ it ( 'CryptoConnection.command() throws if no autoEncrypter is configured' , async function ( ) {
415+ const connection = new CryptoConnection ( new Socket ( ) , {
416+ ...connectionOptionsDefaults ,
417+ hostAddress : HostAddress . fromString ( 'localhost:27017' ) ,
418+ authProviders : new MongoClientAuthProviders ( ) ,
419+ extendedMetadata : Promise . resolve ( { } )
420+ } ) ;
421+
422+ const error = await connection
423+ . command ( MongoDBNamespace . fromString ( 'foo.bar' ) , { } , { } )
424+ . catch ( e => e ) ;
425+
426+ expect ( error )
427+ . to . be . instanceOf ( MongoRuntimeError )
428+ . to . match ( / N o A u t o E n c r y p t e r a v a i l a b l e f o r e n c r y p t i o n / ) ;
429+ } ) ;
430+ } ) ;
0 commit comments