mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:08:28 +00:00
test: dedupe repeated validation and throw assertions
This commit is contained in:
@@ -142,8 +142,8 @@ describe("resolveConfigIncludes", () => {
|
|||||||
for (const testCase of cases) {
|
for (const testCase of cases) {
|
||||||
const files = { [configPath(testCase.includeFile)]: testCase.included };
|
const files = { [configPath(testCase.includeFile)]: testCase.included };
|
||||||
const obj = { $include: `./${testCase.includeFile}`, extra: true };
|
const obj = { $include: `./${testCase.includeFile}`, extra: true };
|
||||||
expect(() => resolve(obj, files), testCase.includeFile).toThrow(ConfigIncludeError);
|
expectResolveIncludeError(
|
||||||
expect(() => resolve(obj, files), testCase.includeFile).toThrow(
|
() => resolve(obj, files),
|
||||||
/Sibling keys require included content to be an object/,
|
/Sibling keys require included content to be an object/,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ import type { SessionEntry } from "./types.js";
|
|||||||
|
|
||||||
describe("session path safety", () => {
|
describe("session path safety", () => {
|
||||||
it("rejects unsafe session IDs", () => {
|
it("rejects unsafe session IDs", () => {
|
||||||
expect(() => validateSessionId("../etc/passwd")).toThrow(/Invalid session ID/);
|
const unsafeSessionIds = ["../etc/passwd", "a/b", "a\\b", "/abs"];
|
||||||
expect(() => validateSessionId("a/b")).toThrow(/Invalid session ID/);
|
for (const sessionId of unsafeSessionIds) {
|
||||||
expect(() => validateSessionId("a\\b")).toThrow(/Invalid session ID/);
|
expect(() => validateSessionId(sessionId), sessionId).toThrow(/Invalid session ID/);
|
||||||
expect(() => validateSessionId("/abs")).toThrow(/Invalid session ID/);
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resolves transcript path inside an explicit sessions dir", () => {
|
it("resolves transcript path inside an explicit sessions dir", () => {
|
||||||
|
|||||||
@@ -333,9 +333,16 @@ describe("buildGatewayConnectionDetails", () => {
|
|||||||
resolveGatewayPort.mockReturnValue(18789);
|
resolveGatewayPort.mockReturnValue(18789);
|
||||||
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
|
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
|
||||||
|
|
||||||
expect(() => buildGatewayConnectionDetails()).toThrow("SECURITY ERROR");
|
let thrown: unknown;
|
||||||
expect(() => buildGatewayConnectionDetails()).toThrow("plaintext ws://");
|
try {
|
||||||
expect(() => buildGatewayConnectionDetails()).toThrow("wss://");
|
buildGatewayConnectionDetails();
|
||||||
|
} catch (error) {
|
||||||
|
thrown = error;
|
||||||
|
}
|
||||||
|
expect(thrown).toBeInstanceOf(Error);
|
||||||
|
expect((thrown as Error).message).toContain("SECURITY ERROR");
|
||||||
|
expect((thrown as Error).message).toContain("plaintext ws://");
|
||||||
|
expect((thrown as Error).message).toContain("wss://");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows ws:// for loopback addresses in local mode", () => {
|
it("allows ws:// for loopback addresses in local mode", () => {
|
||||||
|
|||||||
@@ -19,23 +19,39 @@ describe("parseSlackBlocksInput", () => {
|
|||||||
expect(parsed).toEqual([{ type: "section", text: { type: "mrkdwn", text: "hi" } }]);
|
expect(parsed).toEqual([{ type: "section", text: { type: "mrkdwn", text: "hi" } }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects invalid JSON", () => {
|
it("rejects invalid block payloads", () => {
|
||||||
expect(() => parseSlackBlocksInput("{bad-json")).toThrow(/valid JSON/i);
|
const cases = [
|
||||||
});
|
{
|
||||||
|
name: "invalid JSON",
|
||||||
|
input: "{bad-json",
|
||||||
|
expectedMessage: /valid JSON/i,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-array payload",
|
||||||
|
input: { type: "divider" },
|
||||||
|
expectedMessage: /must be an array/i,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty array",
|
||||||
|
input: [],
|
||||||
|
expectedMessage: /at least one block/i,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-object block",
|
||||||
|
input: ["not-a-block"],
|
||||||
|
expectedMessage: /must be an object/i,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "missing block type",
|
||||||
|
input: [{}],
|
||||||
|
expectedMessage: /non-empty string type/i,
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
it("rejects non-array payloads", () => {
|
for (const testCase of cases) {
|
||||||
expect(() => parseSlackBlocksInput({ type: "divider" })).toThrow(/must be an array/i);
|
expect(() => parseSlackBlocksInput(testCase.input), testCase.name).toThrow(
|
||||||
});
|
testCase.expectedMessage,
|
||||||
|
);
|
||||||
it("rejects empty arrays", () => {
|
}
|
||||||
expect(() => parseSlackBlocksInput([])).toThrow(/at least one block/i);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects non-object blocks", () => {
|
|
||||||
expect(() => parseSlackBlocksInput(["not-a-block"])).toThrow(/must be an object/i);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects blocks without type", () => {
|
|
||||||
expect(() => parseSlackBlocksInput([{}])).toThrow(/non-empty string type/i);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user