diff --git a/examples/react-native/src/ui/components/authenticator/reset-password/Example.tsx b/examples/react-native/src/ui/components/authenticator/reset-password/Example.tsx index d7bd668c109..f2f78f551c6 100644 --- a/examples/react-native/src/ui/components/authenticator/reset-password/Example.tsx +++ b/examples/react-native/src/ui/components/authenticator/reset-password/Example.tsx @@ -3,15 +3,18 @@ import { StyleSheet, View } from 'react-native'; import { Authenticator } from '@aws-amplify/ui-react-native'; import { Amplify } from 'aws-amplify'; +import { parseAWSExports } from '@aws-amplify/core/lib-esm/parseAWSExports'; import { SignOutButton } from '../SignOutButton'; import awsconfig from './aws-exports'; -Amplify.configure({ - ...awsconfig, - // mock server endpoint for Detox e2es - Auth: { endpoint: 'http://127.0.0.1:9091/' }, -}); +const config = parseAWSExports(awsconfig); +if (!config.Auth) { + throw new Error('Auth config not found'); +} +// mock server endpoint for Detox e2es +config.Auth.Cognito.userPoolEndpoint = 'http://127.0.0.1:9091/'; +Amplify.configure(config); function App() { return ( diff --git a/examples/react-native/src/ui/components/authenticator/sign-up-with-attributes/Example.tsx b/examples/react-native/src/ui/components/authenticator/sign-up-with-attributes/Example.tsx index 0470ce8c931..f0bb7b71ba6 100644 --- a/examples/react-native/src/ui/components/authenticator/sign-up-with-attributes/Example.tsx +++ b/examples/react-native/src/ui/components/authenticator/sign-up-with-attributes/Example.tsx @@ -4,50 +4,18 @@ import { StyleSheet, View } from 'react-native'; import { Authenticator } from '@aws-amplify/ui-react-native'; import { TextField } from '@aws-amplify/ui-react-native/dist/primitives'; import { Amplify } from 'aws-amplify'; +import { parseAWSExports } from '@aws-amplify/core/lib-esm/parseAWSExports'; import { SignOutButton } from '../SignOutButton'; import awsconfig from './aws-exports'; -Amplify.configure({ - ...awsconfig, - // mock server endpoint for Detox e2es - Auth: { endpoint: 'http://127.0.0.1:9091/' }, -}); - -const formFields = { - signUp: { - zoneinfo: { - label: 'Zone Info', - isRequired: false, - type: 'text', - }, - picture: { - label: 'Picture', - isRequired: false, - type: 'text', - }, - updated_at: { - label: 'Updated at', - isRequired: false, - type: 'text', - }, - address: { - label: 'Address', - isRequired: false, - type: 'text', - }, - gender: { - label: 'Gender', - isRequired: false, - type: 'text', - }, - locale: { - label: 'Locale', - isRequired: false, - type: 'text', - }, - }, -}; +const config = parseAWSExports(awsconfig); +if (!config.Auth) { + throw new Error('Auth config not found'); +} +// mock server endpoint for Detox e2es +config.Auth.Cognito.userPoolEndpoint = 'http://127.0.0.1:9091/'; +Amplify.configure(config); function App() { return ( @@ -62,7 +30,6 @@ function App() { ), }} - formFields={formFields} > diff --git a/examples/react-native/src/ui/components/authenticator/sign-up-with-email/Example.tsx b/examples/react-native/src/ui/components/authenticator/sign-up-with-email/Example.tsx index cc61a8d0149..d5606db0984 100644 --- a/examples/react-native/src/ui/components/authenticator/sign-up-with-email/Example.tsx +++ b/examples/react-native/src/ui/components/authenticator/sign-up-with-email/Example.tsx @@ -3,17 +3,20 @@ import { StyleSheet, View } from 'react-native'; import { Authenticator } from '@aws-amplify/ui-react-native'; import { Amplify } from 'aws-amplify'; +import { parseAWSExports } from '@aws-amplify/core/lib-esm/parseAWSExports'; import { I18n } from 'aws-amplify/utils'; import { translations } from '@aws-amplify/ui'; import { SignOutButton } from '../SignOutButton'; import awsconfig from './aws-exports'; -Amplify.configure({ - ...awsconfig, - // mock server endpoint for Detox e2es - Auth: { endpoint: 'http://127.0.0.1:9091/' }, -}); +const config = parseAWSExports(awsconfig); +if (!config.Auth) { + throw new Error('Auth config not found'); +} +// mock server endpoint for Detox e2es +config.Auth.Cognito.userPoolEndpoint = 'http://127.0.0.1:9091/'; +Amplify.configure(config); // @todo-migration remove cast I18n.putVocabularies(translations); diff --git a/examples/react-native/src/ui/components/authenticator/sign-up-with-phone/Example.tsx b/examples/react-native/src/ui/components/authenticator/sign-up-with-phone/Example.tsx index 92c3d5b2934..9931f4e91df 100644 --- a/examples/react-native/src/ui/components/authenticator/sign-up-with-phone/Example.tsx +++ b/examples/react-native/src/ui/components/authenticator/sign-up-with-phone/Example.tsx @@ -3,14 +3,18 @@ import { StyleSheet, View } from 'react-native'; import { Authenticator } from '@aws-amplify/ui-react-native'; import { Amplify } from 'aws-amplify'; +import { parseAWSExports } from '@aws-amplify/core/lib-esm/parseAWSExports'; import { SignOutButton } from '../SignOutButton'; import awsconfig from './aws-exports'; -Amplify.configure({ - ...awsconfig, - // mock server endpoint for Detox e2es - Auth: { endpoint: 'http://127.0.0.1:9091/' }, -}); + +const config = parseAWSExports(awsconfig); +if (!config.Auth) { + throw new Error('Auth config not found'); +} +// mock server endpoint for Detox e2es +config.Auth.Cognito.userPoolEndpoint = 'http://127.0.0.1:9091/'; +Amplify.configure(config); function App() { return ( diff --git a/examples/react-native/src/ui/components/authenticator/sign-up-with-username/Example.tsx b/examples/react-native/src/ui/components/authenticator/sign-up-with-username/Example.tsx index 92c3d5b2934..9931f4e91df 100644 --- a/examples/react-native/src/ui/components/authenticator/sign-up-with-username/Example.tsx +++ b/examples/react-native/src/ui/components/authenticator/sign-up-with-username/Example.tsx @@ -3,14 +3,18 @@ import { StyleSheet, View } from 'react-native'; import { Authenticator } from '@aws-amplify/ui-react-native'; import { Amplify } from 'aws-amplify'; +import { parseAWSExports } from '@aws-amplify/core/lib-esm/parseAWSExports'; import { SignOutButton } from '../SignOutButton'; import awsconfig from './aws-exports'; -Amplify.configure({ - ...awsconfig, - // mock server endpoint for Detox e2es - Auth: { endpoint: 'http://127.0.0.1:9091/' }, -}); + +const config = parseAWSExports(awsconfig); +if (!config.Auth) { + throw new Error('Auth config not found'); +} +// mock server endpoint for Detox e2es +config.Auth.Cognito.userPoolEndpoint = 'http://127.0.0.1:9091/'; +Amplify.configure(config); function App() { return ( diff --git a/packages/e2e/cypress/fixtures/AWSCognitoIdentityProviderService.ConfirmSignUp-invalid-code.json b/packages/e2e/cypress/fixtures/AWSCognitoIdentityProviderService.ConfirmSignUp-invalid-code.json index fa42c61b542..6b6a1f8461c 100644 --- a/packages/e2e/cypress/fixtures/AWSCognitoIdentityProviderService.ConfirmSignUp-invalid-code.json +++ b/packages/e2e/cypress/fixtures/AWSCognitoIdentityProviderService.ConfirmSignUp-invalid-code.json @@ -1,4 +1,4 @@ { - "__type": "UserNotFoundException", - "message": "Username/client id combination not found." + "__type": "CodeMismatchException", + "message": "Invalid verification code provided, please try again." } diff --git a/packages/e2e/detox/integration/common/authenticator.ts b/packages/e2e/detox/integration/common/authenticator.ts index d49ff0c1c44..0718b9800af 100644 --- a/packages/e2e/detox/integration/common/authenticator.ts +++ b/packages/e2e/detox/integration/common/authenticator.ts @@ -12,6 +12,16 @@ const getUserAlias = (status: string) => status === 'UNKNOWN' ? status + Date.now() : status }`; +const getInputByLoginMechanism = (loginMechanism: string) => { + if (loginMechanism === 'email') { + return `${process.env.USERNAME}+${Date.now()}@${process.env.DOMAIN}`; + } else if (loginMechanism === 'username') { + return `${process.env.USERNAME}+${Date.now()}`; + } else if (loginMechanism === 'phone number') { + return `+1${process.env.PHONE_NUMBER}`; + } +}; + const getCountryCode = (status: string) => { switch (status) { case 'CONFIRMED': @@ -124,7 +134,7 @@ When('I type an invalid no lower case new password', async () => { When('I type a new {string}', async (field: string) => { await typeInInputField( by.id(`${AUTHENTICATOR_TEXT_FIELD_TEST_ID_PREFIX}-${field}`), - `${Date.now()}` + getInputByLoginMechanism(field) ); }); diff --git a/packages/e2e/detox/mockServer.js b/packages/e2e/detox/mockServer.js index f5884a4c8cf..737c1645bc8 100644 --- a/packages/e2e/detox/mockServer.js +++ b/packages/e2e/detox/mockServer.js @@ -10,12 +10,18 @@ const server = app.listen(9091, '127.0.0.1', () => { ); }); -const errorMessage = { +const userNotFoundErrorMessage = { __type: 'UserNotFoundException', message: 'Username/client id combination not found.', error: true, }; +const invalidCodeErrorMessage = { + __type: 'CodeMismatchException', + message: 'Invalid verification code provided, please try again.', + error: true, +}; + const buildMockResponse = (header, body) => { switch (header) { case 'AWSCognitoIdentityProviderService.InitiateAuth': @@ -57,13 +63,24 @@ const buildMockResponse = (header, body) => { }; case 'AWSCognitoIdentityProviderService.ConfirmSignUp': if (body['ConfirmationCode'] === '0000') { - return errorMessage; + return invalidCodeErrorMessage; } else { return {}; } + case 'AWSCognitoIdentityProviderService.SignUp': + return { + CodeDeliveryDetails: { + AttributeName: 'email', + DeliveryMedium: 'EMAIL', + Destination: 'a***@e***.com', + }, + UserConfirmed: false, + UserSub: '••••••-••••-••••-••••-•••••••••••••', + }; + case 'AWSCognitoIdentityProviderService.ForgotPassword': if (body['Username'].includes('UNKNOWN')) { - return errorMessage; + return userNotFoundErrorMessage; } else { return {}; } diff --git a/packages/e2e/features/ui/components/authenticator/confirm-sign-up.feature b/packages/e2e/features/ui/components/authenticator/confirm-sign-up.feature index b3331e8ac97..8a60b5ba265 100644 --- a/packages/e2e/features/ui/components/authenticator/confirm-sign-up.feature +++ b/packages/e2e/features/ui/components/authenticator/confirm-sign-up.feature @@ -26,7 +26,6 @@ Feature: Confirm Sign Up Then I confirm my password Then I click the "Create Account" button Then I see "Confirmation Code" - Then I see "Your code is on the way. To log in, enter the code we sent you. It will take several minutes to arrive." @angular @react @vue @react-native Scenario: Confirm a new username & password with an invalid code @@ -38,8 +37,7 @@ Feature: Confirm Sign Up Then I type an invalid confirmation code Then I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ConfirmSignUp" } }' with error fixture "AWSCognitoIdentityProviderService.ConfirmSignUp-invalid-code" Then I click the "Confirm" button - # Not the actual error a real user would see because this is a test user with a mock API call - Then I see "Username/client id combination not found." + Then I see "Invalid verification code provided, please try again." @angular @react @vue @react-native Scenario: Confirm a new username & password with a valid code @@ -52,6 +50,7 @@ Feature: Confirm Sign Up Then I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.ConfirmSignUp" } }' with fixture "confirm-sign-up-with-email" Then I spy request '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth" } }' Then I click the "Confirm" button + Then I don't see "Confirmation Code" Then I confirm request '{"headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth" } }' @angular @react @vue diff --git a/packages/e2e/features/ui/components/authenticator/sign-up-with-username.feature b/packages/e2e/features/ui/components/authenticator/sign-up-with-username.feature index 743d934268f..1ebe8770317 100644 --- a/packages/e2e/features/ui/components/authenticator/sign-up-with-username.feature +++ b/packages/e2e/features/ui/components/authenticator/sign-up-with-username.feature @@ -25,17 +25,18 @@ Feature: Sign Up with Username Then I confirm my password Then I type my "email" with status "UNCONFIRMED" Then I click the "Create Account" button - Then I see "Your code is on the way" + Then I see "We Emailed You" Then I see "Confirmation Code" @react-native Scenario: Sign up a new username & password + # Note: For RN tests, mocking of "AWSCognitoIdentityProviderService.SignUp" is done with mockServer.js When I type a new "username" Then I type my password Then I confirm my password Then I type my "email" with status "UNCONFIRMED" Then I click the "Create Account" button - Then I see "Your code is on the way. To log in, enter the code we sent you. It may take a minute to arrive." + Then I see "We Emailed You" Then I see "Confirmation Code" @angular @react @vue