From: Sagar Gopale Date: Tue, 28 Jul 2026 11:47:17 +0000 (+0530) Subject: mgr/dashboard: Fix password form validation mismatch errors X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4adc02dffb09a859d811972c5f0140d71bc1004e;p=ceph.git mgr/dashboard: Fix password form validation mismatch errors Fixes: https://tracker.ceph.com/issues/78781 Signed-off-by: Sagar Gopale --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts index d1a71b4ed550..91bc0816023c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts @@ -52,6 +52,19 @@ describe('UserPasswordFormComponent', () => { formHelper.expectValidChange('oldpassword', 'foo'); }); + it('should validate old and new password must be different', () => { + formHelper.setMultipleValues({ + oldpassword: 'aaa', + newpassword: 'aaa' + }); + formHelper.expectError('oldpassword', 'notmatch'); + formHelper.expectError('newpassword', 'notmatch'); + + formHelper.setValue('newpassword', 'bbb'); + formHelper.expectValid('oldpassword'); + formHelper.expectValid('newpassword'); + }); + it('should validate password match', () => { formHelper.setValue('newpassword', 'aaa'); formHelper.expectErrorChange('confirmnewpassword', 'bbb', 'match'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.ts index 22b4cc41e902..bccbe28fc59a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.ts @@ -103,6 +103,13 @@ export class UserPasswordFormComponent { validators: [CdValidators.match('newpassword', 'confirmnewpassword')] } ); + + this.userForm.get('oldpassword').valueChanges.subscribe(() => { + this.userForm.get('newpassword').updateValueAndValidity({ emitEvent: false }); + }); + this.userForm.get('newpassword').valueChanges.subscribe(() => { + this.userForm.get('oldpassword').updateValueAndValidity({ emitEvent: false }); + }); } onSubmit() { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.spec.ts index 0b065f464ddd..55816de02fc2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.spec.ts @@ -524,6 +524,12 @@ describe('CdValidators', () => { formHelper.expectValid('x'); formHelper.expectError('y', 'notUnique'); }); + + it('should not error when confirm value is empty', () => { + formHelper.setValue('y', ''); + CdValidators.match('x', 'y')(form); + formHelper.expectValid('y'); + }); }); describe('unique', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts index beb3ad0cfd1c..15613a75b5e8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts @@ -352,7 +352,7 @@ export class CdValidators { if (!ctrl1 || !ctrl2) { return null; } - if (ctrl1.value !== ctrl2.value) { + if (ctrl2.value && ctrl1.value !== ctrl2.value) { const errors = _.merge({}, ctrl2.errors, { match: true }); ctrl2.setErrors(errors); } else {