From f43bf482154e0ba4ef6e0d444f6bb79366056bc2 Mon Sep 17 00:00:00 2001 From: Daniel Riera Date: Mon, 4 Nov 2024 08:40:00 -0600 Subject: [PATCH] [PM-11777] fix: TOTP not copied when autofilling passkey (#11814) * PM-11777 fix: TOTP not copied when autofilling passkey - Added totpService to overlay background constructor - Edited spec to account for totpsService - Edited fillInlineMenuCipher to copy totp to clipboard if present * add optional chaining --- .../src/autofill/background/overlay.background.spec.ts | 4 ++++ .../browser/src/autofill/background/overlay.background.ts | 8 +++++++- apps/browser/src/background/main.background.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 29ae35d5ce..6ec3c0a9b5 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -32,6 +32,7 @@ import { } from "@bitwarden/common/spec"; import { UserId } from "@bitwarden/common/types/guid"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; +import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service"; import { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault-settings/vault-settings.service"; import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; @@ -106,6 +107,7 @@ describe("OverlayBackground", () => { let selectedThemeMock$: BehaviorSubject; let inlineMenuFieldQualificationService: InlineMenuFieldQualificationService; let themeStateService: MockProxy; + let totpService: MockProxy; let overlayBackground: OverlayBackground; let portKeyForTabSpy: Record; let pageDetailsForTabSpy: PageDetailsForTab; @@ -184,6 +186,7 @@ describe("OverlayBackground", () => { inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); themeStateService = mock(); themeStateService.selectedTheme$ = selectedThemeMock$; + totpService = mock(); overlayBackground = new OverlayBackground( logService, cipherService, @@ -198,6 +201,7 @@ describe("OverlayBackground", () => { fido2ActiveRequestManager, inlineMenuFieldQualificationService, themeStateService, + totpService, generatedPasswordCallbackMock, addPasswordCallbackMock, ); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index a2b3e33d74..c42d1f7e64 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -33,6 +33,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { Utils } from "@bitwarden/common/platform/misc/utils"; import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; +import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service"; import { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault-settings/vault-settings.service"; import { CipherType } from "@bitwarden/common/vault/enums"; import { buildCipherIcon } from "@bitwarden/common/vault/icon/build-cipher-icon"; @@ -217,6 +218,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { private fido2ActiveRequestManager: Fido2ActiveRequestManager, private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService, private themeStateService: ThemeStateService, + private totpService: TotpService, private generatePasswordCallback: () => Promise, private addPasswordCallback: (password: string) => Promise, ) { @@ -1058,7 +1060,6 @@ export class OverlayBackground implements OverlayBackgroundInterface { } const cipher = this.inlineMenuCiphers.get(inlineMenuCipherId); - if (usePasskey && cipher.login?.hasFido2Credentials) { await this.authenticatePasskeyCredential( sender, @@ -1066,6 +1067,11 @@ export class OverlayBackground implements OverlayBackgroundInterface { ); this.updateLastUsedInlineMenuCipher(inlineMenuCipherId, cipher); + if (cipher.login?.totp) { + this.platformUtilsService.copyToClipboard( + await this.totpService.getCode(cipher.login.totp), + ); + } return; } diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index c3ecb5d3fe..27d83af132 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1678,6 +1678,7 @@ export default class MainBackground { this.fido2ActiveRequestManager, inlineMenuFieldQualificationService, this.themeStateService, + this.totpService, () => this.generatePassword(), (password) => this.addPasswordToHistory(password), );