Skip to content

Commit

Permalink
chore: add more assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Taiwo committed Jan 25, 2025
1 parent 473aebf commit 232ab14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/__test__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe("server.ts tests", () => {
challenge: "test_challenge",
});

// Spy on console
// spy on console.debug
const debugSpy = jest.spyOn(console, "debug");

// Mock out rpIdHash comparison so it passes
Expand Down
22 changes: 22 additions & 0 deletions src/__test__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,37 @@ describe("Encoding/Decoding utils", () => {
test("returns true for valid signature", async () => {
jest.spyOn(global.crypto.subtle, "verify").mockResolvedValueOnce(true);

// spy on console.debug
const debugSpy = jest.spyOn(console, "debug");

const params = {
algorithm: "ES256" as NamedAlgo,
publicKey: ES256_SPKI_KEY,
authenticatorData: "FAKE_AUTH_DATA",
clientData: "FAKE_CLIENT_DATA",
signature: "FAKE_SIGNATURE",
verbose: true,
};

const result = await verifySignature(params);
expect(result).toBe(true);
expect(debugSpy).toHaveBeenCalledTimes(5);
expect(debugSpy.mock.calls).toEqual([
[
expect.objectContaining({
algorithm: { name: "ECDSA", namedCurve: "P-256" },
extractable: false,
type: "public",
usages: ["verify"],
}),
],
["Algorithm: ES256"],
[
"Public key: MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEol4zrYnJVbFPkOCqeWV5NCPnmzyfC-l0xsDQDIxBsA0RvfMi_KLqC7ksZyMXHqspq37pGPOxBwmhY3h6DGYrKQ",
],
["Data: FAKE_AUTH_DATMTf4DoKP8RlZmw-3HUKDfA83kIeG7pCNKTwDQDRoLGo"],
["Signature: FAKE_SIGNATURE"],
]);
});

test("returns false for invalid signature", async () => {
Expand Down

0 comments on commit 232ab14

Please sign in to comment.