Skip to content

Commit 72aad53

Browse files
committed
chode: bring back token missing fix
1 parent 5186fb1 commit 72aad53

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class AutomatedCallbackWorkflow extends CallbackWorkflow {
3434
// If the server fails for any other reason, do not clear the cache.
3535
if (this.cache.hasAccessToken) {
3636
const token = this.cache.getAccessToken();
37+
if (!connection.accessToken) {
38+
connection.accessToken = token;
39+
}
3740
try {
3841
return await this.finishAuthentication(connection, credentials, token);
3942
} catch (error) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
4+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
5+
import { AutomatedCallbackWorkflow } from '../../../../../src/cmap/auth/mongodb_oidc/automated_callback_workflow';
6+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
7+
import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow';
8+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
9+
import { TokenCache } from '../../../../../src/cmap/auth/mongodb_oidc/token_cache';
10+
import { Connection, MongoCredentials } from '../../../../mongodb';
11+
12+
describe('AutomatedCallbackWorkflow', function () {
13+
describe('#execute', function () {
14+
context('when the cache has a token', function () {
15+
context('when the connection has no token', function () {
16+
const cache = new TokenCache();
17+
const connection = sinon.createStubInstance(Connection);
18+
const credentials = sinon.createStubInstance(MongoCredentials);
19+
const workflow = new AutomatedCallbackWorkflow(cache, callback);
20+
sinon.stub(workflow, 'finishAuthentication').returns(Promise.resolve());
21+
22+
beforeEach(function () {
23+
cache.put({ accessToken: 'test', expiresInSeconds: 7200 });
24+
workflow.execute(connection, credentials);
25+
});
26+
27+
afterEach(function () {
28+
sinon.restore();
29+
});
30+
31+
it('sets the token on the connection', async function () {
32+
expect(connection.accessToken).to.equal('test');
33+
});
34+
});
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)