zxcvbn-strength.test.ts

1.2 KB · raw

1// LV-8: the @zxcvbn-ts replacement must score the master-password strength2// meter on the same 0-4 scale as the old zxcvbn, with dictionaries loaded3// (language-common is what keeps weak passwords from scoring optimistically).4import { beforeAll, describe, expect, it } from "vitest";5import { zxcvbn, zxcvbnOptions } from "@zxcvbn-ts/core";6import * as common from "@zxcvbn-ts/language-common";7import * as en from "@zxcvbn-ts/language-en";89beforeAll(() => {10  // Mirror the loader in Lock.tsx exactly.11  zxcvbnOptions.setOptions({12    translations: en.translations,13    graphs: common.adjacencyGraphs,14    dictionary: { ...common.dictionary, ...en.dictionary },15  });16});1718describe("LV-8 password strength scoring", () => {19  it("scores a common weak password low (<= 1)", () => {20    expect(zxcvbn("password123").score).toBeLessThanOrEqual(1);21  });2223  it("scores a long random passphrase at the top of the scale (4)", () => {24    expect(zxcvbn("9xQ!vZ2pLm74Tr#Ke8Wd5Bn").score).toBe(4);25  });2627  it("keeps the 0-4 integer scale", () => {28    const s = zxcvbn("correct horse battery staple").score;29    expect(Number.isInteger(s)).toBe(true);30    expect(s).toBeGreaterThanOrEqual(0);31    expect(s).toBeLessThanOrEqual(4);32  });33});