From 837f141e1362e01d2a25c979c43c4cbf4a95007c Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Tue, 28 May 2024 08:00:39 -0400 Subject: [PATCH] Convert to `function`'s Co-authored-by: Andreas Coroiu --- .../platform/services/crypto.service.spec.ts | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/libs/common/src/platform/services/crypto.service.spec.ts b/libs/common/src/platform/services/crypto.service.spec.ts index 4ef2e7e7365..4ae11ceef76 100644 --- a/libs/common/src/platform/services/crypto.service.spec.ts +++ b/libs/common/src/platform/services/crypto.service.spec.ts @@ -350,13 +350,12 @@ describe("cryptoService", () => { }); describe("userPrivateKey$", () => { - const setupKeys = ({ - makeMasterKey, - makeUserKey, - }: { + type SetupKeysParams = { makeMasterKey: boolean; makeUserKey: boolean; - }): [UserKey, MasterKey] => { + }; + + function setupKeys({ makeMasterKey, makeUserKey }: SetupKeysParams): [UserKey, MasterKey] { const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY); const fakeMasterKey = makeMasterKey ? makeSymmetricCryptoKey(64) : null; masterPasswordService.masterKeySubject.next(fakeMasterKey); @@ -364,7 +363,7 @@ describe("cryptoService", () => { const fakeUserKey = makeUserKey ? makeSymmetricCryptoKey(64) : null; userKeyState.stateSubject.next([mockUserId, fakeUserKey]); return [fakeUserKey, fakeMasterKey]; - }; + } it("will return users decrypted private key when legacy support set to %legacySupport and user hasUserKey = $hasUserKey and user hasMasterKey = $hasMasterKey", async () => { const [userKey] = setupKeys({ @@ -426,7 +425,7 @@ describe("cryptoService", () => { }); describe("cipherDecryptionKeys$", () => { - const fakePrivateKeyDecryption = (encryptedPrivateKey: Encrypted, key: SymmetricCryptoKey) => { + function fakePrivateKeyDecryption(encryptedPrivateKey: Encrypted, key: SymmetricCryptoKey) { const output = new Uint8Array(64); output.set(encryptedPrivateKey.dataBytes); output.set( @@ -434,9 +433,9 @@ describe("cryptoService", () => { encryptedPrivateKey.dataBytes.length, ); return output; - }; + } - const fakeOrgKeyDecryption = (encryptedString: EncString, userPrivateKey: Uint8Array) => { + function fakeOrgKeyDecryption(encryptedString: EncString, userPrivateKey: Uint8Array) { const output = new Uint8Array(64); output.set(encryptedString.dataBytes); output.set( @@ -444,18 +443,18 @@ describe("cryptoService", () => { encryptedString.dataBytes.length, ); return output; - }; + } const org1Id = "org1" as OrganizationId; - const updateKeys = ( - keys: Partial<{ - userKey: UserKey; - encryptedPrivateKey: EncString; - orgKeys: Record; - providerKeys: Record; - }> = {}, - ) => { + type UpdateKeysParams = { + userKey: UserKey; + encryptedPrivateKey: EncString; + orgKeys: Record; + providerKeys: Record; + }; + + function updateKeys(keys: Partial = {}) { if ("userKey" in keys) { const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY); userKeyState.stateSubject.next([mockUserId, keys.userKey]); @@ -496,7 +495,7 @@ describe("cryptoService", () => { encryptService.rsaDecrypt.mockImplementation((data, privateKey) => { return Promise.resolve(fakeOrgKeyDecryption(data, privateKey)); }); - }; + } it("returns decryption keys when there are not org or provider keys set", async () => { updateKeys({