mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-13365] - don't display totp capture when in popout (#12645)
* don't display totp capture when in popout * add canCaptureTotp method * dry up logic * add unit tests * fix failing tests * add missing mock to cipher-form story
This commit is contained in:
@@ -6,4 +6,9 @@ export abstract class TotpCaptureService {
|
||||
* Captures a TOTP secret and returns it as a string. Returns null if no TOTP secret was found.
|
||||
*/
|
||||
abstract captureTotpSecret(): Promise<string | null>;
|
||||
/**
|
||||
* Returns whether the TOTP secret can be captured from the current tab.
|
||||
* Only available in the browser extension and when not in a popout window.
|
||||
*/
|
||||
abstract canCaptureTotp(window: Window): boolean;
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ export default {
|
||||
provide: TotpCaptureService,
|
||||
useValue: {
|
||||
captureTotpSecret: () => Promise.resolve("some-value"),
|
||||
canCaptureTotp: () => true,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -434,6 +434,7 @@ describe("LoginDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should call captureTotp when the capture totp button is clicked", fakeAsync(() => {
|
||||
jest.spyOn(component, "canCaptureTotp", "get").mockReturnValue(true);
|
||||
component.captureTotp = jest.fn();
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -445,7 +446,8 @@ describe("LoginDetailsSectionComponent", () => {
|
||||
}));
|
||||
|
||||
describe("canCaptureTotp", () => {
|
||||
it("should return true when totpCaptureService is present and totp is editable", () => {
|
||||
it("should return true when totpCaptureService is present and totpCaptureService.canCaptureTotp is true and totp is editable", () => {
|
||||
jest.spyOn(component, "canCaptureTotp", "get").mockReturnValue(true);
|
||||
component.loginDetailsForm.controls.totp.enable();
|
||||
expect(component.canCaptureTotp).toBe(true);
|
||||
});
|
||||
|
||||
@@ -65,10 +65,14 @@ export class LoginDetailsSectionComponent implements OnInit {
|
||||
newPasswordGenerated: boolean;
|
||||
|
||||
/**
|
||||
* Whether the TOTP field can be captured from the current tab. Only available in the browser extension.
|
||||
* Whether the TOTP field can be captured from the current tab. Only available in the browser extension and
|
||||
* when not in a popout window.
|
||||
*/
|
||||
get canCaptureTotp() {
|
||||
return this.totpCaptureService != null && this.loginDetailsForm.controls.totp.enabled;
|
||||
return (
|
||||
!!this.totpCaptureService?.canCaptureTotp(window) &&
|
||||
this.loginDetailsForm.controls.totp.enabled
|
||||
);
|
||||
}
|
||||
|
||||
private datePipe = inject(DatePipe);
|
||||
|
||||
Reference in New Issue
Block a user