mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 16:20:23 +00:00
Harden Telegram poll gating and schema consistency (#36547)
Merged via squash.
Prepared head SHA: f77824419e
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
f771ba8de9
commit
6dfd39c32f
60
src/poll-params.test.ts
Normal file
60
src/poll-params.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { hasPollCreationParams, resolveTelegramPollVisibility } from "./poll-params.js";
|
||||
|
||||
describe("poll params", () => {
|
||||
it("does not treat explicit false booleans as poll creation params", () => {
|
||||
expect(
|
||||
hasPollCreationParams({
|
||||
pollMulti: false,
|
||||
pollAnonymous: false,
|
||||
pollPublic: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it.each([{ key: "pollMulti" }, { key: "pollAnonymous" }, { key: "pollPublic" }])(
|
||||
"treats $key=true as poll creation intent",
|
||||
({ key }) => {
|
||||
expect(
|
||||
hasPollCreationParams({
|
||||
[key]: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it("treats finite numeric poll params as poll creation intent", () => {
|
||||
expect(hasPollCreationParams({ pollDurationHours: 0 })).toBe(true);
|
||||
expect(hasPollCreationParams({ pollDurationSeconds: 60 })).toBe(true);
|
||||
expect(hasPollCreationParams({ pollDurationSeconds: "60" })).toBe(true);
|
||||
expect(hasPollCreationParams({ pollDurationSeconds: "1e3" })).toBe(true);
|
||||
expect(hasPollCreationParams({ pollDurationHours: Number.NaN })).toBe(false);
|
||||
expect(hasPollCreationParams({ pollDurationSeconds: Infinity })).toBe(false);
|
||||
expect(hasPollCreationParams({ pollDurationSeconds: "60abc" })).toBe(false);
|
||||
});
|
||||
|
||||
it("treats string-encoded boolean poll params as poll creation intent when true", () => {
|
||||
expect(hasPollCreationParams({ pollPublic: "true" })).toBe(true);
|
||||
expect(hasPollCreationParams({ pollAnonymous: "false" })).toBe(false);
|
||||
});
|
||||
|
||||
it("treats string poll options as poll creation intent", () => {
|
||||
expect(hasPollCreationParams({ pollOption: "Yes" })).toBe(true);
|
||||
});
|
||||
|
||||
it("detects snake_case poll fields as poll creation intent", () => {
|
||||
expect(hasPollCreationParams({ poll_question: "Lunch?" })).toBe(true);
|
||||
expect(hasPollCreationParams({ poll_option: ["Pizza", "Sushi"] })).toBe(true);
|
||||
expect(hasPollCreationParams({ poll_duration_seconds: "60" })).toBe(true);
|
||||
expect(hasPollCreationParams({ poll_public: "true" })).toBe(true);
|
||||
});
|
||||
|
||||
it("resolves telegram poll visibility flags", () => {
|
||||
expect(resolveTelegramPollVisibility({ pollAnonymous: true })).toBe(true);
|
||||
expect(resolveTelegramPollVisibility({ pollPublic: true })).toBe(false);
|
||||
expect(resolveTelegramPollVisibility({})).toBeUndefined();
|
||||
expect(() => resolveTelegramPollVisibility({ pollAnonymous: true, pollPublic: true })).toThrow(
|
||||
/mutually exclusive/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user