@@ -16,7 +16,7 @@ const metadata: MongoDBMetadataUI = {
16
16
}
17
17
} ;
18
18
19
- describe ( 'Authentication Spec Prose Tests' , function ( ) {
19
+ describe . only ( 'Authentication Spec Prose Tests' , function ( ) {
20
20
describe ( 'SCRAM-SHA-256 and mechanism negotiation' , ( ) => {
21
21
describe ( 'Steps 1-3' , function ( ) {
22
22
const userMap = {
@@ -41,6 +41,7 @@ describe('Authentication Spec Prose Tests', function () {
41
41
} ;
42
42
const users = Object . keys ( userMap ) . map ( name => userMap [ name ] ) ;
43
43
let utilClient : MongoClient ;
44
+ let client : MongoClient ;
44
45
45
46
/**
46
47
* Step 1
@@ -66,6 +67,8 @@ describe('Authentication Spec Prose Tests', function () {
66
67
afterEach ( async function ( ) {
67
68
await Promise . all ( users . map ( user => utilClient . db ( 'admin' ) . removeUser ( user . username ) ) ) ;
68
69
await utilClient ?. close ( ) ;
70
+ await client ?. close ( ) ;
71
+ sinon . restore ( ) ;
69
72
} ) ;
70
73
71
74
/**
@@ -90,13 +93,9 @@ describe('Authentication Spec Prose Tests', function () {
90
93
authSource : 'admin'
91
94
} ;
92
95
93
- const client = this . configuration . newClient ( { } , options ) ;
94
- try {
95
- const stats = await client . db ( 'test' ) . stats ( ) ;
96
- expect ( stats ) . to . exist ;
97
- } finally {
98
- await client . close ( ) ;
99
- }
96
+ client = this . configuration . newClient ( { } , options ) ;
97
+ const stats = await client . db ( 'test' ) . stats ( ) ;
98
+ expect ( stats ) . to . exist ;
100
99
}
101
100
) ;
102
101
@@ -113,13 +112,9 @@ describe('Authentication Spec Prose Tests', function () {
113
112
password
114
113
) } authMechanism=${ mechanism } `;
115
114
116
- const client = this . configuration . newClient ( url ) ;
117
- try {
118
- const stats = await client . db ( 'test' ) . stats ( ) ;
119
- expect ( stats ) . to . exist ;
120
- } finally {
121
- await client . close ( ) ;
122
- }
115
+ client = this . configuration . newClient ( url ) ;
116
+ const stats = await client . db ( 'test' ) . stats ( ) ;
117
+ expect ( stats ) . to . exist ;
123
118
}
124
119
) ;
125
120
}
@@ -136,13 +131,9 @@ describe('Authentication Spec Prose Tests', function () {
136
131
authSource : 'admin'
137
132
} ;
138
133
139
- const client = this . configuration . newClient ( { } , options ) ;
140
- try {
141
- const stats = await client . db ( 'test' ) . stats ( ) ;
142
- expect ( stats ) . to . exist ;
143
- } finally {
144
- await client . close ( ) ;
145
- }
134
+ client = this . configuration . newClient ( { } , options ) ;
135
+ const stats = await client . db ( 'test' ) . stats ( ) ;
136
+ expect ( stats ) . to . exist ;
146
137
}
147
138
) ;
148
139
@@ -154,13 +145,9 @@ describe('Authentication Spec Prose Tests', function () {
154
145
const password = encodeURIComponent ( user . password ) ;
155
146
const url = makeConnectionString ( this . configuration , username , password ) ;
156
147
157
- const client = this . configuration . newClient ( url ) ;
158
- try {
159
- const stats = await client . db ( 'test' ) . stats ( ) ;
160
- expect ( stats ) . to . exist ;
161
- } finally {
162
- await client . close ( ) ;
163
- }
148
+ client = this . configuration . newClient ( url ) ;
149
+ const stats = await client . db ( 'test' ) . stats ( ) ;
150
+ expect ( stats ) . to . exist ;
164
151
}
165
152
) ;
166
153
}
@@ -184,16 +171,11 @@ describe('Authentication Spec Prose Tests', function () {
184
171
authSource : this . configuration . db
185
172
} ;
186
173
174
+ client = this . configuration . newClient ( { } , options ) ;
187
175
const spy = sinon . spy ( ScramSHA256 . prototype , 'auth' ) ;
188
- const client = this . configuration . newClient ( { } , options ) ;
189
- try {
190
- const stats = await client . db ( 'test' ) . stats ( ) ;
191
- expect ( stats ) . to . exist ;
192
- expect ( spy . called ) . to . equal ( true ) ;
193
- } finally {
194
- sinon . restore ( ) ;
195
- await client . close ( ) ;
196
- }
176
+ const stats = await client . db ( 'test' ) . stats ( ) ;
177
+ expect ( stats ) . to . exist ;
178
+ expect ( spy . called ) . to . equal ( true ) ;
197
179
}
198
180
) . skipReason = 'todo(NODE-5629): Test passes locally but will fail on CI runs.' ;
199
181
@@ -215,13 +197,12 @@ describe('Authentication Spec Prose Tests', function () {
215
197
authMechanism : 'SCRAM-SHA-1'
216
198
} ;
217
199
218
- const client = this . configuration . newClient ( { } , options ) ;
200
+ client = this . configuration . newClient ( { } , options ) ;
219
201
const error = await client
220
202
. db ( 'test' )
221
203
. stats ( )
222
204
. catch ( e => e ) ;
223
205
expect ( error . message ) . to . match ( / A u t h e n t i c a t i o n f a i l e d | S C R A M / ) ;
224
- await client . close ( ) ;
225
206
}
226
207
) ;
227
208
@@ -238,13 +219,12 @@ describe('Authentication Spec Prose Tests', function () {
238
219
authMechanism : 'SCRAM-SHA-256'
239
220
} ;
240
221
241
- const client = this . configuration . newClient ( { } , options ) ;
222
+ client = this . configuration . newClient ( { } , options ) ;
242
223
const error = await client
243
224
. db ( 'test' )
244
225
. stats ( )
245
226
. catch ( e => e ) ;
246
227
expect ( error . message ) . to . match ( / A u t h e n t i c a t i o n f a i l e d | S C R A M / ) ;
247
- await client . close ( ) ;
248
228
}
249
229
) ;
250
230
@@ -310,24 +290,19 @@ describe('Authentication Spec Prose Tests', function () {
310
290
authSource : 'admin'
311
291
} ;
312
292
293
+ client = this . configuration . newClient ( { } , options ) ;
313
294
const commandSpy = sinon . spy ( Connection . prototype , 'command' ) ;
314
- const client = this . configuration . newClient ( { } , options ) ;
315
- try {
316
- await client . connect ( ) ;
317
- const calls = commandSpy
318
- . getCalls ( )
319
- . filter ( c => c . thisValue . id !== '<monitor>' ) // ignore all monitor connections
320
- . filter (
321
- c => c . args [ 1 ] [ process . env . MONGODB_API_VERSION ? 'hello' : LEGACY_HELLO_COMMAND ]
322
- ) ;
323
-
324
- expect ( calls ) . to . have . length ( 1 ) ;
325
- const handshakeDoc = calls [ 0 ] . args [ 1 ] ;
326
- expect ( handshakeDoc ) . to . have . property ( 'speculativeAuthenticate' ) ;
327
- } finally {
328
- sinon . restore ( ) ;
329
- await client . close ( ) ;
330
- }
295
+ await client . connect ( ) ;
296
+ const calls = commandSpy
297
+ . getCalls ( )
298
+ . filter ( c => c . thisValue . id !== '<monitor>' ) // ignore all monitor connections
299
+ . filter (
300
+ c => c . args [ 1 ] [ process . env . MONGODB_API_VERSION ? 'hello' : LEGACY_HELLO_COMMAND ]
301
+ ) ;
302
+
303
+ expect ( calls ) . to . have . length ( 1 ) ;
304
+ const handshakeDoc = calls [ 0 ] . args [ 1 ] ;
305
+ expect ( handshakeDoc ) . to . have . property ( 'speculativeAuthenticate' ) ;
331
306
}
332
307
) ;
333
308
} ) ;
@@ -351,7 +326,8 @@ describe('Authentication Spec Prose Tests', function () {
351
326
* mongodb://%E2%85%A8:IV\@mongodb.example.com/admin
352
327
* mongodb://%E2%85%A8:I%C2%ADV\@mongodb.example.com/admin
353
328
*/
354
- let utilClient ;
329
+ let utilClient : MongoClient ;
330
+ let client : MongoClient ;
355
331
const users = [
356
332
{
357
333
username : 'IX' ,
@@ -401,13 +377,9 @@ describe('Authentication Spec Prose Tests', function () {
401
377
authMechanism : 'SCRAM-SHA-256'
402
378
} ;
403
379
404
- const client = this . configuration . newClient ( options ) ;
405
- try {
406
- const stats = await client . db ( 'admin' ) . stats ( ) ;
407
- expect ( stats ) . to . exist ;
408
- } finally {
409
- await client . close ( ) ;
410
- }
380
+ client = this . configuration . newClient ( options ) ;
381
+ const stats = await client . db ( 'admin' ) . stats ( ) ;
382
+ expect ( stats ) . to . exist ;
411
383
}
412
384
) . skipReason = 'todo(NODE-5621): fix the issue with unicode characters.' ;
413
385
}
0 commit comments