Skip to content

Commit 7924792

Browse files
committed
test: create new client
1 parent e1e6b58 commit 7924792

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

test/manual/mongodb_oidc.prose.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -758,17 +758,21 @@ describe('MONGODB-OIDC', function () {
758758
});
759759

760760
describe('4.4 Error clears cache', function () {
761-
before(function () {
761+
const authMechanismProperties = {
762+
REQUEST_TOKEN_CALLBACK: createRequestCallback('test_user1', 300),
763+
REFRESH_TOKEN_CALLBACK: () => {
764+
return Promise.resolve({});
765+
}
766+
};
767+
768+
before(async function () {
762769
cache.clear();
763770
client = new MongoClient('mongodb://localhost/?authMechanism=MONGODB-OIDC', {
764-
authMechanismProperties: {
765-
REQUEST_TOKEN_CALLBACK: createRequestCallback('test_user1', 300),
766-
REFRESH_TOKEN_CALLBACK: () => {
767-
return Promise.resolve({});
768-
}
769-
}
771+
authMechanismProperties: authMechanismProperties
770772
});
771-
collection = client.db('test').collection('test');
773+
await client.db('test').collection('test').findOne();
774+
expect(cache.entries.size).to.equal(1);
775+
await client.close();
772776
});
773777

774778
// Clear the cache.
@@ -778,10 +782,11 @@ describe('MONGODB-OIDC', function () {
778782
// Ensure that the cached token has been cleared.
779783
// Close the client.
780784
it('clears the cache on authentication error', async function () {
781-
await collection.findOne();
782-
expect(cache.entries.size).to.equal(1);
785+
client = new MongoClient('mongodb://localhost/?authMechanism=MONGODB-OIDC', {
786+
authMechanismProperties: authMechanismProperties
787+
});
783788
try {
784-
await collection.findOne();
789+
await client.db('test').collection('test').findOne();
785790
expect.fail('Expected OIDC auth to fail with invalid fields from refresh callback');
786791
} catch (error) {
787792
expect(error).to.be.instanceOf(MongoMissingCredentialsError);

0 commit comments

Comments
 (0)