Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 2 additions & 78 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thank you for your interest in contributing to our project! <3 Whether it's a bu
- [Our Design](#our-design)
- [Development Process](#development-process)
- [Setting up for local development](#setting-up-for-local-development)
- [Packages inside Amplify Flutter](#packages-inside-amplify-flutter)
- [Packages inside Amplify Flutter](#packages-inside-amplify-flutter)
- [Steps towards contributions](#steps-towards-contributions)
- [Pull Requests](#pull-requests)
- [Release](#release)
Expand Down Expand Up @@ -164,6 +164,7 @@ $ melos run test:unit:flutter
```

or run all unit tests for a given platform

```bash
$ melos run test:unit:android
$ melos run test:unit:ios
Expand Down Expand Up @@ -221,83 +222,6 @@ $ melos run provision_integration_test_resources
Note: you will need to have [`jq`](https://github.com/stedolan/jq) installed, which you can install by running `brew install jq`.
The provisioning script uses the [Amplify CLI headless mode](https://docs.amplify.aws/cli/usage/headless).

The auth tests require some additional configuration to support lambda triggers for automatically
verifying temporary test users. Note that this should only be done for the test environment, never a production one. This can be done manually by [following this process](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html#aws-lambda-triggers-pre-registration-example-2) or by following these instructions for the amplify CLI:

```
$ cd packages/amplify_auth_cognito/example
$ amplify update auth
Please note that certain attributes may not be overwritten if you choose to use defaults settings.
Using service: Cognito, provided by: awscloudformation
What do you want to do?
Walk-through all the auth configurations
Select the authentication/authorization services that you want to use:
User Sign-Up, Sign-In, connected with AWS IAM controls ( Enables per-user Storage features for images or other content, Analytics, and more)
Please enter a name for your identity pool.
authintegrationtest
Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM)
No
Do you want to enable 3rd party authentication providers in your identity pool?
No
Do you want to add User Pool Groups?
No
Do you want to add an admin queries API?
No
Multi-factor authentication (MFA) user login options:
OFF
Email based user registration/forgot password:
Enabled (Requires per-user email entry at registration)
Please specify an email verification subject:
Your verification code
Please specify an email verification message:
Your verification code is {####}
Do you want to override the default password policy for this User Pool?
No
Specify the app's refresh token expiration period (in days):
30
Do you want to specify the user attributes this app can read and write?
No
Do you want to enable any of the following capabilities?
Do you want to use an OAuth flow?
No
? Do you want to configure Lambda Triggers for Cognito?
Yes
? Which triggers do you want to enable for Cognito
Pre Sign-up
? What functionality do you want to use for Pre Sign-up
Create your own module
Successfully added resource authintegrationtestPreSignup locally.
```

When prompted to edit the function now, choose "yes" and add the following code to the `custom.js` file
created by the amplify CLI, from [documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html#aws-lambda-triggers-pre-registration-example-2).

```js
exports.handler = async event => {
// Confirm the user
event.response.autoConfirmUser = true;

// Set the email as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("email")) {
event.response.autoVerifyEmail = true;
}

// Set the phone number as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("phone_number")) {
event.response.autoVerifyPhone = true;
}

// Return to Amazon Cognito
return event;
};
```

Finally, run a push to update the resources with the new function resource (lambda trigger):

```bash
$ amplify push
```

Additionally, the storage category requires some manual configuration as the [headless CLI does not yet support storage](https://github.com/aws-amplify/amplify-cli/issues/7378). Those instructions
are notes in the [storage example app](packages/amplify_storage_s3/example/README.md).

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_auth_cognito/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
**/adminCreateUser.zip

# IntelliJ related
*.iml
Expand Down Expand Up @@ -49,7 +50,6 @@ amplify/.config/local-*
amplify/logs
amplify/mock-data
amplify/backend/amplify-meta.json
amplify/backend/awscloudformation
amplify/backend/.temp
build/
dist/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ void main() {
}, skip: !Platform.isIOS);

group('deleteUser (Android)', () {
setUpAll(() async {
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);
await signOutUser();
});
testWidgets('should throw an UnimplementedError on Android',
(WidgetTester tester) async {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -30,16 +32,17 @@ void main() {

group('fetchSession', () {
setUpAll(() async {
await configureAuth();
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);

// create one user for all tests
await Amplify.Auth.signUp(
username: username,
password: password,
options: CognitoSignUpOptions(userAttributes: {
CognitoUserAttributeKey.email: generateEmail(),
CognitoUserAttributeKey.phoneNumber: mockPhoneNumber
}));
// create one confirmed user for all tests
await adminCreateUser(
username,
password,
autoConfirm: true,
verifyAttributes: true,
);
});

// sign in prior to each test
Expand Down Expand Up @@ -78,7 +81,7 @@ void main() {
testWidgets('should return isSignedIn as false if the user is signed out',
(WidgetTester tester) async {
await Amplify.Auth.signOut();
var res = await Amplify.Auth.fetchAuthSession() as CognitoAuthSession;
var res = await Amplify.Auth.fetchAuthSession();
expect(res.isSignedIn, isFalse);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -30,16 +32,17 @@ void main() {

group('getCurrentUser', () {
setUpAll(() async {
await configureAuth();
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);

// create one user for all tests
await Amplify.Auth.signUp(
username: username,
password: password,
options: CognitoSignUpOptions(userAttributes: {
CognitoUserAttributeKey.email: generateEmail(),
CognitoUserAttributeKey.phoneNumber: mockPhoneNumber
}));
await adminCreateUser(
username,
password,
autoConfirm: true,
verifyAttributes: true,
);
});

// sign in prior to each test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,37 @@ void main() {
'should broadcast events for deleteUser',
(WidgetTester tester) async {
// setup
var nextEvent;
var signinEvent;
var deleteEvent;
var signoutEvent;
var event;
var eventCount = 0;
var authEventStream = Amplify.Hub.availableStreams[HubChannel.Auth]!;
authEventStream.listen((event) => eventCount++);

// assert sign in event is broadcast
nextEvent = authEventStream.first;
signinEvent =
authEventStream.firstWhere((el) => el.eventName == 'SIGNED_IN');
deleteEvent =
authEventStream.firstWhere((el) => el.eventName == 'USER_DELETED');
signoutEvent =
authEventStream.firstWhere((el) => el.eventName == 'SIGNED_OUT');

await Amplify.Auth.signIn(
username: username,
password: password,
);
event = await nextEvent;
expect(event.eventName, 'SIGNED_IN');
var event1 = await signinEvent;
expect(event1.eventName, 'SIGNED_IN');

// assert signed out event is broadcast
nextEvent = authEventStream.first;
await Amplify.Auth.deleteUser();
event = await nextEvent;
expect(event.eventName, 'SIGNED_OUT');
var event2 = await signoutEvent;
var event3 = await deleteEvent;
expect(event2.eventName, 'SIGNED_OUT');

// assert delete user event is broadcast
nextEvent = authEventStream.first;
event = await nextEvent;
expect(event.eventName, 'USER_DELETED');
expect(event3.eventName, 'USER_DELETED');

// assert 3 total events are broadcast
expect(eventCount, 3);
},
skip: !Platform.isIOS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ void main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('amplify_auth_cognito', () {
setUpAll(() async {
final authPlugin = AmplifyAuthCognito();
await Amplify.addPlugins([authPlugin]);
await Amplify.configure(amplifyconfig);
});

sign_in_sign_out_tests.main();
sign_up_tests.main();
user_attributes_tests.main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -23,24 +25,24 @@ import 'utils/setup_utils.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

late String username;
late String password;
group('signIn', () {
late String username;
late String password;
setUp(() async {
await configureAuth();
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);

// create new user for each test
username = generateUsername();
password = generatePassword();

await Amplify.Auth.signUp(
username: username,
password: password,
options: CognitoSignUpOptions(userAttributes: {
CognitoUserAttributeKey.email: generateEmail(),
CognitoUserAttributeKey.phoneNumber: mockPhoneNumber
}));
await adminCreateUser(
username,
password,
autoConfirm: true,
verifyAttributes: true,
);

await signOutUser();
});
Expand Down Expand Up @@ -99,17 +101,6 @@ void main() {
});

testWidgets('should sign a user out', (WidgetTester tester) async {
// sign up user
final username = generateUsername();
final password = generatePassword();
await Amplify.Auth.signUp(
username: username,
password: password,
options: CognitoSignUpOptions(userAttributes: {
CognitoUserAttributeKey.email: generateEmail(),
CognitoUserAttributeKey.phoneNumber: mockPhoneNumber
}));

// Ensure signed in before testing signOut.
await Amplify.Auth.signIn(username: username, password: password);
final authSession = await Amplify.Auth.fetchAuthSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* permissions and limitations under the License.
*/

import 'package:amplify_api/amplify_api.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -26,7 +27,9 @@ void main() {

group('signUp', () {
setUpAll(() async {
await configureAuth();
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);
await signOutUser();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -29,20 +31,21 @@ void main() {

group('updatePassword', () {
setUpAll(() async {
await configureAuth();
await configureAuth(additionalPlugins: [
AmplifyAPI(),
]);
});

setUp(() async {
// create new user for each test
username = generateUsername();
password = generatePassword();
await Amplify.Auth.signUp(
username: username,
password: password,
options: CognitoSignUpOptions(userAttributes: {
CognitoUserAttributeKey.email: generateEmail(),
CognitoUserAttributeKey.phoneNumber: mockPhoneNumber
}));
await adminCreateUser(
username,
password,
autoConfirm: true,
verifyAttributes: true,
);

await signOutUser();
// sign in with current password
Expand Down
Loading