Public: anyone can read this; the crew can change it.

Full suite red: test/quotas-storage.test.ts #13369

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/13367-full-suite-red-test-quotas-storage-test → main 1 commit fork

  • Merged. mason/13367-full-suite-red-test-quotas-storage-test was merged into main as bc5c621.

Review

Sign in to review this change.
1 file changed +34 −35
test/quotas-storage.test.ts +34 −35
@@ -47,6 +47,8 @@ describe("storage quota", () => {
4747 let ginaTok: string;
4848 let migrated: Awaited<ReturnType<typeof mirrorAndWait>>;
4949 let migratedFromEmpty = false;
50 let mirrored: Awaited<ReturnType<typeof mirrorAndWait>>;
51 let mirroredFromEmpty = false;
5052
5153 beforeAll(async () => {
5254 dataDir = await mkdtemp(join(tmpdir(), "forge-quotas-storage-"));
@@ -105,6 +107,22 @@ describe("storage quota", () => {
105107 await post("/api/v1/migrate", { source: { originId, fullName: "ada/bigorigin" }, name: "moved" }),
106108 );
107109 if (!migrated || migrated.stage !== "done") throw new Error(`migrate import did not finish: ${JSON.stringify(migrated)}`);
110 // dave mirrors it, the same way, from an empty account.
111 const daveConnected = await fetch(`${servers.url}/api/v1/user/origins`, {
112 method: "POST",
113 headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" },
114 body: JSON.stringify({ host: fake.url, token: "tok" }),
115 });
116 const daveOriginId = ((await daveConnected.json()) as { id: string }).id;
117 mirroredFromEmpty = (await accountBytes(app, daveId)) === 0;
118 mirrored = await mirrorAndWait(
119 await fetch(`${servers.url}/api/v1/user/origins/${daveOriginId}/mirror`, {
120 method: "POST",
121 headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" },
122 body: JSON.stringify({ fullName: "ada/bigorigin" }),
123 }),
124 );
125 if (!mirrored || mirrored.stage !== "done") throw new Error(`mirror did not finish: ${JSON.stringify(mirrored)}`);
108126 } finally {
109127 fake.stop();
110128 }
@@ -286,42 +304,23 @@ describe("storage quota", () => {
286304 });
287305
288306 test("a mirror bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => {
289 // The origin: a public repository of 1.1 MB on this same forge.
290 const state = newFakeState("forgejo", "someone", "tok");
291 state.repos.push({
292 id: 2,
293 fullName: "ada/bigorigin",
294 cloneUrl: `${servers.url}/ada/bigorigin.git`,
295 defaultBranch: "main",
307 // The mirror ran in beforeAll, from an empty account (the same 1.1 MB
308 // public origin as the migrate import), so it is not timed here.
309 expect(mirroredFromEmpty).toBe(true);
310 expect(mirrored!.stage).toBe("done");
311 // The fetch marked the figure stale, so this check walks it and refuses.
312 const made = await createRepo(app, getUserById(app.db, daveId)!, {
313 name: "more",
314 visibility: "private",
296315 });
297 const fake = serveFakeForge(state);
298 try {
299 const post = (path: string, body: unknown) =>
300 fetch(`${servers.url}${path}`, {
301 method: "POST",
302 headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" },
303 body: JSON.stringify(body),
304 });
305 const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" });
306 const originId = ((await connected.json()) as { id: string }).id;
307 // Empty at the start, so the mirror is let in; the figure is read once.
308 expect(await accountBytes(app, daveId)).toBe(0);
309 const job = await mirrorAndWait(
310 await post(`/api/v1/user/origins/${originId}/mirror`, { fullName: "ada/bigorigin" }),
311 );
312 expect(job?.stage).toBe("done");
313 // The fetch marked the figure stale, so this check walks it and refuses.
314 const made = await createRepo(app, getUserById(app.db, daveId)!, {
315 name: "more",
316 visibility: "private",
317 });
318 expect(made).toEqual({ ok: false, error: "storage_limit" });
319 const api = await post("/api/v1/repos", { name: "more" });
320 expect(api.status).toBe(403);
321 expect(await api.json()).toMatchObject({ error: "storage_limit" });
322 } finally {
323 fake.stop();
324 }
316 expect(made).toEqual({ ok: false, error: "storage_limit" });
317 const api = await fetch(`${servers.url}/api/v1/repos`, {
318 method: "POST",
319 headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" },
320 body: JSON.stringify({ name: "more" }),
321 });
322 expect(api.status).toBe(403);
323 expect(await api.json()).toMatchObject({ error: "storage_limit" });
325324 });
326325
327326 test("a migrate import bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs