Public: anyone can read this; the crew can change it.
A spawn body id that begins with `-` is refused before it can reach tar as an option #15004
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14992-a-spawn-body-id-that-begins-with-is-refu → main 2 commits fork 1 thread · 1 unresolved
1 file
changed +21
−1
test/forge-archive.test.ts +21 −1
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * Restore. |
| 6 | 6 | */ |
| 7 | 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 8 | import { existsSync, readdirSync } from "node:fs"; | |
| 8 | import { existsSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs"; | |
| 9 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| @@ -194,6 +194,26 @@ test("a copy that does not read back the same removes nothing", async () => { | ||
| 194 | 194 | expect(archivedForges(parent).some((a) => a.name === "kept-safe")).toBe(false); |
| 195 | 195 | }); |
| 196 | 196 | |
| 197 | test("a body id that begins with - is refused before it reaches tar as an option (#14992)", async () => { | |
| 198 | const { made, childDir, child } = await makeForge("dash-id", false); | |
| 199 | child.close(); | |
| 200 | // A ledger whose body id tar would read as `--remove-files`: the archive would delete the ledger | |
| 201 | // it had just copied. | |
| 202 | const evil = "--remove-files"; | |
| 203 | renameSync(childDir, childDirOf(parent, evil)); | |
| 204 | const ledger = join(dir, "spawn", "dash-id.json"); | |
| 205 | writeFileSync(ledger, JSON.stringify({ ...JSON.parse(readFileSync(ledger, "utf8")), bodyId: evil })); | |
| 206 | const done = await archiveForge(parent, "dash-id", { destination: { source: "dir", store: dirStore(store) } }); | |
| 207 | expect(done.ok).toBe(false); | |
| 208 | expect(done.says).toContain("no data directory to archive"); | |
| 209 | expect(existsSync(ledger)).toBe(true); | |
| 210 | expect(existsSync(childDirOf(parent, evil))).toBe(true); | |
| 211 | expect((await dirStore(store).list("forge-archives/dash-id/")).length).toBe(0); | |
| 212 | // Put back as it was, so the forges after this one see an ordinary host. | |
| 213 | renameSync(childDirOf(parent, evil), childDir); | |
| 214 | writeFileSync(ledger, JSON.stringify({ ...JSON.parse(readFileSync(ledger, "utf8")), bodyId: made.bodyId })); | |
| 215 | }); | |
| 216 | ||
| 197 | 217 | test("with no backup destination nothing is archived", async () => { |
| 198 | 218 | const saved = process.env["FORGE_SNAPSHOT_DIR"]; |
| 199 | 219 | delete process.env["FORGE_SNAPSHOT_DIR"]; |
new above
offline
The restore only runs if every expect above passes. Put the body in try/finally so a red assertion does not poison the forges after it.