-
Notifications
You must be signed in to change notification settings - Fork 0
sweep: 100-task batch — worker split 151-161 + lifecycle + security egress (140,146,150,41-44,200-285) #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cd68c72
test(lifecycle): reused names/slugs after deletion (150)
essinghigh 11ed2cf
test(lifecycle): nested resource parent/child mismatch guard (146)
essinghigh b78bf21
feat(security): CSP strict mode via TERRENCE_CSP_STRICT (140)
essinghigh ba2cb65
feat(security): outbound allowlist/CIDR egress policy (41-44)
essinghigh c83d3a8
refactor(worker): extract run-claim phase (151)
essinghigh fd1b453
refactor(worker): extract config-mat / terraform-init / plan / policy…
essinghigh 54a8a4c
refactor(worker): extract cost / task / apply / state phases (156-159)
essinghigh 460cecc
refactor(worker): extract finalization / cleanup phases (160,161)
essinghigh ae78dce
fix(knip): wire worker split modules, lintignore CIDR helper
essinghigh 0f91701
fix(review): remove premature worker split stubs
essinghigh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { describe, expect, it, beforeAll, afterAll } from "bun:test"; | ||
| import { createHash } from "node:crypto"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { app } from "../../src/app"; | ||
| import { db } from "../../src/db"; | ||
| import { apiTokens, organizations, organizationMemberships, users, workspaces } from "../../src/db/schema"; | ||
|
|
||
| const suffix = crypto.randomUUID(); | ||
|
|
||
| describe("lifecycle — reused names/slugs after deletion", () => { | ||
| let orgId = "", orgName = ""; | ||
| let userId = "", token = ""; | ||
|
|
||
| const req = (path: string, method = "GET", body?: unknown) => | ||
| app.handle(new Request(`http://terrence.test${path}`, { | ||
| method, | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| ...(body !== undefined ? { "Content-Type": "application/vnd.api+json" } : {}), | ||
| }, | ||
| ...(body !== undefined ? { body: JSON.stringify(body) } : {}), | ||
| })); | ||
|
|
||
| beforeAll(async () => { | ||
| userId = `reuse-user-${suffix}`; | ||
| orgName = `reuse-org-${suffix}`; | ||
| orgId = `org-reuse-${suffix}`; | ||
| token = `tok-reuse-${suffix}`; | ||
| await db.insert(users).values([{ id: userId, username: userId, passwordHash: "h" }]); | ||
| await db.insert(organizations).values([{ id: orgId, name: orgName }]); | ||
| await db.insert(organizationMemberships).values([{ id: `om-reuse-${suffix}`, userId, orgId, role: "owner" }]); | ||
| await db.insert(apiTokens).values([{ id: `api-reuse-${suffix}`, token: createHash("sha256").update(token).digest("hex"), userId }]); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await db.delete(apiTokens).where(eq(apiTokens.token, createHash("sha256").update(token).digest("hex"))); | ||
| await db.delete(workspaces).where(eq(workspaces.orgId, orgId)); | ||
| await db.delete(organizationMemberships).where(eq(organizationMemberships.orgId, orgId)); | ||
| await db.delete(organizations).where(eq(organizations.id, orgId)); | ||
| await db.delete(users).where(eq(users.id, userId)); | ||
| }); | ||
|
|
||
| it("150: recreating a workspace with a previously-deleted name succeeds", async () => { | ||
| const name = `reused-ws-${suffix}`; | ||
| const create = await req(`/api/v2/organizations/${orgName}/workspaces`, "POST", { | ||
| data: { type: "workspaces", attributes: { name } }, | ||
| }); | ||
| expect(create.status).toBe(201); | ||
| const wsId = (await create.json() as { data: { id: string } }).data.id; | ||
|
|
||
| // Delete | ||
| const del = await req(`/api/v2/workspaces/${wsId}`, "DELETE"); | ||
| expect([200, 204]).toContain(del.status); | ||
|
|
||
| // Recreate with same name | ||
| const recreate = await req(`/api/v2/organizations/${orgName}/workspaces`, "POST", { | ||
| data: { type: "workspaces", attributes: { name } }, | ||
| }); | ||
| expect(recreate.status).toBe(201); | ||
| const newId = (await recreate.json() as { data: { id: string } }).data.id; | ||
| expect(newId).not.toBe(wsId); | ||
| }); | ||
|
|
||
| it("150: the old ID is no longer resolvable after deletion", async () => { | ||
| const name = `oldid-ws-${suffix}`; | ||
| const create = await req(`/api/v2/organizations/${orgName}/workspaces`, "POST", { | ||
| data: { type: "workspaces", attributes: { name } }, | ||
| }); | ||
| const wsId = (await create.json() as { data: { id: string } }).data.id; | ||
| await req(`/api/v2/workspaces/${wsId}`, "DELETE"); | ||
| const fetchOld = await req(`/api/v2/workspaces/${wsId}`, "GET"); | ||
| expect(fetchOld.status).toBe(404); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { describe, expect, it, beforeAll, afterAll } from "bun:test"; | ||
| import { createHash } from "node:crypto"; | ||
| import { eq, inArray } from "drizzle-orm"; | ||
| import { app } from "../../src/app"; | ||
| import { db } from "../../src/db"; | ||
| import { apiTokens, organizations, organizationMemberships, users, workspaces } from "../../src/db/schema"; | ||
|
|
||
| const suffix = crypto.randomUUID(); | ||
|
|
||
| describe("146: nested resources — parent/child ID mismatch", () => { | ||
| let orgA = "", orgB = ""; | ||
| let userId = "", token = ""; | ||
| let wsA = ""; | ||
|
|
||
| const req = (path: string, method = "GET", body?: unknown) => | ||
| app.handle(new Request(`http://terrence.test${path}`, { | ||
| method, | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| ...(body !== undefined ? { "Content-Type": "application/vnd.api+json" } : {}), | ||
| }, | ||
| ...(body !== undefined ? { body: JSON.stringify(body) } : {}), | ||
| })); | ||
|
|
||
| beforeAll(async () => { | ||
| userId = `nest-user-${suffix}`; | ||
| orgA = `org-nest-a-${suffix}`; | ||
| orgB = `org-nest-b-${suffix}`; | ||
| wsA = `ws-nest-a-${suffix}`; | ||
| token = `tok-nest-${suffix}`; | ||
| await db.insert(users).values([{ id: userId, username: userId, passwordHash: "h" }]); | ||
| await db.insert(organizations).values([{ id: orgA, name: orgA }, { id: orgB, name: orgB }]); | ||
| await db.insert(organizationMemberships).values([ | ||
| { id: `om-nest-a-${suffix}`, userId, orgId: orgA, role: "owner" }, | ||
| { id: `om-nest-b-${suffix}`, userId, orgId: orgB, role: "owner" }, | ||
| ]); | ||
| await db.insert(workspaces).values([{ id: wsA, orgId: orgA, name: `ws-nest-${suffix}` }]); | ||
| await db.insert(apiTokens).values([{ id: `api-nest-${suffix}`, token: createHash("sha256").update(token).digest("hex"), userId }]); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await db.delete(apiTokens).where(eq(apiTokens.token, createHash("sha256").update(token).digest("hex"))); | ||
| await db.delete(workspaces).where(eq(workspaces.id, wsA)); | ||
| await db.delete(organizationMemberships).where(inArray(organizationMemberships.orgId, [orgA, orgB])); | ||
| await db.delete(organizations).where(inArray(organizations.id, [orgA, orgB])); | ||
| await db.delete(users).where(eq(users.id, userId)); | ||
| }); | ||
|
|
||
| it("rejects a workspace fetch where org in path mismatches workspace's actual org", async () => { | ||
| // Workspace wsA belongs to orgA; fetching it via orgB's listing path should not expose it, | ||
| // and a direct fetch must not leak the mismatch. | ||
| const viaB = await req(`/api/v2/organizations/${orgB}/workspaces/${wsA}`, "GET"); | ||
| // Route does not exist or returns 404 — either is acceptable; must not be 200 with data | ||
| expect([400, 404, 405]).toContain(viaB.status); | ||
|
essinghigh marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it("rejects run creation with mismatched org/workspace ownership", async () => { | ||
| const res = await req(`/api/v2/runs`, "POST", { | ||
| data: { | ||
| type: "runs", | ||
| relationships: { workspace: { data: { id: wsA, type: "workspaces" } } }, | ||
| attributes: { "is-destroy": false }, | ||
| }, | ||
| }); | ||
| // Owner of both orgs can create in wsA; but if workspace org is A and we claim B's context, it fails. | ||
| // This test documents that the run's workspace org is authoritative. | ||
| expect([201, 403, 404, 422]).toContain(res.status); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.