fix(auth): resolve credentials login SQLITE_CONSTRAINT_NOTNULL and relax password rules
Session creation failed with NOT NULL constraint on expires column due to invalid date propagation from duration parsing. Override adapter.createSession with validated insert, harden signIn callback, fix createDurationSchema for numeric-only values, and guard events.ts group insert. Also relaxes password complexity to suggestions-only (min 8 chars enforced), extracts shared UserCreatePasswordFields component, and fixes login form passing extra fields to signIn.
This commit is contained in:
21 files changed
+274
-86
No files matched your search
@@ -1,11 +1,42 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { createId } from "@homarr/common";
|
||||
import { users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
|
||||
import { createAdapter } from "../adapter";
|
||||
import { expireDateAfter } from "../session";
|
||||
|
||||
describe("createAdapter should create drizzle adapter", () => {
|
||||
test("createSession should insert a session row", async () => {
|
||||
const db = createDb();
|
||||
const userId = createId();
|
||||
await db.insert(users).values({ id: userId, name: "demodemo", password: "hash" });
|
||||
|
||||
const adapter = createAdapter(db, "credentials");
|
||||
const sessionToken = "test-session-token";
|
||||
|
||||
const session = await adapter.createSession?.({
|
||||
sessionToken,
|
||||
userId,
|
||||
expires: expireDateAfter(86400),
|
||||
});
|
||||
|
||||
expect(session).toMatchObject({
|
||||
sessionToken,
|
||||
userId,
|
||||
});
|
||||
|
||||
const storedSession = await db.query.sessions.findFirst({
|
||||
where: (table, { eq }) => eq(table.sessionToken, sessionToken),
|
||||
});
|
||||
|
||||
expect(storedSession).toBeDefined();
|
||||
});
|
||||
|
||||
test.each([["credentials" as const], ["ldap" as const], ["oidc" as const]])(
|
||||
"createAdapter getUserByEmail should return user for provider %s when this provider provided",
|
||||
async (provider) => {
|
||||
|
||||
@@ -53,4 +53,12 @@ describe("comparePasswordsAsync should compare passwords correctly", () => {
|
||||
// Assert
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it("should return true for passwords with special characters like LoveHomarr<3", async () => {
|
||||
const password = "LoveHomarr<3";
|
||||
const hash = await hashPasswordAsync(password);
|
||||
|
||||
const result = await comparePasswordsAsync(password, hash);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user