Image store: room directory must share the Persona directory's group; never create the Persona directory

The room directory's gid must equal the Persona directory's, else store-failed (a setgid
directory in the wrong group would still give files the wrong group). A missing Persona
directory is refused rather than created; only the room directory is made. The stat is
injectable so the group case is testable where the sandbox cannot chown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-08 09:29:59 +00:00
commit fd0a43e0e4
2 changed files with 30 additions and 3 deletions

View file

@ -188,6 +188,27 @@ test("a Persona directory without setgid refuses the image: nothing is written,
assert.equal(statSync(join(root, sha("!r:x"))).mode & 0o7777, 0o750, "the room directory it made is left as mkdir made it");
});
test("a room directory whose group is not the Persona directory's is refused: nothing is written", () => {
const root = personaStoreRoot();
const wrong = createImageStore({ root, stat: path => { const s = statSync(path); return path === root ? s : Object.assign(Object.create(Object.getPrototypeOf(s)), s, { gid: s.gid + 1 }); } });
assert.throws(() => wrong.put("!r:x", png(), "image/png"), { code: "ENOGROUP" });
assert.deepEqual(files(root), []);
const right = createImageStore({ root });
assert.ok(right.put("!r:x", png(), "image/png").path, "the same directory is accepted when the group matches");
});
test("a missing Persona directory is refused, not created, and nothing above or below it appears", () => {
const parent = join(personaStoreRoot(), "..");
const root = join(parent, "absent", "eureka");
const store = createImageStore({ root });
assert.throws(() => store.put("!r:x", png(), "image/png"), { code: "ENOPERSONADIR" });
assert.equal(existsSync(join(parent, "absent")), false);
const file = join(parent, "not-a-dir");
writeFileSync(file, "x");
assert.throws(() => createImageStore({ root: file }).put("!r:x", png(), "image/png"), { code: "ENOPERSONADIR" });
});
test("a write that cannot finish leaves no temp file and no partial image under the final name", () => {
const { root, store } = storeIn();
const bytes = png(6, 6);