|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as sinon from 'sinon'; |
| 3 | + |
| 4 | +// eslint-disable-next-line @typescript-eslint/no-restricted-imports |
| 5 | +import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow'; |
| 6 | +// eslint-disable-next-line @typescript-eslint/no-restricted-imports |
| 7 | +import { TokenCache } from '../../../../../src/cmap/auth/mongodb_oidc/token_cache'; |
| 8 | +import { |
| 9 | + AutomatedCallbackWorkflow, |
| 10 | + CallbackWorkflow, |
| 11 | + Connection, |
| 12 | + MongoCredentials |
| 13 | +} from '../../../../mongodb'; |
| 14 | + |
| 15 | +describe('AutomatedCallbackWorkflow', function () { |
| 16 | + describe('#execute', function () { |
| 17 | + context('when the cache has a token', function () { |
| 18 | + const sandbox = sinon.createSandbox(); |
| 19 | + |
| 20 | + // See NODE-6801 and corresponding PR: https://github.com/mongodb/node-mongodb-native/pull/4438 |
| 21 | + // This is a test to ensure that we do not regress on the above issue. Do NOT remove this test. |
| 22 | + context('when the connection has no token', function () { |
| 23 | + const cache = new TokenCache(); |
| 24 | + const connection = sandbox.createStubInstance(Connection); |
| 25 | + const credentials = sandbox.createStubInstance(MongoCredentials); |
| 26 | + sandbox.stub(CallbackWorkflow.prototype, 'finishAuthentication').resolves(); |
| 27 | + const workflow = new AutomatedCallbackWorkflow(cache, callback); |
| 28 | + |
| 29 | + beforeEach(function () { |
| 30 | + cache.put({ accessToken: 'test', expiresInSeconds: 7200 }); |
| 31 | + workflow.execute(connection, credentials); |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(function () { |
| 35 | + sandbox.restore(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('sets the token on the connection', async function () { |
| 39 | + expect(connection.accessToken).to.equal('test'); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | +}); |
0 commit comments