mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 09:01:12 +00:00
fix(onepassword): validate audit limit strictly (#106926)
* fix(onepassword): validate audit limit strictly * test(onepassword): strengthen audit limit coverage --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -160,4 +160,27 @@ describe("1Password CLI output", () => {
|
||||
`${"x".repeat(76)}...`,
|
||||
]);
|
||||
});
|
||||
|
||||
it.each(["", "0", "-1", "1.5", "0x10", "1e3", "1001"])(
|
||||
"rejects invalid audit limits: %j",
|
||||
async (limit) => {
|
||||
const store = new MemoryKeyedStore<AuditRow>();
|
||||
const entries = vi.spyOn(store, "entries");
|
||||
const { onepassword, write } = setupCommands(store);
|
||||
|
||||
await expect(onepassword.child("audit").run({ limit })).rejects.toThrow(
|
||||
"--limit must be an integer from 1 to 1000",
|
||||
);
|
||||
expect(entries).not.toHaveBeenCalled();
|
||||
expect(write).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it("accepts the maximum decimal audit limit", async () => {
|
||||
const { onepassword, write } = setupCommands();
|
||||
|
||||
await onepassword.child("audit").run({ limit: "1000" });
|
||||
|
||||
expect(JSON.parse(String(write.mock.calls[0]?.[0]))).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
|
||||
import type { PluginStateKeyedStore } from "openclaw/plugin-sdk/plugin-state-runtime";
|
||||
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
||||
import type { AuditRow } from "./broker.js";
|
||||
@@ -23,8 +24,8 @@ function parseLimit(value: unknown): number {
|
||||
if (value === undefined) {
|
||||
return 50;
|
||||
}
|
||||
const parsed = typeof value === "string" ? Number(value) : Number.NaN;
|
||||
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 1000) {
|
||||
const parsed = parseStrictPositiveInteger(value);
|
||||
if (parsed === undefined || parsed > 1000) {
|
||||
throw new Error("--limit must be an integer from 1 to 1000");
|
||||
}
|
||||
return parsed;
|
||||
|
||||
Reference in New Issue
Block a user