@@ -39,10 +39,6 @@ void main() {
39
39
UnauthenticatedState .continueSignInWithEmailMfaSetup,
40
40
UnauthenticatedState .confirmSignInWithEmailMfaCode,
41
41
isA <AuthenticatedState >(),
42
- UnauthenticatedState .signIn,
43
- isA <ContinueSignInWithMfaSelection >(),
44
- UnauthenticatedState .confirmSignInWithTotpMfaCode,
45
- isA <AuthenticatedState >(),
46
42
emitsDone,
47
43
]),
48
44
);
@@ -62,7 +58,7 @@ void main() {
62
58
// And I click the "Sign in" button
63
59
await signInPage.submitSignIn ();
64
60
65
- // Then I will be redirected to the confirm email mfa page
61
+ // Then I will be redirected to the MFA setup selection page
66
62
await confirmSignInPage
67
63
.expectContinueSignInWithMfaSetupSelectionIsPresent ();
68
64
@@ -72,7 +68,7 @@ void main() {
72
68
// And I click the "Confirm" button
73
69
await confirmSignInPage.submitConfirmSignInMfaSetupSelection ();
74
70
75
- // Then I will be redirected to the EMAIL mfa setup page
71
+ // Then I will be redirected to the EMAIL MFA setup page
76
72
await emailMfaSetupPage.expectEmailMfaSetupIsPresent ();
77
73
78
74
// When I type a valid email
@@ -90,15 +86,44 @@ void main() {
90
86
// Then I see the authenticated app
91
87
await signInPage.expectAuthenticated ();
92
88
93
- // When I enable TOTP for MFA instead of the default set up by cognito (EMAIL)
94
- await setUpTotp ( );
89
+ await tester.bloc. close ();
90
+ } );
95
91
96
- // And I sign out using Auth.signOut()
97
- await Amplify .Auth .signOut ();
98
- await tester.pumpAndSettle ();
92
+ // Scenario: Select TOTP MFA to set up from the setup selection page
93
+ testWidgets ('can select TOTP MFA to set up' , (tester) async {
94
+ final username = env.generateUsername ();
95
+ final password = generatePassword ();
96
+ late String sharedSecret;
97
+
98
+ await adminCreateUser (
99
+ username,
100
+ password,
101
+ autoConfirm: true ,
102
+ verifyAttributes: false ,
103
+ autoFillAttributes: false ,
104
+ );
105
+
106
+ await loadAuthenticator (tester: tester);
107
+
108
+ tester.bloc.stream.listen ((event) {
109
+ if (event is ContinueSignInTotpSetup ) {
110
+ sharedSecret = event.totpSetupDetails.sharedSecret;
111
+ }
112
+ });
113
+
114
+ expect (
115
+ tester.bloc.stream,
116
+ emitsInOrder ([
117
+ UnauthenticatedState .signIn,
118
+ isA <ContinueSignInWithMfaSetupSelection >(),
119
+ isA <ContinueSignInTotpSetup >(),
120
+ isA <AuthenticatedState >(),
121
+ emitsDone,
122
+ ]),
123
+ );
99
124
100
- // Then I see the sign in page
101
- signInPage. expectUsername ( );
125
+ final signInPage = SignInPage (tester : tester);
126
+ final confirmSignInPage = ConfirmSignInPage (tester : tester );
102
127
103
128
// When I type my "username"
104
129
await signInPage.enterUsername (username);
@@ -109,22 +134,23 @@ void main() {
109
134
// And I click the "Sign in" button
110
135
await signInPage.submitSignIn ();
111
136
112
- // Then I will be redirected to the MFA selection page
113
- await confirmSignInPage.expectConfirmSignInMfaSelectionIsPresent ();
137
+ // Then I will be redirected to the MFA setup selection page
138
+ await confirmSignInPage
139
+ .expectContinueSignInWithMfaSetupSelectionIsPresent ();
114
140
115
141
// When I select "TOTP"
116
- await confirmSignInPage.selectMfaMethod (mfaMethod: MfaType .totp);
142
+ await confirmSignInPage.selectMfaSetupMethod (mfaMethod: MfaType .totp);
117
143
118
144
// And I click the "Confirm" button
119
- await confirmSignInPage.submitConfirmSignInMfaSelection ();
145
+ await confirmSignInPage.submitConfirmSignInMfaSetupSelection ();
120
146
121
- // Then I will be redirected to the TOTP MFA code page
122
- await confirmSignInPage.expectConfirmSignInWithTotpMfaCodeIsPresent ();
147
+ // Then I will be redirected to the TOTP MFA setup page
148
+ await confirmSignInPage.expectSignInTotpSetupIsPresent ();
123
149
124
- final code_2 = await generateTotpCode ();
150
+ final totpCode = await generateTotpCode (sharedSecret );
125
151
126
152
// When I type a valid TOTP code
127
- await confirmSignInPage.enterVerificationCode (code_2 );
153
+ await confirmSignInPage.enterVerificationCode (totpCode );
128
154
129
155
// And I click the "Confirm" button
130
156
await confirmSignInPage.submitConfirmSignIn ();
@@ -135,8 +161,8 @@ void main() {
135
161
await tester.bloc.close ();
136
162
});
137
163
138
- // Scenario: Sign in using a EMAIL code when both EMAIL and TOTP are enabled
139
- testWidgets ('can select TOTP MFA to set up ' , (tester) async {
164
+ // Scenario: Sign in using an invalid TOTP code
165
+ testWidgets ('sign in with invalid TOTP code ' , (tester) async {
140
166
final username = env.generateUsername ();
141
167
final password = generatePassword ();
142
168
late String sharedSecret;
@@ -166,7 +192,6 @@ void main() {
166
192
isA <AuthenticatedState >(),
167
193
UnauthenticatedState .signIn,
168
194
UnauthenticatedState .confirmSignInWithTotpMfaCode,
169
- isA <AuthenticatedState >(),
170
195
emitsDone,
171
196
]),
172
197
);
@@ -183,7 +208,7 @@ void main() {
183
208
// And I click the "Sign in" button
184
209
await signInPage.submitSignIn ();
185
210
186
- // Then I will be redirected to the confirm email mfa page
211
+ // Then I will be redirected to the MFA setup selection page
187
212
await confirmSignInPage
188
213
.expectContinueSignInWithMfaSetupSelectionIsPresent ();
189
214
@@ -193,12 +218,12 @@ void main() {
193
218
// And I click the "Confirm" button
194
219
await confirmSignInPage.submitConfirmSignInMfaSetupSelection ();
195
220
196
- // Then I will be redirected to the TOTP mfa setup page
221
+ // Then I will be redirected to the TOTP MFA setup page
197
222
await confirmSignInPage.expectSignInTotpSetupIsPresent ();
198
223
199
224
final totpCode = await generateTotpCode (sharedSecret);
200
225
201
- // And I type a valid TOTP code
226
+ // When I type a valid TOTP code
202
227
await confirmSignInPage.enterVerificationCode (totpCode);
203
228
204
229
// And I click the "Confirm" button
@@ -207,35 +232,27 @@ void main() {
207
232
// Then I see the authenticated app
208
233
await signInPage.expectAuthenticated ();
209
234
210
- // And I sign out using Auth.signOut()
235
+ // Sign out to test invalid TOTP code during sign-in
211
236
await Amplify .Auth .signOut ();
212
237
await tester.pumpAndSettle ();
213
238
214
- // Then I see the sign in page
215
- signInPage.expectUsername ();
216
-
217
- // When I type my "username"
239
+ // When I attempt to sign in again
218
240
await signInPage.enterUsername (username);
219
-
220
- // And I type my password
221
241
await signInPage.enterPassword (password);
222
-
223
- // And I click the "Sign in" button
224
242
await signInPage.submitSignIn ();
225
243
226
244
// Then I will be redirected to the TOTP MFA code page
227
- await confirmSignInPage.expectConfirmSignInWithTotpMfaCodeIsPresent ();
245
+ await confirmSignInPage
246
+ .expectConfirmSignInWithTotpMfaCodeIsPresent ();
228
247
229
- final code_2 = await generateTotpCode (sharedSecret);
230
-
231
- // When I type a valid TOTP code
232
- await confirmSignInPage.enterVerificationCode (code_2);
248
+ // When I type an invalid TOTP code
249
+ await confirmSignInPage.enterVerificationCode ('000000' );
233
250
234
251
// And I click the "Confirm" button
235
252
await confirmSignInPage.submitConfirmSignIn ();
236
253
237
- // Then I see the authenticated app
238
- await signInPage. expectAuthenticated ();
254
+ // Then I see "Invalid code" error message
255
+ confirmSignInPage. expectInvalidVerificationCode ();
239
256
240
257
await tester.bloc.close ();
241
258
});
0 commit comments