|
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
6 | | -// // import { assertTelemetry } from '../../../testUtil' |
7 | | -// import assert from 'assert' |
8 | | -// import { AmazonQLoginWebview } from '../../../../login/webview/vue/amazonq/backend_amazonq' |
9 | | -// import { AuthUtil } from '../../../../codewhisperer/util/authUtil' |
10 | | -// import * as sinon from 'sinon' |
11 | | -// import { LanguageClientAuth } from '../../../../auth/auth2' |
12 | | - |
13 | | -// describe('Amazon Q Login', function () { |
14 | | -// const region = 'fakeRegion' |
15 | | -// const startUrl = 'fakeUrl' |
16 | | - |
17 | | -// let sandbox: sinon.SinonSandbox |
18 | | -// let backend: AmazonQLoginWebview |
19 | | - |
20 | | -// const mockLspAuth: Partial<LanguageClientAuth> = { |
21 | | -// registerSsoTokenChangedHandler: sinon.stub().resolves(), |
22 | | -// }; |
23 | | -// AuthUtil.create(mockLspAuth as LanguageClientAuth); |
24 | | - |
25 | | -// beforeEach(function () { |
26 | | -// sandbox = sinon.createSandbox() |
27 | | -// backend = new AmazonQLoginWebview() |
28 | | -// }) |
29 | | - |
30 | | -// afterEach(function () { |
31 | | -// sandbox.restore() |
32 | | -// }) |
33 | | - |
34 | | -// it('signs into builder ID and emits telemetry', async function () { |
35 | | -// await backend.startBuilderIdSetup() |
36 | | - |
37 | | -// assert.ok(AuthUtil.instance.isConnected()) |
38 | | -// assert.ok(AuthUtil.instance.isBuilderIdConnection()) |
39 | | - |
40 | | -// // TODO: @opieter implement telemetry |
41 | | -// // assertTelemetry('auth_addConnection', { |
42 | | -// // result: 'Succeeded', |
43 | | -// // credentialSourceId: 'awsId', |
44 | | -// // authEnabledFeatures: 'codewhisperer', |
45 | | -// // isReAuth: false, |
46 | | -// // ssoRegistrationExpiresAt: mockRegistration.expiresAt.toISOString(), |
47 | | -// // ssoRegistrationClientId: mockRegistration.clientId, |
48 | | -// // }) |
49 | | -// }) |
50 | | - |
51 | | -// it('signs into IdC and emits telemetry', async function () { |
52 | | -// await backend.startEnterpriseSetup(startUrl, region) |
53 | | - |
54 | | -// assert.ok(AuthUtil.instance.isConnected()) |
55 | | -// assert.ok(AuthUtil.instance.isIdcConnection()) |
56 | | -// assert.ok(AuthUtil.instance.isSsoSession()) |
57 | | -// assert.deepStrictEqual(AuthUtil.instance.connection?.startUrl, startUrl) |
58 | | -// assert.deepStrictEqual(AuthUtil.instance.connection?.region, region) |
59 | | - |
60 | | -// // TODO: @opieter implement telemetry |
61 | | -// // assertTelemetry('auth_addConnection', { |
62 | | -// // result: 'Succeeded', |
63 | | -// // credentialSourceId: 'iamIdentityCenter', |
64 | | -// // authEnabledFeatures: 'codewhisperer', |
65 | | -// // credentialStartUrl: startUrl, |
66 | | -// // awsRegion: region, |
67 | | -// // isReAuth: false, |
68 | | -// // ssoRegistrationExpiresAt: mockRegistration.expiresAt.toISOString(), |
69 | | -// // ssoRegistrationClientId: mockRegistration.clientId, |
70 | | -// // }) |
71 | | -// }) |
72 | | - |
73 | | -// it('reauths builder ID and emits telemetry', async function () { |
74 | | -// AuthUtil.instance.logout() |
75 | | - |
76 | | -// // method under test |
77 | | -// await backend.reauthenticateConnection() |
78 | | - |
79 | | -// assert.ok(AuthUtil.instance.isConnected()) |
80 | | - |
81 | | -// // TODO: @opieter implement telemetry |
82 | | -// // assertTelemetry('auth_addConnection', { |
83 | | -// // result: 'Succeeded', |
84 | | -// // credentialSourceId: 'awsId', |
85 | | -// // authEnabledFeatures: 'codewhisperer', |
86 | | -// // isReAuth: true, |
87 | | -// // ssoRegistrationExpiresAt: mockRegistration.expiresAt.toISOString(), |
88 | | -// // ssoRegistrationClientId: mockRegistration.clientId, |
89 | | -// // }) |
90 | | -// }) |
91 | | - |
92 | | -// it('reauths IdC and emits telemetry', async function () { |
93 | | -// AuthUtil.instance.logout() |
94 | | - |
95 | | -// // method under test |
96 | | -// await backend.reauthenticateConnection() |
97 | | - |
98 | | -// assert.ok(AuthUtil.instance.isConnected()) |
99 | | - |
100 | | -// // TODO: @opieter implement telemetry |
101 | | -// // assertTelemetry('auth_addConnection', { |
102 | | -// // result: 'Succeeded', |
103 | | -// // credentialSourceId: 'iamIdentityCenter', |
104 | | -// // authEnabledFeatures: 'codewhisperer', |
105 | | -// // credentialStartUrl: startUrl, |
106 | | -// // awsRegion: region, |
107 | | -// // isReAuth: true, |
108 | | -// // ssoRegistrationExpiresAt: mockRegistration.expiresAt.toISOString(), |
109 | | -// // ssoRegistrationClientId: mockRegistration.clientId, |
110 | | -// // }) |
111 | | -// }) |
112 | | - |
113 | | -// it('signs out of reauth and emits telemetry', async function () { |
114 | | -// await backend.signout() |
115 | | - |
116 | | -// assert.ok(!AuthUtil.instance.isConnected()) |
117 | | - |
118 | | -// // TODO: @opieter implement telemetry |
119 | | -// // assertTelemetry('auth_addConnection', { |
120 | | -// // result: 'Cancelled', |
121 | | -// // credentialSourceId: 'iamIdentityCenter', |
122 | | -// // authEnabledFeatures: 'codewhisperer', |
123 | | -// // credentialStartUrl: startUrl, |
124 | | -// // awsRegion: region, |
125 | | -// // isReAuth: true, |
126 | | -// // ssoRegistrationExpiresAt: mockRegistration.expiresAt.toISOString(), |
127 | | -// // ssoRegistrationClientId: mockRegistration.clientId, |
128 | | -// // }) |
129 | | -// }) |
130 | | -// }) |
| 6 | +import assert from 'assert' |
| 7 | +import { AmazonQLoginWebview } from '../../../../login/webview/vue/amazonq/backend_amazonq' |
| 8 | +import { AuthUtil } from '../../../../codewhisperer/util/authUtil' |
| 9 | +import * as sinon from 'sinon' |
| 10 | +import { assertTelemetry } from '../../../testUtil' |
| 11 | +import { connectToEnterpriseSso } from '../../../../codewhisperer/util/getStartUrl' |
| 12 | +import { awsIdSignIn } from '../../../../codewhisperer/util/showSsoPrompt' |
| 13 | +import { createTestAuthUtil } from '../../../testAuthUtil' |
| 14 | + |
| 15 | +describe('Amazon Q Login', async function () { |
| 16 | + const region = 'fakeRegion' |
| 17 | + const startUrl = 'fakeUrl' |
| 18 | + |
| 19 | + let sandbox: sinon.SinonSandbox |
| 20 | + let backend: AmazonQLoginWebview |
| 21 | + |
| 22 | + await createTestAuthUtil() |
| 23 | + |
| 24 | + beforeEach(function () { |
| 25 | + sandbox = sinon.createSandbox() |
| 26 | + backend = new AmazonQLoginWebview() |
| 27 | + }) |
| 28 | + |
| 29 | + afterEach(function () { |
| 30 | + sandbox.restore() |
| 31 | + }) |
| 32 | + |
| 33 | + it('signs into builder ID and emits telemetry', async function () { |
| 34 | + await backend.startBuilderIdSetup() |
| 35 | + |
| 36 | + assert.ok(AuthUtil.instance.isConnected()) |
| 37 | + assert.ok(AuthUtil.instance.isBuilderIdConnection()) |
| 38 | + |
| 39 | + assertTelemetry('auth_addConnection', { |
| 40 | + result: 'Succeeded', |
| 41 | + credentialSourceId: 'awsId', |
| 42 | + authEnabledFeatures: 'codewhisperer', |
| 43 | + isReAuth: false, |
| 44 | + ssoRegistrationExpiresAt: undefined, |
| 45 | + ssoRegistrationClientId: undefined, |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + it('signs into IdC and emits telemetry', async function () { |
| 50 | + await backend.startEnterpriseSetup(startUrl, region) |
| 51 | + |
| 52 | + assert.ok(AuthUtil.instance.isConnected()) |
| 53 | + assert.ok(AuthUtil.instance.isIdcConnection()) |
| 54 | + assert.ok(AuthUtil.instance.isSsoSession()) |
| 55 | + assert.deepStrictEqual(AuthUtil.instance.connection?.startUrl, startUrl) |
| 56 | + assert.deepStrictEqual(AuthUtil.instance.connection?.region, region) |
| 57 | + |
| 58 | + assertTelemetry('auth_addConnection', { |
| 59 | + result: 'Succeeded', |
| 60 | + credentialSourceId: 'iamIdentityCenter', |
| 61 | + authEnabledFeatures: 'codewhisperer', |
| 62 | + credentialStartUrl: startUrl, |
| 63 | + awsRegion: region, |
| 64 | + isReAuth: false, |
| 65 | + ssoRegistrationExpiresAt: undefined, |
| 66 | + ssoRegistrationClientId: undefined, |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + it('reauths builder ID and emits telemetry', async function () { |
| 71 | + await awsIdSignIn() |
| 72 | + |
| 73 | + await backend.reauthenticateConnection() |
| 74 | + |
| 75 | + assert.ok(AuthUtil.instance.isConnected()) |
| 76 | + |
| 77 | + assertTelemetry('auth_addConnection', { |
| 78 | + result: 'Succeeded', |
| 79 | + credentialSourceId: 'awsId', |
| 80 | + authEnabledFeatures: 'codewhisperer', |
| 81 | + isReAuth: true, |
| 82 | + ssoRegistrationExpiresAt: undefined, |
| 83 | + ssoRegistrationClientId: undefined, |
| 84 | + }) |
| 85 | + }) |
| 86 | + |
| 87 | + it('reauths IdC and emits telemetry', async function () { |
| 88 | + await connectToEnterpriseSso(startUrl, region) |
| 89 | + |
| 90 | + await backend.reauthenticateConnection() |
| 91 | + |
| 92 | + assert.ok(AuthUtil.instance.isConnected()) |
| 93 | + |
| 94 | + assertTelemetry('auth_addConnection', { |
| 95 | + result: 'Succeeded', |
| 96 | + credentialSourceId: 'iamIdentityCenter', |
| 97 | + authEnabledFeatures: 'codewhisperer', |
| 98 | + credentialStartUrl: startUrl, |
| 99 | + awsRegion: region, |
| 100 | + isReAuth: true, |
| 101 | + ssoRegistrationExpiresAt: undefined, |
| 102 | + ssoRegistrationClientId: undefined, |
| 103 | + }) |
| 104 | + }) |
| 105 | + |
| 106 | + it('signs out of reauth and emits telemetry', async function () { |
| 107 | + await backend.signout() |
| 108 | + |
| 109 | + assert.ok(!AuthUtil.instance.isConnected()) |
| 110 | + |
| 111 | + assertTelemetry('auth_addConnection', { |
| 112 | + result: 'Cancelled', |
| 113 | + credentialSourceId: 'iamIdentityCenter', |
| 114 | + authEnabledFeatures: 'codewhisperer', |
| 115 | + credentialStartUrl: startUrl, |
| 116 | + awsRegion: region, |
| 117 | + isReAuth: true, |
| 118 | + ssoRegistrationExpiresAt: undefined, |
| 119 | + ssoRegistrationClientId: undefined, |
| 120 | + }) |
| 121 | + }) |
| 122 | +}) |
0 commit comments