Skip to content

Commit 7926beb

Browse files
add unit test
Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 71bdffc commit 7926beb

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/core/src/auth/sso/ssoAccessTokenProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ async function pollForTokenWithProgress<T extends { requestId?: string }>(
397397
*/
398398
function getSessionDuration(id: string) {
399399
const creationDate = globals.globalState.getSsoSessionCreationDate(id)
400-
return creationDate !== undefined ? Date.now() - creationDate : undefined
400+
return creationDate !== undefined ? globals.clock.Date.now() - creationDate : undefined
401401
}
402402

403403
/**

packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,50 @@ describe('SsoAccessTokenProvider', function () {
265265
assert.notDeepStrictEqual(await sut.getToken(), cachedToken)
266266
})
267267

268+
it(`emits session duration between logins of the same startUrl`, async function () {
269+
setupFlow()
270+
stubOpen()
271+
272+
await sut.createToken()
273+
clock.tick(5000)
274+
await sut.createToken()
275+
clock.tick(10_000)
276+
await sut.createToken()
277+
278+
// Mimic when we sign out then in again with the same region+startUrl. The ID is the only thing different.
279+
sut = SsoAccessTokenProvider.create(
280+
{ region, startUrl, identifier: 'bbb' },
281+
cache,
282+
oidcClient,
283+
reAuthState,
284+
() => true
285+
)
286+
await sut.createToken()
287+
288+
assertTelemetry('aws_loginWithBrowser', [
289+
{
290+
credentialStartUrl: startUrl,
291+
awsRegion: region,
292+
sessionDuration: undefined, // A new login.
293+
},
294+
{
295+
credentialStartUrl: startUrl,
296+
awsRegion: region,
297+
sessionDuration: 5000, // A reauth. 5000 - 0, is the diff between this and previous login
298+
},
299+
{
300+
credentialStartUrl: startUrl,
301+
awsRegion: region,
302+
sessionDuration: 10000, // A reauth. 15_000 - 5000 is the diff between this and previous login
303+
},
304+
{
305+
credentialStartUrl: startUrl,
306+
awsRegion: region,
307+
sessionDuration: undefined, // A new login, since we signed out of the last.
308+
},
309+
])
310+
})
311+
268312
it('respects the device authorization expiration time', async function () {
269313
// XXX: Don't know how to fix this "unhandled rejection" caused by this test:
270314
// rejected promise not handled within 1 second: Error: Timed-out waiting for browser login flow to complete

0 commit comments

Comments
 (0)