@@ -6,10 +6,17 @@ import * as sinon from 'sinon';
6
6
import { setTimeout } from 'timers/promises' ;
7
7
8
8
import { connect } from '../../../src/cmap/connect' ;
9
- import { Connection , SizedMessageTransform } from '../../../src/cmap/connection' ;
9
+ import { Connection , CryptoConnection , SizedMessageTransform } from '../../../src/cmap/connection' ;
10
10
import { MongoNetworkTimeoutError , MongoRuntimeError } from '../../../src/error' ;
11
11
import { 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' ;
13
20
import * as mock from '../../tools/mongodb-mock/index' ;
14
21
15
22
const connectionOptionsDefaults = {
@@ -402,3 +409,22 @@ describe('new Connection()', function () {
402
409
} ) ;
403
410
} ) ;
404
411
} ) ;
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