-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(#8676): added usernameMatch criteria to login methods to matc…
…h signup (#8686) This PR adds insensitive matching to the login step of dbAuth, this is to match the matching we implemented previously in the register step. For full details please see the bug #8676
- Loading branch information
Showing
5 changed files
with
613 additions
and
521 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
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 |
---|---|---|
|
@@ -884,6 +884,9 @@ describe('dbAuth', () => { | |
expect.assertions(1) | ||
}) | ||
it('throws an error if username is not found', async () => { | ||
delete options.signup.usernameMatch | ||
delete options.login.usernameMatch | ||
|
||
await createDbUser() | ||
event.body = JSON.stringify({ | ||
username: '[email protected]', | ||
|
@@ -1026,6 +1029,58 @@ describe('dbAuth', () => { | |
|
||
expectLoggedInResponse(response) | ||
}) | ||
|
||
it('login db check is called with insensitive string when user has provided one in LoginFlowOptions', async () => { | ||
jest.clearAllMocks() | ||
const spy = jest.spyOn(db.user, 'findFirst') | ||
|
||
options.signup.usernameMatch = 'insensitive' | ||
options.login.usernameMatch = 'insensitive' | ||
|
||
await createDbUser() | ||
event.body = JSON.stringify({ | ||
username: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
const dbAuth = new DbAuthHandler(event, context, options) | ||
|
||
try { | ||
await dbAuth.login() | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(dbAuthError.UserNotFoundError) | ||
} | ||
|
||
return expect(spy).toHaveBeenCalledWith({ | ||
where: { | ||
email: expect.objectContaining({ mode: 'insensitive' }), | ||
}, | ||
}) | ||
}) | ||
|
||
it('login db check is not called with insensitive string when user has not provided one in LoginFlowOptions', async () => { | ||
jest.clearAllMocks() | ||
const spy = jest.spyOn(db.user, 'findFirst') | ||
|
||
delete options.signup.usernameMatch | ||
delete options.login.usernameMatch | ||
|
||
await createDbUser() | ||
event.body = JSON.stringify({ | ||
username: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
const dbAuth = new DbAuthHandler(event, context, options) | ||
|
||
await dbAuth.login() | ||
|
||
return expect(spy).not.toHaveBeenCalledWith({ | ||
where: { | ||
email: expect.objectContaining({ mode: 'insensitive' }), | ||
}, | ||
}) | ||
}) | ||
}) | ||
|
||
describe('logout', () => { | ||
|
Oops, something went wrong.