-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sync console-preview with next/main (#12303)
- Loading branch information
Showing
18 changed files
with
224 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,19 +84,18 @@ describe('Loading tokens', () => { | |
const memoryStorage = new MemoryStorage(); | ||
const userPoolClientId = 'userPoolClientId'; | ||
const userSub1 = '[email protected]'; | ||
const userSub1Encoded = 'user1%40email.com'; | ||
const userSub2 = '[email protected]'; | ||
|
||
memoryStorage.setItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1Encoded}.deviceKey`, | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1}.deviceKey`, | ||
'user1-device-key' | ||
); | ||
memoryStorage.setItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1Encoded}.deviceGroupKey`, | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1}.deviceGroupKey`, | ||
'user1-device-group-key' | ||
); | ||
memoryStorage.setItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1Encoded}.randomPasswordKey`, | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${userSub1}.randomPasswordKey`, | ||
'user1-random-password' | ||
); | ||
memoryStorage.setItem( | ||
|
@@ -144,7 +143,7 @@ describe('saving tokens', () => { | |
userPoolClientId, | ||
}, | ||
}); | ||
|
||
const lastAuthUser = 'amplify@user'; | ||
await tokenStore.storeTokens({ | ||
accessToken: decodeJWT( | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzAsInVzZXJuYW1lIjoiYW1wbGlmeUB1c2VyIn0.AAA' | ||
|
@@ -159,59 +158,57 @@ describe('saving tokens', () => { | |
deviceGroupKey: 'device-group-key2', | ||
randomPassword: 'random-password2', | ||
}, | ||
username: 'amplify@user', | ||
username: lastAuthUser, | ||
}); | ||
|
||
const usernameDecoded = 'amplify%40user'; | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.LastAuthUser` | ||
) | ||
).toBe(usernameDecoded); // from decoded JWT | ||
).toBe(lastAuthUser); | ||
|
||
// Refreshed tokens | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.accessToken` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.accessToken` | ||
) | ||
).toBe( | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzAsInVzZXJuYW1lIjoiYW1wbGlmeUB1c2VyIn0.AAA' | ||
); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.idToken` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.idToken` | ||
) | ||
).toBe( | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzAsInVzZXJuYW1lIjoiYW1wbGlmeUB1c2VyIn0.III' | ||
); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.refreshToken` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.refreshToken` | ||
) | ||
).toBe('refresh-token'); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.clockDrift` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.clockDrift` | ||
) | ||
).toBe('150'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.deviceKey` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.deviceKey` | ||
) | ||
).toBe('device-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.deviceGroupKey` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.deviceGroupKey` | ||
) | ||
).toBe('device-group-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameDecoded}.randomPasswordKey` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${lastAuthUser}.randomPasswordKey` | ||
) | ||
).toBe('random-password2'); | ||
}); | ||
|
@@ -276,115 +273,59 @@ describe('saving tokens', () => { | |
deviceGroupKey: 'device-group-key2', | ||
randomPassword: 'random-password2', | ||
}, | ||
username: 'amplify@user', | ||
username: oldUserName, | ||
}); | ||
|
||
const usernameEncoded = 'amplify%40user'; | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.LastAuthUser` | ||
) | ||
).toBe(usernameEncoded); // from decoded JWT | ||
).toBe(oldUserName); | ||
|
||
// Refreshed tokens | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.accessToken` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.accessToken` | ||
) | ||
).toBe( | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzAsInVzZXJuYW1lIjoiYW1wbGlmeUB1c2VyIn0.AAA' | ||
); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.idToken` | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.idToken` | ||
) | ||
).toBe( | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzAsInVzZXJuYW1lIjoiYW1wbGlmeUB1c2VyIn0.III' | ||
); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.refreshToken` | ||
) | ||
).toBe('refresh-token'); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.clockDrift` | ||
) | ||
).toBe('150'); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.deviceKey` | ||
) | ||
).toBe('device-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.deviceGroupKey` | ||
) | ||
).toBe('device-group-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${usernameEncoded}.randomPasswordKey` | ||
) | ||
).toBe('random-password2'); | ||
|
||
// old tokens cleared | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.accessToken` | ||
) | ||
).toBeUndefined(); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.idToken` | ||
) | ||
).toBeUndefined(); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.refreshToken` | ||
) | ||
).toBeUndefined(); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.clockDrift` | ||
) | ||
).toBeUndefined(); | ||
).toBe('refresh-token'); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.idToken` | ||
) | ||
).toBeUndefined(); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.refreshToken` | ||
) | ||
).toBeUndefined(); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.clockDrift` | ||
) | ||
).toBeUndefined(); | ||
).toBe('150'); | ||
|
||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.deviceKey` | ||
) | ||
).not.toBeUndefined(); | ||
).toBe('device-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.deviceGroupKey` | ||
) | ||
).not.toBeUndefined(); | ||
).toBe('device-group-key2'); | ||
expect( | ||
await memoryStorage.getItem( | ||
`CognitoIdentityServiceProvider.${userPoolClientId}.${oldUserName}.randomPasswordKey` | ||
) | ||
).not.toBeUndefined(); | ||
).toBe('random-password2'); | ||
}); | ||
}); |
Oops, something went wrong.