@@ -4,31 +4,31 @@ import * as fs from 'fs';
44import { dirname , resolve } from 'path' ;
55import * as sinon from 'sinon' ;
66
7- /* eslint-disable @typescript-eslint/no-restricted-imports */
8- import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter' ;
9- /* eslint-disable @typescript-eslint/no-restricted-imports */
10- import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager' ;
11- /* eslint-disable @typescript-eslint/no-restricted-imports */
12- import { StateMachine } from '../../../src/client-side-encryption/state_machine' ;
137import {
8+ AutoEncrypter ,
149 BSON ,
10+ type CollectionInfo ,
11+ type DataKey ,
1512 deserialize ,
1613 type MongoClient ,
14+ MongocryptdManager ,
1715 MongoError ,
1816 MongoNetworkTimeoutError ,
19- serialize
17+ serialize ,
18+ StateMachine
2019} from '../../mongodb' ;
20+ import { ClientSideEncryptionFilter } from '../../tools/runner/filters/client_encryption_filter' ;
2121import { getEncryptExtraOptions } from '../../tools/utils' ;
2222
2323const { EJSON } = BSON ;
2424const cryptShared = ( status : 'enabled' | 'disabled' ) => ( ) => {
25- const isPathPresent = ( getEncryptExtraOptions ( ) . cryptSharedLibPath ?? '' ) . length > 0 ;
25+ const isCryptSharedLoaded = ClientSideEncryptionFilter . cryptShared != null ;
2626
2727 if ( status === 'enabled' ) {
28- return isPathPresent ? true : 'Test requires the shared library.' ;
28+ return isCryptSharedLoaded ? true : 'Test requires the shared library.' ;
2929 }
3030
31- return isPathPresent ? 'Test requires that the crypt shared library NOT be present' : true ;
31+ return isCryptSharedLoaded ? 'Test requires that the crypt shared library NOT be present' : true ;
3232} ;
3333
3434const dataPath = ( fileName : string ) =>
@@ -51,7 +51,7 @@ const MOCK_MONGOCRYPTD_RESPONSE = readExtendedJsonToBuffer(dataPath(`mongocryptd
5151const MOCK_KEYDOCUMENT_RESPONSE = readExtendedJsonToBuffer ( dataPath ( `key-document.json` ) ) ;
5252const MOCK_KMS_DECRYPT_REPLY = readHttpResponse ( dataPath ( `kms-decrypt-reply.txt` ) ) ;
5353
54- describe ( 'crypt_shared library' , function ( ) {
54+ describe . only ( 'crypt_shared library' , function ( ) {
5555 let client : MongoClient ;
5656 let autoEncrypter : AutoEncrypter | undefined ;
5757
@@ -68,37 +68,24 @@ describe('crypt_shared library', function () {
6868
6969 beforeEach ( ( ) => {
7070 sandbox . restore ( ) ;
71- sandbox . stub ( StateMachine . prototype , 'kmsRequest' ) . callsFake ( request => {
71+ sandbox . stub ( StateMachine . prototype , 'kmsRequest' ) . callsFake ( async request => {
7272 request . addResponse ( MOCK_KMS_DECRYPT_REPLY ) ;
73- return Promise . resolve ( ) ;
7473 } ) ;
7574
7675 sandbox
7776 . stub ( StateMachine . prototype , 'fetchCollectionInfo' )
78- . callsFake ( ( client , ns , filter , callback ) => {
79- callback ( null , MOCK_COLLINFO_RESPONSE ) ;
80- } ) ;
81-
82- sandbox
83- . stub ( StateMachine . prototype , 'markCommand' )
84- . callsFake ( ( client , ns , command , callback ) => {
85- if ( ENABLE_LOG_TEST ) {
86- const response = bson . deserialize ( MOCK_MONGOCRYPTD_RESPONSE ) ;
87- response . schemaRequiresEncryption = false ;
88-
89- ENABLE_LOG_TEST = false ; // disable test after run
90- callback ( null , bson . serialize ( response ) ) ;
91- return ;
77+ . callsFake ( function ( _client , __ns , ___filter ) {
78+ async function * iterator ( ) {
79+ yield deserialize ( MOCK_COLLINFO_RESPONSE ) as CollectionInfo ;
9280 }
93-
94- callback ( null , MOCK_MONGOCRYPTD_RESPONSE ) ;
81+ return iterator ( ) ;
9582 } ) ;
9683
97- sandbox . stub ( StateMachine . prototype , 'fetchKeys ' ) . callsFake ( ( client , ns , filter , callback ) => {
98- // mock data is already serialized, our action deals with the result of a cursor
99- const deserializedKey = deserialize ( MOCK_KEYDOCUMENT_RESPONSE ) ;
100- callback ( null , [ deserializedKey ] ) ;
101- } ) ;
84+ sandbox . stub ( StateMachine . prototype , 'markCommand ' ) . resolves ( MOCK_MONGOCRYPTD_RESPONSE ) ;
85+
86+ sandbox
87+ . stub ( StateMachine . prototype , 'fetchKeys' )
88+ . resolves ( [ deserialize ( MOCK_KEYDOCUMENT_RESPONSE ) as DataKey ] ) ;
10289 } ) ;
10390
10491 afterEach ( ( ) => {
@@ -134,14 +121,13 @@ describe('crypt_shared library', function () {
134121 { requires : { clientSideEncryption : true , predicate : cryptShared ( 'disabled' ) } } ,
135122 async function ( ) {
136123 let called = false ;
137- StateMachine . prototype . markCommand . callsFake ( ( client , ns , filter , callback ) => {
124+ StateMachine . prototype . markCommand . callsFake ( async ( _client , _ns , _filter ) => {
138125 if ( ! called ) {
139126 called = true ;
140- callback ( new Error ( 'msg' ) ) ;
141- return ;
127+ throw new Error ( 'msg' ) ;
142128 }
143129
144- callback ( null , MOCK_MONGOCRYPTD_RESPONSE ) ;
130+ return MOCK_MONGOCRYPTD_RESPONSE ;
145131 } ) ;
146132
147133 autoEncrypter = new AutoEncrypter ( client , {
@@ -169,14 +155,13 @@ describe('crypt_shared library', function () {
169155 { requires : { clientSideEncryption : true , predicate : cryptShared ( 'disabled' ) } } ,
170156 async function ( ) {
171157 let called = false ;
172- StateMachine . prototype . markCommand . callsFake ( ( client , ns , filter , callback ) => {
158+ StateMachine . prototype . markCommand . callsFake ( async ( _client , _ns , _filter ) => {
173159 if ( ! called ) {
174160 called = true ;
175- callback ( new MongoNetworkTimeoutError ( 'msg' ) ) ;
176- return ;
161+ throw new MongoNetworkTimeoutError ( 'msg' ) ;
177162 }
178163
179- callback ( null , MOCK_MONGOCRYPTD_RESPONSE ) ;
164+ return MOCK_MONGOCRYPTD_RESPONSE ;
180165 } ) ;
181166
182167 autoEncrypter = new AutoEncrypter ( client , {
@@ -203,14 +188,13 @@ describe('crypt_shared library', function () {
203188 { requires : { clientSideEncryption : true , predicate : cryptShared ( 'disabled' ) } } ,
204189 async function ( ) {
205190 let counter = 2 ;
206- StateMachine . prototype . markCommand . callsFake ( ( client , ns , filter , callback ) => {
191+ StateMachine . prototype . markCommand . callsFake ( async ( _client , _ns , _filter ) => {
207192 if ( counter ) {
208193 counter -= 1 ;
209- callback ( new MongoNetworkTimeoutError ( 'msg' ) ) ;
210- return ;
194+ throw new MongoNetworkTimeoutError ( 'msg' ) ;
211195 }
212196
213- callback ( null , MOCK_MONGOCRYPTD_RESPONSE ) ;
197+ return MOCK_MONGOCRYPTD_RESPONSE ;
214198 } ) ;
215199
216200 autoEncrypter = new AutoEncrypter ( client , {
@@ -298,14 +282,13 @@ describe('crypt_shared library', function () {
298282 async function ( ) {
299283 let called = false ;
300284 const timeoutError = new MongoNetworkTimeoutError ( 'msg' ) ;
301- StateMachine . prototype . markCommand . callsFake ( ( client , ns , filter , callback ) => {
285+ StateMachine . prototype . markCommand . callsFake ( async ( _client , _ns , _filter ) => {
302286 if ( ! called ) {
303287 called = true ;
304- callback ( timeoutError ) ;
305- return ;
288+ throw timeoutError ;
306289 }
307290
308- callback ( null , MOCK_MONGOCRYPTD_RESPONSE ) ;
291+ return MOCK_MONGOCRYPTD_RESPONSE ;
309292 } ) ;
310293
311294 autoEncrypter = new AutoEncrypter ( client , {
0 commit comments