1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Auth/PM-8113 - Extension - AuthPopoutWindows - Add new method + refactor names (#13020)

* PM-8113 - Add closeSsoAuthResultPopout

* PM-8113 - Refactor names / tests / comments
This commit is contained in:
Jared Snider
2025-01-22 21:48:38 -05:00
committed by GitHub
parent 649a196e4b
commit 4abbf32638
4 changed files with 46 additions and 25 deletions

View File

@@ -33,7 +33,7 @@ import { BrowserApi } from "../../platform/browser/browser-api";
import { ZonedMessageListenerService } from "../../platform/browser/zoned-message-listener.service"; import { ZonedMessageListenerService } from "../../platform/browser/zoned-message-listener.service";
import BrowserPopupUtils from "../../platform/popup/browser-popup-utils"; import BrowserPopupUtils from "../../platform/popup/browser-popup-utils";
import { closeTwoFactorAuthPopout } from "./utils/auth-popout-window"; import { closeTwoFactorAuthWebAuthnPopout } from "./utils/auth-popout-window";
@Component({ @Component({
selector: "app-two-factor", selector: "app-two-factor",
@@ -171,7 +171,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent implements OnInit
// We don't need this window anymore because the intent is for the user to be left // We don't need this window anymore because the intent is for the user to be left
// on the web vault screen which tells them to continue in the browser extension (sidebar or popup) // on the web vault screen which tells them to continue in the browser extension (sidebar or popup)
await closeTwoFactorAuthPopout(); await closeTwoFactorAuthWebAuthnPopout();
}; };
} }
}); });

View File

@@ -7,8 +7,9 @@ import {
openUnlockPopout, openUnlockPopout,
closeUnlockPopout, closeUnlockPopout,
openSsoAuthResultPopout, openSsoAuthResultPopout,
openTwoFactorAuthPopout, openTwoFactorAuthWebAuthnPopout,
closeTwoFactorAuthPopout, closeTwoFactorAuthWebAuthnPopout,
closeSsoAuthResultPopout,
} from "./auth-popout-window"; } from "./auth-popout-window";
describe("AuthPopoutWindow", () => { describe("AuthPopoutWindow", () => {
@@ -97,22 +98,30 @@ describe("AuthPopoutWindow", () => {
}); });
}); });
describe("openTwoFactorAuthPopout", () => { describe("closeSsoAuthResultPopout", () => {
it("opens a window that facilitates two factor authentication", async () => { it("closes the SSO authentication result popout window", async () => {
await openTwoFactorAuthPopout({ data: "data", remember: "remember" }); await closeSsoAuthResultPopout();
expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.ssoAuthResult);
});
});
describe("openTwoFactorAuthWebAuthnPopout", () => {
it("opens a window that facilitates two factor authentication via WebAuthn", async () => {
await openTwoFactorAuthWebAuthnPopout({ data: "data", remember: "remember" });
expect(openPopoutSpy).toHaveBeenCalledWith( expect(openPopoutSpy).toHaveBeenCalledWith(
"popup/index.html#/2fa;webAuthnResponse=data;remember=remember", "popup/index.html#/2fa;webAuthnResponse=data;remember=remember",
{ singleActionKey: AuthPopoutType.twoFactorAuth }, { singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn },
); );
}); });
}); });
describe("closeTwoFactorAuthPopout", () => { describe("closeTwoFactorAuthWebAuthnPopout", () => {
it("closes the two-factor authentication window", async () => { it("closes the two-factor authentication WebAuthn window", async () => {
await closeTwoFactorAuthPopout(); await closeTwoFactorAuthWebAuthnPopout();
expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuth); expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuthWebAuthn);
}); });
}); });
}); });

View File

@@ -6,7 +6,7 @@ import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
const AuthPopoutType = { const AuthPopoutType = {
unlockExtension: "auth_unlockExtension", unlockExtension: "auth_unlockExtension",
ssoAuthResult: "auth_ssoAuthResult", ssoAuthResult: "auth_ssoAuthResult",
twoFactorAuth: "auth_twoFactorAuth", twoFactorAuthWebAuthn: "auth_twoFactorAuthWebAuthn",
} as const; } as const;
const extensionUnlockUrls = new Set([ const extensionUnlockUrls = new Set([
chrome.runtime.getURL("popup/index.html#/lock"), chrome.runtime.getURL("popup/index.html#/lock"),
@@ -60,26 +60,37 @@ async function openSsoAuthResultPopout(resultData: { code: string; state: string
} }
/** /**
* Opens a window that facilitates two-factor authentication. * Closes the SSO authentication result popout window.
*
* @param twoFactorAuthData - The data from the two-factor authentication.
*/ */
async function openTwoFactorAuthPopout(twoFactorAuthData: { data: string; remember: string }) { async function closeSsoAuthResultPopout() {
const { data, remember } = twoFactorAuthData; await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.ssoAuthResult);
}
/**
* Opens a popout that facilitates two-factor authentication via WebAuthn.
*
* @param twoFactorAuthWebAuthnData - The data to send ot the popout via query param.
* It includes the WebAuthn response and whether to save the 2FA remember me token or not.
*/
async function openTwoFactorAuthWebAuthnPopout(twoFactorAuthWebAuthnData: {
data: string;
remember: string;
}) {
const { data, remember } = twoFactorAuthWebAuthnData;
const params = const params =
`webAuthnResponse=${encodeURIComponent(data)};` + `remember=${encodeURIComponent(remember)}`; `webAuthnResponse=${encodeURIComponent(data)};` + `remember=${encodeURIComponent(remember)}`;
const twoFactorUrl = `popup/index.html#/2fa;${params}`; const twoFactorUrl = `popup/index.html#/2fa;${params}`;
await BrowserPopupUtils.openPopout(twoFactorUrl, { await BrowserPopupUtils.openPopout(twoFactorUrl, {
singleActionKey: AuthPopoutType.twoFactorAuth, singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn,
}); });
} }
/** /**
* Closes the two-factor authentication popout window. * Closes the two-factor authentication popout window.
*/ */
async function closeTwoFactorAuthPopout() { async function closeTwoFactorAuthWebAuthnPopout() {
await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuth); await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuthWebAuthn);
} }
export { export {
@@ -87,6 +98,7 @@ export {
openUnlockPopout, openUnlockPopout,
closeUnlockPopout, closeUnlockPopout,
openSsoAuthResultPopout, openSsoAuthResultPopout,
openTwoFactorAuthPopout, closeSsoAuthResultPopout,
closeTwoFactorAuthPopout, openTwoFactorAuthWebAuthnPopout,
closeTwoFactorAuthWebAuthnPopout,
}; };

View File

@@ -22,7 +22,7 @@ import { BiometricsCommands } from "@bitwarden/key-management";
import { import {
closeUnlockPopout, closeUnlockPopout,
openSsoAuthResultPopout, openSsoAuthResultPopout,
openTwoFactorAuthPopout, openTwoFactorAuthWebAuthnPopout,
} from "../auth/popup/utils/auth-popout-window"; } from "../auth/popup/utils/auth-popout-window";
import { LockedVaultPendingNotificationsData } from "../autofill/background/abstractions/notification.background"; import { LockedVaultPendingNotificationsData } from "../autofill/background/abstractions/notification.background";
import { AutofillService } from "../autofill/services/abstractions/autofill.service"; import { AutofillService } from "../autofill/services/abstractions/autofill.service";
@@ -333,7 +333,7 @@ export default class RuntimeBackground {
return; return;
} }
await openTwoFactorAuthPopout(msg); await openTwoFactorAuthWebAuthnPopout(msg);
break; break;
} }
case "reloadPopup": case "reloadPopup":