Skip to content

Commit

Permalink
fix: Prevent the Change Password dialog from allowing the new passwor…
Browse files Browse the repository at this point in the history
…d to be the same as the current password #1203
  • Loading branch information
arthurgeron committed Apr 8, 2024
1 parent 45f6571 commit 8f5c41a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-balloons-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Prevent the Change Password dialog from allowing the new password to be the same as the current password #1203
19 changes: 19 additions & 0 deletions packages/app/playwright/e2e/ChangePassword.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,23 @@ test.describe('ChangePassword', () => {

await hasText(page, 'Passwords must match');
});

test('should not change the user current and new passwords are the same', async () => {
// goes to the change password page
await visit(page, '/settings/change-password');

// ensure that the page has changed
await hasText(page, /Change Password/i);

// fills form data
await getByAriaLabel(page, 'Current Password').fill('newPass12345$');
await getByAriaLabel(page, 'New Password').fill('newPass12345$');
await getByAriaLabel(page, 'Confirm Password').fill('newPass123456$');
await getByAriaLabel(page, 'Confirm Password').blur();

await hasText(
page,
'New password cannot be the same as the current password'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const schema = yup
}),
confirmPassword: yup
.string()
.oneOf([yup.ref('password'), undefined], 'Passwords must match'),
.oneOf([yup.ref('password'), undefined], 'Passwords must match')
.notOneOf(
[yup.ref('currentPassword')],
'New password cannot be the same as the current password'
),
currentPassword: yup.string().required('Current password is required'),
strength: yup.string().required(),
})
Expand Down Expand Up @@ -74,6 +78,11 @@ export function ChangePassword() {
}, [error]);

function onSubmit(values: ChangePasswordFormValues) {
if (values.currentPassword === values.password) {
return setError('confirmPassword', {
message: 'New password cannot be the same as the current password',
});
}
if (values.confirmPassword !== values.password) {
return setError('confirmPassword', {
message: 'Passwords must match',
Expand Down

0 comments on commit 8f5c41a

Please sign in to comment.