-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return updated failed login attempts (#4474)
* fix: return updated failed login attempts * fix: testing coverage * fix: update naming * fix: testing tweak
- Loading branch information
1 parent
eeafe62
commit fc05ac1
Showing
4 changed files
with
56 additions
and
7 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
47 changes: 47 additions & 0 deletions
47
api/test/unit/passports/passport-validator-utilities.spec.ts
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,47 @@ | ||
import { checkUserLockout } from '../../../src/utilities/passport-validator-utilities'; | ||
|
||
describe('Testing checkUserLockout', () => { | ||
it('should return without erroring and set failedLoginAttemptsCount to be 0 if lockout expired', () => { | ||
const val = { | ||
lastLoginAt: new Date('01/01/2024'), | ||
failedLoginAttemptsCount: 5, | ||
}; | ||
const updatedFailedLoginCount = checkUserLockout( | ||
val.lastLoginAt, | ||
val.failedLoginAttemptsCount, | ||
5, | ||
10, | ||
); | ||
expect(updatedFailedLoginCount).toEqual(0); | ||
}); | ||
|
||
it('should return without erroring and leave failed login count unchanged if user is and was not locked out', () => { | ||
const val = { | ||
lastLoginAt: new Date('01/01/2024'), | ||
failedLoginAttemptsCount: 2, | ||
}; | ||
const updatedFailedLoginCount = checkUserLockout( | ||
val.lastLoginAt, | ||
val.failedLoginAttemptsCount, | ||
5, | ||
10, | ||
); | ||
expect(updatedFailedLoginCount).toEqual(2); | ||
}); | ||
|
||
it('should error if user is still in lockout period', () => { | ||
const val = { | ||
lastLoginAt: new Date(), | ||
failedLoginAttemptsCount: 5, | ||
}; | ||
expect( | ||
async () => | ||
await checkUserLockout( | ||
val.lastLoginAt, | ||
val.failedLoginAttemptsCount, | ||
5, | ||
10, | ||
), | ||
).rejects.toThrowError(`Failed login attempts exceeded.`); | ||
}); | ||
}); |