| 12345678910111213141516171819202122232425262728293031 |
- /* @vitest-environment node */
- import { describe, it, expect } from "vitest";
- import { PASSWORD_POLICY, validateNewPassword } from "@/lib/auth/passwordPolicy";
- import { generateAdminTemporaryPassword } from "./adminTempPassword.js";
- describe("lib/auth/adminTempPassword", () => {
- it("generates passwords that pass the configured password policy", () => {
- for (let i = 0; i < 25; i += 1) {
- const password = generateAdminTemporaryPassword();
- const result = validateNewPassword({ newPassword: password });
- expect(password.length).toBeGreaterThanOrEqual(PASSWORD_POLICY.minLength);
- expect(result.ok).toBe(true);
- }
- });
- it("respects custom length but never below the policy minimum", () => {
- const belowMin = generateAdminTemporaryPassword({
- length: PASSWORD_POLICY.minLength - 3,
- });
- const custom = generateAdminTemporaryPassword({
- length: PASSWORD_POLICY.minLength + 4,
- });
- expect(belowMin.length).toBeGreaterThanOrEqual(PASSWORD_POLICY.minLength);
- expect(custom.length).toBe(PASSWORD_POLICY.minLength + 4);
- });
- });
|