test(shared): narrow PasswordCheckResult before reading reason
CI / Architecture Guardrails (pull_request) Successful in 6m11s
CI / Assistant Split Regression (pull_request) Successful in 7m19s
CI / Lint (pull_request) Successful in 7m59s
CI / Typecheck (pull_request) Successful in 9m28s
CI / Build (pull_request) Successful in 6m53s
CI / E2E Tests (pull_request) Successful in 6m7s
CI / Fresh-Linux Docker Deploy (pull_request) Successful in 6m52s
CI / Release Images (pull_request) Has been skipped
CI / Unit Tests (pull_request) Successful in 8m30s

CI typecheck failed because the discriminated union returned by
checkPasswordPolicy only exposes `reason` on the `{ ok: false }` branch.
Guard each `.reason` assertion with `if (!result.ok)` so the test file
typechecks under exactOptionalPropertyTypes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-18 14:53:30 +02:00
parent e01074926e
commit cfce1f2a15
@@ -6,13 +6,13 @@ describe("checkPasswordPolicy", () => {
it("rejects passwords shorter than 12 chars", () => {
const result = checkPasswordPolicy("short1!");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/at least 12/i);
if (!result.ok) expect(result.reason).toMatch(/at least 12/i);
});
it("rejects passwords longer than 128 chars", () => {
const result = checkPasswordPolicy("A".repeat(129));
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/no more than 128/i);
if (!result.ok) expect(result.reason).toMatch(/no more than 128/i);
});
it("accepts passwords at the lower bound that pass other checks", () => {
@@ -25,25 +25,25 @@ describe("checkPasswordPolicy", () => {
it("rejects single char repeated", () => {
const result = checkPasswordPolicy("aaaaaaaaaaaa");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/single character/i);
if (!result.ok) expect(result.reason).toMatch(/single character/i);
});
it("rejects short patterns repeated", () => {
const result = checkPasswordPolicy("abcabcabcabc");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/short pattern/i);
if (!result.ok) expect(result.reason).toMatch(/short pattern/i);
});
it("rejects '1212121212121212' (2-char pattern repeated)", () => {
const result = checkPasswordPolicy("1212121212121212");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/short pattern/i);
if (!result.ok) expect(result.reason).toMatch(/short pattern/i);
});
it("rejects keyboard sequences like 'abcdefghijkl'", () => {
const result = checkPasswordPolicy("abcdefghijkl");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/sequence/i);
if (!result.ok) expect(result.reason).toMatch(/sequence/i);
});
it("rejects numeric runs like '1234567890ab'", () => {
@@ -57,13 +57,13 @@ describe("checkPasswordPolicy", () => {
it("rejects 'PasswordPassword' (case-insensitive)", () => {
const result = checkPasswordPolicy("PasswordPassword");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/commonly used/i);
if (!result.ok) expect(result.reason).toMatch(/commonly used/i);
});
it("rejects 'Welcome2026!' seasonal password", () => {
const result = checkPasswordPolicy("Welcome2026!");
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/commonly used/i);
if (!result.ok) expect(result.reason).toMatch(/commonly used/i);
});
it("rejects 'Summer2025!' regardless of case", () => {
@@ -78,7 +78,7 @@ describe("checkPasswordPolicy", () => {
email: "hartmut@example.com",
});
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/email or name/i);
if (!result.ok) expect(result.reason).toMatch(/email or name/i);
});
it("rejects passwords containing the user name", () => {
@@ -86,7 +86,7 @@ describe("checkPasswordPolicy", () => {
name: "Hartmut Noerenberg",
});
expect(result.ok).toBe(false);
expect(result.reason).toMatch(/email or name/i);
if (!result.ok) expect(result.reason).toMatch(/email or name/i);
});
it("ignores short email locals to avoid false positives", () => {