-
Notifications
You must be signed in to change notification settings - Fork 7
Add remember-me support to the reference login form (#79) #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe62e58
chore: adopt ds-spring-user-framework 5.2.0
devondragon 1a840d2
feat(auth): add remember-me checkbox to login form and enable remembe…
devondragon 1e9b458
test(e2e): cover the remember-me cookie flow
devondragon 0620a16
docs: document REMEMBER_ME_KEY in the production env vars list
devondragon 65247f7
fix(config): use a random per-start fallback for the remember-me key
devondragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,137 @@ | ||
| import { test, expect, generateTestUser } from '../../src/fixtures'; | ||
|
|
||
| /** | ||
| * Remember-me cookie flow (issue #79 / framework #351). | ||
| * | ||
| * The demo enables user.security.rememberMe with the framework defaults: the | ||
| * login form posts a "remember-me" checkbox and Spring Security issues a | ||
| * hash-based "remember-me" cookie only when that parameter is present. | ||
| */ | ||
| test.describe('Remember Me', () => { | ||
| test.describe('Cookie Issuance', () => { | ||
| test('should issue persistent remember-me cookie when checkbox is checked', async ({ | ||
| page, | ||
| loginPage, | ||
| testApiClient, | ||
| cleanupEmails, | ||
| }) => { | ||
| const user = generateTestUser('remember-me-on'); | ||
| cleanupEmails.push(user.email); | ||
|
|
||
| await testApiClient.createUser({ | ||
| email: user.email, | ||
| password: user.password, | ||
| firstName: user.firstName, | ||
| lastName: user.lastName, | ||
| enabled: true, | ||
| }); | ||
|
|
||
| await loginPage.goto(); | ||
|
|
||
| // The checkbox label renders from the label.form.login-remember message key | ||
| await expect(page.locator('label[for="remember-me"]')).toHaveText('Remember me'); | ||
|
|
||
| await loginPage.fillCredentials(user.email, user.password); | ||
| await loginPage.checkRememberMe(); | ||
| await loginPage.submit(); | ||
| await page.waitForURL((url) => !url.pathname.includes('login'), { timeout: 10000 }); | ||
|
|
||
| const cookies = await page.context().cookies(); | ||
| const rememberMeCookie = cookies.find((c) => c.name === 'remember-me'); | ||
| expect(rememberMeCookie).toBeDefined(); | ||
| expect(rememberMeCookie!.value.length).toBeGreaterThan(0); | ||
| expect(rememberMeCookie!.httpOnly).toBe(true); | ||
| // A persistent cookie has a future expiry; a session cookie reports expires === -1 | ||
| expect(rememberMeCookie!.expires).toBeGreaterThan(Date.now() / 1000); | ||
| }); | ||
|
|
||
| test('should not issue remember-me cookie when checkbox is unchecked', async ({ | ||
| page, | ||
| loginPage, | ||
| testApiClient, | ||
| cleanupEmails, | ||
| }) => { | ||
| const user = generateTestUser('remember-me-off'); | ||
| cleanupEmails.push(user.email); | ||
|
|
||
| await testApiClient.createUser({ | ||
| email: user.email, | ||
| password: user.password, | ||
| firstName: user.firstName, | ||
| lastName: user.lastName, | ||
| enabled: true, | ||
| }); | ||
|
|
||
| await loginPage.loginAndWait(user.email, user.password); | ||
|
|
||
| const cookies = await page.context().cookies(); | ||
| expect(cookies.find((c) => c.name === 'remember-me')).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Session Expiry', () => { | ||
| test('should auto-login from remember-me cookie after session cookie is gone', async ({ | ||
| page, | ||
| loginPage, | ||
| protectedPage, | ||
| testApiClient, | ||
| cleanupEmails, | ||
| }) => { | ||
| const user = generateTestUser('remember-me-relogin'); | ||
| cleanupEmails.push(user.email); | ||
|
|
||
| await testApiClient.createUser({ | ||
| email: user.email, | ||
| password: user.password, | ||
| firstName: user.firstName, | ||
| lastName: user.lastName, | ||
| enabled: true, | ||
| }); | ||
|
|
||
| await loginPage.goto(); | ||
| await loginPage.fillCredentials(user.email, user.password); | ||
| await loginPage.checkRememberMe(); | ||
| await loginPage.submit(); | ||
| await page.waitForURL((url) => !url.pathname.includes('login'), { timeout: 10000 }); | ||
|
|
||
| const cookies = await page.context().cookies(); | ||
| const rememberMeCookie = cookies.find((c) => c.name === 'remember-me'); | ||
| expect(rememberMeCookie).toBeDefined(); | ||
| expect(rememberMeCookie!.expires).toBeGreaterThan(Date.now() / 1000); | ||
|
|
||
| // Drop the server session cookie, simulating an expired/closed session. | ||
| // The remember-me cookie survives and should re-authenticate the request. | ||
| await page.context().clearCookies({ name: 'JSESSIONID' }); | ||
|
|
||
| await protectedPage.goto(); | ||
| expect(page.url()).not.toContain('login'); | ||
| expect(await protectedPage.isLoggedIn()).toBe(true); | ||
| }); | ||
|
|
||
| test('should require fresh login without remember-me once session cookie is gone', async ({ | ||
| page, | ||
| loginPage, | ||
| protectedPage, | ||
| testApiClient, | ||
| cleanupEmails, | ||
| }) => { | ||
| const user = generateTestUser('remember-me-baseline'); | ||
| cleanupEmails.push(user.email); | ||
|
|
||
| await testApiClient.createUser({ | ||
| email: user.email, | ||
| password: user.password, | ||
| firstName: user.firstName, | ||
| lastName: user.lastName, | ||
| enabled: true, | ||
| }); | ||
|
|
||
| await loginPage.loginAndWait(user.email, user.password); | ||
|
|
||
| await page.context().clearCookies({ name: 'JSESSIONID' }); | ||
|
|
||
| await protectedPage.goto(); | ||
| await page.waitForURL('**/login**', { timeout: 10000 }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Playwright has supported filtering in
BrowserContext.clearCookies()since v1.43 (this repo uses ^1.58) — see https://playwright.dev/docs/api/class-browsercontext#browser-context-clear-cookies. The test passes locally and in this PR's Playwright E2E CI job, which exercises exactly this call.