Skip to content

Commit

Permalink
fix(api): adminDeleteUser handles email usernames
Browse files Browse the repository at this point in the history
The delete call to StormDB was parsing dots in email addresses as
JSONPath separators and failing to delete the user.

Fixes jagregory#99
  • Loading branch information
jagregory committed Jan 11, 2022
1 parent 1ca2b99 commit 8faa78f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions integration-tests/aws-sdk/adminDeleteUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,57 @@ describe(
.promise()
).rejects.toEqual(new UserNotFoundError("User does not exist"));
});

it("deletes a user with an email address as a username", async () => {
const client = Cognito();

// create the user
const createUserResult = await client
.adminCreateUser({
UserAttributes: [
{ Name: "email", Value: "[email protected]" },
{ Name: "phone_number", Value: "0400000000" },
],
Username: "[email protected]",
UserPoolId: "test",
})
.promise();

// verify they exist
const beforeUserResult = await client
.adminGetUser({
Username: "[email protected]",
UserPoolId: "test",
})
.promise();

expect(beforeUserResult).toEqual({
Enabled: true,
UserAttributes: createUserResult.User?.Attributes,
UserCreateDate: createUserResult.User?.UserCreateDate,
UserLastModifiedDate: createUserResult.User?.UserLastModifiedDate,
Username: createUserResult.User?.Username,
UserStatus: createUserResult.User?.UserStatus,
});

// delete the user
await client
.adminDeleteUser({
Username: "[email protected]",
UserPoolId: "test",
})
.promise();

// verify they don't exist anymore
await expect(
client
.adminGetUser({
Username: "[email protected]",
UserPoolId: "test",
})
.promise()
).rejects.toEqual(new UserNotFoundError("User does not exist"));
});
},
{
clock,
Expand Down
2 changes: 1 addition & 1 deletion src/services/dataStore/stormDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class StormDBDataStore implements DataStore {
async delete(ctx: Context, key: string | string[]) {
ctx.logger.debug({ key }, "DataStore.delete");
(key instanceof Array ? key : [key])
.reduce((acc, k) => acc.get(k), this.db)
.reduce((acc, k) => acc.get([k]), this.db)
.delete(false);

ctx.logger.debug({ store: this.db.value() }, "DataStore.save");
Expand Down

0 comments on commit 8faa78f

Please sign in to comment.