feat: 新增租户 active 状态与统一禁用闸门

This commit is contained in:
gitea committed 2026-11-08 12:52:05 +08:00
1 parent 634f0e2b78
commit 0ff3d9a313
21 files changed
+855 -14

No files matched your search

+74
View File
@@ -300,6 +300,80 @@ describe("loadCorpConfigs", () => {
});
});
describe("loadCorpConfigs tenant active materialization", () => {
const sources = [
{
label: "hose",
source: {
type: "hose",
domain: "https://app.ekuaibao.com",
appKey: "app-key",
appSecurity: "app-security",
corpId: "ID01",
staffId: "ID01:STAFF01"
}
},
{
label: "seal",
source: { type: "seal", token: "seal-token", sealUrl: "https://seal.sealai.cc" }
}
];
test("materializes active=true for legacy configs of both sources and keeps explicit false", () => {
const dir = makeTempDir();
for (const { label, source } of sources) {
writeFileSync(join(dir, `${label}-legacy.json`), JSON.stringify({
id: `${label}-legacy`, name: `${label} Legacy`, source
}));
writeFileSync(join(dir, `${label}-disabled.json`), JSON.stringify({
id: `${label}-disabled`, name: `${label} Disabled`, active: false, source
}));
}
process.env.SEAL_USE_ENTERPRISES_DIR = dir;
const byId = new Map(loadCorpConfigs().map((item) => [item.id, item]));
for (const { label } of sources) {
expect(byId.get(`${label}-legacy`)?.active).toBe(true);
expect(byId.get(`${label}-disabled`)?.active).toBe(false);
}
});
test("a malformed active value loads as disabled without dropping the enterprise", () => {
const dir = makeTempDir();
process.env.SEAL_USE_ENTERPRISES_DIR = dir;
for (const { label, source } of sources) {
writeFileSync(join(dir, `${label}-malformed.json`), JSON.stringify({
id: `${label}-malformed`, name: `${label} Malformed`, active: "false", source
}));
}
const byId = new Map(loadCorpConfigs().map((item) => [item.id, item]));
for (const { label } of sources) {
expect(byId.has(`${label}-malformed`)).toBe(true);
expect(byId.get(`${label}-malformed`)?.active).toBe(false);
}
// Fail-closed is NOT a parse failure: the file must never be skipped.
expect(getLastCorpConfigLoadIssues()).toEqual([]);
});
test("updateCorpConfig writes an explicit active value for both sources", () => {
const dir = makeTempDir();
process.env.SEAL_USE_ENTERPRISES_DIR = dir;
for (const { label, source } of sources) {
writeFileSync(join(dir, `${label}-update.json`), JSON.stringify({
id: `${label}-update`, name: `${label} Update`, source
}));
const updated = updateCorpConfig(`${label}-update`, { active: false });
expect(updated.active).toBe(false);
expect(JSON.parse(readFileSync(join(dir, `${label}-update.json`), "utf-8")).active).toBe(false);
const restored = updateCorpConfig(`${label}-update`, { active: true });
expect(restored.active).toBe(true);
expect(JSON.parse(readFileSync(join(dir, `${label}-update.json`), "utf-8")).active).toBe(true);
}
});
});
describe("syncLegacyEnterprisesDir", () => {
test("migrates files from legacy to primary and deletes legacy when > 7 days old", () => {
const primary = makeTempDir();