1
0
silverbullet/packages/server/auth.test.ts

30 lines
732 B
TypeScript
Raw Normal View History

2022-04-29 16:54:27 +00:00
import { beforeEach, afterEach, expect, test } from "@jest/globals";
import { unlink } from "fs/promises";
import knex, { Knex } from "knex";
import { Authenticator } from "./auth";
let db: Knex<any, unknown[]> | undefined;
beforeEach(async () => {
db = knex({
client: "better-sqlite3",
connection: {
2022-07-04 07:34:11 +00:00
filename: "auth-test.db",
2022-04-29 16:54:27 +00:00
},
useNullAsDefault: true,
});
});
afterEach(async () => {
db!.destroy();
2022-07-04 07:34:11 +00:00
await unlink("auth-test.db");
2022-04-29 16:54:27 +00:00
});
test("Test auth", async () => {
let auth = new Authenticator(db!);
await auth.ensureTables();
await auth.createAccount("admin", "admin");
expect(await auth.verify("admin", "admin")).toBe(true);
expect(await auth.verify("admin", "sup")).toBe(false);
});