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

30 lines
722 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: {
filename: "test.db",
},
useNullAsDefault: true,
});
});
afterEach(async () => {
db!.destroy();
await unlink("test.db");
});
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);
});