Skip to content

Commit

Permalink
Merge master into feature/cwltail
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Nov 14, 2024
2 parents d7f4be6 + 384d287 commit 3a4785e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present"
},
"devDependencies": {
"@aws-toolkits/telemetry": "^1.0.274",
"@aws-toolkits/telemetry": "^1.0.282",
"@playwright/browser-chromium": "^1.43.1",
"@types/he": "^1.2.3",
"@types/vscode": "^1.68.0",
Expand Down Expand Up @@ -71,7 +71,6 @@
},
"dependencies": {
"@types/node": "^22.7.5",
"@aws-toolkits/telemetry": "^1.0.242",
"vscode-nls": "^5.2.0",
"vscode-nls-dev": "^4.0.4"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export abstract class SsoAccessTokenProvider {
awsRegion: this.profile.region,
ssoRegistrationExpiresAt: args?.registrationExpiresAt,
ssoRegistrationClientId: args?.registrationClientId,
sessionDuration: getSessionDuration(this.tokenCacheKey),
})

// Reset source in case there is a case where browser login was called but we forgot to set the source.
Expand Down Expand Up @@ -396,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 session duration 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 is 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,
sessionDuration: undefined, // A new login.
},
{
credentialStartUrl: startUrl,
awsRegion: region,
sessionDuration: 5000, // A reauth. 5000 - 0, is the diff between this and previous login
},
{
credentialStartUrl: startUrl,
awsRegion: region,
sessionDuration: 10000, // A reauth. 15_000 - 5000 is the diff between this and previous login
},
{
credentialStartUrl: startUrl,
awsRegion: region,
sessionDuration: undefined, // A new login, since we signed out of the last.
},
])
})

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 3a4785e

Please sign in to comment.