From 8f5c41a7a7c9e0a238fc847a01fe5b1772735b5c Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:22:59 -0300 Subject: [PATCH] fix: Prevent the Change Password dialog from allowing the new password to be the same as the current password #1203 --- .changeset/lovely-balloons-behave.md | 5 +++++ .../app/playwright/e2e/ChangePassword.test.ts | 19 +++++++++++++++++++ .../pages/ChangePassword/ChangePassword.tsx | 11 ++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .changeset/lovely-balloons-behave.md diff --git a/.changeset/lovely-balloons-behave.md b/.changeset/lovely-balloons-behave.md new file mode 100644 index 0000000000..db9c911fe1 --- /dev/null +++ b/.changeset/lovely-balloons-behave.md @@ -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 diff --git a/packages/app/playwright/e2e/ChangePassword.test.ts b/packages/app/playwright/e2e/ChangePassword.test.ts index 0e554dd15e..c1bfb1da9e 100644 --- a/packages/app/playwright/e2e/ChangePassword.test.ts +++ b/packages/app/playwright/e2e/ChangePassword.test.ts @@ -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' + ); + }); }); diff --git a/packages/app/src/systems/Settings/pages/ChangePassword/ChangePassword.tsx b/packages/app/src/systems/Settings/pages/ChangePassword/ChangePassword.tsx index 20cbe7f2db..db3457545b 100644 --- a/packages/app/src/systems/Settings/pages/ChangePassword/ChangePassword.tsx +++ b/packages/app/src/systems/Settings/pages/ChangePassword/ChangePassword.tsx @@ -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(), }) @@ -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',