mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:51:23 +00:00
refactor(allowlists): share user entry collection
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildAllowlistResolutionSummary } from "./resolve-utils.js";
|
||||
import {
|
||||
addAllowlistUserEntriesFromConfigEntry,
|
||||
buildAllowlistResolutionSummary,
|
||||
} from "./resolve-utils.js";
|
||||
|
||||
describe("buildAllowlistResolutionSummary", () => {
|
||||
it("returns mapping, additions, and unresolved (including missing ids)", () => {
|
||||
@@ -23,3 +26,17 @@ describe("buildAllowlistResolutionSummary", () => {
|
||||
expect(result.mapping).toEqual(["a→1 (note)"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("addAllowlistUserEntriesFromConfigEntry", () => {
|
||||
it("adds trimmed users and skips '*' and blanks", () => {
|
||||
const target = new Set<string>();
|
||||
addAllowlistUserEntriesFromConfigEntry(target, { users: [" a ", "*", "", "b"] });
|
||||
expect(Array.from(target).toSorted()).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("ignores non-objects", () => {
|
||||
const target = new Set<string>(["a"]);
|
||||
addAllowlistUserEntriesFromConfigEntry(target, null);
|
||||
expect(Array.from(target)).toEqual(["a"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,6 +96,22 @@ export function patchAllowlistUsersInConfigEntries<
|
||||
return nextEntries as TEntries;
|
||||
}
|
||||
|
||||
export function addAllowlistUserEntriesFromConfigEntry(target: Set<string>, entry: unknown): void {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return;
|
||||
}
|
||||
const users = (entry as { users?: Array<string | number> }).users;
|
||||
if (!Array.isArray(users)) {
|
||||
return;
|
||||
}
|
||||
for (const value of users) {
|
||||
const trimmed = String(value).trim();
|
||||
if (trimmed && trimmed !== "*") {
|
||||
target.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function summarizeMapping(
|
||||
label: string,
|
||||
mapping: string[],
|
||||
|
||||
Reference in New Issue
Block a user