1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00

[PM-11941] Migrate TOTP Generator to use SDK (#12987)

* Refactored totp service to use sdk

Fixed strict typescript issues

* Fixed dependency issues

* Returned object that contains code and period, removed get interval function

* removed dependencies

* Updated to use refactored totp service

* removed sdk service undefined check

* removed undefined as an input from the getCode function

* Made getcode$ an observable

* refactored to use getcodee$

* Filter out emmissions

* updated sdk version

* Fixed readability nit

* log error on overlay if totp response does not return a code

* fix(totpGeneration): [PM-11941] Totp countdown not working on clients

* Used optional chaining if totpresponse returns null or undefined
This commit is contained in:
SmithThe4th
2025-03-06 14:01:07 -05:00
committed by GitHub
parent 1415041fd7
commit e327816bc4
24 changed files with 345 additions and 443 deletions

View File

@@ -136,10 +136,10 @@ describe("CopyCipherFieldService", () => {
it("should get TOTP code when allowed from premium", async () => {
billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(true));
totpService.getCode.mockResolvedValue("123456");
totpService.getCode$.mockReturnValue(of({ code: "123456", period: 30 }));
const result = await service.copy(valueToCopy, actionType, cipher, skipReprompt);
expect(result).toBeTruthy();
expect(totpService.getCode).toHaveBeenCalledWith(valueToCopy);
expect(totpService.getCode$).toHaveBeenCalledWith(valueToCopy);
expect(platformUtilsService.copyToClipboard).toHaveBeenCalledWith("123456");
expect(billingAccountProfileStateService.hasPremiumFromAnySource$).toHaveBeenCalledWith(
userId,
@@ -148,10 +148,10 @@ describe("CopyCipherFieldService", () => {
it("should get TOTP code when allowed from organization", async () => {
cipher.organizationUseTotp = true;
totpService.getCode.mockResolvedValue("123456");
totpService.getCode$.mockReturnValue(of({ code: "123456", period: 30 }));
const result = await service.copy(valueToCopy, actionType, cipher, skipReprompt);
expect(result).toBeTruthy();
expect(totpService.getCode).toHaveBeenCalledWith(valueToCopy);
expect(totpService.getCode$).toHaveBeenCalledWith(valueToCopy);
expect(platformUtilsService.copyToClipboard).toHaveBeenCalledWith("123456");
});
@@ -159,7 +159,7 @@ describe("CopyCipherFieldService", () => {
billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(false));
const result = await service.copy(valueToCopy, actionType, cipher, skipReprompt);
expect(result).toBeFalsy();
expect(totpService.getCode).not.toHaveBeenCalled();
expect(totpService.getCode$).not.toHaveBeenCalled();
expect(platformUtilsService.copyToClipboard).not.toHaveBeenCalled();
expect(billingAccountProfileStateService.hasPremiumFromAnySource$).toHaveBeenCalledWith(
userId,
@@ -170,7 +170,7 @@ describe("CopyCipherFieldService", () => {
cipher.login.totp = null;
const result = await service.copy(valueToCopy, actionType, cipher, skipReprompt);
expect(result).toBeFalsy();
expect(totpService.getCode).not.toHaveBeenCalled();
expect(totpService.getCode$).not.toHaveBeenCalled();
expect(platformUtilsService.copyToClipboard).not.toHaveBeenCalled();
});
});