From 4ce9cee362e6e7c4aa74f6bcfdf31570ecd39000 Mon Sep 17 00:00:00 2001 From: Daniel Riera Date: Thu, 31 Oct 2024 15:20:30 -0400 Subject: [PATCH] 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 --- .../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 d59ed447dde..bf8ceec7598 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 41791b3b75f..400c528d17c 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"; @@ -219,6 +220,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, ) { @@ -1060,7 +1062,6 @@ export class OverlayBackground implements OverlayBackgroundInterface { } const cipher = this.inlineMenuCiphers.get(inlineMenuCipherId); - if (usePasskey && cipher.login?.hasFido2Credentials) { await this.authenticatePasskeyCredential( sender, @@ -1068,6 +1069,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 6e2421e499f..f6f1ae703d1 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1674,6 +1674,7 @@ export default class MainBackground { this.fido2ActiveRequestManager, inlineMenuFieldQualificationService, this.themeStateService, + this.totpService, () => this.generatePassword(), (password) => this.addPasswordToHistory(password), );