Skip to content

ci(NODE-6752): unskip flaky SCRAM auth tests #4571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions test/integration/auth/auth.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ 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?`;
}

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
}
Expand Down Expand Up @@ -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:
Expand All @@ -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 = [
{
Expand All @@ -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,
Expand All @@ -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();
});

Expand Down Expand Up @@ -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',
Expand Down