fix: cap wall flags and scene extra as opaque objects (#35)

One shared validator next to the property caps: 8 KB serialized, 64 keys
per object, depth 8 (top-level object = 1). At a cap is accepted; over
is invalid and applies nothing. Both call sites use it, and a refusal is
logged once with the field and limit, never the value. Token flags and
props keep their existing rules; stored over-cap rows still load as
stored.
This commit is contained in:
2026-11-20 21:46:53 +01:00
parent 41c2fe695b
commit b0e1633aa9
9 changed files with 264 additions and 8 deletions
+44
View File
@@ -46,6 +46,50 @@ suite "caps (6.1, numbers FIXED owner-delegated by #22)":
let big = %repeat("x", MaxPropValueBytes + 1)
check valueBytes(big) > MaxPropValueBytes
suite "opaque object caps (6.1, FIXED owner-delegated by #35)":
proc objectWith(keys: int): JsonNode =
result = newJObject()
for i in 0 ..< keys: result["k" & $i] = %i
proc nestedObjects(depth: int): JsonNode =
result = newJObject()
var cur = result
for _ in 1 ..< depth:
let child = newJObject()
cur["a"] = child
cur = child
test "size: exactly 8 KB is accepted, one byte over is refused":
let atCap = %*{"blob": repeat("x", MaxOpaqueObjectBytes - 11)}
check ($atCap).len == MaxOpaqueObjectBytes
check checkOpaqueObject(atCap) == olOk
let over = %*{"blob": repeat("x", MaxOpaqueObjectBytes - 10)}
check ($over).len == MaxOpaqueObjectBytes + 1
check checkOpaqueObject(over) == olSize
test "keys: 64 per object is accepted, 65 is refused, and it is per object":
check checkOpaqueObject(objectWith(MaxOpaqueObjectKeys)) == olOk
check checkOpaqueObject(objectWith(MaxOpaqueObjectKeys + 1)) == olKeys
# a nested object has its own budget, not a shared one
var nested = objectWith(MaxOpaqueObjectKeys - 1)
nested["inner"] = objectWith(MaxOpaqueObjectKeys)
check checkOpaqueObject(nested) == olOk
nested["inner"] = objectWith(MaxOpaqueObjectKeys + 1)
check checkOpaqueObject(nested) == olKeys
test "depth: 8 containers is accepted, 9 is refused":
check checkOpaqueObject(nestedObjects(MaxOpaqueObjectDepth)) == olOk
check checkOpaqueObject(nestedObjects(MaxOpaqueObjectDepth + 1)) == olDepth
# arrays are containers too
var deep = newJArray()
let root = newJObject()
root["a"] = deep
for _ in 1 ..< MaxOpaqueObjectDepth - 1:
let next = newJArray()
deep.add next
deep = next
check checkOpaqueObject(root) == olOk
suite "parseProps (the `props` field of token.create)":
test "absent and null mean three empty buckets":
for node in [JsonNode(nil), newJNull()]: