Skip to content

Commit

Permalink
chore: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Sep 13, 2024
1 parent be27341 commit b9bf86a
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit b9bf86a

Please sign in to comment.