test(visual): cover the shot placeholder cards and R2 key traversal guard#1536
test(visual): cover the shot placeholder cards and R2 key traversal guard#1536RenzoMXD wants to merge 2 commits into
Conversation
…uard handleShot has three modes; the suite only exercised the on-demand ?url= SSRF-render path. The placeholder card mode (?placeholder=loading|failed|auth) and the R2 key-serve mode (?key=) — including its path-traversal / out-of-prefix 400 guard — were reachable but untested. Add nine cases: the three SVG placeholder cards (content-type + cache header + body marker), the unknown-placeholder fall-through, a valid-key PNG stream, a missing-key 404, a ..-traversal rejection, an out-of-prefix rejection, and a custom-namespace prefix check. Introduces a minimal REVIEW_AUDIT R2 stub. No source changes; coverage only.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1536 +/- ##
==========================================
+ Coverage 95.37% 95.41% +0.04%
==========================================
Files 199 199
Lines 21546 21546
Branches 7791 7791
==========================================
+ Hits 20550 20559 +9
+ Misses 416 409 -7
+ Partials 580 578 -2 🚀 New features to boost your workflow:
|
|
Caution 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥 🛑 Gittensory review — blocked
🛑 Blocked Review summary CI checks failing
Nits — 4 non-blocking
Review context
Contributor next steps
Signal definitions
Review detailsGenerated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative. Test-only PR adding nine cases that cover the two previously untested modes of `handleShot`: the three SVG placeholder cards (Mode 0) and the R2 key fast-serve path including both arms of the traversal guard (Mode A). The `r2Env` stub correctly approximates the R2 object interface via `new Response(bytes).body`, and `shotRequest` cleanly generalises the existing `request` helper without redundancy. All nine test assertions are tightly scoped and the security-relevant guard paths (`..` traversal and out-of-prefix rejection) each get their own isolated case with explicit `'bad key'` body checks. Nits (4)
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Summary
handleShot(src/review/visual/shot.ts) has three modes, but the unit suite only exercised the on-demand?url=SSRF-render path (Mode B). Two reachable modes had no tests:?placeholder=loading|failed|auth(shot.ts:188-194): the static SVG cards served for an "after" cell that is still building, has failed, or is behind an auth wall. A three-way ternary selects the card; all three arms and the content-type /cache-controlheaders were untested.?key=<r2key>(shot.ts:198-208): the R2 fast-serve path. Its key guard (!key.startsWith(r2Prefix) || key.includes("..")->400 bad key) is the security-adjacent bit -- a crafted?key=must never read an object outside the namespace -- and it, the404miss, and the200PNG stream were all untested.This adds nine cases covering both modes, including both rejection arms of the traversal guard and the custom-namespace option. No production behavior changes.
Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
git diff --checknpm run typechecknpm run test:coverage--test/unit/visual-shot.test.ts18/18 pass; scoped coverage onsrc/review/visual/shot.tsshows lines 188-208 (placeholder + key modes) now covered.Targeted run:
Safety
UI Evidence
Not applicable -- test-only change with no visible UI, frontend, docs, or extension surface.