@@ -2,15 +2,14 @@ import { expect } from 'chai';
2
2
import * as sinon from 'sinon' ;
3
3
4
4
import { Connection , LEGACY_HELLO_COMMAND , type MongoClient , ScramSHA256 } from '../../mongodb' ;
5
+ import { type TestConfiguration } from '../../tools/runner/config' ;
5
6
6
7
function makeConnectionString ( config , username , password ) {
7
8
return `mongodb://${ username } :${ password } @${ config . host } :${ config . port } /admin?` ;
8
9
}
9
10
10
11
const metadata : MongoDBMetadataUI = {
11
12
requires : {
12
- auth : 'enabled' ,
13
- mongodb : '>=3.7.3' ,
14
13
predicate : ( ) =>
15
14
process . env . LOAD_BALANCER ? 'TODO(NODE-5631): fix tests to run in load balancer mode.' : true
16
15
}
@@ -305,8 +304,7 @@ describe('Authentication Spec Prose Tests', function () {
305
304
) ;
306
305
} ) ;
307
306
308
- // TODO(NODE-6752): Fix flaky SCRAM-SHA-256 tests
309
- describe . skip ( 'Step 4' , function ( ) {
307
+ describe ( 'Step 4' , function ( ) {
310
308
/**
311
309
* Step 4
312
310
* To test SASLprep behavior, create two users:
@@ -324,7 +322,6 @@ describe('Authentication Spec Prose Tests', function () {
324
322
* mongodb://%E2%85%A8:IV\@mongodb.example.com/admin
325
323
* mongodb://%E2%85%A8:I%C2%ADV\@mongodb.example.com/admin
326
324
*/
327
- let utilClient : MongoClient ;
328
325
let client : MongoClient ;
329
326
const users = [
330
327
{
@@ -339,15 +336,18 @@ describe('Authentication Spec Prose Tests', function () {
339
336
}
340
337
] ;
341
338
342
- beforeEach ( async function ( ) {
343
- utilClient = this . configuration . newClient ( this . configuration . url ( ) ) ;
339
+ async function cleanUpUsers ( configuration : TestConfiguration ) {
340
+ const utilClient = configuration . newClient ( ) ;
344
341
const db = utilClient . db ( 'admin' ) ;
345
342
346
- try {
347
- await Promise . all ( users . map ( user => db . removeUser ( user . username ) ) ) ;
348
- } catch {
349
- /** We ensure that users are deleted. No action needed. */
350
- }
343
+ await Promise . allSettled ( users . map ( user => db . removeUser ( user . username ) ) ) ;
344
+
345
+ await utilClient . close ( ) ;
346
+ }
347
+
348
+ async function createUsers ( configuration : TestConfiguration ) {
349
+ const utilClient = configuration . newClient ( ) ;
350
+ const db = utilClient . db ( 'admin' ) ;
351
351
352
352
const createUserCommands = users . map ( user => ( {
353
353
createUser : user . username ,
@@ -356,11 +356,29 @@ describe('Authentication Spec Prose Tests', function () {
356
356
mechanisms : user . mechanisms
357
357
} ) ) ;
358
358
359
- await Promise . all ( createUserCommands . map ( cmd => db . command ( cmd ) ) ) ;
359
+ const failures = await Promise . allSettled (
360
+ createUserCommands . map ( cmd => db . command ( cmd ) )
361
+ ) . then ( resolutions => resolutions . filter ( resolution => resolution . status === 'rejected' ) ) ;
362
+
363
+ await utilClient . close ( ) ;
364
+
365
+ if ( failures . length ) {
366
+ throw new Error (
367
+ 'Error(s) creating users: ' + failures . map ( failure => failure . reason ) . join ( ' | ' )
368
+ ) ;
369
+ }
370
+ }
371
+
372
+ before ( async function ( ) {
373
+ await cleanUpUsers ( this . configuration ) ;
374
+ await createUsers ( this . configuration ) ;
375
+ } ) ;
376
+
377
+ after ( function ( ) {
378
+ return cleanUpUsers ( this . configuration ) ;
360
379
} ) ;
361
380
362
381
afterEach ( async function ( ) {
363
- await utilClient ?. close ( ) ;
364
382
await client ?. close ( ) ;
365
383
} ) ;
366
384
@@ -391,7 +409,7 @@ describe('Authentication Spec Prose Tests', function () {
391
409
const stats = await client . db ( 'admin' ) . stats ( ) ;
392
410
expect ( stats ) . to . exist ;
393
411
}
394
- ) . skipReason = 'TODO(NODE-6752): Fix flaky SCRAM-SHA-256 test' ;
412
+ ) ;
395
413
396
414
it (
397
415
'logs in with normalized username and non-normalized password' ,
0 commit comments