mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-23 23:52:18 +03:00
Validated on the combined batch board over release/v3.8.50 tip d91238b7: static gates clean, typecheck:core clean, focused tests green.
Strict schema + {sanitized, rejected} DB boundary — silent validation degradation now answers 400 with the offending keys. Caller audit done: only the providers write path consumes the sanitizers. Thank you @maxmad64bis!
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { updateProviderConnectionSchema } from "@/shared/validation/schemas/provider";
|
|
|
|
test("PATCH rateLimitOverrides {rpm:\"60\"} coerces to a valid number", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({ rateLimitOverrides: { rpm: "60" } });
|
|
assert.equal(r.success, true);
|
|
});
|
|
|
|
test("unknown key in rateLimitOverrides is rejected (no silent drop)", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({ rateLimitOverrides: { rpm: 10, foo: 1 } });
|
|
assert.equal(r.success, false);
|
|
const flaggedFoo = r.error!.issues.some(
|
|
(i) => i.path.includes("foo") || (i as { keys?: string[] }).keys?.includes("foo") || i.message.includes("foo")
|
|
);
|
|
assert.ok(
|
|
flaggedFoo,
|
|
`expected an issue flagging "foo", got: ${JSON.stringify(r.error!.issues)}`
|
|
);
|
|
});
|
|
|
|
test("quotaWindowThresholds key longer than 64 chars is rejected", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({
|
|
quotaWindowThresholds: { ["a".repeat(65)]: 50 },
|
|
});
|
|
assert.equal(r.success, false);
|
|
});
|
|
|
|
test("empty string rate limit value is rejected (coerce \"\"→0 trap)", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({ rateLimitOverrides: { rpm: "" } });
|
|
assert.equal(r.success, false);
|
|
});
|
|
|
|
test("non-numeric rate limit value is rejected", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({ rateLimitOverrides: { rpm: "60abc" } });
|
|
assert.equal(r.success, false);
|
|
});
|
|
|
|
test("quotaWindowThresholds value outside 0-100 is rejected", () => {
|
|
const r = updateProviderConnectionSchema.safeParse({ quotaWindowThresholds: { win: 101 } });
|
|
assert.equal(r.success, false);
|
|
});
|