From dd2204709201eeccf9950b1eca350357d7a75500 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Wed, 20 Jul 2022 13:50:18 +1000 Subject: [PATCH] wip: optimizing client tests Related #420 --- tests/client/GRPCClientClient.test.ts | 17 +++-------- .../gestaltsGestaltTrustByNode.test.ts | 25 ++++------------ tests/client/service/identitiesClaim.test.ts | 18 +++--------- .../client/service/keysCertsChainGet.test.ts | 15 ++-------- tests/client/service/keysCertsGet.test.ts | 15 ++-------- .../client/service/keysEncryptDecrypt.test.ts | 19 ++---------- tests/client/service/keysKeyPairRoot.test.ts | 29 ++++++------------- .../client/service/keysPasswordChange.test.ts | 15 ++-------- tests/client/service/keysSignVerify.test.ts | 19 ++---------- tests/client/service/nodesAdd.test.ts | 19 ++---------- tests/client/service/nodesClaim.test.ts | 14 ++------- tests/client/service/nodesFind.test.ts | 15 ++-------- tests/client/service/nodesPing.test.ts | 15 ++-------- .../client/service/notificationsClear.test.ts | 15 ++-------- .../client/service/notificationsRead.test.ts | 15 ++-------- .../client/service/notificationsSend.test.ts | 15 ++-------- tests/client/service/vaultsClone.test.ts | 16 ---------- .../service/vaultsCreateDeleteList.test.ts | 18 ++---------- tests/client/service/vaultsLog.test.ts | 18 ++---------- .../vaultsPermissionSetUnsetGet.test.ts | 14 ++------- tests/client/service/vaultsPull.test.ts | 16 ---------- tests/client/service/vaultsRename.test.ts | 18 ++---------- tests/client/service/vaultsScan.test.ts | 16 ---------- .../client/service/vaultsSecretsEdit.test.ts | 18 ++---------- .../client/service/vaultsSecretsMkdir.test.ts | 18 ++---------- .../service/vaultsSecretsNewDeleteGet.test.ts | 18 ++---------- .../service/vaultsSecretsNewDirList.test.ts | 18 ++---------- .../service/vaultsSecretsRename.test.ts | 18 ++---------- .../client/service/vaultsSecretsStat.test.ts | 18 ++---------- tests/client/service/vaultsVersion.test.ts | 18 ++---------- 30 files changed, 69 insertions(+), 453 deletions(-) diff --git a/tests/client/GRPCClientClient.test.ts b/tests/client/GRPCClientClient.test.ts index b90406a803..bde326c752 100644 --- a/tests/client/GRPCClientClient.test.ts +++ b/tests/client/GRPCClientClient.test.ts @@ -8,20 +8,17 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger'; import GRPCClientClient from '@/client/GRPCClientClient'; import PolykeyAgent from '@/PolykeyAgent'; import Session from '@/sessions/Session'; -import * as keysUtils from '@/keys/utils'; import * as clientErrors from '@/client/errors'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import { timerStart } from '@/utils'; import * as testClientUtils from './utils'; -import * as testUtils from '../utils'; +import { globalRootKeyPems } from '../globalRootKeyPems'; describe(GRPCClientClient.name, () => { const password = 'password'; const logger = new Logger(`${GRPCClientClient.name} test`, LogLevel.WARN, [ new StreamHandler(), ]); - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let client: GRPCClientClient; let server: grpc.Server; let port: number; @@ -31,13 +28,6 @@ describe(GRPCClientClient.name, () => { let nodeId: NodeId; let session: Session; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); dataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'polykey-test-'), ); @@ -46,6 +36,9 @@ describe(GRPCClientClient.name, () => { password, nodePath, logger: logger, + keysConfig: { + privateKeyPemOverride: globalRootKeyPems[0], + }, }); nodeId = pkAgent.keyManager.getNodeId(); [server, port] = await testClientUtils.openTestClientServer({ @@ -67,8 +60,6 @@ describe(GRPCClientClient.name, () => { force: true, recursive: true, }); - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); }); test('cannot be called when destroyed', async () => { client = await GRPCClientClient.createGRPCClientClient({ diff --git a/tests/client/service/gestaltsGestaltTrustByNode.test.ts b/tests/client/service/gestaltsGestaltTrustByNode.test.ts index df84503a73..88e9a8ab17 100644 --- a/tests/client/service/gestaltsGestaltTrustByNode.test.ts +++ b/tests/client/service/gestaltsGestaltTrustByNode.test.ts @@ -34,11 +34,11 @@ import * as claimsUtils from '@/claims/utils'; import * as keysUtils from '@/keys/utils'; import * as clientUtils from '@/client/utils/utils'; import * as nodesUtils from '@/nodes/utils'; -import * as testUtils from '../../utils'; import TestProvider from '../../identities/TestProvider'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('gestaltsGestaltTrustByNode', () => { - const logger = new Logger('gestaltsGestaltTrustByNode test', LogLevel.WARN, [ + const logger = new Logger('gestaltsGestaltTrustByNode test', LogLevel.INFO, [ new StreamHandler(), ]); const password = 'helloworld'; @@ -52,22 +52,7 @@ describe('gestaltsGestaltTrustByNode', () => { let nodeId: NodeIdEncoded; const nodeChainData: ChainData = {}; let mockedRequestChainData: jest.SpyInstance; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - const nodeKeyPair = await keysUtils.generateKeyPair(2048); - mockedRequestChainData = jest - .spyOn(NodeManager.prototype, 'requestChainData') - .mockResolvedValue(nodeChainData); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValueOnce(nodeKeyPair) - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValueOnce(nodeKeyPair) - .mockResolvedValue(globalKeyPair); nodeDataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'trusted-node-'), ); @@ -81,6 +66,9 @@ describe('gestaltsGestaltTrustByNode', () => { agentHost: '127.0.0.1' as Host, clientHost: '127.0.0.1' as Host, }, + keysConfig: { + privateKeyPemOverride: globalRootKeyPems[0], + }, logger, }); nodeId = nodesUtils.encodeNodeId(node.keyManager.getNodeId()); @@ -106,8 +94,6 @@ describe('gestaltsGestaltTrustByNode', () => { force: true, recursive: true, }); - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedRequestChainData.mockRestore(); }); const authToken = 'abc123'; @@ -136,6 +122,7 @@ describe('gestaltsGestaltTrustByNode', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[1], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/identitiesClaim.test.ts b/tests/client/service/identitiesClaim.test.ts index 3a17b79a8b..cdc77090cb 100644 --- a/tests/client/service/identitiesClaim.test.ts +++ b/tests/client/service/identitiesClaim.test.ts @@ -23,13 +23,12 @@ import identitiesClaim from '@/client/service/identitiesClaim'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as identitiesPB from '@/proto/js/polykey/v1/identities/identities_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as claimsUtils from '@/claims/utils'; import * as nodesUtils from '@/nodes/utils'; import * as validationErrors from '@/validation/errors'; -import * as testUtils from '../../utils'; import TestProvider from '../../identities/TestProvider'; import { expectRemoteError } from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('identitiesClaim', () => { const logger = new Logger('identitiesClaim test', LogLevel.WARN, [ @@ -54,32 +53,22 @@ describe('identitiesClaim', () => { const claimId = claimsUtils.createClaimIdGenerator( nodesUtils.decodeNodeId(claimData.node)!, )(); - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedAddClaim: jest.SpyInstance; const dummyNodeManager = { setNode: jest.fn() } as unknown as NodeManager; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); + const privateKey = globalRootKeyPems[0]; const claim = await claimsUtils.createClaim({ - privateKey: keysUtils.keyPairToPem(globalKeyPair).privateKey, + privateKey: privateKey, hPrev: null, seq: 0, data: claimData, kid: claimData.node, }); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedAddClaim = jest .spyOn(Sigchain.prototype, 'addClaim') .mockResolvedValue([claimId, claim]); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedAddClaim.mockRestore(); }); const authToken = 'abc123'; @@ -105,6 +94,7 @@ describe('identitiesClaim', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/keysCertsChainGet.test.ts b/tests/client/service/keysCertsChainGet.test.ts index 48b734c95e..cacc4c37d4 100644 --- a/tests/client/service/keysCertsChainGet.test.ts +++ b/tests/client/service/keysCertsChainGet.test.ts @@ -12,8 +12,7 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as keysPB from '@/proto/js/polykey/v1/keys/keys_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysCertsChainGet', () => { const logger = new Logger('keysCertsChainGet test', LogLevel.WARN, [ @@ -24,24 +23,13 @@ describe('keysCertsChainGet', () => { metaServer; const certs = ['cert1', 'cert2', 'cert3']; let mockedGetRootCertChainPems: jest.SpyInstance; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); mockedGetRootCertChainPems = jest .spyOn(KeyManager.prototype, 'getRootCertChainPems') .mockResolvedValue(certs); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); }); afterAll(async () => { mockedGetRootCertChainPems.mockRestore(); - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); }); let dataDir: string; let keyManager: KeyManager; @@ -56,6 +44,7 @@ describe('keysCertsChainGet', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysCertsChainGet: keysCertsChainGet({ diff --git a/tests/client/service/keysCertsGet.test.ts b/tests/client/service/keysCertsGet.test.ts index d3bd83e092..96495f76a8 100644 --- a/tests/client/service/keysCertsGet.test.ts +++ b/tests/client/service/keysCertsGet.test.ts @@ -12,8 +12,7 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as keysPB from '@/proto/js/polykey/v1/keys/keys_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysCertsGet', () => { const logger = new Logger('keysCertsGet test', LogLevel.WARN, [ @@ -23,24 +22,13 @@ describe('keysCertsGet', () => { const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; let mockedGetRootCertPem: jest.SpyInstance; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); mockedGetRootCertPem = jest .spyOn(KeyManager.prototype, 'getRootCertPem') .mockReturnValue('rootCertPem'); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); }); afterAll(async () => { mockedGetRootCertPem.mockRestore(); - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); }); let dataDir: string; let keyManager: KeyManager; @@ -55,6 +43,7 @@ describe('keysCertsGet', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysCertsGet: keysCertsGet({ diff --git a/tests/client/service/keysEncryptDecrypt.test.ts b/tests/client/service/keysEncryptDecrypt.test.ts index a6421649f5..0065752938 100644 --- a/tests/client/service/keysEncryptDecrypt.test.ts +++ b/tests/client/service/keysEncryptDecrypt.test.ts @@ -12,8 +12,7 @@ import keysDecrypt from '@/client/service/keysDecrypt'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as keysPB from '@/proto/js/polykey/v1/keys/keys_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysEncryptDecrypt', () => { const logger = new Logger('keysEncryptDecrypt test', LogLevel.WARN, [ @@ -22,21 +21,6 @@ describe('keysEncryptDecrypt', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let grpcServer: GRPCServer; @@ -50,6 +34,7 @@ describe('keysEncryptDecrypt', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysEncrypt: keysEncrypt({ diff --git a/tests/client/service/keysKeyPairRoot.test.ts b/tests/client/service/keysKeyPairRoot.test.ts index e5d5f2629d..fb6429e0c4 100644 --- a/tests/client/service/keysKeyPairRoot.test.ts +++ b/tests/client/service/keysKeyPairRoot.test.ts @@ -13,7 +13,7 @@ import * as keysPB from '@/proto/js/polykey/v1/keys/keys_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as clientUtils from '@/client/utils/utils'; import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysKeyPairRoot', () => { const logger = new Logger('keysKeyPairRoot test', LogLevel.WARN, [ @@ -22,22 +22,6 @@ describe('keysKeyPairRoot', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let globalKeyPair; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let grpcServer: GRPCServer; @@ -51,6 +35,7 @@ describe('keysKeyPairRoot', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysKeyPairRoot: keysKeyPairRoot({ @@ -88,8 +73,12 @@ describe('keysKeyPairRoot', () => { clientUtils.encodeAuthFromPassword(password), ); expect(response).toBeInstanceOf(keysPB.KeyPair); - const keyPairPem = keysUtils.keyPairToPem(globalKeyPair); - expect(response.getPublic()).toBe(keyPairPem.publicKey); - expect(response.getPrivate()).toBe(keyPairPem.privateKey); + const publicKey = keysUtils.publicKeyToPem( + keysUtils.publicKeyFromPrivateKey( + keysUtils.privateKeyFromPem(globalRootKeyPems[0]), + ), + ); + expect(response.getPublic()).toBe(publicKey); + expect(response.getPrivate()).toBe(globalRootKeyPems[0]); }); }); diff --git a/tests/client/service/keysPasswordChange.test.ts b/tests/client/service/keysPasswordChange.test.ts index 7814ec86a0..b60910fbf6 100644 --- a/tests/client/service/keysPasswordChange.test.ts +++ b/tests/client/service/keysPasswordChange.test.ts @@ -12,8 +12,7 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as sessionsPB from '@/proto/js/polykey/v1/sessions/sessions_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysPasswordChange', () => { const logger = new Logger('keysPasswordChange test', LogLevel.WARN, [ @@ -23,26 +22,15 @@ describe('keysPasswordChange', () => { const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; let mockedChangePassword: jest.SpyInstance; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); mockedChangePassword = jest .spyOn(KeyManager.prototype, 'changePassword') .mockImplementation(async () => { password = 'newpassword'; }); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); }); afterAll(async () => { mockedChangePassword.mockRestore(); - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); }); let dataDir: string; let keyManager: KeyManager; @@ -57,6 +45,7 @@ describe('keysPasswordChange', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysPasswordChange: keysPasswordChange({ diff --git a/tests/client/service/keysSignVerify.test.ts b/tests/client/service/keysSignVerify.test.ts index c420d7ed6d..999114517e 100644 --- a/tests/client/service/keysSignVerify.test.ts +++ b/tests/client/service/keysSignVerify.test.ts @@ -13,8 +13,7 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as keysPB from '@/proto/js/polykey/v1/keys/keys_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('keysSignVerify', () => { const logger = new Logger('keysSignVerify test', LogLevel.WARN, [ @@ -23,21 +22,6 @@ describe('keysSignVerify', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let grpcServer: GRPCServer; @@ -51,6 +35,7 @@ describe('keysSignVerify', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const clientService = { keysSign: keysSign({ diff --git a/tests/client/service/nodesAdd.test.ts b/tests/client/service/nodesAdd.test.ts index f00e62566f..a4fb7f7146 100644 --- a/tests/client/service/nodesAdd.test.ts +++ b/tests/client/service/nodesAdd.test.ts @@ -21,10 +21,9 @@ import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as nodesUtils from '@/nodes/utils'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as validationErrors from '@/validation/errors'; -import * as testUtils from '../../utils'; import { expectRemoteError } from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('nodesAdd', () => { const logger = new Logger('nodesAdd test', LogLevel.WARN, [ @@ -33,21 +32,6 @@ describe('nodesAdd', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); const authToken = 'abc123'; let dataDir: string; let nodeGraph: NodeGraph; @@ -70,6 +54,7 @@ describe('nodesAdd', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/nodesClaim.test.ts b/tests/client/service/nodesClaim.test.ts index 95eaf8b6e4..7ce971d322 100644 --- a/tests/client/service/nodesClaim.test.ts +++ b/tests/client/service/nodesClaim.test.ts @@ -23,9 +23,9 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as validationErrors from '@/validation/errors'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('nodesClaim', () => { const logger = new Logger('nodesClaim test', LogLevel.WARN, [ @@ -42,19 +42,10 @@ describe('nodesClaim', () => { 'vrcacp9vsb4ht25hds6s4lpp2abfaso0mptcfnh499n35vfcn2gkg' as NodeIdEncoded, isRead: false, }; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedFindGestaltInvite: jest.SpyInstance; let mockedSendNotification: jest.SpyInstance; let mockedClaimNode: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedFindGestaltInvite = jest .spyOn(NotificationsManager.prototype, 'findGestaltInvite') .mockResolvedValueOnce(undefined) @@ -67,8 +58,6 @@ describe('nodesClaim', () => { .mockResolvedValue(undefined); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedFindGestaltInvite.mockRestore(); mockedSendNotification.mockRestore(); mockedClaimNode.mockRestore(); @@ -96,6 +85,7 @@ describe('nodesClaim', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/nodesFind.test.ts b/tests/client/service/nodesFind.test.ts index 4ff59d9f1e..6a483aa83e 100644 --- a/tests/client/service/nodesFind.test.ts +++ b/tests/client/service/nodesFind.test.ts @@ -19,10 +19,9 @@ import nodesFind from '@/client/service/nodesFind'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as validationErrors from '@/validation/errors'; -import * as testUtils from '../../utils'; import { expectRemoteError } from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('nodesFind', () => { const logger = new Logger('nodesFind test', LogLevel.WARN, [ @@ -31,17 +30,8 @@ describe('nodesFind', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedFindNode: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedFindNode = jest .spyOn(NodeConnectionManager.prototype, 'findNode') .mockResolvedValue({ @@ -50,8 +40,6 @@ describe('nodesFind', () => { }); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedFindNode.mockRestore(); }); const authToken = 'abc123'; @@ -75,6 +63,7 @@ describe('nodesFind', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/nodesPing.test.ts b/tests/client/service/nodesPing.test.ts index 14f9cbceee..5f3fcb4295 100644 --- a/tests/client/service/nodesPing.test.ts +++ b/tests/client/service/nodesPing.test.ts @@ -20,10 +20,9 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as validationErrors from '@/validation/errors'; -import * as testUtils from '../../utils'; import { expectRemoteError } from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('nodesPing', () => { const logger = new Logger('nodesPing test', LogLevel.WARN, [ @@ -32,25 +31,14 @@ describe('nodesPing', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedPingNode: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedPingNode = jest .spyOn(NodeManager.prototype, 'pingNode') .mockResolvedValueOnce(false) .mockResolvedValue(true); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedPingNode.mockRestore(); }); const authToken = 'abc123'; @@ -75,6 +63,7 @@ describe('nodesPing', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/notificationsClear.test.ts b/tests/client/service/notificationsClear.test.ts index 4a9002f21d..452f338bc9 100644 --- a/tests/client/service/notificationsClear.test.ts +++ b/tests/client/service/notificationsClear.test.ts @@ -20,9 +20,8 @@ import GRPCClientClient from '@/client/GRPCClientClient'; import notificationsClear from '@/client/service/notificationsClear'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; -import * as keysUtils from '@/keys/utils'; import * as clientUtils from '@/client/utils/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('notificationsClear', () => { const logger = new Logger('notificationsClear test', LogLevel.WARN, [ @@ -31,24 +30,13 @@ describe('notificationsClear', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedClearNotifications: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedClearNotifications = jest .spyOn(NotificationsManager.prototype, 'clearNotifications') .mockResolvedValue(); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedClearNotifications.mockRestore(); }); const authToken = 'abc123'; @@ -75,6 +63,7 @@ describe('notificationsClear', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/notificationsRead.test.ts b/tests/client/service/notificationsRead.test.ts index b5a3de17af..69f308b57a 100644 --- a/tests/client/service/notificationsRead.test.ts +++ b/tests/client/service/notificationsRead.test.ts @@ -21,11 +21,10 @@ import GRPCClientClient from '@/client/GRPCClientClient'; import notificationsRead from '@/client/service/notificationsRead'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as notificationsPB from '@/proto/js/polykey/v1/notifications/notifications_pb'; -import * as keysUtils from '@/keys/utils'; import * as nodesUtils from '@/nodes/utils'; import * as clientUtils from '@/client/utils'; -import * as testUtils from '../../utils'; import * as testNodesUtils from '../../nodes/utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('notificationsRead', () => { const logger = new Logger('notificationsRead test', LogLevel.WARN, [ @@ -36,17 +35,8 @@ describe('notificationsRead', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedReadNotifications: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedReadNotifications = jest .spyOn(NotificationsManager.prototype, 'readNotifications') .mockResolvedValueOnce([ @@ -122,8 +112,6 @@ describe('notificationsRead', () => { .mockResolvedValueOnce([]); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedReadNotifications.mockRestore(); }); const authToken = 'abc123'; @@ -150,6 +138,7 @@ describe('notificationsRead', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/notificationsSend.test.ts b/tests/client/service/notificationsSend.test.ts index 35a6a15bbe..b1d9facbb8 100644 --- a/tests/client/service/notificationsSend.test.ts +++ b/tests/client/service/notificationsSend.test.ts @@ -21,11 +21,10 @@ import notificationsSend from '@/client/service/notificationsSend'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as notificationsPB from '@/proto/js/polykey/v1/notifications/notifications_pb'; -import * as keysUtils from '@/keys/utils'; import * as nodesUtils from '@/nodes/utils'; import * as notificationsUtils from '@/notifications/utils'; import * as clientUtils from '@/client/utils'; -import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('notificationsSend', () => { const logger = new Logger('notificationsSend test', LogLevel.WARN, [ @@ -34,18 +33,9 @@ describe('notificationsSend', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedSignNotification: jest.SpyInstance; let mockedSendNotification: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedSignNotification = jest .spyOn(notificationsUtils, 'signNotification') .mockImplementation(async () => { @@ -56,8 +46,6 @@ describe('notificationsSend', () => { .mockImplementation(); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedSignNotification.mockRestore(); mockedSendNotification.mockRestore(); }); @@ -84,6 +72,7 @@ describe('notificationsSend', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsClone.test.ts b/tests/client/service/vaultsClone.test.ts index b54f629db1..536cbd8ba9 100644 --- a/tests/client/service/vaultsClone.test.ts +++ b/tests/client/service/vaultsClone.test.ts @@ -15,7 +15,6 @@ import GRPCServer from '@/grpc/GRPCServer'; import GRPCClientClient from '@/client/GRPCClientClient'; import vaultsClone from '@/client/service/vaultsClone'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; describe('vaultsClone', () => { @@ -24,21 +23,6 @@ describe('vaultsClone', () => { ]); const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let db: DB; let vaultManager: VaultManager; diff --git a/tests/client/service/vaultsCreateDeleteList.test.ts b/tests/client/service/vaultsCreateDeleteList.test.ts index c046440562..e3d6441296 100644 --- a/tests/client/service/vaultsCreateDeleteList.test.ts +++ b/tests/client/service/vaultsCreateDeleteList.test.ts @@ -20,8 +20,8 @@ import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsCreateDeleteList', () => { const logger = new Logger('vaultsCreateDeleteList test', LogLevel.WARN, [ @@ -30,21 +30,6 @@ describe('vaultsCreateDeleteList', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -60,6 +45,7 @@ describe('vaultsCreateDeleteList', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsLog.test.ts b/tests/client/service/vaultsLog.test.ts index 9a3e9f6c98..3fddf3aba7 100644 --- a/tests/client/service/vaultsLog.test.ts +++ b/tests/client/service/vaultsLog.test.ts @@ -18,8 +18,8 @@ import vaultsLog from '@/client/service/vaultsLog'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsLog', () => { const logger = new Logger('vaultsLog test', LogLevel.WARN, [ @@ -28,21 +28,6 @@ describe('vaultsLog', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); const vaultName = 'test-vault'; const secret1 = { name: 'secret1', content: 'Secret-1-content' }; const secret2 = { name: 'secret2', content: 'Secret-2-content' }; @@ -65,6 +50,7 @@ describe('vaultsLog', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsPermissionSetUnsetGet.test.ts b/tests/client/service/vaultsPermissionSetUnsetGet.test.ts index 299ab6219c..1dbefbfb47 100644 --- a/tests/client/service/vaultsPermissionSetUnsetGet.test.ts +++ b/tests/client/service/vaultsPermissionSetUnsetGet.test.ts @@ -22,9 +22,9 @@ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as nodesUtils from '@/nodes/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsPermissionSetUnsetGet', () => { const logger = new Logger('vaultsPermissionSetUnsetGet test', LogLevel.WARN, [ @@ -33,24 +33,13 @@ describe('vaultsPermissionSetUnsetGet', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; let mockedSendNotification: jest.SpyInstance; beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); mockedSendNotification = jest .spyOn(NotificationsManager.prototype, 'sendNotification') .mockImplementation(); }); afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); mockedSendNotification.mockRestore(); }); const nodeId = testUtils.generateRandomNodeId(); @@ -72,6 +61,7 @@ describe('vaultsPermissionSetUnsetGet', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsPull.test.ts b/tests/client/service/vaultsPull.test.ts index 8240e167dc..8d3951cb8a 100644 --- a/tests/client/service/vaultsPull.test.ts +++ b/tests/client/service/vaultsPull.test.ts @@ -15,7 +15,6 @@ import GRPCServer from '@/grpc/GRPCServer'; import GRPCClientClient from '@/client/GRPCClientClient'; import vaultsPull from '@/client/service/vaultsPull'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; describe('vaultsPull', () => { @@ -24,21 +23,6 @@ describe('vaultsPull', () => { ]); const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let db: DB; let vaultManager: VaultManager; diff --git a/tests/client/service/vaultsRename.test.ts b/tests/client/service/vaultsRename.test.ts index 0e7dd856e0..b5b47db5b7 100644 --- a/tests/client/service/vaultsRename.test.ts +++ b/tests/client/service/vaultsRename.test.ts @@ -17,9 +17,9 @@ import vaultsRename from '@/client/service/vaultsRename'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as vaultsUtils from '@/vaults/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsRename', () => { const logger = new Logger('vaultsRename test', LogLevel.WARN, [ @@ -28,21 +28,6 @@ describe('vaultsRename', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -58,6 +43,7 @@ describe('vaultsRename', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsScan.test.ts b/tests/client/service/vaultsScan.test.ts index 40abc72ebd..8e0409c80f 100644 --- a/tests/client/service/vaultsScan.test.ts +++ b/tests/client/service/vaultsScan.test.ts @@ -15,7 +15,6 @@ import GRPCServer from '@/grpc/GRPCServer'; import GRPCClientClient from '@/client/GRPCClientClient'; import vaultsScan from '@/client/service/vaultsScan'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; describe('vaultsScan', () => { @@ -24,21 +23,6 @@ describe('vaultsScan', () => { ]); const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let vaultManager: VaultManager; let grpcServer: GRPCServer; diff --git a/tests/client/service/vaultsSecretsEdit.test.ts b/tests/client/service/vaultsSecretsEdit.test.ts index 0956bac33d..601de8e921 100644 --- a/tests/client/service/vaultsSecretsEdit.test.ts +++ b/tests/client/service/vaultsSecretsEdit.test.ts @@ -20,8 +20,8 @@ import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as secretsPB from '@/proto/js/polykey/v1/secrets/secrets_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsEdit', () => { const logger = new Logger('vaultsSecretsEdit test', LogLevel.WARN, [ @@ -30,21 +30,6 @@ describe('vaultsSecretsEdit', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -60,6 +45,7 @@ describe('vaultsSecretsEdit', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsSecretsMkdir.test.ts b/tests/client/service/vaultsSecretsMkdir.test.ts index 1e4c1b971e..cd4f6d5d73 100644 --- a/tests/client/service/vaultsSecretsMkdir.test.ts +++ b/tests/client/service/vaultsSecretsMkdir.test.ts @@ -19,8 +19,8 @@ import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsMkdir', () => { const logger = new Logger('vaultsSecretsMkdir test', LogLevel.WARN, [ @@ -29,21 +29,6 @@ describe('vaultsSecretsMkdir', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -59,6 +44,7 @@ describe('vaultsSecretsMkdir', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsSecretsNewDeleteGet.test.ts b/tests/client/service/vaultsSecretsNewDeleteGet.test.ts index f743f6ff0c..0600f0487c 100644 --- a/tests/client/service/vaultsSecretsNewDeleteGet.test.ts +++ b/tests/client/service/vaultsSecretsNewDeleteGet.test.ts @@ -22,9 +22,9 @@ import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as secretsPB from '@/proto/js/polykey/v1/secrets/secrets_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as vaultsErrors from '@/vaults/errors'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsNewDeleteGet', () => { const logger = new Logger('vaultsSecretsNewDeleteGet test', LogLevel.WARN, [ @@ -33,21 +33,6 @@ describe('vaultsSecretsNewDeleteGet', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -63,6 +48,7 @@ describe('vaultsSecretsNewDeleteGet', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsSecretsNewDirList.test.ts b/tests/client/service/vaultsSecretsNewDirList.test.ts index 7e8911dbd6..d61b404f91 100644 --- a/tests/client/service/vaultsSecretsNewDirList.test.ts +++ b/tests/client/service/vaultsSecretsNewDirList.test.ts @@ -21,8 +21,8 @@ import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as secretsPB from '@/proto/js/polykey/v1/secrets/secrets_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsNewDirList', () => { const logger = new Logger('vaultsSecretsNewDirList test', LogLevel.WARN, [ @@ -31,21 +31,6 @@ describe('vaultsSecretsNewDirList', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -61,6 +46,7 @@ describe('vaultsSecretsNewDirList', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsSecretsRename.test.ts b/tests/client/service/vaultsSecretsRename.test.ts index 1d6027aa3c..098c494a1e 100644 --- a/tests/client/service/vaultsSecretsRename.test.ts +++ b/tests/client/service/vaultsSecretsRename.test.ts @@ -20,8 +20,8 @@ import * as secretsPB from '@/proto/js/polykey/v1/secrets/secrets_pb'; import * as utilsPB from '@/proto/js/polykey/v1/utils/utils_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsRename', () => { const logger = new Logger('vaultsSecretsRename test', LogLevel.WARN, [ @@ -30,21 +30,6 @@ describe('vaultsSecretsRename', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -60,6 +45,7 @@ describe('vaultsSecretsRename', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsSecretsStat.test.ts b/tests/client/service/vaultsSecretsStat.test.ts index 909ee82b8d..5b07fbe344 100644 --- a/tests/client/service/vaultsSecretsStat.test.ts +++ b/tests/client/service/vaultsSecretsStat.test.ts @@ -20,8 +20,8 @@ import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as secretsPB from '@/proto/js/polykey/v1/secrets/secrets_pb'; import * as clientUtils from '@/client/utils/utils'; import * as vaultsUtils from '@/vaults/utils'; -import * as keysUtils from '@/keys/utils'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsSecretsStat', () => { const logger = new Logger('vaultsSecretsStat test', LogLevel.WARN, [ @@ -30,21 +30,6 @@ describe('vaultsSecretsStat', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); let dataDir: string; let keyManager: KeyManager; let db: DB; @@ -60,6 +45,7 @@ describe('vaultsSecretsStat', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ diff --git a/tests/client/service/vaultsVersion.test.ts b/tests/client/service/vaultsVersion.test.ts index 09373743a4..0b1bd810aa 100644 --- a/tests/client/service/vaultsVersion.test.ts +++ b/tests/client/service/vaultsVersion.test.ts @@ -18,10 +18,10 @@ import vaultsVersion from '@/client/service/vaultsVersion'; import { ClientServiceService } from '@/proto/js/polykey/v1/client_service_grpc_pb'; import * as vaultsPB from '@/proto/js/polykey/v1/vaults/vaults_pb'; import * as clientUtils from '@/client/utils/utils'; -import * as keysUtils from '@/keys/utils'; import * as vaultsUtils from '@/vaults/utils'; import * as vaultsErrors from '@/vaults/errors'; import * as testUtils from '../../utils'; +import { globalRootKeyPems } from '../../globalRootKeyPems'; describe('vaultsVersion', () => { const logger = new Logger('vaultsVersion test', LogLevel.WARN, [ @@ -30,21 +30,6 @@ describe('vaultsVersion', () => { const password = 'helloworld'; const authenticate = async (metaClient, metaServer = new Metadata()) => metaServer; - let mockedGenerateKeyPair: jest.SpyInstance; - let mockedGenerateDeterministicKeyPair: jest.SpyInstance; - beforeAll(async () => { - const globalKeyPair = await testUtils.setupGlobalKeypair(); - mockedGenerateKeyPair = jest - .spyOn(keysUtils, 'generateKeyPair') - .mockResolvedValue(globalKeyPair); - mockedGenerateDeterministicKeyPair = jest - .spyOn(keysUtils, 'generateDeterministicKeyPair') - .mockResolvedValue(globalKeyPair); - }); - afterAll(async () => { - mockedGenerateKeyPair.mockRestore(); - mockedGenerateDeterministicKeyPair.mockRestore(); - }); const secretVer1 = { name: 'secret1v1', content: 'Secret-1-content-ver1', @@ -70,6 +55,7 @@ describe('vaultsVersion', () => { password, keysPath, logger, + privateKeyPemOverride: globalRootKeyPems[0], }); const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({