You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
876 B
27 lines
876 B
import { describe, expect, it } from "vitest";
|
|
import {
|
|
DEFAULT_EMBED_PASSWORD,
|
|
hashEmbedPassword,
|
|
validateEmbedPassword,
|
|
compareEmbedPassword,
|
|
} from "@/modules/customer/embed-password";
|
|
|
|
describe("embed-password", () => {
|
|
it("默认演示密码为 123456", () => {
|
|
expect(DEFAULT_EMBED_PASSWORD).toBe("123456");
|
|
});
|
|
|
|
it("校验密码长度", () => {
|
|
expect(validateEmbedPassword("")).toMatch(/不能为空/);
|
|
expect(validateEmbedPassword("12345")).toMatch(/至少/);
|
|
expect(validateEmbedPassword("a".repeat(65))).toMatch(/不能超过/);
|
|
expect(validateEmbedPassword("123456")).toBeNull();
|
|
});
|
|
|
|
it("哈希后可验证", async () => {
|
|
const hash = await hashEmbedPassword("my-secret");
|
|
expect(await compareEmbedPassword("my-secret", hash)).toBe(true);
|
|
expect(await compareEmbedPassword("wrong", hash)).toBe(false);
|
|
});
|
|
});
|