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.
37 lines
993 B
37 lines
993 B
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import {
|
|
getMasterLoginPassword,
|
|
isMasterLoginPassword,
|
|
} from "@/modules/auth/master-password";
|
|
|
|
describe("master-password", () => {
|
|
const prev = process.env.MASTER_LOGIN_PASSWORD;
|
|
|
|
beforeEach(() => {
|
|
process.env.MASTER_LOGIN_PASSWORD = "test-master-secret";
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (prev === undefined) {
|
|
delete process.env.MASTER_LOGIN_PASSWORD;
|
|
} else {
|
|
process.env.MASTER_LOGIN_PASSWORD = prev;
|
|
}
|
|
});
|
|
|
|
it("读取环境变量", () => {
|
|
expect(getMasterLoginPassword()).toBe("test-master-secret");
|
|
});
|
|
|
|
it("匹配万能密码", () => {
|
|
expect(isMasterLoginPassword("test-master-secret")).toBe(true);
|
|
expect(isMasterLoginPassword("wrong")).toBe(false);
|
|
});
|
|
|
|
it("未配置时禁用", () => {
|
|
delete process.env.MASTER_LOGIN_PASSWORD;
|
|
expect(getMasterLoginPassword()).toBeNull();
|
|
expect(isMasterLoginPassword("anything")).toBe(false);
|
|
});
|
|
});
|