Skip to content

Commit 33e3bc6

Browse files
committed
(wip) add envelope encryption tests
1 parent 7342010 commit 33e3bc6

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

packages/keyring-controller/src/KeyringController.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,60 @@ describe('KeyringController', () => {
796796
);
797797
});
798798

799+
describe('envelope encryption mode', () => {
800+
it('should create new vault with encryption key', async () => {
801+
await withController(
802+
{ cacheEncryptionKey: true, skipVaultCreation: true },
803+
async ({ controller }) => {
804+
await controller.createNewVaultAndKeychain(
805+
password,
806+
MOCK_ENCRYPTION_KEY,
807+
);
808+
809+
expect(controller.state.encryptionKey).toBeDefined();
810+
// expect(controller.state.encryptionSalt).toBeDefined();
811+
expect(controller.state.encryptedEncryptionKey).toBeDefined();
812+
},
813+
);
814+
});
815+
816+
it('should unlock with password', async () => {
817+
await withController(
818+
{ cacheEncryptionKey: true, skipVaultCreation: true },
819+
async ({ controller }) => {
820+
await controller.createNewVaultAndKeychain(
821+
password,
822+
MOCK_ENCRYPTION_KEY,
823+
);
824+
825+
expect(controller.isUnlocked()).toBe(true);
826+
expect(controller.state.isUnlocked).toBe(true);
827+
828+
await controller.setLocked();
829+
830+
expect(controller.isUnlocked()).toBe(false);
831+
expect(controller.state.isUnlocked).toBe(false);
832+
833+
await controller.submitPassword(password);
834+
835+
expect(controller.isUnlocked()).toBe(true);
836+
expect(controller.state.isUnlocked).toBe(true);
837+
},
838+
);
839+
});
840+
841+
it('should throw error if creating new vault with encryption key and cacheEncryptionKey is false', async () => {
842+
await withController(
843+
{ cacheEncryptionKey: false, skipVaultCreation: true },
844+
async ({ controller }) => {
845+
await expect(
846+
controller.createNewVaultAndKeychain(password, MOCK_ENCRYPTION_KEY),
847+
).rejects.toThrow(KeyringControllerError.CacheEncryptionKeyDisabled);
848+
},
849+
);
850+
});
851+
});
852+
799853
describe('setLocked', () => {
800854
it('should set locked correctly', async () => {
801855
await withController(async ({ controller }) => {

0 commit comments

Comments
 (0)