]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix password form validation mismatch errors 70621/head
authorSagar Gopale <sagar.gopale@ibm.com>
Tue, 28 Jul 2026 11:47:17 +0000 (17:17 +0530)
committerSagar Gopale <sagar.gopale@ibm.com>
Thu, 30 Jul 2026 06:37:13 +0000 (12:07 +0530)
Fixes: https://tracker.ceph.com/issues/78781
Signed-off-by: Sagar Gopale <sagar.gopale@ibm.com>
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts

index d1a71b4ed550553bc0d4234926f84464b50b98b8..91bc0816023cff9507a85a9a2d3e931a923e46d0 100644 (file)
@@ -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');
index 22b4cc41e902fe534d75ba327097ba97bcfc01a9..bccbe28fc59a581b60590fbaf73a5d5282947026 100644 (file)
@@ -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() {
index 0b065f464dddf5d5f18b31e0c06107b72ad5ee14..55816de02fc20b22506fe2d130dbddd19157d6a2 100644 (file)
@@ -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', () => {
index beb3ad0cfd1c2116b33f315450c53e6f169398e0..15613a75b5e82c8774773e3b83f3d4c9b13143d6 100644 (file)
@@ -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 {