tests: vault locking (#2394)

This commit is contained in:
Mo
2023-08-07 15:27:06 -05:00
committed by GitHub
parent a9edf671b1
commit 3b531ce8bb
23 changed files with 268 additions and 82 deletions

View File

@@ -0,0 +1,30 @@
import { EncryptionProviderInterface } from './../../Encryption/EncryptionProviderInterface'
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
import { KeySystemPasswordType, VaultListingInterface } from '@standardnotes/models'
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
export class ValidateVaultPassword implements SyncUseCaseInterface<boolean> {
constructor(
private encryption: EncryptionProviderInterface,
private keys: KeySystemKeyManagerInterface,
) {}
execute(vault: VaultListingInterface, password: string): Result<boolean> {
if (vault.keyPasswordType !== KeySystemPasswordType.UserInputted) {
throw new Error('Vault uses randomized password and cannot be validated with password')
}
const rootKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
if (!rootKey) {
return Result.ok(false)
}
const derivedRootKey = this.encryption.deriveUserInputtedKeySystemRootKey({
keyParams: vault.rootKeyParams,
userInputtedPassword: password,
})
return Result.ok(rootKey.isEqual(derivedRootKey))
}
}

View File

@@ -1,3 +1,5 @@
import { GetVaultItems } from './../Vault/UseCase/GetVaultItems'
import { RemoveItemsFromMemory } from './../Storage/UseCase/RemoveItemsFromMemory'
import { GetVaults } from '../Vault/UseCase/GetVaults'
import { KeySystemPasswordType, KeySystemRootKeyStorageMode, VaultListingInterface } from '@standardnotes/models'
import { VaultLockServiceInterface } from './VaultLockServiceInterface'
@@ -22,6 +24,8 @@ export class VaultLockService
private keys: KeySystemKeyManagerInterface,
private _getVaults: GetVaults,
private _decryptErroredPayloads: DecryptErroredPayloads,
private _removeItemsFromMemory: RemoveItemsFromMemory,
private _getVaultItems: GetVaultItems,
eventBus: InternalEventBusInterface,
) {
super(eventBus)
@@ -40,6 +44,8 @@ export class VaultLockService
;(this.keys as unknown) = undefined
;(this._getVaults as unknown) = undefined
;(this._decryptErroredPayloads as unknown) = undefined
;(this._removeItemsFromMemory as unknown) = undefined
;(this._getVaultItems as unknown) = undefined
this.lockMap.clear()
}
@@ -68,6 +74,9 @@ export class VaultLockService
await this.keys.wipeVaultKeysFromMemory(vault)
const vaultItems = this._getVaultItems.execute(vault).getValue()
await this._removeItemsFromMemory.execute(vaultItems)
this.lockMap.set(vault.uuid, true)
void this.notifyEventSync(VaultLockServiceEvent.VaultLocked, { vault })