Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Sep 20, 2024
1 parent 39972fc commit 0f3b850
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 96 deletions.
3 changes: 0 additions & 3 deletions src/client/handlers/VaultsSecretsRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class VaultsSecretsRemove extends ClientHandler<
await vaultManager.withVaults(
[vaultId],
async (vault) => {
// console.log('in here', metadata);
// console.log('options', metadata?.options);
// console.log('recursive', metadata?.options?.recursive);
await vaultOps.deleteSecret(vault, secretNames, {
recursive: metadata?.options?.recursive,
});
Expand Down
164 changes: 71 additions & 93 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type NodeManager from '@/nodes/NodeManager';
import type {
LogEntryMessage,
SecretContentMessage,
ContentMessage,
VaultListMessage,
VaultPermissionMessage,
} from '@/client/types';
Expand Down Expand Up @@ -1464,15 +1463,14 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
expect(createResponse.success).toBeTruthy();
// Get secret
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = getStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secret,
});
await writer.close();
resolve(0);
});
})();
const secretContent: Array<string> = [];
for await (const data of getStream.readable) {
secretContent.push(data.secretContent);
Expand All @@ -1481,34 +1479,31 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
expect(concatenatedContent).toStrictEqual(secret);
// Delete secret
const deleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secret,
});
await writer.close();
resolve(0);
});
})();
expect((await deleteStream.output).success).toBeTruthy();
// Check secret was deleted
const deleteGetStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteGetStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secret,
});
await writer.close();
resolve(0);
});
await expect(async () => {
try {
})();
await testsUtils.expectRemoteError(
(async () => {
for await (const _ of deleteGetStream.readable);
} catch (e) {
throw e.cause;
}
}).rejects.toThrow(vaultsErrors.ErrorSecretsSecretUndefined);
})(),
vaultsErrors.ErrorSecretsSecretUndefined,
);
});
test('concatenates multiple secrets together', async () => {
// Create secret
Expand All @@ -1525,7 +1520,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
}
// Get secret
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = getStream.writable.getWriter();
for (const name of secretNames) {
await writer.write({
Expand All @@ -1534,8 +1529,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
const secretContent: Array<string> = [];
for await (const data of getStream.readable) {
secretContent.push(data.secretContent);
Expand All @@ -1556,7 +1550,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
}
// Get secret
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = getStream.writable.getWriter();
for (const name of secretNames) {
await writer.write({
Expand All @@ -1565,16 +1559,15 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
const secretContent: Array<string> = [];
for await (const data of getStream.readable) {
secretContent.push(data.secretContent);
}
expect(secretContent.join('')).toStrictEqual(secretNames.join(''));
// Delete secret
const deleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteStream.writable.getWriter();
for (const secretName of secretNames) {
await writer.write({
Expand All @@ -1583,28 +1576,25 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
expect((await deleteStream.output).success).toBeTruthy();
// Check each secret was deleted
for (const secretName of secretNames) {
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
const writer = getStream.writable.getWriter();
const deleteGetStream = await rpcClient.methods.vaultsSecretsGet();
await (async () => {
const writer = deleteGetStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secretName,
});
await writer.close();
resolve(0);
});
await expect(async () => {
try {
for await (const _ of getStream.readable); // Consume
} catch (e) {
throw e.cause;
}
}).rejects.toThrow(vaultsErrors.ErrorSecretsSecretUndefined);
})();
await testsUtils.expectRemoteError(
(async () => {
for await (const _ of deleteGetStream.readable);
})(),
vaultsErrors.ErrorSecretsSecretUndefined,
);
}
});
test('gets secrets from multiple vaults', async () => {
Expand All @@ -1629,7 +1619,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
}
// Get secret
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = getStream.writable.getWriter();
for (const [vault, name] of secretVaultNames) {
await writer.write({
Expand All @@ -1638,16 +1628,15 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
const secretContent: Array<string> = [];
for await (const data of getStream.readable) {
secretContent.push(data.secretContent);
}
expect(secretContent.join('')).toStrictEqual(secretNames.join(''));
// Delete secret
const deleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteStream.writable.getWriter();
for (const [vault, name] of secretVaultNames) {
await writer.write({
Expand All @@ -1656,28 +1645,25 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
expect((await deleteStream.output).success).toBeTruthy();
// Check each secret was deleted
for (const [vault, name] of secretVaultNames) {
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
const writer = getStream.writable.getWriter();
const deleteGetStream = await rpcClient.methods.vaultsSecretsGet();
await (async () => {
const writer = deleteGetStream.writable.getWriter();
await writer.write({
nameOrId: vault,
secretName: name,
});
await writer.close();
resolve(0);
});
await expect(async () => {
try {
for await (const _ of getStream.readable); // Consume
} catch (e) {
throw e.cause;
}
}).rejects.toThrow(vaultsErrors.ErrorSecretsSecretUndefined);
})();
await testsUtils.expectRemoteError(
(async () => {
for await (const _ of deleteGetStream.readable);
})(),
vaultsErrors.ErrorSecretsSecretUndefined,
);
}
});
test('deletes secrets from multiple vaults in one log', async () => {
Expand All @@ -1702,7 +1688,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
}
// Get secret
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
await (async () => {
const writer = getStream.writable.getWriter();
for (const [vault, name] of secretVaultNames) {
await writer.write({
Expand All @@ -1711,23 +1697,22 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
const secretContent: Array<string> = [];
for await (const data of getStream.readable) {
secretContent.push(data.secretContent);
}
expect(secretContent.join('')).toStrictEqual(secretNames.join(''));
// Get log size
let logLength: [number, number] = [0, 0];
const logLength: [number, number] = [0, 0];
await vaultManager.withVaults(vaultIds, async (...vaults) => {
for (let i = 0; i < vaults.length; i++) {
logLength[i] = (await vaults[i].log()).length;
}
});
// Delete secret
const deleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteStream.writable.getWriter();
for (const [vault, name] of secretVaultNames) {
await writer.write({
Expand All @@ -1736,28 +1721,25 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
});
}
await writer.close();
resolve(0);
});
})();
expect((await deleteStream.output).success).toBeTruthy();
// Check each secret was deleted
for (const [vault, name] of secretVaultNames) {
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
const writer = getStream.writable.getWriter();
const deleteGetStream = await rpcClient.methods.vaultsSecretsGet();
await (async () => {
const writer = deleteGetStream.writable.getWriter();
await writer.write({
nameOrId: vault,
secretName: name,
});
await writer.close();
resolve(0);
});
await expect(async () => {
try {
for await (const _ of getStream.readable); // Consume
} catch (e) {
throw e.cause;
}
}).rejects.toThrow(vaultsErrors.ErrorSecretsSecretUndefined);
})();
await testsUtils.expectRemoteError(
(async () => {
for await (const _ of deleteGetStream.readable);
})(),
vaultsErrors.ErrorSecretsSecretUndefined,
);
}
// Ensure single log message for deleting the secrets
await vaultManager.withVaults(vaultIds, async (...vaults) => {
Expand All @@ -1774,9 +1756,9 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
const secretDir = path.join(dataDir, secretDirName);
const secretNames = secretList.map((v) => path.join(secretDirName, v));
await fs.promises.mkdir(secretDir);
// Write secrets to files
for (const secret of secretList) {
const secretFile = path.join(secretDir, secret);
// Write secret to file
await fs.promises.writeFile(secretFile, secret);
}
const vaultId = await vaultManager.createVault(vaultName);
Expand All @@ -1788,15 +1770,14 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
expect(addResponse.success).toBeTruthy();
// Delete secret
const failDeleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = failDeleteStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secretDirName,
});
await writer.close();
resolve(0);
});
})();
await expect(async () => {
try {
(await failDeleteStream.output).success;
Expand All @@ -1805,36 +1786,33 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => {
}
}).rejects.toThrow(vaultsErrors.ErrorVaultsRecursive);
const deleteStream = await rpcClient.methods.vaultsSecretsRemove();
await new Promise(async (resolve) => {
await (async () => {
const writer = deleteStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: secretDirName,
metadata: { options: { recursive: true } },
});
await writer.close();
resolve(0);
});
})();
expect((await deleteStream.output).success).toBeTruthy();
// Check each secret and the secret directory were deleted
for (const name of secretNames) {
const getStream = await rpcClient.methods.vaultsSecretsGet();
await new Promise(async (resolve) => {
const writer = getStream.writable.getWriter();
const deleteGetStream = await rpcClient.methods.vaultsSecretsGet();
await (async () => {
const writer = deleteGetStream.writable.getWriter();
await writer.write({
nameOrId: vaultIdEncoded,
secretName: name,
});
await writer.close();
resolve(0);
});
await expect(async () => {
try {
for await (const _ of getStream.readable); // Consume
} catch (e) {
throw e.cause;
}
}).rejects.toThrow(vaultsErrors.ErrorSecretsSecretUndefined);
})();
await testsUtils.expectRemoteError(
(async () => {
for await (const _ of deleteGetStream.readable);
})(),
vaultsErrors.ErrorSecretsSecretUndefined,
);
}
await testsUtils.expectRemoteError(
rpcClient.methods.vaultsSecretsStat({
Expand Down

0 comments on commit 0f3b850

Please sign in to comment.