From a2926d972cc1058c9574de00d594bf0b42230e5a Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 7 Nov 2022 17:14:02 -0330 Subject: [PATCH] Ensure newly created vaults are unlocked A new vault should be unlocked after being created, because the password is submitted as part of creating the vault. This was accidentally broken as part of #148. A unit test has been added to ensure this doesn't happen again. --- index.js | 2 +- test/index.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5f92493b..f964680e 100644 --- a/index.js +++ b/index.js @@ -80,7 +80,7 @@ class KeyringController extends EventEmitter { async createNewVaultAndKeychain(password) { await this.createFirstKeyTree(password); await this.persistAllKeyrings(password); - this.setUnlocked.bind(); + this.setUnlocked(); this.fullUpdate(); } diff --git a/test/index.js b/test/index.js index 35d8000e..775fd9ba 100644 --- a/test/index.js +++ b/test/index.js @@ -85,7 +85,7 @@ describe('KeyringController', function () { }); describe('createNewVaultAndKeychain', function () { - it('should set a vault on the configManager', async function () { + it('should create a new vault', async function () { keyringController.store.updateState({ vault: null }); assert(!keyringController.store.getState().vault, 'no previous vault'); @@ -95,6 +95,15 @@ describe('KeyringController', function () { expect(vault).toBeTruthy(); }); + it('should unlock the vault', async function () { + keyringController.store.updateState({ vault: null }); + assert(!keyringController.store.getState().vault, 'no previous vault'); + + await keyringController.createNewVaultAndKeychain(password); + const { isUnlocked } = keyringController.memStore.getState(); + expect(isUnlocked).toBe(true); + }); + it('should encrypt keyrings with the correct password each time they are persisted', async function () { keyringController.store.updateState({ vault: null }); assert(!keyringController.store.getState().vault, 'no previous vault');