1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-01 13:13:36 +01:00

[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
This commit is contained in:
Daniel Riera 2024-11-04 08:40:00 -06:00 committed by GitHub
parent 2f1f9cd333
commit f43bf48215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import {
} from "@bitwarden/common/spec"; } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.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 { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault-settings/vault-settings.service";
import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums"; import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
@ -106,6 +107,7 @@ describe("OverlayBackground", () => {
let selectedThemeMock$: BehaviorSubject<ThemeType>; let selectedThemeMock$: BehaviorSubject<ThemeType>;
let inlineMenuFieldQualificationService: InlineMenuFieldQualificationService; let inlineMenuFieldQualificationService: InlineMenuFieldQualificationService;
let themeStateService: MockProxy<ThemeStateService>; let themeStateService: MockProxy<ThemeStateService>;
let totpService: MockProxy<TotpService>;
let overlayBackground: OverlayBackground; let overlayBackground: OverlayBackground;
let portKeyForTabSpy: Record<number, string>; let portKeyForTabSpy: Record<number, string>;
let pageDetailsForTabSpy: PageDetailsForTab; let pageDetailsForTabSpy: PageDetailsForTab;
@ -184,6 +186,7 @@ describe("OverlayBackground", () => {
inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService();
themeStateService = mock<ThemeStateService>(); themeStateService = mock<ThemeStateService>();
themeStateService.selectedTheme$ = selectedThemeMock$; themeStateService.selectedTheme$ = selectedThemeMock$;
totpService = mock<TotpService>();
overlayBackground = new OverlayBackground( overlayBackground = new OverlayBackground(
logService, logService,
cipherService, cipherService,
@ -198,6 +201,7 @@ describe("OverlayBackground", () => {
fido2ActiveRequestManager, fido2ActiveRequestManager,
inlineMenuFieldQualificationService, inlineMenuFieldQualificationService,
themeStateService, themeStateService,
totpService,
generatedPasswordCallbackMock, generatedPasswordCallbackMock,
addPasswordCallbackMock, addPasswordCallbackMock,
); );

View File

@ -33,6 +33,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.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 { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault-settings/vault-settings.service";
import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherType } from "@bitwarden/common/vault/enums";
import { buildCipherIcon } from "@bitwarden/common/vault/icon/build-cipher-icon"; import { buildCipherIcon } from "@bitwarden/common/vault/icon/build-cipher-icon";
@ -217,6 +218,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private fido2ActiveRequestManager: Fido2ActiveRequestManager, private fido2ActiveRequestManager: Fido2ActiveRequestManager,
private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService, private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService,
private themeStateService: ThemeStateService, private themeStateService: ThemeStateService,
private totpService: TotpService,
private generatePasswordCallback: () => Promise<string>, private generatePasswordCallback: () => Promise<string>,
private addPasswordCallback: (password: string) => Promise<void>, private addPasswordCallback: (password: string) => Promise<void>,
) { ) {
@ -1058,7 +1060,6 @@ export class OverlayBackground implements OverlayBackgroundInterface {
} }
const cipher = this.inlineMenuCiphers.get(inlineMenuCipherId); const cipher = this.inlineMenuCiphers.get(inlineMenuCipherId);
if (usePasskey && cipher.login?.hasFido2Credentials) { if (usePasskey && cipher.login?.hasFido2Credentials) {
await this.authenticatePasskeyCredential( await this.authenticatePasskeyCredential(
sender, sender,
@ -1066,6 +1067,11 @@ export class OverlayBackground implements OverlayBackgroundInterface {
); );
this.updateLastUsedInlineMenuCipher(inlineMenuCipherId, cipher); this.updateLastUsedInlineMenuCipher(inlineMenuCipherId, cipher);
if (cipher.login?.totp) {
this.platformUtilsService.copyToClipboard(
await this.totpService.getCode(cipher.login.totp),
);
}
return; return;
} }

View File

@ -1678,6 +1678,7 @@ export default class MainBackground {
this.fido2ActiveRequestManager, this.fido2ActiveRequestManager,
inlineMenuFieldQualificationService, inlineMenuFieldQualificationService,
this.themeStateService, this.themeStateService,
this.totpService,
() => this.generatePassword(), () => this.generatePassword(),
(password) => this.addPasswordToHistory(password), (password) => this.addPasswordToHistory(password),
); );