From c3268346a8c25948e58faa67a6be1d98be75dd68 Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Fri, 13 Sep 2024 16:17:44 +1000 Subject: [PATCH] chore: added tests --- tests/client/handlers/vaults.test.ts | 88 ++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index 8644b2ba4..7e592bbde 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -1533,6 +1533,94 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => { vaultsErrors.ErrorSecretsSecretUndefined, ); }); + test('deletes multiple secrets from multiple vaults with a single log message', async () => { + // Create secret + const secret1 = 'test-secret1'; + const secret2 = 'test-secret2'; + const secret3 = 'test-secret3'; + const vaultId1 = await vaultManager.createVault('test-vault1'); + const vaultId2 = await vaultManager.createVault('test-vault2'); + const vaultIdEncoded1 = vaultsUtils.encodeVaultId(vaultId1); + const vaultIdEncoded2 = vaultsUtils.encodeVaultId(vaultId2); + await rpcClient.methods.vaultsSecretsNew({ + nameOrId: vaultIdEncoded1, + secretName: secret1, + secretContent: Buffer.from(secret1).toString('binary'), + }); + await rpcClient.methods.vaultsSecretsNew({ + nameOrId: vaultIdEncoded1, + secretName: secret2, + secretContent: Buffer.from(secret2).toString('binary'), + }); + await rpcClient.methods.vaultsSecretsNew({ + nameOrId: vaultIdEncoded2, + secretName: secret3, + secretContent: Buffer.from(secret3).toString('binary'), + }); + // Get secret + const getResponse1 = await rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded1, + secretName: secret1, + }); + const getResponse2 = await rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded1, + secretName: secret2, + }); + const getResponse3 = await rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded2, + secretName: secret3, + }); + expect(getResponse1.secretContent).toStrictEqual(secret1); + expect(getResponse2.secretContent).toStrictEqual(secret2); + expect(getResponse3.secretContent).toStrictEqual(secret3); + // Get log size + let logLength1: number; + let logLength2: number; + await vaultManager.withVaults([vaultId1], async (vault) => { + logLength1 = (await vault.log()).length; + }); + await vaultManager.withVaults([vaultId2], async (vault) => { + logLength2 = (await vault.log()).length; + }); + // Delete secret + const deleteResponse = await rpcClient.methods.vaultsSecretsRemove({ + secretNames: [ + [vaultIdEncoded1, secret1], + [vaultIdEncoded1, secret2], + [vaultIdEncoded2, secret3], + ], + }); + expect(deleteResponse.success).toBeTruthy(); + // Check secret was deleted + await testsUtils.expectRemoteError( + rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded1, + secretName: secret1, + }), + vaultsErrors.ErrorSecretsSecretUndefined, + ); + await testsUtils.expectRemoteError( + rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded1, + secretName: secret2, + }), + vaultsErrors.ErrorSecretsSecretUndefined, + ); + await testsUtils.expectRemoteError( + rpcClient.methods.vaultsSecretsGet({ + nameOrId: vaultIdEncoded2, + secretName: secret3, + }), + vaultsErrors.ErrorSecretsSecretUndefined, + ); + // Ensure single log message for deleting the secrets + await vaultManager.withVaults([vaultId1], async (vault) => { + expect((await vault.log()).length).toEqual(logLength1 + 1) + }); + await vaultManager.withVaults([vaultId2], async (vault) => { + expect((await vault.log()).length).toEqual(logLength2 + 1) + }); + }); test('deletes directory recursively', async () => { // Create secrets const vaultName = 'test-vault';