Skip to content

Commit 8b9ebfa

Browse files
authored
chore(test): added emailmfa attribute to first user sign up in test (#6141)
* changed mfa preference flow for verifying if we can set sms as preferred and forego selection of mfa type upon sign in * removed duplicate test and changed "because" clause of test * changed test text to properly reflect the flow of the test
1 parent 09c62c5 commit 8b9ebfa

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

packages/auth/amplify_auth_cognito/example/integration_test/mfa_sms_email_required_test.dart

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void main() {
6262
username: username,
6363
password: password,
6464
);
65+
6566
check(
6667
resignInRes.nextStep.signInStep,
6768
).equals(AuthSignInStep.confirmSignInWithOtpCode);
@@ -99,9 +100,18 @@ void main() {
99100
username: username,
100101
password: password,
101102
);
103+
102104
check(
103105
signInRes.nextStep.signInStep,
104-
because: 'MFA is required so Cognito automatically enables SMS MFA',
106+
because: 'MFA is required so Cognito will ask for MFA type',
107+
).equals(AuthSignInStep.continueSignInWithMfaSelection);
108+
109+
final selectMfaRes = await Amplify.Auth.confirmSignIn(
110+
confirmationValue: 'SMS',
111+
);
112+
113+
check(
114+
selectMfaRes.nextStep.signInStep,
105115
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);
106116

107117
final confirmRes = await Amplify.Auth.confirmSignIn(
@@ -215,9 +225,18 @@ void main() {
215225
username: username,
216226
password: password,
217227
);
228+
218229
check(
219230
signInRes.nextStep.signInStep,
220-
because: 'MFA is required so Cognito automatically enables SMS MFA',
231+
because: 'MFA is required so Cognito prompts MFA type selection',
232+
).equals(AuthSignInStep.continueSignInWithMfaSelection);
233+
234+
final selectMfaRes = await Amplify.Auth.confirmSignIn(
235+
confirmationValue: 'SMS',
236+
);
237+
238+
check(
239+
selectMfaRes.nextStep.signInStep,
221240
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);
222241

223242
final confirmRes = await Amplify.Auth.confirmSignIn(
@@ -227,44 +246,15 @@ void main() {
227246

228247
check(
229248
await cognitoPlugin.fetchMfaPreference(),
230-
because: 'MFA is required so Cognito automatically enables SMS MFA',
249+
because:
250+
'SMS MFA has been selected so Cognito fetches SMS as preferred',
231251
).equals(
232252
const UserMfaPreference(
233253
enabled: {MfaType.sms},
234254
preferred: MfaType.sms,
235255
),
236256
);
237257

238-
// Verify we can set SMS as preferred and forego selection.
239-
240-
{
241-
await signOutUser(assertComplete: true);
242-
243-
final mfaCode = await getOtpCode(UserAttribute.phone(phoneNumber));
244-
final signInRes = await Amplify.Auth.signIn(
245-
username: username,
246-
password: password,
247-
);
248-
check(
249-
signInRes.nextStep.signInStep,
250-
because: 'Preference is SMS MFA now',
251-
).equals(AuthSignInStep.confirmSignInWithSmsMfaCode);
252-
check(signInRes.nextStep.codeDeliveryDetails).isNotNull()
253-
..has(
254-
(d) => d.deliveryMedium,
255-
'deliveryMedium',
256-
).equals(DeliveryMedium.sms)
257-
..has(
258-
(d) => d.destination,
259-
'destination',
260-
).isNotNull().startsWith('+');
261-
262-
final confirmRes = await Amplify.Auth.confirmSignIn(
263-
confirmationValue: await mfaCode.code,
264-
);
265-
check(confirmRes.nextStep.signInStep).equals(AuthSignInStep.done);
266-
}
267-
268258
// Verify we can switch to EMAIL as preferred.
269259

270260
await cognitoPlugin.updateMfaPreference(email: MfaPreference.preferred);

0 commit comments

Comments
 (0)