Files
plainleaf/server/crypto.test.ts
T
MaksandGitHub 8a3782e946 improve dependency management (#770)
* use import_map.json instead of per-file import

* remove test_deps.ts in favor of import_map

* remove common/deps.ts in favor of import_map

* use import_map instead of server/deps.ts

* make all plug-api files usable without an import_map

* make all lib files usable without an import_map

* remove web/deps.ts in favor of import_map

* fix plug build

* remove plug-api/deps.ts in favor of lib/deps.ts

* fix server deps bundled in client deps
2024-03-16 15:29:24 +01:00

28 lines
950 B
TypeScript

import { sleep } from "$lib/async.ts";
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
import { assertEquals } from "$std/testing/asserts.ts";
import { JWTIssuer } from "./crypto.ts";
Deno.test("Test JWT crypto", async () => {
const db = new MemoryKvPrimitives();
const jwt = new JWTIssuer(db);
await jwt.init("test");
// Timeout value is 0 seconds, which means it should expire immediately with a 1 second grace period
const token = await jwt.createJWT({ user: "pete", role: "admin" }, 0);
const verified = await jwt.verifyAndDecodeJWT(token);
assertEquals(verified.user, "pete");
try {
await jwt.verifyAndDecodeJWT(token + "bla");
assertEquals(true, false, "Should have thrown invalid signature");
} catch {
// expected
}
await sleep(1500);
try {
await jwt.verifyAndDecodeJWT(token);
assertEquals(true, false, "Should have thrown a timeout");
} catch {
// expected
}
});