Add PocketBase login, first-sign-in password changes, account settings, and user activation, reactivation and deletion with self-removal guards. Protect application pages and APIs and keep private pages out of PWA caches. Resolve plant locations from site assignments and improve map controls, profit chart views, navigation and mobile table layouts. Validation: production build and TypeScript passed; 28 unit tests passed. Backend access integration tests and mobile verification are documented.
30 lines
1.4 KiB
TypeScript
30 lines
1.4 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { validateLogin, validateNewPassword, validateNewUser, authDestination } from "./auth-policy";
|
|
|
|
test("login rejects missing credentials and malformed email", () => {
|
|
for (const [email, password] of [["", "mega2026"], ["person@example.com", ""], ["person", "mega2026"]]) {
|
|
assert.ok(validateLogin(email, password));
|
|
}
|
|
assert.equal(validateLogin("person@example.com", "mega2026"), null);
|
|
});
|
|
|
|
test("chosen password requires eight characters, confirmation and replacement of the starter password", () => {
|
|
assert.ok(validateNewPassword("short", "short"));
|
|
assert.ok(validateNewPassword("password", "different"));
|
|
assert.ok(validateNewPassword("mega2026", "mega2026"));
|
|
assert.equal(validateNewPassword("abcdefgh", "abcdefgh"), null);
|
|
assert.equal(validateNewPassword("a b c d ", "a b c d "), null);
|
|
});
|
|
|
|
test("add user requires a name and valid email", () => {
|
|
assert.ok(validateNewUser(" ", "person@example.com"));
|
|
assert.ok(validateNewUser("Person", "broken-email"));
|
|
assert.equal(validateNewUser("Person", "person@example.com"), null);
|
|
});
|
|
|
|
test("anonymous and first-login users cannot enter the dashboard", () => {
|
|
assert.equal(authDestination(null), "/login");
|
|
assert.equal(authDestination({ passwordChanged: false }), "/change-password");
|
|
assert.equal(authDestination({ passwordChanged: true }), "/");
|
|
});
|