Skip to content

Commit 3d75358

Browse files
haverchuckDustin Noyesdnys1
authored
test(auth): test for unconfirmed user with customn auth (#1584)
Co-authored-by: Dustin Noyes <[email protected]> Co-authored-by: Dillon Nys <[email protected]>
1 parent 5c6d8ea commit 3d75358

File tree

1 file changed

+94
-43
lines changed

1 file changed

+94
-43
lines changed

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

Lines changed: 94 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,110 @@ void main() {
2727
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
2828
late String username;
2929
late String password;
30-
group('custom auth passwordless signIn', () {
31-
setUp(() async {
32-
await signOutUser();
33-
});
30+
group(
31+
'custom auth passwordless signIn',
32+
() {
33+
setUp(() async {
34+
await signOutUser();
35+
});
3436

35-
setUpAll(() async {
36-
await configureAuth(
37-
additionalPlugins: [
38-
AmplifyAPI(),
39-
],
40-
customAuth: true,
41-
);
42-
// create new user for each test
43-
username = generateUsername();
44-
password = generatePassword();
37+
setUpAll(() async {
38+
await configureAuth(
39+
additionalPlugins: [
40+
AmplifyAPI(),
41+
],
42+
customAuth: true,
43+
);
44+
// create new user for each test
45+
username = generateUsername();
46+
password = generatePassword();
47+
48+
await adminCreateUser(
49+
username,
50+
password,
51+
autoConfirm: true,
52+
verifyAttributes: true,
53+
);
54+
});
4555

46-
await adminCreateUser(
47-
username,
48-
password,
49-
autoConfirm: true,
50-
verifyAttributes: true,
56+
testWidgets(
57+
'Unconfirmed user sign in throws UserNotConfirmedException (even when password not verified)',
58+
(WidgetTester tester) async {
59+
var unconfirmedUsername = '${generateUsername()}unconfirmedUSer';
60+
await Amplify.Auth.signUp(
61+
username: unconfirmedUsername,
62+
password: password,
63+
options: CognitoSignUpOptions(
64+
userAttributes: {
65+
CognitoUserAttributeKey.email: '[email protected]',
66+
CognitoUserAttributeKey.phoneNumber: '+15555555555',
67+
},
68+
),
69+
);
70+
71+
expect(
72+
Amplify.Auth.signIn(username: unconfirmedUsername, password: null),
73+
throwsA(
74+
isA<UserNotConfirmedException>(),
75+
),
76+
);
77+
},
5178
);
52-
});
5379

54-
testWidgets('signIn should return data from the auth challenge lambda',
80+
testWidgets(
81+
'signIn should return data from the auth challenge lambda',
5582
(WidgetTester tester) async {
56-
final res = await Amplify.Auth.signIn(
57-
username: username,
58-
password: null,
83+
final res = await Amplify.Auth.signIn(
84+
username: username,
85+
password: null,
86+
);
87+
expect(
88+
res.isSignedIn,
89+
false,
90+
);
91+
// additionalInfo key values defined in lambda code
92+
expect(
93+
res.nextStep!.additionalInfo?['test-key'],
94+
'test-value',
95+
);
96+
expect(
97+
res.nextStep?.signInStep,
98+
'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE',
99+
);
100+
},
59101
);
60-
expect(res.isSignedIn, false);
61-
// additionalInfo key values defined in lambda code
62-
expect(res.nextStep!.additionalInfo?['test-key'], 'test-value');
63-
expect(res.nextStep?.signInStep, 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE');
64-
});
65102

66-
testWidgets('a correct challenge reply should sign in the user in',
103+
testWidgets(
104+
'a correct challenge reply should sign in the user in',
67105
(WidgetTester tester) async {
68-
await Amplify.Auth.signIn(username: username, password: null);
69-
// '123' is the arbitrary challenge answer defined in lambda code
70-
final res = await Amplify.Auth.confirmSignIn(confirmationValue: '123');
71-
expect(res.isSignedIn, true);
72-
});
106+
await Amplify.Auth.signIn(
107+
username: username,
108+
password: null,
109+
);
110+
// '123' is the arbitrary challenge answer defined in lambda code
111+
final res = await Amplify.Auth.confirmSignIn(
112+
confirmationValue: '123',
113+
);
114+
expect(
115+
res.isSignedIn,
116+
true,
117+
);
118+
},
119+
);
73120

74-
testWidgets(
121+
testWidgets(
75122
'an incorrect challenge reply should throw a NotAuthorizedException',
76123
(WidgetTester tester) async {
77-
await Amplify.Auth.signIn(username: username, password: null);
78-
// '123' is the arbitrary challenge answer defined in lambda code
79-
expect(
80-
Amplify.Auth.confirmSignIn(confirmationValue: 'wrong'),
81-
throwsA(isA<NotAuthorizedException>()),
124+
await Amplify.Auth.signIn(username: username, password: null);
125+
// '123' is the arbitrary challenge answer defined in lambda code
126+
expect(
127+
Amplify.Auth.confirmSignIn(confirmationValue: 'wrong'),
128+
throwsA(
129+
isA<NotAuthorizedException>(),
130+
),
131+
);
132+
},
82133
);
83-
});
84-
});
134+
},
135+
);
85136
}

0 commit comments

Comments
 (0)