-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix: redirect on required password change #36381
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2cc8f3b
test: add e2e test for required password change flow
jessicaschelly 41a6423
add more tests
jessicaschelly 27fb6e7
improve test
jessicaschelly 93e56ea
Merge branch 'develop' into test/require-password-change
cardoso 1895762
Update apps/meteor/tests/e2e/user-required-password-change.spec.ts
cardoso 10daeed
fix: setUserPassword does not broadcast change
cardoso 26e64b6
Create stupid-fishes-turn.md
cardoso 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
166 changes: 166 additions & 0 deletions
166
apps/meteor/tests/e2e/user-required-password-change.spec.ts
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,166 @@ | ||
| import { faker } from '@faker-js/faker'; | ||
|
|
||
| import { DEFAULT_USER_CREDENTIALS } from './config/constants'; | ||
| import { Registration } from './page-objects'; | ||
| import { HomeSidenav } from './page-objects/fragments/home-sidenav'; | ||
| import { getSettingValueById, setSettingValueById } from './utils'; | ||
| import { test, expect } from './utils/test'; | ||
| import type { ITestUser } from './utils/user-helpers'; | ||
| import { createTestUser } from './utils/user-helpers'; | ||
|
|
||
| test.describe('User - Password change required', () => { | ||
| let poRegistration: Registration; | ||
| let poSidenav: HomeSidenav; | ||
| let userRequiringPasswordChange: ITestUser; | ||
| let userNotRequiringPasswordChange: ITestUser; | ||
| let userNotAbleToLogin: ITestUser; | ||
| let settingDefaultValue: unknown; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| settingDefaultValue = await getSettingValueById(api, 'Accounts_RequirePasswordConfirmation'); | ||
| await setSettingValueById(api, 'Accounts_RequirePasswordConfirmation', true); | ||
| userRequiringPasswordChange = await createTestUser(api, { data: { requirePasswordChange: true } }); | ||
| userNotRequiringPasswordChange = await createTestUser(api, { data: { requirePasswordChange: false } }); | ||
| userNotAbleToLogin = await createTestUser(api, { data: { requirePasswordChange: true } }); | ||
| }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| poRegistration = new Registration(page); | ||
| poSidenav = new HomeSidenav(page); | ||
| await page.goto('/home'); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ api }) => { | ||
| await Promise.all([ | ||
| setSettingValueById(api, 'Accounts_RequirePasswordConfirmation', settingDefaultValue), | ||
| userRequiringPasswordChange.delete(), | ||
| userNotRequiringPasswordChange.delete(), | ||
| userNotAbleToLogin.delete(), | ||
| ]); | ||
| }); | ||
|
|
||
| test.fail('should redirect to home after successful password change for new user', async ({ page }) => { | ||
| await test.step('login with temporary password', async () => { | ||
| await poRegistration.username.fill(userRequiringPasswordChange.data.username); | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.btnLogin.click(); | ||
| }); | ||
|
|
||
| await test.step('should be redirected to password change screen', async () => { | ||
| await expect(poRegistration.inputPassword).toBeVisible(); | ||
| await expect(poRegistration.inputPasswordConfirm).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('enter new password and confirm', async () => { | ||
| const newPassword = faker.internet.password(); | ||
| await poRegistration.inputPassword.fill(newPassword); | ||
| await poRegistration.inputPasswordConfirm.fill(newPassword); | ||
| }); | ||
|
|
||
| await test.step('click reset button', async () => { | ||
| await poRegistration.btnReset.click(); | ||
| }); | ||
|
|
||
| await test.step('verify password reset form is not visible', async () => { | ||
| await page.waitForURL('/home'); | ||
| await expect(poRegistration.inputPassword).not.toBeVisible(); | ||
| await expect(poRegistration.inputPasswordConfirm).not.toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('verify user is properly logged in', async () => { | ||
| await expect(poSidenav.userProfileMenu).toBeVisible(); | ||
| await expect(poSidenav.sidebarChannelsList).toBeVisible(); | ||
| }); | ||
| }); | ||
|
|
||
| test('should show error when password confirmation does not match', async () => { | ||
| await test.step('login with temporary password', async () => { | ||
| await poRegistration.username.fill(userNotAbleToLogin.data.username); | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.btnLogin.click(); | ||
| }); | ||
|
|
||
| await test.step('should be redirected to password change screen', async () => { | ||
| await expect(poRegistration.inputPassword).toBeVisible(); | ||
| await expect(poRegistration.inputPasswordConfirm).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('enter different passwords in password and confirm fields', async () => { | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.inputPasswordConfirm.fill(faker.internet.password()); | ||
| }); | ||
|
|
||
| await test.step('attempt to submit password change', async () => { | ||
| await poRegistration.btnReset.click(); | ||
| }); | ||
|
|
||
| await test.step('verify error message appears for password mismatch', async () => { | ||
| await expect(poRegistration.inputPasswordConfirm).toBeInvalid(); | ||
| }); | ||
| }); | ||
|
|
||
| test('should show error when user tries to use the same password as current', async () => { | ||
| await test.step('login with temporary password', async () => { | ||
| await poRegistration.username.fill(userNotAbleToLogin.data.username); | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.btnLogin.click(); | ||
| }); | ||
|
|
||
| await test.step('should be redirected to password change screen', async () => { | ||
| await expect(poRegistration.inputPassword).toBeVisible(); | ||
| await expect(poRegistration.inputPasswordConfirm).toBeVisible(); | ||
| }); | ||
|
|
||
| await test.step('enter the same password as current password', async () => { | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.inputPasswordConfirm.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| }); | ||
|
|
||
| await test.step('attempt to submit password change', async () => { | ||
| await poRegistration.btnReset.click(); | ||
| }); | ||
|
|
||
| await test.step('verify error message appears for same password', async () => { | ||
| await expect(poRegistration.inputPassword).toBeInvalid(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('User - Password change not required', () => { | ||
| let poRegistration: Registration; | ||
| let poSidenav: HomeSidenav; | ||
| let userNotRequiringPasswordChange: ITestUser; | ||
| let settingDefaultValue: unknown; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| settingDefaultValue = await getSettingValueById(api, 'Accounts_RequirePasswordConfirmation'); | ||
| userNotRequiringPasswordChange = await createTestUser(api, { data: { requirePasswordChange: false } }); | ||
| }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| poRegistration = new Registration(page); | ||
| poSidenav = new HomeSidenav(page); | ||
| await page.goto('/home'); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ api }) => { | ||
| await Promise.all([ | ||
| setSettingValueById(api, 'Accounts_RequirePasswordConfirmation', settingDefaultValue), | ||
| userNotRequiringPasswordChange.delete(), | ||
| ]); | ||
| }); | ||
|
|
||
| test('should not require password change if the requirePasswordChange is disabled', async ({ page }) => { | ||
| await test.step('login with user not requiring password change', async () => { | ||
| await poRegistration.username.fill(userNotRequiringPasswordChange.data.username); | ||
| await poRegistration.inputPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
| await poRegistration.btnLogin.click(); | ||
| }); | ||
|
|
||
| await test.step('verify user is properly logged in', async () => { | ||
| await page.waitForURL('/home'); | ||
| await expect(poSidenav.userProfileMenu).toBeVisible(); | ||
| await expect(poSidenav.sidebarChannelsList).toBeVisible(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.