From 66f5d908035554960b350e534f2c7a05220b3ee7 Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Mon, 13 May 2024 17:04:26 -0400 Subject: [PATCH] PM-5501 - VaultTimeoutSettingsSvc State Provider Migration - Small bugfixes (#9164) * PM-5501 - VaultTimeoutSettingsSvc - fix setVaultTimeoutOptions condition which needed to use never instead of null. * PM-5501 - Fix browser and desktop not showing the never lock warning * PM-5501 - Use true equality. --- .../popup/settings/account-security.component.ts | 4 ++-- .../desktop/src/app/accounts/settings.component.ts | 2 +- .../vault-timeout-settings.service.spec.ts | 14 +++++++++++++- .../vault-timeout-settings.service.ts | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/browser/src/auth/popup/settings/account-security.component.ts b/apps/browser/src/auth/popup/settings/account-security.component.ts index ea7c3a5e8d7..32cfbe416d1 100644 --- a/apps/browser/src/auth/popup/settings/account-security.component.ts +++ b/apps/browser/src/auth/popup/settings/account-security.component.ts @@ -254,7 +254,7 @@ export class AccountSecurityComponent implements OnInit { } async saveVaultTimeout(previousValue: VaultTimeout, newValue: VaultTimeout) { - if (newValue == null) { + if (newValue === VaultTimeoutStringType.Never) { const confirmed = await this.dialogService.openSimpleDialog({ title: { key: "warning" }, content: { key: "neverLockWarning" }, @@ -289,7 +289,7 @@ export class AccountSecurityComponent implements OnInit { newValue, vaultTimeoutAction, ); - if (newValue == null) { + if (newValue === VaultTimeoutStringType.Never) { this.messagingService.send("bgReseedStorage"); } } diff --git a/apps/desktop/src/app/accounts/settings.component.ts b/apps/desktop/src/app/accounts/settings.component.ts index eedf072a813..ade019b9fba 100644 --- a/apps/desktop/src/app/accounts/settings.component.ts +++ b/apps/desktop/src/app/accounts/settings.component.ts @@ -371,7 +371,7 @@ export class SettingsComponent implements OnInit { } async saveVaultTimeout(newValue: VaultTimeout) { - if (newValue == null) { + if (newValue === VaultTimeoutStringType.Never) { const confirmed = await this.dialogService.openSimpleDialog({ title: { key: "warning" }, content: { key: "neverLockWarning" }, diff --git a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts index 894d550bdac..e9839fc4e63 100644 --- a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts +++ b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.spec.ts @@ -313,7 +313,7 @@ describe("VaultTimeoutSettingsService", () => { expect(cryptoService.refreshAdditionalKeys).toHaveBeenCalled(); }); - it("should clear the tokens when the timeout is non-null and the action is log out", async () => { + it("should clear the tokens when the timeout is not never and the action is log out", async () => { // Arrange const action = VaultTimeoutAction.LogOut; const timeout = 30; @@ -324,6 +324,18 @@ describe("VaultTimeoutSettingsService", () => { // Assert expect(tokenService.clearTokens).toHaveBeenCalled(); }); + + it("should not clear the tokens when the timeout is never and the action is log out", async () => { + // Arrange + const action = VaultTimeoutAction.LogOut; + const timeout = VaultTimeoutStringType.Never; + + // Act + await vaultTimeoutSettingsService.setVaultTimeoutOptions(mockUserId, timeout, action); + + // Assert + expect(tokenService.clearTokens).not.toHaveBeenCalled(); + }); }); function createVaultTimeoutSettingsService( diff --git a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts index 282b86fb630..d48729e9c61 100644 --- a/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts +++ b/libs/common/src/services/vault-timeout/vault-timeout-settings.service.ts @@ -30,7 +30,7 @@ import { LogService } from "../../platform/abstractions/log.service"; import { BiometricStateService } from "../../platform/biometrics/biometric-state.service"; import { StateProvider } from "../../platform/state"; import { UserId } from "../../types/guid"; -import { VaultTimeout } from "../../types/vault-timeout.type"; +import { VaultTimeout, VaultTimeoutStringType } from "../../types/vault-timeout.type"; import { VAULT_TIMEOUT, VAULT_TIMEOUT_ACTION } from "./vault-timeout-settings.state"; @@ -74,7 +74,7 @@ export class VaultTimeoutSettingsService implements VaultTimeoutSettingsServiceA await this.setVaultTimeout(userId, timeout); - if (timeout != null && action === VaultTimeoutAction.LogOut) { + if (timeout != VaultTimeoutStringType.Never && action === VaultTimeoutAction.LogOut) { // if we have a vault timeout and the action is log out, reset tokens // as the tokens were stored on disk and now should be stored in memory await this.tokenService.clearTokens();