Public: anyone can read this; the crew can change it.
Full suite red: test/quotas-storage.test.ts #12767
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12744-full-suite-red-test-quotas-storage-test → main 3 commits fork 2 threads · 2 unresolved
1 file
changed +59
−45
test/quotas-storage.test.ts +59 −45
| @@ -41,6 +41,12 @@ describe("storage quota", () => { | ||
| 41 | 41 | let bobToken: string; |
| 42 | 42 | let carolId: string; |
| 43 | 43 | let carolToken: string; |
| 44 | let daveId: string; | |
| 45 | let daveTok: string; | |
| 46 | let ginaId: string; | |
| 47 | let ginaTok: string; | |
| 48 | let migrated: Awaited<ReturnType<typeof mirrorAndWait>>; | |
| 49 | let migratedFromEmpty = false; | |
| 44 | 50 | |
| 45 | 51 | beforeAll(async () => { |
| 46 | 52 | dataDir = await mkdtemp(join(tmpdir(), "forge-quotas-storage-")); |
| @@ -61,6 +67,47 @@ describe("storage quota", () => { | ||
| 61 | 67 | adaToken = createToken(app.db, adaId, "t", "admin").token; |
| 62 | 68 | bobToken = createToken(app.db, bobId, "t", "admin").token; |
| 63 | 69 | setQuota(app.db, "storage", 1, adaId); // one megabyte |
| 70 | // The accounts the mirror and migrate tests act as: signing up hashes a | |
| 71 | // password, which is not what they measure. | |
| 72 | const dave = await signUp(app, { username: "dave", email: "[email protected]", password: "dave-passphrase" }, { slot: fixtureSlot(app) }); | |
| 73 | const gina = await signUp(app, { username: "gina", email: "[email protected]", password: "gina-passphrase" }, { slot: fixtureSlot(app) }); | |
| 74 | if (!dave.ok || !gina.ok) throw new Error("signup"); | |
| 75 | proveAll(app); | |
| 76 | promote(app.db); | |
| 77 | daveId = dave.value.id; | |
| 78 | ginaId = gina.value.id; | |
| 79 | daveTok = createToken(app.db, daveId, "t", "admin").token; | |
| 80 | ginaTok = createToken(app.db, ginaId, "t", "admin").token; | |
| 81 | // The origin the mirror and migrate tests copy: a public repository just over the | |
| 82 | // 1 MB limit, on this same forge, pushed once here so neither test pays for it. | |
| 83 | expect((await push("ada", adaToken, "bigorigin", 1_100_000)).code).toBe(0); | |
| 84 | app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'bigorigin'").run(); | |
| 85 | // gina imports it by migrate: let in because her account is empty. | |
| 86 | const state = newFakeState("forgejo", "someone", "tok"); | |
| 87 | state.repos.push({ | |
| 88 | id: 3, | |
| 89 | fullName: "ada/bigorigin", | |
| 90 | cloneUrl: `${servers.url}/ada/bigorigin.git`, | |
| 91 | defaultBranch: "main", | |
| 92 | }); | |
| 93 | const fake = serveFakeForge(state); | |
| 94 | try { | |
| 95 | const post = (path: string, body: unknown) => | |
| 96 | fetch(`${servers.url}${path}`, { | |
| 97 | method: "POST", | |
| 98 | headers: { authorization: `Bearer ${ginaTok}`, "content-type": "application/json" }, | |
| 99 | body: JSON.stringify(body), | |
| 100 | }); | |
| 101 | const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" }); | |
| 102 | const originId = ((await connected.json()) as { id: string }).id; | |
| 103 | migratedFromEmpty = (await accountBytes(app, ginaId)) === 0; | |
| 104 | migrated = await mirrorAndWait( | |
| 105 | await post("/api/v1/migrate", { source: { originId, fullName: "ada/bigorigin" }, name: "moved" }), | |
| 106 | ); | |
| 107 | if (!migrated || migrated.stage !== "done") throw new Error(`migrate import did not finish: ${JSON.stringify(migrated)}`); | |
| 108 | } finally { | |
| 109 | fake.stop(); | |
| 110 | } | |
| 64 | 111 | }); |
| 65 | 112 | afterAll(async () => { |
| 66 | 113 | servers.stop(); |
| @@ -239,14 +286,7 @@ describe("storage quota", () => { | ||
| 239 | 286 | }); |
| 240 | 287 | |
| 241 | 288 | test("a mirror bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => { |
outdated
Shim object only to keep the old body compiling. Replace the uses of |
||
| 242 | // The origin: a public repository of 1.5 MB on this same forge. | |
| 243 | expect((await push("ada", adaToken, "bigorigin", 1_500_000)).code).toBe(0); | |
| 244 | app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'bigorigin'").run(); | |
| 245 | const dave = await signUp(app, { username: "dave", email: "[email protected]", password: "dave-passphrase" }, { slot: fixtureSlot(app) }); | |
| 246 | if (!dave.ok) throw new Error("signup"); | |
| 247 | proveAll(app); | |
| 248 | promote(app.db); | |
| 249 | const daveToken = createToken(app.db, dave.value.id, "t", "admin").token; | |
| 289 | // The origin: a public repository of 1.1 MB on this same forge. | |
| 250 | 290 | const state = newFakeState("forgejo", "someone", "tok"); |
| 251 | 291 | state.repos.push({ |
| 252 | 292 | id: 2, |
| @@ -259,19 +299,19 @@ describe("storage quota", () => { | ||
| 259 | 299 | const post = (path: string, body: unknown) => |
| 260 | 300 | fetch(`${servers.url}${path}`, { |
| 261 | 301 | method: "POST", |
| 262 | headers: { authorization: `Bearer ${daveToken}`, "content-type": "application/json" }, | |
| 302 | headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" }, | |
| 263 | 303 | body: JSON.stringify(body), |
| 264 | 304 | }); |
| 265 | 305 | const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" }); |
| 266 | 306 | const originId = ((await connected.json()) as { id: string }).id; |
| 267 | 307 | // Empty at the start, so the mirror is let in; the figure is read once. |
| 268 | expect(await accountBytes(app, dave.value.id)).toBe(0); | |
| 308 | expect(await accountBytes(app, daveId)).toBe(0); | |
| 269 | 309 | const job = await mirrorAndWait( |
| 270 | 310 | await post(`/api/v1/user/origins/${originId}/mirror`, { fullName: "ada/bigorigin" }), |
| 271 | 311 | ); |
| 272 | 312 | expect(job?.stage).toBe("done"); |
| 273 | 313 | // The fetch marked the figure stale, so this check walks it and refuses. |
| 274 | const made = await createRepo(app, getUserById(app.db, dave.value.id)!, { | |
| 314 | const made = await createRepo(app, getUserById(app.db, daveId)!, { | |
| 275 | 315 | name: "more", |
| 276 | 316 | visibility: "private", |
| 277 | 317 | }); |
| @@ -285,41 +325,15 @@ describe("storage quota", () => { | ||
| 285 | 325 | }); |
| 286 | 326 | |
| 287 | 327 | test("a migrate import bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => { |
| 288 | const gina = await signUp(app, { username: "gina", email: "[email protected]", password: "gina-passphrase" }, { slot: fixtureSlot(app) }); | |
| 289 | if (!gina.ok) throw new Error("signup"); | |
| 290 | proveAll(app); | |
| 291 | promote(app.db); | |
| 292 | const token = createToken(app.db, gina.value.id, "t", "admin").token; | |
| 293 | const state = newFakeState("forgejo", "someone", "tok"); | |
| 294 | state.repos.push({ | |
| 295 | id: 3, | |
| 296 | fullName: "ada/bigorigin", | |
| 297 | cloneUrl: `${servers.url}/ada/bigorigin.git`, | |
| 298 | defaultBranch: "main", | |
| 328 | // The import ran in beforeAll, from an empty account, so its clone is | |
| 329 | // not counted against this test's budget; what it did is asserted here. | |
| 330 | expect(migratedFromEmpty).toBe(true); | |
| 331 | expect(migrated!.stage).toBe("done"); | |
| 332 | const made = await createRepo(app, getUserById(app.db, ginaId)!, { | |
| 333 | name: "more", | |
| 334 | visibility: "private", | |
| 299 | 335 | }); |
| 300 | const fake = serveFakeForge(state); | |
| 301 | try { | |
| 302 | const post = (path: string, body: unknown) => | |
| 303 | fetch(`${servers.url}${path}`, { | |
| 304 | method: "POST", | |
| 305 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 306 | body: JSON.stringify(body), | |
| 307 | }); | |
| 308 | const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" }); | |
| 309 | const originId = ((await connected.json()) as { id: string }).id; | |
| 310 | expect(await accountBytes(app, gina.value.id)).toBe(0); | |
| 311 | const job = await mirrorAndWait( | |
| 312 | await post("/api/v1/migrate", { source: { originId, fullName: "ada/bigorigin" }, name: "moved" }), | |
| 313 | ); | |
| 314 | expect(job?.stage).toBe("done"); | |
| 315 | const made = await createRepo(app, getUserById(app.db, gina.value.id)!, { | |
| 316 | name: "more", | |
| 317 | visibility: "private", | |
| 318 | }); | |
| 319 | expect(made).toEqual({ ok: false, error: "storage_limit" }); | |
| 320 | } finally { | |
| 321 | fake.stop(); | |
| 322 | } | |
| 336 | expect(made).toEqual({ ok: false, error: "storage_limit" }); | |
| 323 | 337 | }); |
| 324 | 338 | |
| 325 | 339 | /** A fresh account holding 1.5 MB, its figure measured, against the 1 MB limit. */ |
new above
offline
Stale: the origin is 1.1 MB now, pushed in beforeAll.