-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): integrate basic sentinel (#4562)
* feat(core): integrate basic sentinel * chore: add integration tests * refactor(test): fix toast matching * chore: add changeset * refactor(test): update naming
- Loading branch information
Showing
32 changed files
with
385 additions
and
84 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@logto/core": patch | ||
--- | ||
|
||
block an identifier from verification for 10 minutes after 5 failed attempts within 1 hour |
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
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,7 @@ | ||
import { Sentinel, SentinelDecision } from '@logto/schemas'; | ||
|
||
export class MockSentinel extends Sentinel { | ||
override async reportActivity(activity: unknown) { | ||
return [SentinelDecision.Allowed, Date.now()] as const; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { i18n } from 'i18next'; | ||
import _i18next from 'i18next'; | ||
|
||
// This may be fixed by a cjs require wrapper. TBD. | ||
// See https://github.com/microsoft/TypeScript/issues/49189 | ||
// eslint-disable-next-line no-restricted-syntax | ||
export const i18next = _i18next as unknown as i18n; |
56 changes: 56 additions & 0 deletions
56
packages/integration-tests/src/tests/experience/basic-sentinel.test.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,56 @@ | ||
import { demoAppUrl } from '#src/constants.js'; | ||
import ExpectExperience from '#src/ui-helpers/expect-experience.js'; | ||
import { setupUsernameAndEmailExperience } from '#src/ui-helpers/index.js'; | ||
|
||
describe('basic sentinel', () => { | ||
beforeAll(async () => { | ||
await setupUsernameAndEmailExperience(); | ||
}); | ||
|
||
it('should block a non-existing identifier after 5 failed attempts in 1 hour', async () => { | ||
const experience = new ExpectExperience(await browser.newPage(), { forgotPassword: true }); | ||
// Open the demo app and navigate to the sign-in page | ||
await experience.startWith(demoAppUrl, 'sign-in'); | ||
await experience.toFillInput('identifier', 'nonexisting_username_9', { submit: true }); | ||
|
||
// Password tests | ||
experience.toBeAt('sign-in/password'); | ||
|
||
await experience.toFillPasswordsToInputs( | ||
{ inputNames: ['password'], shouldNavigate: false }, | ||
['1', 'account or password'], | ||
['2', 'account or password'], | ||
['3', 'account or password'], | ||
['4', 'account or password'], | ||
'5' | ||
); | ||
|
||
await experience.waitForToast('Too many attempts'); | ||
await experience.page.reload({ waitUntil: 'networkidle0' }); | ||
await experience.toFillPasswordsToInputs( | ||
{ inputNames: ['password'], shouldNavigate: false }, | ||
'6' | ||
); | ||
await experience.waitForToast('Too many attempts'); | ||
}); | ||
|
||
it('should block failed attempts from both password and verification code', async () => { | ||
const experience = new ExpectExperience(await browser.newPage(), { forgotPassword: true }); | ||
// Open the demo app and navigate to the sign-in page | ||
await experience.startWith(demoAppUrl, 'sign-in'); | ||
await experience.toFillInput('identifier', '[email protected]', { submit: true }); | ||
await experience.toFillPasswordsToInputs( | ||
{ inputNames: ['password'], shouldNavigate: false }, | ||
['1', 'account or password'], | ||
['2', 'account or password'], | ||
['3', 'account or password'] | ||
); | ||
await experience.toClick('a', 'with verification code'); | ||
await experience.toFillVerificationCode('000000'); | ||
await experience.toFillVerificationCode('000000'); | ||
await experience.waitForToast('Too many attempts'); | ||
await experience.page.reload({ waitUntil: 'networkidle0' }); | ||
await experience.toFillVerificationCode('000000'); | ||
await experience.waitForToast('Too many attempts'); | ||
}); | ||
}); |
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.