diff --git a/test/integration/auth/auth.prose.test.ts b/test/integration/auth/auth.prose.test.ts index 3bf068dbb9..d9408a4200 100644 --- a/test/integration/auth/auth.prose.test.ts +++ b/test/integration/auth/auth.prose.test.ts @@ -2,6 +2,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { Connection, LEGACY_HELLO_COMMAND, type MongoClient, ScramSHA256 } from '../../mongodb'; +import { type TestConfiguration } from '../../tools/runner/config'; function makeConnectionString(config, username, password) { return `mongodb://${username}:${password}@${config.host}:${config.port}/admin?`; @@ -9,8 +10,6 @@ function makeConnectionString(config, username, password) { const metadata: MongoDBMetadataUI = { requires: { - auth: 'enabled', - mongodb: '>=3.7.3', predicate: () => process.env.LOAD_BALANCER ? 'TODO(NODE-5631): fix tests to run in load balancer mode.' : true } @@ -305,8 +304,7 @@ describe('Authentication Spec Prose Tests', function () { ); }); - // TODO(NODE-6752): Fix flaky SCRAM-SHA-256 tests - describe.skip('Step 4', function () { + describe('Step 4', function () { /** * Step 4 * To test SASLprep behavior, create two users: @@ -324,7 +322,6 @@ describe('Authentication Spec Prose Tests', function () { * mongodb://%E2%85%A8:IV\@mongodb.example.com/admin * mongodb://%E2%85%A8:I%C2%ADV\@mongodb.example.com/admin */ - let utilClient: MongoClient; let client: MongoClient; const users = [ { @@ -339,15 +336,18 @@ describe('Authentication Spec Prose Tests', function () { } ]; - beforeEach(async function () { - utilClient = this.configuration.newClient(this.configuration.url()); + async function cleanUpUsers(configuration: TestConfiguration) { + const utilClient = configuration.newClient(); const db = utilClient.db('admin'); - try { - await Promise.all(users.map(user => db.removeUser(user.username))); - } catch { - /** We ensure that users are deleted. No action needed. */ - } + await Promise.allSettled(users.map(user => db.removeUser(user.username))); + + await utilClient.close(); + } + + async function createUsers(configuration: TestConfiguration) { + const utilClient = configuration.newClient(); + const db = utilClient.db('admin'); const createUserCommands = users.map(user => ({ createUser: user.username, @@ -356,11 +356,29 @@ describe('Authentication Spec Prose Tests', function () { mechanisms: user.mechanisms })); - await Promise.all(createUserCommands.map(cmd => db.command(cmd))); + const failures = await Promise.allSettled( + createUserCommands.map(cmd => db.command(cmd)) + ).then(resolutions => resolutions.filter(resolution => resolution.status === 'rejected')); + + await utilClient.close(); + + if (failures.length) { + throw new Error( + 'Error(s) creating users: ' + failures.map(failure => failure.reason).join(' | ') + ); + } + } + + before(async function () { + await cleanUpUsers(this.configuration); + await createUsers(this.configuration); + }); + + after(function () { + return cleanUpUsers(this.configuration); }); afterEach(async function () { - await utilClient?.close(); await client?.close(); }); @@ -391,7 +409,7 @@ describe('Authentication Spec Prose Tests', function () { const stats = await client.db('admin').stats(); expect(stats).to.exist; } - ).skipReason = 'TODO(NODE-6752): Fix flaky SCRAM-SHA-256 test'; + ); it( 'logs in with normalized username and non-normalized password',