mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-26 12:25:20 +01:00
Change getUserTrustDeviceChoiceForDecryption / setUserTrustDeviceChoiceForDecryption to getShouldTrustDevice / setShouldTrustDevice (#5795)
This commit is contained in:
parent
89120532b2
commit
511ca540b5
@ -251,9 +251,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"]);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -6,8 +6,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<boolean>;
|
||||
setUserTrustDeviceChoiceForDecryption: (value: boolean) => Promise<void>;
|
||||
getShouldTrustDevice: () => Promise<boolean>;
|
||||
setShouldTrustDevice: (value: boolean) => Promise<void>;
|
||||
|
||||
trustDevice: () => Promise<DeviceResponse>;
|
||||
getDeviceKey: () => Promise<DeviceKey>;
|
||||
|
@ -27,12 +27,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<boolean> {
|
||||
return await this.stateService.getUserTrustDeviceChoiceForDecryption();
|
||||
async getShouldTrustDevice(): Promise<boolean> {
|
||||
return await this.stateService.getShouldTrustDevice();
|
||||
}
|
||||
|
||||
async setUserTrustDeviceChoiceForDecryption(value: boolean): Promise<void> {
|
||||
await this.stateService.setUserTrustDeviceChoiceForDecryption(value);
|
||||
async setShouldTrustDevice(value: boolean): Promise<void> {
|
||||
await this.stateService.setShouldTrustDevice(value);
|
||||
}
|
||||
|
||||
async trustDevice(): Promise<DeviceResponse> {
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -262,11 +262,8 @@ export abstract class StateService<T extends Account = Account> {
|
||||
setDuckDuckGoSharedKey: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
getDeviceKey: (options?: StorageOptions) => Promise<DeviceKey | null>;
|
||||
setDeviceKey: (value: DeviceKey, options?: StorageOptions) => Promise<void>;
|
||||
getUserTrustDeviceChoiceForDecryption: (options?: StorageOptions) => Promise<boolean | null>;
|
||||
setUserTrustDeviceChoiceForDecryption: (
|
||||
value: boolean,
|
||||
options?: StorageOptions
|
||||
) => Promise<void>;
|
||||
getShouldTrustDevice: (options?: StorageOptions) => Promise<boolean | null>;
|
||||
setShouldTrustDevice: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
getAccountDecryptionOptions: (
|
||||
options?: StorageOptions
|
||||
) => Promise<AccountDecryptionOptions | null>;
|
||||
|
@ -1319,7 +1319,7 @@ export class StateService<
|
||||
await this.saveAccount(account, options);
|
||||
}
|
||||
|
||||
async getUserTrustDeviceChoiceForDecryption(options?: StorageOptions): Promise<boolean> {
|
||||
async getShouldTrustDevice(options?: StorageOptions): Promise<boolean> {
|
||||
options = this.reconcileOptions(options, await this.defaultOnDiskLocalOptions());
|
||||
|
||||
if (options?.userId == null) {
|
||||
@ -1331,10 +1331,7 @@ export class StateService<
|
||||
return account?.settings?.trustDeviceChoiceForDecryption ?? false;
|
||||
}
|
||||
|
||||
async setUserTrustDeviceChoiceForDecryption(
|
||||
value: boolean,
|
||||
options?: StorageOptions
|
||||
): Promise<void> {
|
||||
async setShouldTrustDevice(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
options = this.reconcileOptions(options, await this.defaultOnDiskLocalOptions());
|
||||
if (options?.userId == null) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user