Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: nkomonen-amazon <[email protected]>
  • Loading branch information
nkomonen-amazon committed Nov 14, 2024
1 parent 71bdffc commit 013873e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async function pollForTokenWithProgress<T extends { requestId?: string }>(
*/
function getSessionDuration(id: string) {
const creationDate = globals.globalState.getSsoSessionCreationDate(id)
return creationDate !== undefined ? Date.now() - creationDate : undefined
return creationDate !== undefined ? globals.clock.Date.now() - creationDate : undefined
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,50 @@ describe('SsoAccessTokenProvider', function () {
assert.notDeepStrictEqual(await sut.getToken(), cachedToken)
})

it(`emits diff between logins of the same startUrl`, async function () {
setupFlow()
stubOpen()

await sut.createToken()
clock.tick(5000)
await sut.createToken()
clock.tick(10_000)
await sut.createToken()

// Mimic when we sign out then in again with the same region+startUrl. The ID will be the only thing different.
sut = SsoAccessTokenProvider.create(
{ region, startUrl, identifier: 'bbb' },
cache,
oidcClient,
reAuthState,
() => true
)
await sut.createToken()

assertTelemetry('aws_loginWithBrowser', [
{
credentialStartUrl: startUrl,
awsRegion: region,
diffInt: undefined,
},
{
credentialStartUrl: startUrl,
awsRegion: region,
diffInt: 5000, // 5000 - 0 is the diff between this and previous login
},
{
credentialStartUrl: startUrl,
awsRegion: region,
diffInt: 10000, // 15_000 - 5000 is the diff between this and previous login
},
{
credentialStartUrl: startUrl,
awsRegion: region,
diffInt: undefined, // This is the new SSO session which knows nothing about the previous logins
},
])
})

it('respects the device authorization expiration time', async function () {
// XXX: Don't know how to fix this "unhandled rejection" caused by this test:
// rejected promise not handled within 1 second: Error: Timed-out waiting for browser login flow to complete
Expand Down

0 comments on commit 013873e

Please sign in to comment.