mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
test(kit): refuse a sealed field in any response the route kit drives
callRoute now fails a call whose JSON body carries a key ending in Encrypted, or bytes serialised as an index-keyed object or a Buffer, on every route it drives and regardless of the contract exemption. A sealed column is decrypted or dropped before a response is built; one that leaks is a defect, whatever the contract says. The kit's own test proves the check finds both shapes and leaves an hour map alone.
This commit is contained in:
1 parent
36fe53bbaa
commit
7b9737c7b1
2 files changed
+80
-1
No files matched your search
@@ -12,7 +12,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { apiHandler } from "@/lib/api-handler";
|
||||
|
||||
import { ContractViolation, anonymous, callRoute } from "../../kit/call-route";
|
||||
import {
|
||||
ContractViolation,
|
||||
anonymous,
|
||||
callRoute,
|
||||
sealedFieldPaths,
|
||||
} from "../../kit/call-route";
|
||||
|
||||
const token = {
|
||||
id: "tok-1",
|
||||
@@ -28,6 +33,31 @@ function answering(status: number, body: unknown) {
|
||||
return apiHandler(async () => NextResponse.json(body, { status }));
|
||||
}
|
||||
|
||||
describe("callRoute's sealed-field check", () => {
|
||||
it("finds a sealed key and serialised bytes at any depth, and nothing else", () => {
|
||||
const bytes = Object.fromEntries(
|
||||
Array.from({ length: 32 }, (_, i) => [String(i), (i * 7) % 256]),
|
||||
);
|
||||
expect(
|
||||
sealedFieldPaths({
|
||||
data: {
|
||||
rows: [{ notes: "a", notesEncrypted: null }],
|
||||
track: { geometry: bytes },
|
||||
raw: { type: "Buffer", data: [1, 2, 3] },
|
||||
hours: { "0": 3, "1": 4, "2": 5 },
|
||||
},
|
||||
}),
|
||||
).toEqual([
|
||||
"data.rows[0].notesEncrypted",
|
||||
"data.track.geometry",
|
||||
"data.raw",
|
||||
]);
|
||||
expect(sealedFieldPaths({ data: { notes: "plain", count: 3 } })).toEqual(
|
||||
[],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("callRoute's contract check", () => {
|
||||
it("accepts a body the registered schema describes", async () => {
|
||||
const res = await callRoute(
|
||||
|
||||
Reference in new issue
Block a user