]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Hide password notification when expiration date is far 35874/head
authorTiago Melo <tmelo@suse.com>
Wed, 1 Jul 2020 14:31:59 +0000 (14:31 +0000)
committerTiago Melo <tmelo@suse.com>
Mon, 6 Jul 2020 20:01:21 +0000 (20:01 +0000)
Fixes: https://tracker.ceph.com/issues/46306
Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.ts

index 07c9a8a4d8ea1c612f2b25ead09c808146c2a516..63f59601f50186cdcd7cb92942889d950d89ecbe 100644 (file)
@@ -23,6 +23,11 @@ describe('PwdExpirationNotificationComponent', () => {
 
   const routes: Routes = [{ path: 'login', component: FakeComponent }];
 
+  const spyOnDate = (fakeDate: string) => {
+    const dateValue = Date;
+    spyOn(global, 'Date').and.callFake((date) => new dateValue(date ? date : fakeDate));
+  };
+
   configureTestBed({
     declarations: [PwdExpirationNotificationComponent, FakeComponent],
     imports: [NgbAlertModule, HttpClientTestingModule, RouterTestingModule.withRoutes(routes)],
@@ -58,42 +63,29 @@ describe('PwdExpirationNotificationComponent', () => {
     });
 
     it('should calculate password expiration in days', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-18T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-18T00:00:00.000Z');
       component.ngOnInit();
       expect(component['expirationDays']).toBe(4);
     });
 
     it('should set alert type warning correctly', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-14T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-14T00:00:00.000Z');
       component.ngOnInit();
       expect(component['alertType']).toBe('warning');
+      expect(component.displayNotification).toBeTruthy();
     });
 
     it('should set alert type danger correctly', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-18T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-18T00:00:00.000Z');
       component.ngOnInit();
       expect(component['alertType']).toBe('danger');
+      expect(component.displayNotification).toBeTruthy();
+    });
+
+    it('should not display if date is far', () => {
+      spyOnDate('2022-01-01T00:00:00.000Z');
+      component.ngOnInit();
+      expect(component.displayNotification).toBeFalsy();
     });
   });
 
index 83e1664643bd386874fa615b62e302a6e18b30e0..c713d4c7b6db19f849bfbbda9b821492a8e60260 100644 (file)
@@ -31,8 +31,9 @@ export class PwdExpirationNotificationComponent implements OnInit, OnDestroy {
         } else {
           this.alertType = 'warning';
         }
-        this.displayNotification = true;
-        this.authStorageService.isPwdDisplayedSource.next(true);
+        this.displayNotification =
+          this.expirationDays <= this.pwdExpirationSettings.pwdExpirationWarning1;
+        this.authStorageService.isPwdDisplayedSource.next(this.displayNotification);
       }
     });
   }