Skip to content

Commit c48bbcf

Browse files
ci(NODE-6752): unskip flaky SCRAM auth tests (#4571)
1 parent da46aea commit c48bbcf

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

test/integration/auth/auth.prose.test.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { expect } from 'chai';
22
import * as sinon from 'sinon';
33

44
import { Connection, LEGACY_HELLO_COMMAND, type MongoClient, ScramSHA256 } from '../../mongodb';
5+
import { type TestConfiguration } from '../../tools/runner/config';
56

67
function makeConnectionString(config, username, password) {
78
return `mongodb://${username}:${password}@${config.host}:${config.port}/admin?`;
89
}
910

1011
const metadata: MongoDBMetadataUI = {
1112
requires: {
12-
auth: 'enabled',
13-
mongodb: '>=3.7.3',
1413
predicate: () =>
1514
process.env.LOAD_BALANCER ? 'TODO(NODE-5631): fix tests to run in load balancer mode.' : true
1615
}
@@ -305,8 +304,7 @@ describe('Authentication Spec Prose Tests', function () {
305304
);
306305
});
307306

308-
// TODO(NODE-6752): Fix flaky SCRAM-SHA-256 tests
309-
describe.skip('Step 4', function () {
307+
describe('Step 4', function () {
310308
/**
311309
* Step 4
312310
* To test SASLprep behavior, create two users:
@@ -324,7 +322,6 @@ describe('Authentication Spec Prose Tests', function () {
324322
* mongodb://%E2%85%A8:IV\@mongodb.example.com/admin
325323
* mongodb://%E2%85%A8:I%C2%ADV\@mongodb.example.com/admin
326324
*/
327-
let utilClient: MongoClient;
328325
let client: MongoClient;
329326
const users = [
330327
{
@@ -339,15 +336,18 @@ describe('Authentication Spec Prose Tests', function () {
339336
}
340337
];
341338

342-
beforeEach(async function () {
343-
utilClient = this.configuration.newClient(this.configuration.url());
339+
async function cleanUpUsers(configuration: TestConfiguration) {
340+
const utilClient = configuration.newClient();
344341
const db = utilClient.db('admin');
345342

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');
351351

352352
const createUserCommands = users.map(user => ({
353353
createUser: user.username,
@@ -356,11 +356,29 @@ describe('Authentication Spec Prose Tests', function () {
356356
mechanisms: user.mechanisms
357357
}));
358358

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);
360379
});
361380

362381
afterEach(async function () {
363-
await utilClient?.close();
364382
await client?.close();
365383
});
366384

@@ -391,7 +409,7 @@ describe('Authentication Spec Prose Tests', function () {
391409
const stats = await client.db('admin').stats();
392410
expect(stats).to.exist;
393411
}
394-
).skipReason = 'TODO(NODE-6752): Fix flaky SCRAM-SHA-256 test';
412+
);
395413

396414
it(
397415
'logs in with normalized username and non-normalized password',

0 commit comments

Comments
 (0)