45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { test } from "node:test";
|
|
import { auth, checkPassword } from "../../server/better-auth";
|
|
import assert from "node:assert";
|
|
|
|
// @ts-ignore
|
|
import TestDB from "../mock-testdb";
|
|
|
|
const testDb = new TestDB();
|
|
|
|
test("Basic Auth", async (t) => {
|
|
t.before(async () => {
|
|
await testDb.create();
|
|
await auth().api.createUser({
|
|
body: {
|
|
name: "admin",
|
|
email: "admin@noreply.uptime-kuma.internal",
|
|
password: "Kuma-Test-8f4Q2xR9p",
|
|
role: "admin",
|
|
data: {
|
|
username: "admin",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
t.after(async () => {
|
|
console.log("Cleaning up test database...");
|
|
await testDb.destroy();
|
|
});
|
|
|
|
await t.test("[Basic Auth] returns true for valid credentials", async () => {
|
|
const result = await checkPassword("admin", "Kuma-Test-8f4Q2xR9p");
|
|
assert.strictEqual(result, true);
|
|
});
|
|
|
|
await t.test("returns false for wrong password", async () => {
|
|
const result = await checkPassword("admin", "wrongpassword");
|
|
assert.strictEqual(result, false);
|
|
});
|
|
|
|
await t.test("returns false for non-existent user", async () => {
|
|
const result = await checkPassword("nonexistent", "Kuma-Test-8f4Q2xR9p");
|
|
assert.strictEqual(result, false);
|
|
});
|
|
});
|