-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: conflation of a user's Sub and their Username
BREAKING CHANGE: potential -- the autogenerated Sub and user-supplied Username were treated interchangeably before, but now are independent. Previously lookups by the Sub attribute were possible, but it now doesn't appear necessary so has been removed. Databases should be unaffected.
- Loading branch information
Showing
12 changed files
with
121 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,15 +45,18 @@ describe("User Pool Client", () => { | |
}); | ||
|
||
describe("saveUser", () => { | ||
it("saves a user with their username as an additional attribute", async () => { | ||
it("saves the user", async () => { | ||
const now = new Date().getTime(); | ||
const userPool = await cognitoClient.getUserPool("local"); | ||
|
||
await userPool.saveUser({ | ||
Username: "1", | ||
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [{ Name: "email", Value: "[email protected]" }], | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
UserCreateDate: now, | ||
Enabled: true, | ||
|
@@ -69,7 +72,7 @@ describe("User Pool Client", () => { | |
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
|
@@ -89,7 +92,10 @@ describe("User Pool Client", () => { | |
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
ConfirmationCode: "1234", | ||
Attributes: [{ Name: "email", Value: "[email protected]" }], | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
UserCreateDate: now, | ||
Enabled: true, | ||
|
@@ -106,7 +112,7 @@ describe("User Pool Client", () => { | |
UserStatus: "UNCONFIRMED", | ||
ConfirmationCode: "1234", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
|
@@ -120,7 +126,10 @@ describe("User Pool Client", () => { | |
Username: "1", | ||
Password: "hunter3", | ||
UserStatus: "CONFIRMED", | ||
Attributes: [{ Name: "email", Value: "[email protected]" }], | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
UserCreateDate: now, | ||
Enabled: true, | ||
|
@@ -136,7 +145,7 @@ describe("User Pool Client", () => { | |
Password: "hunter3", | ||
UserStatus: "CONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
|
@@ -158,6 +167,7 @@ describe("User Pool Client", () => { | |
Password: "hunter2", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0411000111" }, | ||
], | ||
|
@@ -194,6 +204,7 @@ describe("User Pool Client", () => { | |
Password: "hunter2", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0411000111" }, | ||
], | ||
|
@@ -206,7 +217,7 @@ describe("User Pool Client", () => { | |
Username: "2", | ||
Password: "password1", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [], | ||
Attributes: [{ Name: "sub", Value: "uuid-5678" }], | ||
UserCreateDate: now.getTime(), | ||
UserLastModifiedDate: now.getTime(), | ||
Enabled: true, | ||
|
@@ -222,7 +233,7 @@ describe("User Pool Client", () => { | |
Password: "hunter2", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0411000111" }, | ||
], | ||
|
@@ -234,7 +245,7 @@ describe("User Pool Client", () => { | |
Username: "2", | ||
Password: "password1", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [{ Name: "sub", Value: "2" }], | ||
Attributes: [{ Name: "sub", Value: "uuid-5678" }], | ||
UserCreateDate: now.getTime(), | ||
UserLastModifiedDate: now.getTime(), | ||
Enabled: true, | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i; |
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
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,6 +6,7 @@ import { | |
attributesInclude, | ||
attributesIncludeMatch, | ||
attributesToRecord, | ||
User, | ||
UserAttribute, | ||
UserPoolClient, | ||
UserPoolClientService, | ||
|
@@ -82,7 +83,7 @@ describe("User Pool Client", () => { | |
}); | ||
|
||
describe("saveUser", () => { | ||
it("saves a user with their username as an additional attribute", async () => { | ||
it("saves the user", async () => { | ||
const now = new Date().getTime(); | ||
const set = jest.fn(); | ||
|
||
|
@@ -99,21 +100,24 @@ describe("User Pool Client", () => { | |
); | ||
|
||
await userPool.saveUser({ | ||
Username: "1", | ||
Username: "user-supplied", | ||
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [{ Name: "email", Value: "[email protected]" }], | ||
Attributes: [ | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
UserCreateDate: now, | ||
Enabled: true, | ||
}); | ||
|
||
expect(set).toHaveBeenCalledWith("Users.1", { | ||
Username: "1", | ||
expect(set).toHaveBeenCalledWith(["Users", "user-supplied"], { | ||
Username: "user-supplied", | ||
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
UserLastModifiedDate: now, | ||
|
@@ -140,13 +144,13 @@ describe("User Pool Client", () => { | |
Id: "local", | ||
UsernameAttributes: username_attributes, | ||
}; | ||
const users = { | ||
"1": { | ||
Username: "1", | ||
const users: Record<string, User> = { | ||
"user-supplied": { | ||
Username: "user-supplied", | ||
Password: "hunter3", | ||
UserStatus: "UNCONFIRMED", | ||
Attributes: [ | ||
{ Name: "sub", Value: "1" }, | ||
{ Name: "sub", Value: "uuid-1234" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0411000111" }, | ||
], | ||
|
@@ -161,6 +165,8 @@ describe("User Pool Client", () => { | |
return Promise.resolve(users); | ||
} else if (key === "Options") { | ||
return Promise.resolve(options); | ||
} else if (Array.isArray(key) && key[0] === "Users") { | ||
return Promise.resolve(users[key[1]]); | ||
} | ||
|
||
return Promise.resolve(null); | ||
|
@@ -185,11 +191,11 @@ describe("User Pool Client", () => { | |
expect(user).toBeNull(); | ||
}); | ||
|
||
it("returns existing user by their sub attribute", async () => { | ||
const user = await userPool.getUserByUsername("1"); | ||
it("returns existing user by their username", async () => { | ||
const user = await userPool.getUserByUsername("user-supplied"); | ||
|
||
expect(user).not.toBeNull(); | ||
expect(user?.Username).toEqual("1"); | ||
expect(user?.Username).toEqual("user-supplied"); | ||
}); | ||
|
||
if (find_by_email) { | ||
|
@@ -199,7 +205,7 @@ describe("User Pool Client", () => { | |
); | ||
|
||
expect(user).not.toBeNull(); | ||
expect(user?.Username).toEqual("1"); | ||
expect(user?.Username).toEqual("user-supplied"); | ||
}); | ||
} else { | ||
it("does not return the user by their email", async () => { | ||
|
@@ -216,7 +222,7 @@ describe("User Pool Client", () => { | |
const user = await userPool.getUserByUsername("0411000111"); | ||
|
||
expect(user).not.toBeNull(); | ||
expect(user?.Username).toEqual("1"); | ||
expect(user?.Username).toEqual("user-supplied"); | ||
}); | ||
} else { | ||
it("does not return the user by their phone number", async () => { | ||
|
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
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
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.
This causes some troubles if username contains dots (.):
Error handling target: InitiateAuth Error: Can't run .value() on non-existant property of non-existant object. at StormDB2.value (/app/start.js:33848:19) at Object.get (/app/start.js:556061:104) at UserPoolClientService.getUserByUsername (/app/start.js:555742:49) at /app/start.js:556345:29
because StormDB uses dot-notation for a key in its get method:
https://github.com/TomPrograms/stormdb/blob/master/src/stormdb.js#L103