Skip to content

Commit

Permalink
PM-8113 - Refactor names / tests / comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredSnider-Bitwarden committed Jan 22, 2025
1 parent 2203aae commit 07e6894
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions apps/browser/src/auth/popup/two-factor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { BrowserApi } from "../../platform/browser/browser-api";
import { ZonedMessageListenerService } from "../../platform/browser/zoned-message-listener.service";
import BrowserPopupUtils from "../../platform/popup/browser-popup-utils";

import { closeTwoFactorAuthPopout } from "./utils/auth-popout-window";
import { closeTwoFactorAuthWebAuthnPopout } from "./utils/auth-popout-window";

Check warning on line 36 in apps/browser/src/auth/popup/two-factor.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/two-factor.component.ts#L36

Added line #L36 was not covered by tests

@Component({
selector: "app-two-factor",
Expand Down Expand Up @@ -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
// on the web vault screen which tells them to continue in the browser extension (sidebar or popup)
await closeTwoFactorAuthPopout();
await closeTwoFactorAuthWebAuthnPopout();

Check warning on line 174 in apps/browser/src/auth/popup/two-factor.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/two-factor.component.ts#L174

Added line #L174 was not covered by tests
};
}
});
Expand Down
20 changes: 10 additions & 10 deletions apps/browser/src/auth/popup/utils/auth-popout-window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
openUnlockPopout,
closeUnlockPopout,
openSsoAuthResultPopout,
openTwoFactorAuthPopout,
closeTwoFactorAuthPopout,
openTwoFactorAuthWebAuthnPopout,
closeTwoFactorAuthWebAuthnPopout,
closeSsoAuthResultPopout,
} from "./auth-popout-window";

Expand Down Expand Up @@ -106,22 +106,22 @@ describe("AuthPopoutWindow", () => {
});
});

describe("openTwoFactorAuthPopout", () => {
it("opens a window that facilitates two factor authentication", async () => {
await openTwoFactorAuthPopout({ data: "data", remember: "remember" });
describe("openTwoFactorAuthWebAuthnPopout", () => {
it("opens a window that facilitates two factor authentication via WebAuthn", async () => {
await openTwoFactorAuthWebAuthnPopout({ data: "data", remember: "remember" });

expect(openPopoutSpy).toHaveBeenCalledWith(
"popup/index.html#/2fa;webAuthnResponse=data;remember=remember",
{ singleActionKey: AuthPopoutType.twoFactorAuth },
{ singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn },
);
});
});

describe("closeTwoFactorAuthPopout", () => {
it("closes the two-factor authentication window", async () => {
await closeTwoFactorAuthPopout();
describe("closeTwoFactorAuthWebAuthnPopout", () => {
it("closes the two-factor authentication WebAuthn window", async () => {
await closeTwoFactorAuthWebAuthnPopout();

expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuth);
expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuthWebAuthn);
});
});
});
26 changes: 15 additions & 11 deletions apps/browser/src/auth/popup/utils/auth-popout-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
const AuthPopoutType = {
unlockExtension: "auth_unlockExtension",
ssoAuthResult: "auth_ssoAuthResult",
twoFactorAuth: "auth_twoFactorAuth",
twoFactorAuthWebAuthn: "auth_twoFactorAuthWebAuthn",
} as const;
const extensionUnlockUrls = new Set([
chrome.runtime.getURL("popup/index.html#/lock"),
Expand Down Expand Up @@ -60,33 +60,37 @@ async function openSsoAuthResultPopout(resultData: { code: string; state: string
}

/**
* Closes the two-factor authentication popout window.
* Closes the SSO authentication result popout window.
*/
async function closeSsoAuthResultPopout() {
await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.ssoAuthResult);
}

/**
* Opens a window that facilitates two-factor authentication.
* Opens a popout that facilitates two-factor authentication via WebAuthn.
*
* @param twoFactorAuthData - The data from the two-factor authentication.
* @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 openTwoFactorAuthPopout(twoFactorAuthData: { data: string; remember: string }) {
const { data, remember } = twoFactorAuthData;
async function openTwoFactorAuthWebAuthnPopout(twoFactorAuthWebAuthnData: {
data: string;
remember: string;
}) {
const { data, remember } = twoFactorAuthWebAuthnData;
const params =
`webAuthnResponse=${encodeURIComponent(data)};` + `remember=${encodeURIComponent(remember)}`;
const twoFactorUrl = `popup/index.html#/2fa;${params}`;

await BrowserPopupUtils.openPopout(twoFactorUrl, {
singleActionKey: AuthPopoutType.twoFactorAuth,
singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn,
});
}

/**
* Closes the two-factor authentication popout window.
*/
async function closeTwoFactorAuthPopout() {
await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuth);
async function closeTwoFactorAuthWebAuthnPopout() {
await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuthWebAuthn);
}

export {
Expand All @@ -95,6 +99,6 @@ export {
closeUnlockPopout,
openSsoAuthResultPopout,
closeSsoAuthResultPopout,
openTwoFactorAuthPopout,
closeTwoFactorAuthPopout,
openTwoFactorAuthWebAuthnPopout,
closeTwoFactorAuthWebAuthnPopout,
};
4 changes: 2 additions & 2 deletions apps/browser/src/background/runtime.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { BiometricsCommands } from "@bitwarden/key-management";
import {
closeUnlockPopout,
openSsoAuthResultPopout,
openTwoFactorAuthPopout,
openTwoFactorAuthWebAuthnPopout,
} from "../auth/popup/utils/auth-popout-window";
import { LockedVaultPendingNotificationsData } from "../autofill/background/abstractions/notification.background";
import { AutofillService } from "../autofill/services/abstractions/autofill.service";
Expand Down Expand Up @@ -333,7 +333,7 @@ export default class RuntimeBackground {
return;
}

await openTwoFactorAuthPopout(msg);
await openTwoFactorAuthWebAuthnPopout(msg);

Check warning on line 336 in apps/browser/src/background/runtime.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/runtime.background.ts#L336

Added line #L336 was not covered by tests
break;
}
case "reloadPopup":
Expand Down

0 comments on commit 07e6894

Please sign in to comment.