-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from jagregory/fix-race-conditions
fix!: user pool creation race conditions
- Loading branch information
Showing
37 changed files
with
607 additions
and
413 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 |
---|---|---|
|
@@ -15,11 +15,18 @@ describe( | |
it("creates a user with only the required parameters", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
const createUserResult = await client | ||
.adminCreateUser({ | ||
UserAttributes: [{ Name: "phone_number", Value: "0400000000" }], | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -45,12 +52,20 @@ describe( | |
it("sends a welcome email", async () => { | ||
const fakeMessageDelivery = messageDelivery(); | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
const createUserResult = await client | ||
.adminCreateUser({ | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
UserAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -88,11 +103,19 @@ describe( | |
it("creates a user without sending a welcome email if MessageAction=SUPPRESS is passed", async () => { | ||
const fakeMessageDelivery = messageDelivery(); | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
const createUserResult = await client | ||
.adminCreateUser({ | ||
MessageAction: "SUPPRESS", | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { ClockFake } from "../../src/__tests__/clockFake"; | ||
import { UUID } from "../../src/__tests__/patterns"; | ||
import { UserNotFoundError } from "../../src/errors"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
|
@@ -16,20 +15,27 @@ describe( | |
it("deletes a user", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
// create the user | ||
const createUserResult = await client | ||
.adminCreateUser({ | ||
UserAttributes: [{ Name: "phone_number", Value: "0400000000" }], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
// verify they exist | ||
const beforeUserResult = await client | ||
.adminGetUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -46,7 +52,7 @@ describe( | |
await client | ||
.adminDeleteUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -55,7 +61,7 @@ describe( | |
client | ||
.adminGetUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise() | ||
).rejects.toEqual(new UserNotFoundError("User does not exist.")); | ||
|
@@ -64,6 +70,13 @@ describe( | |
it("deletes a user with an email address as a username", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
// create the user | ||
const createUserResult = await client | ||
.adminCreateUser({ | ||
|
@@ -72,15 +85,15 @@ describe( | |
{ Name: "phone_number", Value: "0400000000" }, | ||
], | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
// verify they exist | ||
const beforeUserResult = await client | ||
.adminGetUser({ | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -97,7 +110,7 @@ describe( | |
await client | ||
.adminDeleteUser({ | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise(); | ||
|
||
|
@@ -106,7 +119,7 @@ describe( | |
client | ||
.adminGetUser({ | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
}) | ||
.promise() | ||
).rejects.toEqual(new UserNotFoundError("User does not exist.")); | ||
|
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 |
---|---|---|
|
@@ -7,21 +7,28 @@ describe( | |
it("updates a user's attributes", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
await client | ||
.adminCreateUser({ | ||
UserAttributes: [ | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "custom:example", Value: "1" }, | ||
], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
}) | ||
.promise(); | ||
|
||
let user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
@@ -34,15 +41,15 @@ describe( | |
|
||
await client | ||
.adminDeleteUserAttributes({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
UserAttributeNames: ["custom:example"], | ||
}) | ||
.promise(); | ||
|
||
user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
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 |
---|---|---|
|
@@ -6,28 +6,35 @@ describe( | |
it("updates a user's attributes", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
await client | ||
.adminCreateUser({ | ||
UserAttributes: [ | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "custom:example", Value: "1" }, | ||
], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminDisableUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
const user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
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 |
---|---|---|
|
@@ -6,28 +6,35 @@ describe( | |
it("updates a user's attributes", async () => { | ||
const client = Cognito(); | ||
|
||
const pool = await client | ||
.createUserPool({ | ||
PoolName: "test", | ||
}) | ||
.promise(); | ||
const userPoolId = pool.UserPool?.Id!!; | ||
|
||
await client | ||
.adminCreateUser({ | ||
UserAttributes: [ | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "custom:example", Value: "1" }, | ||
], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminDisableUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
let user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
@@ -36,14 +43,14 @@ describe( | |
|
||
await client | ||
.adminEnableUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
UserPoolId: userPoolId, | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
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.