Skip to content

Commit

Permalink
Add additional tests for keystore
Browse files Browse the repository at this point in the history
  • Loading branch information
mllnd committed Nov 14, 2023
1 parent be8f484 commit 40bb8f7
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion keygen/keystore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "$std/assert/mod.ts";
import { assert, assertEquals, assertRejects } from "$std/assert/mod.ts";

import { createKeystores, saveSigningKeystores, verifySigningKeystores } from "./mod.ts";
import { verifyPassword } from "../keystore/mod.ts";
Expand All @@ -24,4 +24,43 @@ Deno.test("Keystore", async (t) => {

assert(await verifySigningKeystores(storagePath, savedKeystores, keystorePassword));
});

await t.step("Should throw an error when unable to save signing keystores", async () => {
const keystorePassword = "testpassword123";
const storagePath = "/invalid/path/to/storage";

const keystores = await createKeystores(credentialsFixture, keystorePassword);

assertRejects(
() => saveSigningKeystores(keystores, storagePath),
Error,
"Unable to save signing keystores",
);
});

await t.step("Should throw an error when unable to read a signing keystore", async () => {
const keystorePassword = "testpassword123";
const storagePath = "./storage";

const keystores = await createKeystores(credentialsFixture, keystorePassword);
const savedKeystores = await saveSigningKeystores(keystores, storagePath);

await Deno.remove(`${storagePath}/${savedKeystores[0].fileName}`);

assertRejects(
() => verifySigningKeystores(storagePath, savedKeystores, keystorePassword),
Error,
`Unable to read signing keystore: ${savedKeystores[0].fileName}`,
);
});

await t.step("Should return false when a signing keystore password is invalid", async () => {
const keystorePassword = "testpassword123";
const storagePath = "./storage";

const keystores = await createKeystores(credentialsFixture, keystorePassword);
const savedKeystores = await saveSigningKeystores(keystores, storagePath);

assertEquals(await verifySigningKeystores(storagePath, savedKeystores, "invalidpassword"), false);
});
});

0 comments on commit 40bb8f7

Please sign in to comment.