@@ -27,59 +27,110 @@ void main() {
27
27
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
28
28
late String username;
29
29
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
+ });
34
36
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
+ });
45
55
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
+ },
51
78
);
52
- });
53
79
54
- testWidgets ('signIn should return data from the auth challenge lambda' ,
80
+ testWidgets (
81
+ 'signIn should return data from the auth challenge lambda' ,
55
82
(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
+ },
59
101
);
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
- });
65
102
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' ,
67
105
(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
+ );
73
120
74
- testWidgets (
121
+ testWidgets (
75
122
'an incorrect challenge reply should throw a NotAuthorizedException' ,
76
123
(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
+ },
82
133
);
83
- });
84
- } );
134
+ },
135
+ );
85
136
}
0 commit comments