mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:51:24 +00:00
fix(security): keep DM pairing allowlists out of group auth
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { firstDefined, isSenderIdAllowed, mergeAllowFromSources } from "./allow-from.js";
|
||||
import {
|
||||
firstDefined,
|
||||
isSenderIdAllowed,
|
||||
mergeDmAllowFromSources,
|
||||
resolveGroupAllowFromSources,
|
||||
} from "./allow-from.js";
|
||||
|
||||
describe("mergeAllowFromSources", () => {
|
||||
describe("mergeDmAllowFromSources", () => {
|
||||
it("merges, trims, and filters empty values", () => {
|
||||
expect(
|
||||
mergeAllowFromSources({
|
||||
mergeDmAllowFromSources({
|
||||
allowFrom: [" line:user:abc ", "", 123],
|
||||
storeAllowFrom: [" ", "telegram:456"],
|
||||
}),
|
||||
@@ -13,7 +18,7 @@ describe("mergeAllowFromSources", () => {
|
||||
|
||||
it("excludes pairing-store entries when dmPolicy is allowlist", () => {
|
||||
expect(
|
||||
mergeAllowFromSources({
|
||||
mergeDmAllowFromSources({
|
||||
allowFrom: ["+1111"],
|
||||
storeAllowFrom: ["+2222", "+3333"],
|
||||
dmPolicy: "allowlist",
|
||||
@@ -23,7 +28,7 @@ describe("mergeAllowFromSources", () => {
|
||||
|
||||
it("keeps pairing-store entries for non-allowlist policies", () => {
|
||||
expect(
|
||||
mergeAllowFromSources({
|
||||
mergeDmAllowFromSources({
|
||||
allowFrom: ["+1111"],
|
||||
storeAllowFrom: ["+2222"],
|
||||
dmPolicy: "pairing",
|
||||
@@ -32,6 +37,26 @@ describe("mergeAllowFromSources", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveGroupAllowFromSources", () => {
|
||||
it("prefers explicit group allowlist", () => {
|
||||
expect(
|
||||
resolveGroupAllowFromSources({
|
||||
allowFrom: ["owner"],
|
||||
groupAllowFrom: ["group-owner", " group-admin "],
|
||||
}),
|
||||
).toEqual(["group-owner", "group-admin"]);
|
||||
});
|
||||
|
||||
it("falls back to DM allowlist when group allowlist is unset/empty", () => {
|
||||
expect(
|
||||
resolveGroupAllowFromSources({
|
||||
allowFrom: [" owner ", "", "owner2"],
|
||||
groupAllowFrom: [],
|
||||
}),
|
||||
).toEqual(["owner", "owner2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("firstDefined", () => {
|
||||
it("returns the first non-undefined value", () => {
|
||||
expect(firstDefined(undefined, undefined, "x", "y")).toBe("x");
|
||||
|
||||
Reference in New Issue
Block a user