-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-13251] Password History (#11618)
* add password history view component in vault lib * integrate PasswordHistoryView into individual vault * add password history v2 to browser extension * update color of password history link * add check for `cipherId` before rendering password history
- Loading branch information
1 parent
496bc74
commit 97bf459
Showing
12 changed files
with
337 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...up/components/vault-v2/vault-password-history-v2/vault-password-history-v2.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<popup-page> | ||
<popup-header slot="header" pageTitle="{{ 'passwordHistory' | i18n }}" showBackButton> | ||
<ng-container slot="end"> | ||
<app-pop-out></app-pop-out> | ||
</ng-container> | ||
</popup-header> | ||
<vault-password-history-view *ngIf="cipherId" [cipherId]="cipherId" /> | ||
</popup-page> |
56 changes: 56 additions & 0 deletions
56
...components/vault-v2/vault-password-history-v2/vault-password-history-v2.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { ActivatedRoute } from "@angular/router"; | ||
import { mock } from "jest-mock-extended"; | ||
import { Subject } from "rxjs"; | ||
|
||
import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; | ||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; | ||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; | ||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; | ||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; | ||
|
||
import { PopupRouterCacheService } from "../../../../../platform/popup/view-cache/popup-router-cache.service"; | ||
|
||
import { PasswordHistoryV2Component } from "./vault-password-history-v2.component"; | ||
|
||
describe("PasswordHistoryV2Component", () => { | ||
let component: PasswordHistoryV2Component; | ||
let fixture: ComponentFixture<PasswordHistoryV2Component>; | ||
const params$ = new Subject(); | ||
const back = jest.fn().mockResolvedValue(undefined); | ||
|
||
beforeEach(async () => { | ||
back.mockClear(); | ||
|
||
await TestBed.configureTestingModule({ | ||
imports: [PasswordHistoryV2Component], | ||
providers: [ | ||
{ provide: WINDOW, useValue: window }, | ||
{ provide: PlatformUtilsService, useValue: mock<PlatformUtilsService>() }, | ||
{ provide: ConfigService, useValue: mock<ConfigService>() }, | ||
{ provide: CipherService, useValue: mock<CipherService>() }, | ||
{ provide: AccountService, useValue: mock<AccountService>() }, | ||
{ provide: PopupRouterCacheService, useValue: { back } }, | ||
{ provide: ActivatedRoute, useValue: { queryParams: params$ } }, | ||
{ provide: I18nService, useValue: { t: (key: string) => key } }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(PasswordHistoryV2Component); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("sets the cipherId from the params", () => { | ||
params$.next({ cipherId: "444-33-33-1111" }); | ||
|
||
expect(component["cipherId"]).toBe("444-33-33-1111"); | ||
}); | ||
|
||
it("navigates back when a cipherId is not in the params", () => { | ||
params$.next({}); | ||
|
||
expect(back).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
...opup/components/vault-v2/vault-password-history-v2/vault-password-history-v2.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { NgIf } from "@angular/common"; | ||
import { Component, OnInit } from "@angular/core"; | ||
import { ActivatedRoute } from "@angular/router"; | ||
import { first } from "rxjs/operators"; | ||
|
||
import { JslibModule } from "@bitwarden/angular/jslib.module"; | ||
import { CipherId } from "@bitwarden/common/types/guid"; | ||
|
||
import { PasswordHistoryViewComponent } from "../../../../../../../../libs/vault/src/components/password-history-view/password-history-view.component"; | ||
import { PopOutComponent } from "../../../../../platform/popup/components/pop-out.component"; | ||
import { PopupHeaderComponent } from "../../../../../platform/popup/layout/popup-header.component"; | ||
import { PopupPageComponent } from "../../../../../platform/popup/layout/popup-page.component"; | ||
import { PopupRouterCacheService } from "../../../../../platform/popup/view-cache/popup-router-cache.service"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "vault-password-history-v2", | ||
templateUrl: "vault-password-history-v2.component.html", | ||
imports: [ | ||
JslibModule, | ||
PopupPageComponent, | ||
PopOutComponent, | ||
PopupHeaderComponent, | ||
PasswordHistoryViewComponent, | ||
NgIf, | ||
], | ||
}) | ||
export class PasswordHistoryV2Component implements OnInit { | ||
protected cipherId: CipherId; | ||
|
||
constructor( | ||
private browserRouterHistory: PopupRouterCacheService, | ||
private route: ActivatedRoute, | ||
) {} | ||
|
||
ngOnInit() { | ||
// eslint-disable-next-line rxjs-angular/prefer-takeuntil | ||
this.route.queryParams.pipe(first()).subscribe((params) => { | ||
if (params.cipherId) { | ||
this.cipherId = params.cipherId; | ||
} else { | ||
this.close(); | ||
} | ||
}); | ||
} | ||
|
||
close() { | ||
void this.browserRouterHistory.back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
libs/vault/src/components/password-history-view/password-history-view.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div *ngIf="history && history.length"> | ||
<bit-item *ngFor="let h of history"> | ||
<div class="tw-pl-3 tw-py-2"> | ||
<bit-color-password | ||
class="tw-text-base" | ||
[password]="h.password" | ||
[showCount]="false" | ||
></bit-color-password> | ||
<div class="tw-text-sm tw-text-muted">{{ h.lastUsedDate | date: "medium" }}</div> | ||
</div> | ||
<ng-container slot="end"> | ||
<bit-item-action> | ||
<button | ||
type="button" | ||
bitIconButton="bwi-clone" | ||
[appA11yTitle]="'copyPassword' | i18n" | ||
appStopClick | ||
(click)="copy(h.password)" | ||
> | ||
<i class="bwi bwi-lg bwi-clone" aria-hidden="true"></i> | ||
</button> | ||
</bit-item-action> | ||
</ng-container> | ||
</bit-item> | ||
</div> | ||
<div class="no-items" *ngIf="!history?.length"> | ||
<p>{{ "noPasswordsInList" | i18n }}</p> | ||
</div> |
Oops, something went wrong.