From b92e24b2205fbf375a8704bc3b8662d1d54eccf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Tue, 11 Jul 2023 23:25:36 +0100 Subject: [PATCH] Change getUserTrustDeviceChoiceForDecryption / setUserTrustDeviceChoiceForDecryption to getShouldTrustDevice / setShouldTrustDevice (#5795) --- ...base-login-decryption-options.component.ts | 4 +-- .../src/auth/components/lock.component.ts | 4 +-- ...device-trust-crypto.service.abstraction.ts | 4 +-- ...ice-trust-crypto.service.implementation.ts | 8 +++--- .../device-trust-crypto.service.spec.ts | 26 +++++++------------ .../platform/abstractions/state.service.ts | 7 ++--- .../src/platform/services/state.service.ts | 7 ++--- 7 files changed, 23 insertions(+), 37 deletions(-) diff --git a/libs/angular/src/auth/components/base-login-decryption-options.component.ts b/libs/angular/src/auth/components/base-login-decryption-options.component.ts index f4c678e55a97..dc15ce4d14bf 100644 --- a/libs/angular/src/auth/components/base-login-decryption-options.component.ts +++ b/libs/angular/src/auth/components/base-login-decryption-options.component.ts @@ -254,9 +254,7 @@ export class BaseLoginDecryptionOptionsComponent implements OnInit, OnDestroy { } async approveWithMasterPassword() { - await this.deviceTrustCryptoService.setUserTrustDeviceChoiceForDecryption( - this.rememberDevice.value - ); + await this.deviceTrustCryptoService.setShouldTrustDevice(this.rememberDevice.value); this.router.navigate(["/lock"]); } diff --git a/libs/angular/src/auth/components/lock.component.ts b/libs/angular/src/auth/components/lock.component.ts index ce8fd863b0a4..fa303d67e6a6 100644 --- a/libs/angular/src/auth/components/lock.component.ts +++ b/libs/angular/src/auth/components/lock.component.ts @@ -298,10 +298,10 @@ export class LockComponent implements OnInit, OnDestroy { // Now that we have a decrypted user key in memory, we can check if we // need to establish trust on the current device - if (this.deviceTrustCryptoService.getUserTrustDeviceChoiceForDecryption()) { + if (this.deviceTrustCryptoService.getShouldTrustDevice()) { await this.deviceTrustCryptoService.trustDevice(); // reset the trust choice - await this.deviceTrustCryptoService.setUserTrustDeviceChoiceForDecryption(false); + await this.deviceTrustCryptoService.setShouldTrustDevice(false); } await this.doContinue(evaluatePasswordAfterUnlock); diff --git a/libs/common/src/auth/abstractions/device-trust-crypto.service.abstraction.ts b/libs/common/src/auth/abstractions/device-trust-crypto.service.abstraction.ts index aed35080b8da..b89af1a35100 100644 --- a/libs/common/src/auth/abstractions/device-trust-crypto.service.abstraction.ts +++ b/libs/common/src/auth/abstractions/device-trust-crypto.service.abstraction.ts @@ -7,8 +7,8 @@ export abstract class DeviceTrustCryptoServiceAbstraction { * @description Retrieves the users choice to trust the device which can only happen after decryption * Note: this value should only be used once and then reset */ - getUserTrustDeviceChoiceForDecryption: () => Promise; - setUserTrustDeviceChoiceForDecryption: (value: boolean) => Promise; + getShouldTrustDevice: () => Promise; + setShouldTrustDevice: (value: boolean) => Promise; trustDevice: () => Promise; getDeviceKey: () => Promise; diff --git a/libs/common/src/auth/services/device-trust-crypto.service.implementation.ts b/libs/common/src/auth/services/device-trust-crypto.service.implementation.ts index c9f54c7de4a4..81eda787bea0 100644 --- a/libs/common/src/auth/services/device-trust-crypto.service.implementation.ts +++ b/libs/common/src/auth/services/device-trust-crypto.service.implementation.ts @@ -28,12 +28,12 @@ export class DeviceTrustCryptoService implements DeviceTrustCryptoServiceAbstrac * @description Retrieves the users choice to trust the device which can only happen after decryption * Note: this value should only be used once and then reset */ - async getUserTrustDeviceChoiceForDecryption(): Promise { - return await this.stateService.getUserTrustDeviceChoiceForDecryption(); + async getShouldTrustDevice(): Promise { + return await this.stateService.getShouldTrustDevice(); } - async setUserTrustDeviceChoiceForDecryption(value: boolean): Promise { - await this.stateService.setUserTrustDeviceChoiceForDecryption(value); + async setShouldTrustDevice(value: boolean): Promise { + await this.stateService.setShouldTrustDevice(value); } async trustDevice(): Promise { diff --git a/libs/common/src/auth/services/device-trust-crypto.service.spec.ts b/libs/common/src/auth/services/device-trust-crypto.service.spec.ts index 0beabace8da5..0fecb6cae7fa 100644 --- a/libs/common/src/auth/services/device-trust-crypto.service.spec.ts +++ b/libs/common/src/auth/services/device-trust-crypto.service.spec.ts @@ -50,34 +50,28 @@ describe("deviceTrustCryptoService", () => { }); describe("User Trust Device Choice For Decryption", () => { - describe("getUserTrustDeviceChoiceForDecryption", () => { + describe("getShouldTrustDevice", () => { it("gets the user trust device choice for decryption from the state service", async () => { - const stateSvcGetUserTrustDeviceChoiceForDecryptionSpy = jest.spyOn( - stateService, - "getUserTrustDeviceChoiceForDecryption" - ); + const stateSvcGetShouldTrustDeviceSpy = jest.spyOn(stateService, "getShouldTrustDevice"); const expectedValue = true; - stateSvcGetUserTrustDeviceChoiceForDecryptionSpy.mockResolvedValue(expectedValue); - const result = await deviceTrustCryptoService.getUserTrustDeviceChoiceForDecryption(); + stateSvcGetShouldTrustDeviceSpy.mockResolvedValue(expectedValue); + const result = await deviceTrustCryptoService.getShouldTrustDevice(); - expect(stateSvcGetUserTrustDeviceChoiceForDecryptionSpy).toHaveBeenCalledTimes(1); + expect(stateSvcGetShouldTrustDeviceSpy).toHaveBeenCalledTimes(1); expect(result).toEqual(expectedValue); }); }); - describe("setUserTrustDeviceChoiceForDecryption", () => { + describe("setShouldTrustDevice", () => { it("sets the user trust device choice for decryption in the state service", async () => { - const stateSvcSetUserTrustDeviceChoiceForDecryptionSpy = jest.spyOn( - stateService, - "setUserTrustDeviceChoiceForDecryption" - ); + const stateSvcSetShouldTrustDeviceSpy = jest.spyOn(stateService, "setShouldTrustDevice"); const newValue = true; - await deviceTrustCryptoService.setUserTrustDeviceChoiceForDecryption(newValue); + await deviceTrustCryptoService.setShouldTrustDevice(newValue); - expect(stateSvcSetUserTrustDeviceChoiceForDecryptionSpy).toHaveBeenCalledTimes(1); - expect(stateSvcSetUserTrustDeviceChoiceForDecryptionSpy).toHaveBeenCalledWith(newValue); + expect(stateSvcSetShouldTrustDeviceSpy).toHaveBeenCalledTimes(1); + expect(stateSvcSetShouldTrustDeviceSpy).toHaveBeenCalledWith(newValue); }); }); }); diff --git a/libs/common/src/platform/abstractions/state.service.ts b/libs/common/src/platform/abstractions/state.service.ts index 28bd998ae020..97ad807fc265 100644 --- a/libs/common/src/platform/abstractions/state.service.ts +++ b/libs/common/src/platform/abstractions/state.service.ts @@ -262,11 +262,8 @@ export abstract class StateService { setDuckDuckGoSharedKey: (value: string, options?: StorageOptions) => Promise; getDeviceKey: (options?: StorageOptions) => Promise; setDeviceKey: (value: DeviceKey, options?: StorageOptions) => Promise; - getUserTrustDeviceChoiceForDecryption: (options?: StorageOptions) => Promise; - setUserTrustDeviceChoiceForDecryption: ( - value: boolean, - options?: StorageOptions - ) => Promise; + getShouldTrustDevice: (options?: StorageOptions) => Promise; + setShouldTrustDevice: (value: boolean, options?: StorageOptions) => Promise; getAccountDecryptionOptions: ( options?: StorageOptions ) => Promise; diff --git a/libs/common/src/platform/services/state.service.ts b/libs/common/src/platform/services/state.service.ts index 94371428f6df..9822b6d967b4 100644 --- a/libs/common/src/platform/services/state.service.ts +++ b/libs/common/src/platform/services/state.service.ts @@ -1326,7 +1326,7 @@ export class StateService< await this.saveAccount(account, options); } - async getUserTrustDeviceChoiceForDecryption(options?: StorageOptions): Promise { + async getShouldTrustDevice(options?: StorageOptions): Promise { options = this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()); if (options?.userId == null) { @@ -1338,10 +1338,7 @@ export class StateService< return account?.settings?.trustDeviceChoiceForDecryption ?? false; } - async setUserTrustDeviceChoiceForDecryption( - value: boolean, - options?: StorageOptions - ): Promise { + async setShouldTrustDevice(value: boolean, options?: StorageOptions): Promise { options = this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()); if (options?.userId == null) { return;