Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions e2e/tests/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { defaultUserAdmin, routes } from '../config';
import { acceptRecovery } from '../utils/controllers/acceptRecovery';
import { createUser } from '../utils/controllers/createUser';
import { loginBasic, loginRecoveryCodes, loginTOTP } from '../utils/controllers/login';
import { logout } from '../utils/controllers/logout';
import { enableTOTP } from '../utils/controllers/mfa/enableTOTP';
import { changePassword, changePasswordByAdmin } from '../utils/controllers/profile';
import { dockerRestart } from '../utils/docker';
import { waitForBase } from '../utils/waitForBase';
import { waitForRoute } from '../utils/waitForRoute';
Expand Down Expand Up @@ -74,3 +76,27 @@ test('Add user to admin group', async ({ page, context }) => {
await waitForRoute(page, routes.admin.wizard);
expect(page.url()).toBe(routes.base + routes.admin.wizard);
});

test('Change user password', async ({ page, context }) => {
await waitForBase(page);
const testUser = await createUser(context, faker.person.firstName().toLowerCase());
await loginBasic(page, testUser);
testUser.password = await changePassword(page, testUser.password);
await logout(page);
await loginBasic(page, testUser);
await waitForRoute(page, routes.me);
expect(page.url()).toBe(routes.base + routes.me);
});

test('Change user password by admin', async ({ page, context }) => {
await waitForBase(page);
const testUser = await createUser(context, faker.person.firstName().toLowerCase());
await loginBasic(page, defaultUserAdmin);
await page.goto(routes.base + routes.admin.users);
await page.getByText(testUser.username).click();
testUser.password = await changePasswordByAdmin(page);
await logout(page);
await loginBasic(page, testUser);
await waitForRoute(page, routes.me);
expect(page.url()).toBe(routes.base + routes.me);
});
31 changes: 31 additions & 0 deletions e2e/utils/controllers/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Page } from 'playwright';

import { routes } from '../../config';

export const changePassword = async (page: Page, currentPassword: string) => {
await page.goto(routes.base + routes.me);
await page.getByTestId('edit-user').click();
await page.getByTestId('button-change-password').click();
const formElement = page.getByTestId('change-self-password-form');
await formElement.waitFor({ state: 'visible' });
await formElement.getByTestId('field-old_password').type(currentPassword);
const newPassword = 'Test1234#$%';
await formElement.getByTestId('field-new_password').type(newPassword);
await formElement.getByTestId('field-repeat').type(newPassword);
await formElement.locator('button[type="submit"]').click();
await formElement.waitFor({ state: 'hidden', timeout: 2000 });
return newPassword;
};

export const changePasswordByAdmin = async (page: Page) => {
await page.getByTestId('edit-user').click();
await page.getByTestId('button-change-password').click();
const formElement = page.getByTestId('change-password-admin-form');
await formElement.waitFor({ state: 'visible' });
const newPassword = 'Test1234#$%';
await formElement.getByTestId('field-new_password').type(newPassword);
await formElement.getByTestId('field-repeat').type(newPassword);
await formElement.locator('button[type="submit"]').click();
await formElement.waitFor({ state: 'hidden', timeout: 2000 });
return newPassword;
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const UserAuthInfoPassword = () => {
</header>
<div className="row">
<Button
data-testid="button-change-password"
size={ButtonSize.SMALL}
styleVariant={ButtonStyleVariant.STANDARD}
text={LL.userPage.userAuthInfo.password.changePassword()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export const ChangeSelfPasswordForm = () => {
};

return (
<form onSubmit={handleSubmit(handleValidSubmit)}>
<form
data-testid="change-self-password-form"
Comment thread
kchudy marked this conversation as resolved.
onSubmit={handleSubmit(handleValidSubmit)}
>
<FormInput
controller={{ control, name: 'old_password' }}
type="password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const ChangePasswordForm = () => {
};

return (
<form onSubmit={handleSubmit(onValidSubmit)}>
<form onSubmit={handleSubmit(onValidSubmit)} data-testid="change-password-admin-form">
Comment thread
kchudy marked this conversation as resolved.
<FormInput
label={LL.modals.changeUserPassword.form.fields.newPassword.label()}
controller={{ control, name: 'new_password' }}
Expand Down