Skip to content

Commit

Permalink
feat: adds unhappy path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ganchoradkov committed Aug 15, 2024
1 parent 0c4df5c commit 29f8df8
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions packages/utils/test/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("Crypto", () => {
it("calls generateRandomBytes32", () => {
expect(generateRandomBytes32()).toBeTruthy();
});
it.only("should validate verify v2 jwt", async () => {
it("should validate verify v2 jwt", async () => {
const token =
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjM2MzI1MDQsImlkIjoiMDkxN2YzMzk0YTdmMzkyZTg3ZTM1ZjM4OTg2OWU2NDEzZjkyNTBlMGIxZTE4YjUzMDhkNzBhM2VjOTJjZDQ3OCIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCIsImlzU2NhbSI6bnVsbCwiaXNWZXJpZmllZCI6ZmFsc2V9.RehA28c0Ae8D_ixvGS8uG9J9eTJtpGfaC_7kNE9ZNAVFREWBY6Dl_SXc0_E0RSvYkHpupfmXlmjenuDqNcyoeg";

Expand All @@ -130,7 +130,7 @@ describe("Crypto", () => {
expiresAt: 1726209328,
};

const result = await verifyP256Jwt<{
const result = verifyP256Jwt<{
exp: number;
id: string;
origin: string;
Expand All @@ -146,4 +146,56 @@ describe("Crypto", () => {
expect(result.isScam).to.be.null;
await new Promise((resolve) => setTimeout(resolve, 1000));
});
it("should fail to validate invalid jwt with public key", async () => {
const token =
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.oiMDkxN2YzMzk0YTdmMzkyZTg3ZTM1ZjM4OTg2OWU2NDEzZjkyNTBlMGIxZTE4YjUzMDhkNzBhM2VjOTJjZDQ3OCIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCIsImlzU2NhbSI6bnVsbCwiaXNWZXJpZmllZCI6ZmFsc2V9.RehA28c0Ae8D_ixvGS8uG9J9eTJtpGfaC_7kNE9ZNAVFREWBY6Dl_SXc0_E0RSvYkHpupfmXlmjenuDqNcyoeg";

const publicKey = {
publicKey: {
crv: "P-256",
ext: true,
key_ops: ["verify"],
kty: "EC",
x: "CbL4DOYOb1ntd-8OmExO-oS0DWCMC00DntrymJoB8tk",
y: "KTFwjHtQxGTDR91VsOypcdBfvbo6sAMj5p4Wb-9hRA0",
},
expiresAt: 1726209328,
};

expect(() =>
verifyP256Jwt<{
exp: number;
id: string;
origin: string;
isScam: boolean;
isVerified: true;
}>(token, publicKey.publicKey),
).to.throw();
});
it("should fail to validate validate verify v2 jwt with invalid public key", async () => {
const token =
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjM2MzI1MDQsImlkIjoiMDkxN2YzMzk0YTdmMzkyZTg3ZTM1ZjM4OTg2OWU2NDEzZjkyNTBlMGIxZTE4YjUzMDhkNzBhM2VjOTJjZDQ3OCIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCIsImlzU2NhbSI6bnVsbCwiaXNWZXJpZmllZCI6ZmFsc2V9.RehA28c0Ae8D_ixvGS8uG9J9eTJtpGfaC_7kNE9ZNAVFREWBY6Dl_SXc0_E0RSvYkHpupfmXlmjenuDqNcyoeg";

const publicKey = {
publicKey: {
crv: "P-256",
ext: true,
key_ops: ["verify"],
kty: "EC",
x: "CbL4DOYOb1ntd-8OmExO-oS0DWCMC00Dn",
y: "KTFwjHtQxGTDR91VsOypcdBfvbo6sAMj5p4Wb-9hRA0",
},
expiresAt: 1726209328,
};

expect(() =>
verifyP256Jwt<{
exp: number;
id: string;
origin: string;
isScam: boolean;
isVerified: true;
}>(token, publicKey.publicKey),
).to.throw();
});
});

0 comments on commit 29f8df8

Please sign in to comment.