Skip to content

Commit 1085cf9

Browse files
authored
test(api): Updated the API plugin test with instructions (#1751)
1 parent 556d982 commit 1085cf9

File tree

6 files changed

+183
-124
lines changed

6 files changed

+183
-124
lines changed

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithIAMIntegrationTests/README.md

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
44

55
### Set-up
66

7+
Latest tested with amplify CLI version 8.0.1 `amplify -v`
8+
79
1. `amplify init`
810

911
2. `amplify add api`
@@ -19,46 +21,86 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
1921

2022
3. `amplify add auth`
2123
```perl
22-
? Do you want to use the default authentication and security configuration? `Default configuration`
23-
? How do you want users to be able to sign in? `Username`
24-
? Do you want to configure advanced settings? `No, I am done.`
24+
Do you want to use the default authentication and security configuration?
25+
Manual configuration
26+
Select the authentication/authorization services that you want to use:
27+
User Sign-Up, Sign-In, connected with AWS IAM controls (Enables ...)
28+
Please provide a friendly name for your resource that will be used to label this category in the project:
29+
<amplifyintegtest>
30+
Please enter a name for your identity pool.
31+
<amplifyintegtestCIDP>
32+
Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM)
33+
Yes
34+
Do you want to enable 3rd party authentication providers in your identity pool?
35+
No
36+
Please provide a name for your user pool:
37+
<amplifyintegCUP>
38+
39+
How do you want users to be able to sign in?
40+
Username
41+
Do you want to add User Pool Groups?
42+
No
43+
Do you want to add an admin queries API?
44+
Yes
45+
? Do you want to restrict access to the admin queries API to a specific Group
46+
No
47+
Multifactor authentication (MFA) user login options:
48+
OFF
49+
50+
Email based user registration/forgot password:
51+
Enabled (Requires per-user email entry at registration)
52+
Please specify an email verification subject:
53+
Your verification code
54+
Please specify an email verification message:
55+
Your verification code is {####}
56+
Do you want to override the default password policy for this User Pool?
57+
No
58+
59+
What attributes are required for signing up?
60+
(Press Space to deselect Email, if selected, then press Enter with none selected)
61+
Specify the app's refresh token expiration period (in days):
62+
30
63+
Do you want to specify the user attributes this app can read and write?
64+
No
65+
Do you want to enable any of the following capabilities?
66+
(press Enter with none selected)
67+
Do you want to use an OAuth flow?
68+
No
69+
? Do you want to configure Lambda Triggers for Cognito?
70+
Yes
71+
? Which triggers do you want to enable for Cognito
72+
Pre Sign-up
73+
[Choose as many that you would like to manually verify later]
74+
? What functionality do you want to use for Pre Sign-up
75+
Create your own module
76+
Succesfully added the Lambda function locally
77+
? Do you want to edit your custom function now? Yes
78+
Please edit the file in your editor:
2579
```
2680
27-
4. `amplify push`
81+
For Pre Sign-up lambda
2882
29-
5. Copy `amplifyconfiguration.json` over as `GraphQLWithIAMIntegrationTests-amplifyconfiguration.json` to `~/.aws-amplify/amplify-ios/testconfiguration/`
83+
```
84+
exports.handler = (event) => {
85+
event.response.autoConfirmUser = true;
86+
};
87+
```
3088
31-
6. `amplify console auth` and choose `Identity Pool`. Click on **Edit Identity pool** and make note of IAM Role that is assigned for the Authenticated role.
89+
Continue in the terminal;
3290
33-
7. Click on `Unauthenticated identities` and check off *Enable access to unauthenticated identities*, and Save Changes. This will allow users that are using the app but are not signed in to assume the unauthenticated role when making calls to the API.
91+
```
92+
? Press enter to continue
93+
Successfully added resource amplifyintegtest locally
94+
```
3495
35-
8. Navigate to [AWS IAM Console](https://console.aws.amazon.com/iam/home) and select Roles, find the role attached to the Identity Pool's Authenticated role.
96+
4. If you are using the latest CLI, update cli.json to include `"useExperimentalPipelinedTransformer": false` to ensure that it will use the v1 transformer and then `amplify push`
3697
37-
9. Click on Attach Policies, choose **AWSAppSyncInvokeFullAccess**, and attach the policy. This will allow users that are signed into the app to have access to invoke AppSync APIs.
98+
5. Copy `amplifyconfiguration.json` over as `GraphQLWithIAMIntegrationTests-amplifyconfiguration.json` to `~/.aws-amplify/amplify-ios/testconfiguration/`
3899
39-
10. Create `GraphQLWithIAMIntegrationTests-credentials.json` inside `~/.aws-amplify/amplify-ios/testconfiguration/` with a json object containing `username`, and `password`, used to create the cognito user in the userpool.
100+
6. `amplify console auth` and choose `Identity Pool`. Click on **Edit Identity pool** and make note of IAM Role that is assigned for the Authenticated role.
40101
41-
```json
42-
{
43-
"username": "[USERNAME]",
44-
"password": "[PASSWORD]"
45-
}
46-
```
102+
7. Navigate to [AWS IAM Console](https://console.aws.amazon.com/iam/home) and select Roles, find the role attached to the Identity Pool's Authenticated role.
47103

48-
11. Create a new users in the userpool. First, retrieve the Cognito User Pool's Pool Id, you can find this in `amplifyconfiguration.json` under
49-
```
50-
"CognitoUserPool": {
51-
"Default": {
52-
"PoolId": "[POOL_ID]",
53-
```
54-
Run the `admin-create-user` command to create a new user
55-
```
56-
aws cognito-idp admin-create-user --user-pool-id [POOL_ID] --username [USERNAME]
57-
```
58-
Run the `admin-set-user-password` command to confirm the user
59-
```
60-
aws cognito-idp admin-set-user-password --user-pool-id [POOL_ID] --username [USERNAME] --password [PASSWORD] --permanent
61-
```
62-
See https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/index.html#cli-aws-cognito-idp for more details using AWS CLI.
104+
8. Click on Attach Policies, choose **AWSAppSyncInvokeFullAccess**, and attach the policy. This will allow users that are signed into the app to have access to invoke AppSync APIs.
63105

64106
You can now run the tests!

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithLambdaAuthIntegrationTests/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
44

55
### Set-up
66

7+
Latest tested with amplify CLI version 8.0.1 `amplify -v`
8+
79
1. `amplify init`
810

911
2. `amplify add api`
@@ -17,7 +19,7 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
1719
? Choose a schema template: `Single object with fields (e.g., “Todo” with ID, name, description)`
1820
```
1921

20-
3. `amplify push`
22+
3. If you are using the latest CLI, update cli.json to include `"useExperimentalPipelinedTransformer": false` to ensure that it will use the v1 transformer and then `amplify push`
2123

2224
4. Copy `amplifyconfiguration.json` over as `GraphQLWithLambdaAuthIntegrationTests-amplifyconfiguration.json` inside `~/.aws-amplify/amplify-ios/testconfiguration/`
2325
5. Replace the authorization type `API_KEY` with `AWS_LAMBDA` in `GraphQLWithLambdaAuthIntegrationTests-amplifyconfiguration.json`

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithUserPoolIntegrationTests/AuthDirective/GraphQLAuthDirectiveIntegrationTests.swift

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,25 @@ class GraphQLAuthDirectiveIntegrationTests: XCTestCase {
2020
let password: String
2121
}
2222

23-
let amplifyConfigurationFile = "testconfiguration/GraphQLAuthDirectiveIntegrationTests-amplifyconfiguration"
24-
let credentialsFile = "testconfiguration/GraphQLAuthDirectiveIntegrationTests-credentials"
23+
let amplifyConfigurationFile = "testconfiguration/GraphQLWithUserPoolIntegrationTests-amplifyconfiguration"
2524
var user1: User!
2625
var user2: User!
2726

2827
override func setUp() {
2928
do {
30-
let credentials = try TestConfigHelper.retrieveCredentials(forResource: credentialsFile)
31-
32-
guard let user1 = credentials["user1"],
33-
let user2 = credentials["user2"],
34-
let passwordUser1 = credentials["passwordUser1"],
35-
let passwordUser2 = credentials["passwordUser2"] else {
36-
XCTFail("Missing credentials.json data")
37-
return
38-
}
39-
40-
self.user1 = User(username: user1, password: passwordUser1)
41-
self.user2 = User(username: user2, password: passwordUser2)
42-
29+
user1 = User(username: "integTest\(UUID().uuidString)", password: "P123@\(UUID().uuidString)")
30+
user2 = User(username: "integTest\(UUID().uuidString)", password: "P123@\(UUID().uuidString)")
4331
try Amplify.add(plugin: AWSAPIPlugin())
4432
try Amplify.add(plugin: AWSCognitoAuthPlugin())
4533
let amplifyConfig = try TestConfigHelper.retrieveAmplifyConfiguration(forResource: amplifyConfigurationFile)
4634
try Amplify.configure(amplifyConfig)
4735

36+
AuthSignInHelper.signUpUser(username: user1.username,
37+
password: user1.password,
38+
email: "\(user1.username)@\(UUID().uuidString).com") { _, _ in }
39+
AuthSignInHelper.signUpUser(username: user2.username,
40+
password: user2.password,
41+
email: "\(user2.username)@\(UUID().uuidString).com") { _, _ in }
4842
ModelRegistry.register(modelType: SocialNote.self)
4943
} catch {
5044
XCTFail("Error during setup: \(error)")

AmplifyPlugins/API/AWSAPICategoryPluginIntegrationTests/GraphQL/GraphQLWithUserPoolIntegrationTests/README.md

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
44

55
### Set-up
66

7+
Latest tested with amplify CLI version 8.0.1 `amplify -v`
8+
79
* Note that these integration tests are only compatible with the V1 Transformer. *
810

911
1. `amplify init`
@@ -14,31 +16,7 @@ The following steps demonstrate how to set up an GraphQL endpoint with AppSync.
1416
? Please select from one of the below mentioned services: GraphQL
1517
? Provide API name: `<APIName>`
1618
? Choose the default authorization type for the API `Amazon Cognito User Pool`
17-
? Do you want to use the default authentication and security configuration? `Default configuration`
18-
? How do you want users to be able to sign in? `Email`
19-
? Do you want to configure advanced settings? `No, I am done.`
20-
? Do you want to configure advanced settings for the GraphQL API `No, I am done.`
21-
? Do you have an annotated GraphQL schema? `No`
22-
? Do you want a guided schema creation? `Yes`
23-
? What best describes your project: `Single object with fields (e.g., “Todo” with ID, name, description)`
24-
? Do you want to edit the schema now? `No`
25-
```
26-
27-
The guided schema provided should look like this:
28-
```json
29-
type Todo @model {
30-
id: ID!
31-
name: String!
32-
description: String
33-
}
34-
```
35-
36-
3. Some of the tests rely on the Auth plugin to be setup as a prerequisite
37-
38-
`amplify add auth`
39-
40-
```
41-
Do you want to use the default authentication and security configuration?
19+
? Do you want to use the default authentication and security configuration?
4220
Manual configuration
4321
Select the authentication/authorization services that you want to use:
4422
User Sign-Up, Sign-In, connected with AWS IAM controls (Enables ...)
@@ -47,7 +25,7 @@ Please provide a friendly name for your resource that will be used to label this
4725
Please enter a name for your identity pool.
4826
<amplifyintegtestCIDP>
4927
Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM)
50-
Yes
28+
No
5129
Do you want to enable 3rd party authentication providers in your identity pool?
5230
No
5331
Please provide a name for your user pool:
@@ -86,11 +64,8 @@ Do you want to use an OAuth flow?
8664
Do you want to configure Lambda Triggers for Cognito?
8765
Yes
8866
Which triggers do you want to enable for Cognito
89-
Custom Message
9067
Pre Sign-up
9168
[Choose as many that you would like to manually verify later]
92-
What functionality do you want to use for Custom Message
93-
Create your own module
9469
What functionality do you want to use for Pre Sign-up
9570
Create your own module
9671
Succesfully added the Lambda function locally
@@ -107,25 +82,33 @@ exports.handler = async (event, context) => {
10782
};
10883
```
10984
110-
For Custom Message and any other lambdas
111-
112-
```
113-
// you can simply set them to log the input so you can verify valid and correct validationData/clientMetadata
114-
exports.handler = (event) => {
115-
console.log("Reached custom message lambda");
116-
};
117-
```
118-
11985
Continue in the terminal;
12086
12187
```
12288
? Press enter to continue
12389
Successfully added resource amplifyintegtest locally
90+
91+
92+
? Do you want to configure advanced settings for the GraphQL API `No, I am done.`
93+
? Do you have an annotated GraphQL schema? `No`
94+
? Do you want a guided schema creation? `Yes`
95+
? What best describes your project: `Single object with fields (e.g., “Todo” with ID, name, description)`
96+
? Do you want to edit the schema now? `No`
12497
```
12598
99+
The guided schema provided should look like this:
100+
```json
101+
type Todo @model {
102+
id: ID!
103+
name: String!
104+
description: String
105+
}
106+
```
126107
108+
3. If you are using the latest CLI, update cli.json to include `"useExperimentalPipelinedTransformer": false` to ensure that it will use the v1 transformer.
127109
128110
4. `amplify push`
111+
129112
```perl
130113
? Are you sure you want to continue? `Yes`
131114
? Do you want to generate code for your newly created GraphQL API `No`

0 commit comments

Comments
 (0)