mirror of
https://github.com/bitwarden/browser
synced 2026-01-11 04:53:49 +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:
@@ -2,6 +2,7 @@ import { TestBed } from "@angular/core/testing";
|
||||
import qrcodeParser from "qrcode-parser";
|
||||
|
||||
import { BrowserApi } from "../../../platform/browser/browser-api";
|
||||
import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
|
||||
|
||||
import { BrowserTotpCaptureService } from "./browser-totp-capture.service";
|
||||
|
||||
@@ -13,12 +14,14 @@ describe("BrowserTotpCaptureService", () => {
|
||||
let testBed: TestBed;
|
||||
let service: BrowserTotpCaptureService;
|
||||
let mockCaptureVisibleTab: jest.SpyInstance;
|
||||
let mockBrowserPopupUtilsInPopout: jest.SpyInstance;
|
||||
|
||||
const validTotpUrl = "otpauth://totp/label?secret=123";
|
||||
|
||||
beforeEach(() => {
|
||||
mockCaptureVisibleTab = jest.spyOn(BrowserApi, "captureVisibleTab");
|
||||
mockCaptureVisibleTab.mockResolvedValue("screenshot");
|
||||
mockBrowserPopupUtilsInPopout = jest.spyOn(BrowserPopupUtils, "inPopout");
|
||||
|
||||
testBed = TestBed.configureTestingModule({
|
||||
providers: [BrowserTotpCaptureService],
|
||||
@@ -66,4 +69,16 @@ describe("BrowserTotpCaptureService", () => {
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
describe("canCaptureTotp", () => {
|
||||
it("should return true when not in a popout window", () => {
|
||||
mockBrowserPopupUtilsInPopout.mockReturnValue(false);
|
||||
expect(service.canCaptureTotp({} as Window)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false when in a popout window", () => {
|
||||
mockBrowserPopupUtilsInPopout.mockReturnValue(true);
|
||||
expect(service.canCaptureTotp({} as Window)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import qrcodeParser from "qrcode-parser";
|
||||
import { TotpCaptureService } from "@bitwarden/vault";
|
||||
|
||||
import { BrowserApi } from "../../../platform/browser/browser-api";
|
||||
import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
|
||||
|
||||
/**
|
||||
* Implementation of TotpCaptureService for the browser which captures the
|
||||
@@ -20,4 +21,8 @@ export class BrowserTotpCaptureService implements TotpCaptureService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
canCaptureTotp(window: Window) {
|
||||
return !BrowserPopupUtils.inPopout(window);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user