-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(authenticator): fix user attribute parsing for amplify >= v6.0.6 (#…
- Loading branch information
1 parent
977b7c5
commit 190bf28
Showing
9 changed files
with
169 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@aws-amplify/ui": patch | ||
--- | ||
|
||
fix(authenticator): fix user attribute parsing for amplify >= v6.0.6 |
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
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Amplify } from 'aws-amplify'; | ||
import { Amplify, ResourcesConfig } from 'aws-amplify'; | ||
|
||
import { PasswordSettings } from '../../../types'; | ||
import { defaultServices } from '../defaultServices'; | ||
import { ALLOWED_SPECIAL_CHARACTERS } from '../../../helpers/authenticator/constants'; | ||
|
||
jest.mock('aws-amplify'); | ||
const getConfigSpy = jest.spyOn(Amplify, 'getConfig'); | ||
|
||
const { | ||
getAmplifyConfig, | ||
|
@@ -245,15 +245,81 @@ describe('validateConfirmPassword', () => { | |
}); | ||
|
||
describe('getAmplifyConfig', () => { | ||
// @todo-migration | ||
// think we need to mock result here: | ||
// TypeError: Cannot read properties of undefined (reading 'Auth') | ||
// > 21 | const cliConfig = result.Cognito; | ||
it.skip('should call Amplify.configure', async () => { | ||
it('should call Amplify.getConfig', async () => { | ||
await getAmplifyConfig(); | ||
|
||
expect(Amplify.getConfig).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('correctly handles invalid user attributes returned from Amplify.getConfig', async () => { | ||
// previous to [email protected], `Amplify.getConfig` returns the wrong shape for `userAttributes` | ||
const invalidConfig: ResourcesConfig = { | ||
Auth: { | ||
Cognito: { | ||
identityPoolId: 'xxxxxx', | ||
allowGuestAccess: true, | ||
// @ts-expect-error | ||
userAttributes: [{ email: { required: true } }], | ||
userPoolClientId: 'xxxxxx', | ||
userPoolId: 'xxxxxx', | ||
mfa: { status: 'off', totpEnabled: false, smsEnabled: true }, | ||
passwordFormat: { | ||
minLength: 8, | ||
requireLowercase: false, | ||
requireUppercase: false, | ||
requireNumbers: false, | ||
requireSpecialCharacters: false, | ||
}, | ||
loginWith: { username: true, email: false, phone: false }, | ||
}, | ||
}, | ||
}; | ||
|
||
getConfigSpy.mockReturnValueOnce(invalidConfig); | ||
|
||
const output = await getAmplifyConfig(); | ||
|
||
expect(output).toStrictEqual({ | ||
...invalidConfig.Auth.Cognito, | ||
loginMechanisms: ['username'], | ||
socialProviders: undefined, | ||
signUpAttributes: ['email'], | ||
}); | ||
}); | ||
|
||
it('correctly handles user attributes returned from Amplify.getConfig', async () => { | ||
const validConfig: ResourcesConfig = { | ||
Auth: { | ||
Cognito: { | ||
identityPoolId: 'xxxxxx', | ||
allowGuestAccess: true, | ||
userAttributes: { email: { required: true } }, | ||
userPoolClientId: 'xxxxxx', | ||
userPoolId: 'xxxxxx', | ||
mfa: { status: 'off', totpEnabled: false, smsEnabled: true }, | ||
passwordFormat: { | ||
minLength: 8, | ||
requireLowercase: false, | ||
requireUppercase: false, | ||
requireNumbers: false, | ||
requireSpecialCharacters: false, | ||
}, | ||
loginWith: { username: true, email: false, phone: false }, | ||
}, | ||
}, | ||
}; | ||
|
||
getConfigSpy.mockReturnValueOnce(validConfig); | ||
|
||
const output = await getAmplifyConfig(); | ||
|
||
expect(output).toStrictEqual({ | ||
...validConfig.Auth.Cognito, | ||
loginMechanisms: ['username'], | ||
socialProviders: undefined, | ||
signUpAttributes: ['email'], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('validateFormPassword', () => { | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.