Skip to content

Commit

Permalink
feat(api): full support for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jagregory committed Feb 16, 2022
1 parent 93586ae commit 1fc025c
Show file tree
Hide file tree
Showing 31 changed files with 1,596 additions and 75 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| Feature | Support |
| -------------------------------- | -------------------- |
| AddCustomAttributes ||
| AdminAddUserToGroup | |
| AdminAddUserToGroup | |
| AdminConfirmSignUp ||
| AdminCreateUser | 🕒 (partial support) |
| AdminDeleteUser ||
Expand All @@ -44,9 +44,9 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| AdminInitiateAuth | 🕒 (partial support) |
| AdminLinkProviderForUser ||
| AdminListDevices ||
| AdminListGroupsForUser | |
| AdminListGroupsForUser | |
| AdminListUserAuthEvents ||
| AdminRemoveUserFromGroup | |
| AdminRemoveUserFromGroup | |
| AdminResetUserPassword ||
| AdminRespondToAuthChallenge ||
| AdminSetUserMFAPreference ||
Expand All @@ -68,10 +68,10 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| CreateUserPool ||
| CreateUserPoolClient | 🕒 (partial support) |
| CreateUserPoolDomain ||
| DeleteGroup | |
| DeleteGroup | |
| DeleteIdentityProvider ||
| DeleteResourceServer ||
| DeleteUser | |
| DeleteUser |² |
| DeleteUserAttributes ||
| DeleteUserPool ||
| DeleteUserPoolClient ||
Expand All @@ -87,7 +87,7 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| ForgotPassword | 🕒 (partial support) |
| GetCSVHeader ||
| GetDevice ||
| GetGroup | |
| GetGroup | ✅² |
| GetIdentityProviderByIdentifier ||
| GetSigningCertificate ||
| GetUICustomization ||
Expand All @@ -105,7 +105,7 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| ListUserPoolClients ||
| ListUserPools | ✅¹ |
| ListUsers | ✅¹ |
| ListUsersInGroup | |
| ListUsersInGroup | ✅¹ |
| ResendConfirmationCode ||
| RespondToAuthChallenge | 🕒 (partial support) |
| RevokeToken | 🕒 (partial support) |
Expand All @@ -121,7 +121,7 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| UntagResource ||
| UpdateAuthEventFeedback ||
| UpdateDeviceStatus ||
| UpdateGroup | |
| UpdateGroup | |
| UpdateIdentityProvider ||
| UpdateResourceServer ||
| UpdateUserAttributes ||
Expand All @@ -132,6 +132,8 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| VerifyUserAttribute ||

> ¹ does not support pagination or query filters, all results and attributes will be returned in the first request.
>
> ² "requires developer credentials" is not enforced
Additional supported features:

Expand Down
86 changes: 86 additions & 0 deletions integration-tests/aws-sdk/adminListGroupsForUser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ClockFake } from "../../src/__tests__/clockFake";
import { withCognitoSdk } from "./setup";

const originalDate = new Date();
const roundedDate = new Date(originalDate.getTime());
roundedDate.setMilliseconds(0);

const clock = new ClockFake(originalDate);

describe(
"CognitoIdentityServiceProvider.adminListGroupsForUser",
withCognitoSdk(
(Cognito) => {
it("lists groups for a user", async () => {
const client = Cognito();

const createGroupResponse = await client
.createGroup({
GroupName: "group-1",
UserPoolId: "test",
})
.promise();

await client
.adminCreateUser({
DesiredDeliveryMediums: ["EMAIL"],
TemporaryPassword: "def",
UserAttributes: [{ Name: "email", Value: "[email protected]" }],
Username: "user-1",
UserPoolId: "test",
})
.promise();

await client
.adminAddUserToGroup({
Username: "user-1",
GroupName: "group-1",
UserPoolId: "test",
})
.promise();

const result = await client
.adminListGroupsForUser({
UserPoolId: "test",
Username: "user-1",
})
.promise();

expect(result.Groups).toEqual([createGroupResponse.Group]);
});

it("lists groups for an unassigned user", async () => {
const client = Cognito();

await client
.createGroup({
GroupName: "group-2",
UserPoolId: "test",
})
.promise();

await client
.adminCreateUser({
DesiredDeliveryMediums: ["EMAIL"],
TemporaryPassword: "def",
UserAttributes: [{ Name: "email", Value: "[email protected]" }],
Username: "user-1",
UserPoolId: "test",
})
.promise();

const result = await client
.adminListGroupsForUser({
UserPoolId: "test",
Username: "user-1",
})
.promise();

expect(result.Groups).toHaveLength(0);
});
},
{
clock,
}
)
);
73 changes: 73 additions & 0 deletions integration-tests/aws-sdk/adminRemoveUserFromGroup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ClockFake } from "../../src/__tests__/clockFake";
import { withCognitoSdk } from "./setup";

const originalDate = new Date();
const roundedDate = new Date(originalDate.getTime());
roundedDate.setMilliseconds(0);

const clock = new ClockFake(originalDate);

describe(
"CognitoIdentityServiceProvider.adminRemoveUserFromGroup",
withCognitoSdk(
(Cognito) => {
it("lists groups for a user", async () => {
const client = Cognito();

const createGroupResponse = await client
.createGroup({
GroupName: "group-1",
UserPoolId: "test",
})
.promise();

await client
.adminCreateUser({
DesiredDeliveryMediums: ["EMAIL"],
TemporaryPassword: "def",
UserAttributes: [{ Name: "email", Value: "[email protected]" }],
Username: "user-1",
UserPoolId: "test",
})
.promise();

await client
.adminAddUserToGroup({
Username: "user-1",
GroupName: "group-1",
UserPoolId: "test",
})
.promise();

const result = await client
.adminListGroupsForUser({
UserPoolId: "test",
Username: "user-1",
})
.promise();

expect(result.Groups).toEqual([createGroupResponse.Group]);

await client
.adminRemoveUserFromGroup({
Username: "user-1",
GroupName: "group-1",
UserPoolId: "test",
})
.promise();

const resultAfterRemove = await client
.adminListGroupsForUser({
UserPoolId: "test",
Username: "user-1",
})
.promise();

expect(resultAfterRemove.Groups).toHaveLength(0);
});
},
{
clock,
}
)
);
1 change: 0 additions & 1 deletion integration-tests/aws-sdk/createGroup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClockFake } from "../../src/__tests__/clockFake";
import { UUID } from "../../src/__tests__/patterns";
import { withCognitoSdk } from "./setup";

const currentDate = new Date();
Expand Down
44 changes: 44 additions & 0 deletions integration-tests/aws-sdk/deleteGroup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { withCognitoSdk } from "./setup";

describe(
"CognitoIdentityServiceProvider.deleteGroup",
withCognitoSdk((Cognito) => {
it("deletes a group", async () => {
const client = Cognito();

await client
.createGroup({
GroupName: "abc",
UserPoolId: "test",
})
.promise();

const getGroupResponse = await client
.getGroup({
GroupName: "abc",
UserPoolId: "test",
})
.promise();

expect(getGroupResponse.Group).toBeDefined();

await client
.deleteGroup({
GroupName: "abc",
UserPoolId: "test",
})
.promise();

await expect(
client
.getGroup({
GroupName: "abc",
UserPoolId: "test",
})
.promise()
).rejects.toMatchObject({
code: "ResourceNotFoundException",
});
});
})
);
49 changes: 49 additions & 0 deletions integration-tests/aws-sdk/getGroup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ClockFake } from "../../src/__tests__/clockFake";
import { withCognitoSdk } from "./setup";

const currentDate = new Date();
const roundedDate = new Date(currentDate.getTime());
roundedDate.setMilliseconds(0);

const clock = new ClockFake(currentDate);

describe(
"CognitoIdentityServiceProvider.getGroup",
withCognitoSdk(
(Cognito) => {
it("get a group", async () => {
const client = Cognito();

await client
.createGroup({
Description: "Description",
GroupName: "abc",
Precedence: 1,
RoleArn: "arn",
UserPoolId: "test",
})
.promise();

const getGroupResponse = await client
.getGroup({
GroupName: "abc",
UserPoolId: "test",
})
.promise();

expect(getGroupResponse.Group).toEqual({
CreationDate: roundedDate,
Description: "Description",
GroupName: "abc",
LastModifiedDate: roundedDate,
Precedence: 1,
RoleArn: "arn",
UserPoolId: "test",
});
});
},
{
clock,
}
)
);
Loading

0 comments on commit 1fc025c

Please sign in to comment.