Skip to content

Commit 4e9304b

Browse files
Merge staging into feature/lambda-get-started
2 parents 61b61f8 + 6bd59c7 commit 4e9304b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/core/src/testInteg/globalSetup.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import { getLogger } from '../shared/logger'
1111
import { WinstonToolkitLogger } from '../shared/logger/winstonToolkitLogger'
1212
import { mapTestErrors, normalizeError, patchObject, setRunnableTimeout } from '../test/setupUtil'
1313
import { getTestWindow, resetTestWindow } from '../test/shared/vscode/window'
14+
import * as sinon from 'sinon'
15+
import * as tokenProvider from '../auth/sso/ssoAccessTokenProvider'
16+
import { DeviceFlowAuthorization } from '../auth/sso/ssoAccessTokenProvider'
1417

1518
// ASSUMPTION: Tests are not run concurrently
1619

1720
let windowPatch: vscode.Disposable
1821
const maxTestDuration = 300_000
22+
const globalSandbox = sinon.createSandbox()
1923

2024
export async function mochaGlobalSetup(extensionId: string) {
2125
return async function (this: Mocha.Runner) {
@@ -31,6 +35,9 @@ export async function mochaGlobalSetup(extensionId: string) {
3135
// Set up a listener for proxying login requests
3236
patchWindow()
3337

38+
// always use device code authorization
39+
patchAuth()
40+
3441
// Needed for getLogger().
3542
await vscode.extensions.getExtension(extensionId)?.activate()
3643

@@ -51,10 +58,25 @@ export const mochaHooks = {
5158
afterEach(this: Mocha.Context) {
5259
patchWindow()
5360
},
61+
after(this: Mocha.Context) {
62+
globalSandbox.restore()
63+
},
5464
}
5565

5666
function patchWindow() {
5767
windowPatch?.dispose()
5868
resetTestWindow()
5969
windowPatch = patchObject(vscode, 'window', getTestWindow())
6070
}
71+
72+
/**
73+
* We have to fall back to device flow authorization until:
74+
* 1. We can find a way to automatically press the "trust external url" popup
75+
* 2. We support the authorization grant flow in the auth lambda
76+
* otherwise we get: "Error: DialogService: refused to show dialog in tests. Contents: Do you want Code to open the external website?"
77+
*/
78+
function patchAuth() {
79+
globalSandbox.stub(tokenProvider.SsoAccessTokenProvider, 'create').callsFake((profile, cache, oidc) => {
80+
return new DeviceFlowAuthorization(profile, cache, oidc)
81+
})
82+
}

0 commit comments

Comments
 (0)