-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(auth): handle missing or empty signUpOptions (#627)
* handle missing or empty signUpOptions * add android unit test * fix iOS tests * add integration tests for auth.signUp * remove unused imports, formatting * update auth category after NS changes * update unit test for NS changes * address PR comments * remove extra parens * Apply SignUpRequest changes from code review
- Loading branch information
1 parent
ca35915
commit abc22aa
Showing
13 changed files
with
233 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,39 @@ class AmplifyAuthCognitoPluginTest { | |
verify(mockResult, times(1)).success(res); | ||
} | ||
|
||
@Test | ||
fun signUpNoOptions_returnsSuccess() { | ||
// Arrange | ||
doAnswer { invocation: InvocationOnMock -> | ||
plugin.prepareSignUpResult(mockResult, mockSignUpResult) | ||
null as Void? | ||
}.`when`(mockAuth).signUp(anyString(), anyString(), any(AuthSignUpOptions::class.java), ArgumentMatchers.any<Consumer<AuthSignUpResult>>(), ArgumentMatchers.any<Consumer<AuthException>>()) | ||
|
||
val data: HashMap<*, *> = hashMapOf( | ||
"username" to "[email protected]", | ||
"password" to "testPassword" | ||
) | ||
val arguments = hashMapOf("data" to data) | ||
val call = MethodCall("signUp", arguments) | ||
val res = mapOf( | ||
"isSignUpComplete" to false, | ||
"nextStep" to mapOf( | ||
"signUpStep" to "CONFIRM_SIGN_UP_STEP", | ||
"codeDeliveryDetails" to mapOf( | ||
"destination" to "[email protected]", | ||
"deliveryMedium" to AuthCodeDeliveryDetails.DeliveryMedium.EMAIL.name, | ||
"attributeName" to "email" | ||
) | ||
) | ||
) | ||
|
||
// Act | ||
plugin.onMethodCall(call, mockResult) | ||
|
||
// Assert | ||
verify(mockResult, times(1)).success(res); | ||
} | ||
|
||
@Test | ||
fun confirmSignUpWithoutOptions_returnsSuccess() { | ||
// Arrange | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/amplify_auth_cognito/example/integration_test/sign_up_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:amplify_flutter/amplify.dart'; | ||
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; | ||
|
||
import 'utils/mock_data.dart'; | ||
import 'utils/setup_utils.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('signUp', () { | ||
setUpAll(() async { | ||
await configureAuth(); | ||
await signOutUser(); | ||
}); | ||
|
||
testWidgets('should signUp a user with valid parameters', | ||
(WidgetTester tester) async { | ||
final username = generateUsername(); | ||
final password = generatePassword(); | ||
|
||
var res = await Amplify.Auth.signUp( | ||
username: username, | ||
password: password, | ||
options: CognitoSignUpOptions(userAttributes: { | ||
'email': generateEmail(), | ||
'phone_number': mockPhoneNumber | ||
})); | ||
// should be uncommented when https://github.com/aws-amplify/amplify-flutter/issues/581 is closed | ||
// currently this just confirms there is no error thrown | ||
// expect(res.isSignUpComplete, true); | ||
}); | ||
|
||
testWidgets( | ||
'should throw an InvalidParameterException without required attributes', | ||
(WidgetTester tester) async { | ||
final username = generateUsername(); | ||
final password = generatePassword(); | ||
try { | ||
await Amplify.Auth.signUp(username: username, password: password); | ||
} catch (e) { | ||
expect(e, TypeMatcher<InvalidParameterException>()); | ||
return; | ||
} | ||
throw Exception('Expected InvalidParameterException'); | ||
}); | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/amplify_auth_cognito/example/integration_test/utils/mock_data.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:uuid/uuid.dart'; | ||
|
||
final uuid = Uuid(); | ||
|
||
final String mockPhoneNumber = '+15555551234'; | ||
|
||
String generateEmail() => | ||
'test-amplify-flutter-${uuid.v4()}@test${uuid.v4()}.com'; | ||
|
||
String generatePassword() => uuid.v4(); | ||
|
||
String generateUsername() => 'TEMP_USER-${uuid.v4()}'; |
21 changes: 21 additions & 0 deletions
21
packages/amplify_auth_cognito/example/integration_test/utils/setup_utils.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; | ||
import 'package:amplify_auth_cognito_example/amplifyconfiguration.dart'; | ||
import 'package:amplify_flutter/amplify.dart'; | ||
|
||
Future<void> configureAuth() async { | ||
if (!Amplify.isConfigured) { | ||
final authPlugin = AmplifyAuthCognito(); | ||
await Amplify.addPlugins([authPlugin]); | ||
await Amplify.configure(amplifyconfig); | ||
} | ||
} | ||
|
||
// ensure no user is currently signed in | ||
Future<void> signOutUser() async { | ||
try { | ||
await Amplify.Auth.signOut(); | ||
// ignore: unused_catch_clause | ||
} on AuthException catch (e) { | ||
// Ignore a signOut error because we only care when someone signed in. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.