@app-vitals/agent-admin 1.107.3 → 1.107.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/e2e/real/agent-management.real.e2e.ts +195 -0
- package/package.json +2 -2
- package/src/admin-local-agent.smoke.test.ts +25 -3
- package/src/admin-ui-agent-members.smoke.test.ts +2 -6
- package/src/admin-ui-pages.ts +23 -1
- package/src/admin-ui-pages.unit.test.ts +17 -0
- package/src/admin-ui.smoke.test.ts +145 -82
- package/src/admin-ui.ts +112 -43
- package/src/agent-management-access.integration.test.ts +269 -0
- package/src/agents-api.smoke.test.ts +63 -8
- package/src/agents-api.ts +2 -0
- package/src/api-auth.ts +31 -1
- package/src/api-auth.unit.test.ts +106 -6
- package/src/caller-scope.ts +21 -0
- package/src/caller-scope.unit.test.ts +39 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/agent-management.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e, self-serve ON: who may MANAGE an agent (settings, members,
|
|
5
|
+
* credentials, tools, crons, tokens, delete). Only platform admins and the
|
|
6
|
+
* owner of the agent's own account may. A member of the agent keeps using it
|
|
7
|
+
* (pages, JSON reads) but every management action is 403 and the controls are
|
|
8
|
+
* not rendered; an owner of another account is refused entirely.
|
|
9
|
+
*
|
|
10
|
+
* Subject agent: Alpha (Account One). member1 is an AgentMember of it, owner1
|
|
11
|
+
* owns Account One, owner2 owns Account Two.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { expect, test } from "@playwright/test";
|
|
15
|
+
import { AGENTS, EMAILS } from "./constants.ts";
|
|
16
|
+
import { RealHarness } from "./fixture.ts";
|
|
17
|
+
|
|
18
|
+
const harness = new RealHarness({
|
|
19
|
+
selfServe: true,
|
|
20
|
+
adminPort: 3524,
|
|
21
|
+
chatPort: 3525,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test.describe.configure({ mode: "serial" });
|
|
25
|
+
|
|
26
|
+
test.beforeAll(async () => {
|
|
27
|
+
test.setTimeout(240_000);
|
|
28
|
+
await harness.start();
|
|
29
|
+
});
|
|
30
|
+
test.afterAll(async () => {
|
|
31
|
+
await harness.stop();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const alpha = AGENTS.alpha;
|
|
35
|
+
const REFUSED = [403, 404];
|
|
36
|
+
|
|
37
|
+
/** JSON management routes: [method, path, body]. */
|
|
38
|
+
const jsonWrites: [string, string, unknown?][] = [
|
|
39
|
+
["PATCH", `/agents/${alpha.id}`, { cleanupAfterDays: 20 }],
|
|
40
|
+
["POST", `/agents/${alpha.id}/repos`, { repos: ["evil-org/pwn"] }],
|
|
41
|
+
["POST", `/agents/${alpha.id}/envs`, { key: "K", value: "V" }],
|
|
42
|
+
["POST", `/agents/${alpha.id}/tokens`, { label: "pwn" }],
|
|
43
|
+
["POST", `/agents/${alpha.id}/tools`, { name: "pwn" }],
|
|
44
|
+
["POST", `/agents/${alpha.id}/chat-credentials`, { label: "pwn" }],
|
|
45
|
+
["DELETE", `/agents/${alpha.id}`],
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/** UI management form posts. */
|
|
49
|
+
const uiWrites = [
|
|
50
|
+
"settings",
|
|
51
|
+
"members",
|
|
52
|
+
"members/delete",
|
|
53
|
+
"envs",
|
|
54
|
+
"envs/delete",
|
|
55
|
+
"crons",
|
|
56
|
+
"tools",
|
|
57
|
+
"tokens",
|
|
58
|
+
"plugins",
|
|
59
|
+
"marketplaces",
|
|
60
|
+
"connect-slack",
|
|
61
|
+
"delete",
|
|
62
|
+
].map((p) => `/admin/agents/${alpha.id}/${p}`);
|
|
63
|
+
|
|
64
|
+
test.describe("member of the agent: uses it, cannot manage it", () => {
|
|
65
|
+
test("reads and pages still work; management controls are not shown", async ({
|
|
66
|
+
page,
|
|
67
|
+
context,
|
|
68
|
+
}) => {
|
|
69
|
+
await harness.signIn(context, EMAILS.member1);
|
|
70
|
+
const base = harness.adminUrl;
|
|
71
|
+
const res = await page.goto(`${base}/admin/agents/${alpha.id}`);
|
|
72
|
+
expect(res?.status()).toBe(200);
|
|
73
|
+
await expect(page.getByText(alpha.name).first()).toBeVisible();
|
|
74
|
+
await expect(page.getByText("Danger Zone")).toHaveCount(0);
|
|
75
|
+
await expect(page.locator(`form[action$="/delete"]`)).toHaveCount(0);
|
|
76
|
+
|
|
77
|
+
const access = await page.goto(`${base}/admin/agents/${alpha.id}/access`);
|
|
78
|
+
expect(access?.status()).toBe(200);
|
|
79
|
+
await expect(
|
|
80
|
+
page.locator(`form[action="/admin/agents/${alpha.id}/members"]`),
|
|
81
|
+
).toHaveCount(0);
|
|
82
|
+
await expect(
|
|
83
|
+
page.locator(`form[action="/admin/agents/${alpha.id}/tokens"]`),
|
|
84
|
+
).toHaveCount(0);
|
|
85
|
+
|
|
86
|
+
for (const path of [`/agents/${alpha.id}`, `/agents/${alpha.id}/envs`]) {
|
|
87
|
+
expect((await context.request.get(`${base}${path}`)).status()).toBe(200);
|
|
88
|
+
}
|
|
89
|
+
const chat = await page.goto(`${base}/admin/chat?agentId=${alpha.id}`);
|
|
90
|
+
expect(chat?.status()).toBe(200);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("every JSON and UI management action is 403", async ({ context }) => {
|
|
94
|
+
await harness.signIn(context, EMAILS.member1);
|
|
95
|
+
const base = harness.adminUrl;
|
|
96
|
+
for (const [method, path, data] of jsonWrites) {
|
|
97
|
+
const res = await context.request.fetch(`${base}${path}`, {
|
|
98
|
+
method,
|
|
99
|
+
...(data ? { data } : {}),
|
|
100
|
+
});
|
|
101
|
+
expect(res.status(), `${method} ${path}`).toBe(403);
|
|
102
|
+
}
|
|
103
|
+
for (const path of uiWrites) {
|
|
104
|
+
const res = await context.request.post(`${base}${path}`, {
|
|
105
|
+
form: { email: "n@example.com", key: "K", value: "V" },
|
|
106
|
+
maxRedirects: 0,
|
|
107
|
+
});
|
|
108
|
+
expect(res.status(), `POST ${path}`).toBe(403);
|
|
109
|
+
}
|
|
110
|
+
const setup = await context.request.get(
|
|
111
|
+
`${base}/admin/agents/${alpha.id}/setup`,
|
|
112
|
+
);
|
|
113
|
+
expect(setup.status()).toBe(403);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test.describe("owner of another account: refused entirely", () => {
|
|
118
|
+
test("pages, reads and every management action are refused", async ({
|
|
119
|
+
page,
|
|
120
|
+
context,
|
|
121
|
+
}) => {
|
|
122
|
+
await harness.signIn(context, EMAILS.owner2);
|
|
123
|
+
const base = harness.adminUrl;
|
|
124
|
+
const res = await page.goto(`${base}/admin/agents/${alpha.id}`);
|
|
125
|
+
expect(REFUSED).toContain(res?.status());
|
|
126
|
+
await expect(page.getByText(alpha.name)).toHaveCount(0);
|
|
127
|
+
const read = await context.request.get(`${base}/agents/${alpha.id}`);
|
|
128
|
+
expect(REFUSED).toContain(read.status());
|
|
129
|
+
for (const [method, path, data] of jsonWrites) {
|
|
130
|
+
const w = await context.request.fetch(`${base}${path}`, {
|
|
131
|
+
method,
|
|
132
|
+
...(data ? { data } : {}),
|
|
133
|
+
});
|
|
134
|
+
expect(REFUSED, `${method} ${path}`).toContain(w.status());
|
|
135
|
+
}
|
|
136
|
+
for (const path of uiWrites) {
|
|
137
|
+
const w = await context.request.post(`${base}${path}`, {
|
|
138
|
+
form: { email: "n@example.com", key: "K", value: "V" },
|
|
139
|
+
maxRedirects: 0,
|
|
140
|
+
});
|
|
141
|
+
expect(REFUSED, `POST ${path}`).toContain(w.status());
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test.describe("nothing changed by refused requests", () => {
|
|
147
|
+
test("agent record is untouched", async ({ context }) => {
|
|
148
|
+
await harness.signIn(context, EMAILS.admin);
|
|
149
|
+
const res = await context.request.get(
|
|
150
|
+
`${harness.adminUrl}/agents/${alpha.id}`,
|
|
151
|
+
);
|
|
152
|
+
expect(res.status()).toBe(200);
|
|
153
|
+
const row = (await res.json()) as {
|
|
154
|
+
name: string;
|
|
155
|
+
repos: string[];
|
|
156
|
+
cleanupAfterDays: number | null;
|
|
157
|
+
};
|
|
158
|
+
expect(row.name).toBe(alpha.name);
|
|
159
|
+
expect(row.repos).toEqual([...alpha.repos]);
|
|
160
|
+
expect(row.cleanupAfterDays).not.toBe(20);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test.describe("owner of the agent's account and platform admin manage it", () => {
|
|
165
|
+
for (const [label, email] of [
|
|
166
|
+
["account owner", EMAILS.owner1],
|
|
167
|
+
["platform admin", EMAILS.admin],
|
|
168
|
+
] as const) {
|
|
169
|
+
test(`${label}: controls shown, settings change succeeds`, async ({
|
|
170
|
+
page,
|
|
171
|
+
context,
|
|
172
|
+
}) => {
|
|
173
|
+
await harness.signIn(context, email);
|
|
174
|
+
const base = harness.adminUrl;
|
|
175
|
+
const res = await page.goto(`${base}/admin/agents/${alpha.id}`);
|
|
176
|
+
expect(res?.status()).toBe(200);
|
|
177
|
+
await expect(page.getByText("Danger Zone").first()).toBeVisible();
|
|
178
|
+
const access = await page.goto(`${base}/admin/agents/${alpha.id}/access`);
|
|
179
|
+
expect(access?.status()).toBe(200);
|
|
180
|
+
await expect(
|
|
181
|
+
page.locator(`form[action="/admin/agents/${alpha.id}/members"]`),
|
|
182
|
+
).toHaveCount(1);
|
|
183
|
+
|
|
184
|
+
const patch = await context.request.patch(`${base}/agents/${alpha.id}`, {
|
|
185
|
+
data: { cleanupAfterDays: label === "account owner" ? 21 : 22 },
|
|
186
|
+
});
|
|
187
|
+
expect(patch.status()).toBe(200);
|
|
188
|
+
const env = await context.request.post(
|
|
189
|
+
`${base}/admin/agents/${alpha.id}/envs`,
|
|
190
|
+
{ form: { key: "E2E_KEY", value: "v" }, maxRedirects: 0 },
|
|
191
|
+
);
|
|
192
|
+
expect(env.status()).toBe(302);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.107.
|
|
3
|
+
"version": "1.107.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@anthropic-ai/sdk": "0.137.0",
|
|
47
|
-
"@app-vitals/agent-lib": "1.107.
|
|
47
|
+
"@app-vitals/agent-lib": "1.107.4",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
|
@@ -1698,18 +1698,29 @@ describe("admin UI — account users create / delete agents (SSP-4.2)", () => {
|
|
|
1698
1698
|
);
|
|
1699
1699
|
});
|
|
1700
1700
|
|
|
1701
|
-
function deleteDeps(
|
|
1701
|
+
function deleteDeps(
|
|
1702
|
+
ownerAccount: string,
|
|
1703
|
+
role: "owner" | "member" = "owner",
|
|
1704
|
+
) {
|
|
1702
1705
|
const deleted: string[] = [];
|
|
1703
1706
|
const base = makeMockDeps();
|
|
1704
1707
|
const deps = makeMockDeps({
|
|
1705
|
-
//
|
|
1706
|
-
// caller
|
|
1708
|
+
// Delete needs the owner of the agent's account (or a platform admin);
|
|
1709
|
+
// the caller here is always in acct-a, the agent lives in ownerAccount.
|
|
1707
1710
|
selfServe: { enabled: true, defaultMaxAgents: 2, contactEmail: "x@y.z" },
|
|
1708
1711
|
callerScopeResolver: (async () => ({
|
|
1709
1712
|
kind: "scoped" as const,
|
|
1710
1713
|
accountId: "acct-a",
|
|
1711
1714
|
agentIds: ownerAccount === "acct-a" ? [ACCOUNT_AGENT_ID] : [],
|
|
1715
|
+
role,
|
|
1712
1716
|
})) satisfies NonNullable<AdminUIDeps["callerScopeResolver"]>,
|
|
1717
|
+
agentService: {
|
|
1718
|
+
...base.agentService,
|
|
1719
|
+
getDetail: async (id: string) => {
|
|
1720
|
+
const detail = await base.agentService.getDetail(id);
|
|
1721
|
+
return detail && { ...detail, accountId: ownerAccount };
|
|
1722
|
+
},
|
|
1723
|
+
},
|
|
1713
1724
|
accountService: {
|
|
1714
1725
|
...accountServiceStub(),
|
|
1715
1726
|
listAgentIds: async (id: string) =>
|
|
@@ -1726,6 +1737,7 @@ describe("admin UI — account users create / delete agents (SSP-4.2)", () => {
|
|
|
1726
1737
|
slackId: null,
|
|
1727
1738
|
selfHosted: true,
|
|
1728
1739
|
repos: [],
|
|
1740
|
+
accountId: ownerAccount,
|
|
1729
1741
|
createdAt: new Date("2024-01-01"),
|
|
1730
1742
|
updatedAt: new Date("2024-01-01"),
|
|
1731
1743
|
}) as never,
|
|
@@ -1752,6 +1764,16 @@ describe("admin UI — account users create / delete agents (SSP-4.2)", () => {
|
|
|
1752
1764
|
expect(deleted).toEqual([ACCOUNT_AGENT_ID]);
|
|
1753
1765
|
});
|
|
1754
1766
|
|
|
1767
|
+
it("POST /admin/agents/:id/delete — a member of the agent's account is 403 and untouched", async () => {
|
|
1768
|
+
const { deps, deleted } = deleteDeps("acct-a", "member");
|
|
1769
|
+
const res = await createAdminUIApp(deps).request(
|
|
1770
|
+
`/admin/agents/${ACCOUNT_AGENT_ID}/delete`,
|
|
1771
|
+
{ method: "POST", headers: { Cookie: `admin_session=${accountCookie}` } },
|
|
1772
|
+
);
|
|
1773
|
+
expect(res.status).toBe(403);
|
|
1774
|
+
expect(deleted).toEqual([]);
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1755
1777
|
it("POST /admin/agents/:id/delete — another account's agent is 403 and untouched", async () => {
|
|
1756
1778
|
const { deps, deleted } = deleteDeps("acct-b");
|
|
1757
1779
|
const res = await createAdminUIApp(deps).request(
|
|
@@ -166,7 +166,7 @@ describe("POST /admin/agents/:id/members ensures an account member", () => {
|
|
|
166
166
|
expect(added).toEqual([]);
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
it("denies a member-role caller
|
|
169
|
+
it("denies a member-role caller with a 403: nothing written", async () => {
|
|
170
170
|
const { app, records, added } = setup({
|
|
171
171
|
agentAccountId: "acct-1",
|
|
172
172
|
accountIds: ["acct-1"],
|
|
@@ -178,11 +178,7 @@ describe("POST /admin/agents/:id/members ensures an account member", () => {
|
|
|
178
178
|
},
|
|
179
179
|
});
|
|
180
180
|
const res = await post(app, false, "n@example.com");
|
|
181
|
-
|
|
182
|
-
expect(location.startsWith(`${OK_PATH}?error=`)).toBe(true);
|
|
183
|
-
expect(decodeURIComponent(location)).toContain(
|
|
184
|
-
"platform admin or an owner",
|
|
185
|
-
);
|
|
181
|
+
expect(res.status).toBe(403);
|
|
186
182
|
expect(records).toEqual([]);
|
|
187
183
|
expect(added).toEqual([]);
|
|
188
184
|
});
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -1196,6 +1196,17 @@ export function settingsRedirectSection(formData: FormData): AgentSection {
|
|
|
1196
1196
|
return formData.has("restrictSlackToMembers") ? "access" : "configuration";
|
|
1197
1197
|
}
|
|
1198
1198
|
|
|
1199
|
+
/** Remove every state-changing control (POST forms, repo-removal buttons). */
|
|
1200
|
+
function stripManagementControls(html: string): string {
|
|
1201
|
+
return html
|
|
1202
|
+
.replace(
|
|
1203
|
+
/<details>\s*<summary[^>]*>Sync Manifest<\/summary>[\s\S]*?<\/details>/gi,
|
|
1204
|
+
"",
|
|
1205
|
+
)
|
|
1206
|
+
.replace(/<form\b[^>]*\bmethod="POST"[\s\S]*?<\/form>/gi, "")
|
|
1207
|
+
.replace(/<button\b[^>]*repo-removal-preview-btn[\s\S]*?<\/button>/gi, "");
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1199
1210
|
export function renderAgentDetailPage(
|
|
1200
1211
|
agent: AgentDetail,
|
|
1201
1212
|
envResult:
|
|
@@ -2420,7 +2431,7 @@ export function renderAgentDetailPage(
|
|
|
2420
2431
|
}
|
|
2421
2432
|
</div>`;
|
|
2422
2433
|
|
|
2423
|
-
const
|
|
2434
|
+
const rawSectionBodies: Record<AgentSection, string> = {
|
|
2424
2435
|
general: `${headerInfoHtml}
|
|
2425
2436
|
${(opts?.extensionCardsHtml ?? []).join("\n ")}
|
|
2426
2437
|
|
|
@@ -2433,6 +2444,17 @@ export function renderAgentDetailPage(
|
|
|
2433
2444
|
extensions: `${toolsSection}${pluginsSection}${marketplacesSection}`,
|
|
2434
2445
|
};
|
|
2435
2446
|
|
|
2447
|
+
// Members use the agent but do not manage it: no POST form (add/remove/
|
|
2448
|
+
// save/revoke/delete) and no repo-removal button is rendered for them.
|
|
2449
|
+
const sectionBodies: Record<AgentSection, string> = canManage
|
|
2450
|
+
? rawSectionBodies
|
|
2451
|
+
: (Object.fromEntries(
|
|
2452
|
+
Object.entries(rawSectionBodies).map(([k, v]) => [
|
|
2453
|
+
k,
|
|
2454
|
+
stripManagementControls(v),
|
|
2455
|
+
]),
|
|
2456
|
+
) as Record<AgentSection, string>);
|
|
2457
|
+
|
|
2436
2458
|
return renderAdminPage({
|
|
2437
2459
|
title: `${agent.name} — Shipwright Admin`,
|
|
2438
2460
|
body: renderSettingsLayout({
|
|
@@ -4312,6 +4312,23 @@ describe("renderAgentDetailPage — canManage gating (SSP-4.3)", () => {
|
|
|
4312
4312
|
test("admin defaults to canManage", () => {
|
|
4313
4313
|
expect(render(true)).toContain("Danger Zone");
|
|
4314
4314
|
});
|
|
4315
|
+
|
|
4316
|
+
test("without canManage no section renders a POST form; with it they do", () => {
|
|
4317
|
+
const sections = [
|
|
4318
|
+
"general",
|
|
4319
|
+
"automation",
|
|
4320
|
+
"configuration",
|
|
4321
|
+
"access",
|
|
4322
|
+
"extensions",
|
|
4323
|
+
] as const;
|
|
4324
|
+
for (const section of sections) {
|
|
4325
|
+
const member = render(false, { section });
|
|
4326
|
+
expect(member).not.toMatch(/<form[^>]*action="\/admin\/agents\/[^"]*"/i);
|
|
4327
|
+
expect(member).not.toContain("repo-removal-preview-btn");
|
|
4328
|
+
}
|
|
4329
|
+
const owner = render(false, { canManage: true, section: "access" });
|
|
4330
|
+
expect(owner).toMatch(/<form[^>]*action="\/admin\/agents\/[^"]*"/i);
|
|
4331
|
+
});
|
|
4315
4332
|
});
|
|
4316
4333
|
|
|
4317
4334
|
describe("renderNewLocalAgentPage — self-serve account user (SSP-4.2)", () => {
|
|
@@ -3913,7 +3913,7 @@ describe("admin UI — marketplaces (PMK-1.5)", () => {
|
|
|
3913
3913
|
expect(res.headers.get("location")).toContain("error=source%20must%20be");
|
|
3914
3914
|
});
|
|
3915
3915
|
|
|
3916
|
-
it("an agent member
|
|
3916
|
+
it("an agent member and a non-member both get 403 on add and remove", async () => {
|
|
3917
3917
|
let removed: string | null = null;
|
|
3918
3918
|
const service = {
|
|
3919
3919
|
list: async () => [],
|
|
@@ -3945,8 +3945,8 @@ describe("admin UI — marketplaces (PMK-1.5)", () => {
|
|
|
3945
3945
|
`/admin/agents/${AGENT_ID}/marketplaces/delete`,
|
|
3946
3946
|
form({ marketplaceId: "mk1" }, memberCookie),
|
|
3947
3947
|
);
|
|
3948
|
-
expect([add.status, del.status]).toEqual([
|
|
3949
|
-
expect(removed as string | null).
|
|
3948
|
+
expect([add.status, del.status]).toEqual([403, 403]);
|
|
3949
|
+
expect(removed as string | null).toBeNull();
|
|
3950
3950
|
for (const path of ["marketplaces", "marketplaces/delete"]) {
|
|
3951
3951
|
const res = await app.request(
|
|
3952
3952
|
`/admin/agents/${AGENT_ID}/${path}`,
|
|
@@ -4062,7 +4062,7 @@ describe("admin UI — plugin add/remove (PUI-1.2)", () => {
|
|
|
4062
4062
|
expect(removed).toEqual(["pl1"]);
|
|
4063
4063
|
});
|
|
4064
4064
|
|
|
4065
|
-
it("
|
|
4065
|
+
it("an agent member and a non-member both get 403 on add and remove", async () => {
|
|
4066
4066
|
const calls: unknown[][] = [];
|
|
4067
4067
|
const removed: string[] = [];
|
|
4068
4068
|
const memberCookie = await makeSessionCookie(
|
|
@@ -4108,7 +4108,9 @@ describe("admin UI — plugin add/remove (PUI-1.2)", () => {
|
|
|
4108
4108
|
`/admin/agents/${AGENT_ID}/plugins/delete`,
|
|
4109
4109
|
form({ pluginId: "pl1" }, memberCookie),
|
|
4110
4110
|
);
|
|
4111
|
-
expect([add.status, del.status]).toEqual([
|
|
4111
|
+
expect([add.status, del.status]).toEqual([403, 403]);
|
|
4112
|
+
expect(calls).toEqual([]);
|
|
4113
|
+
expect(removed).toEqual([]);
|
|
4112
4114
|
for (const path of ["plugins", "plugins/delete"]) {
|
|
4113
4115
|
const res = await app.request(
|
|
4114
4116
|
`/admin/agents/${AGENT_ID}/${path}`,
|
|
@@ -4116,8 +4118,8 @@ describe("admin UI — plugin add/remove (PUI-1.2)", () => {
|
|
|
4116
4118
|
);
|
|
4117
4119
|
expect(res.status).toBe(403);
|
|
4118
4120
|
}
|
|
4119
|
-
expect(calls
|
|
4120
|
-
expect(removed).toEqual([
|
|
4121
|
+
expect(calls).toEqual([]);
|
|
4122
|
+
expect(removed).toEqual([]);
|
|
4121
4123
|
});
|
|
4122
4124
|
});
|
|
4123
4125
|
|
|
@@ -7392,7 +7394,7 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7392
7394
|
expect(provisionRes.status).toBe(403);
|
|
7393
7395
|
});
|
|
7394
7396
|
|
|
7395
|
-
it("Okta-authenticated
|
|
7397
|
+
it("Okta-authenticated member cannot configure the agent's settings (403)", async () => {
|
|
7396
7398
|
const memberCookie = await makeSessionCookie(
|
|
7397
7399
|
SESSION_SECRET,
|
|
7398
7400
|
"okta-sub-member",
|
|
@@ -7447,8 +7449,8 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7447
7449
|
body: form,
|
|
7448
7450
|
headers: { Cookie: `admin_session=${memberCookie}` },
|
|
7449
7451
|
});
|
|
7450
|
-
expect(res.status).toBe(
|
|
7451
|
-
expect(upsertCalledWith.length).
|
|
7452
|
+
expect(res.status).toBe(403);
|
|
7453
|
+
expect(upsertCalledWith.length).toBe(0);
|
|
7452
7454
|
});
|
|
7453
7455
|
|
|
7454
7456
|
it("/admin/chat?agentId=<unrelated agent> returns 403 for an Okta-authenticated non-member", async () => {
|
|
@@ -7787,104 +7789,165 @@ describe("admin UI — POST /admin/push/notify", () => {
|
|
|
7787
7789
|
});
|
|
7788
7790
|
});
|
|
7789
7791
|
|
|
7790
|
-
// ───
|
|
7792
|
+
// ─── Agent management: platform admins and the agent's account owner only ───
|
|
7791
7793
|
|
|
7792
|
-
describe("admin UI —
|
|
7793
|
-
const
|
|
7794
|
-
const selfServe =
|
|
7795
|
-
enabled,
|
|
7794
|
+
describe("admin UI — agent management is limited to admins and account owners", () => {
|
|
7795
|
+
const CALLER = "caller@example.com";
|
|
7796
|
+
const selfServe = {
|
|
7797
|
+
enabled: true,
|
|
7796
7798
|
defaultMaxAgents: 1,
|
|
7797
7799
|
contactEmail: "ops@example.com",
|
|
7798
|
-
}
|
|
7799
|
-
const
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
const form = (fields: Record<string, string
|
|
7800
|
+
};
|
|
7801
|
+
const scopeOf =
|
|
7802
|
+
(accountId: string | null, role: "owner" | "member") => async () => ({
|
|
7803
|
+
kind: "scoped" as const,
|
|
7804
|
+
accountId,
|
|
7805
|
+
agentIds: [AGENT_ID],
|
|
7806
|
+
role,
|
|
7807
|
+
});
|
|
7808
|
+
const form = (fields: Record<string, string>, cookie: string) => ({
|
|
7807
7809
|
method: "POST",
|
|
7808
7810
|
body: new URLSearchParams(fields).toString(),
|
|
7809
|
-
headers: {
|
|
7811
|
+
headers: {
|
|
7812
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
7813
|
+
Cookie: `admin_session=${cookie}`,
|
|
7814
|
+
},
|
|
7810
7815
|
});
|
|
7816
|
+
const makeApp = (
|
|
7817
|
+
scope: ReturnType<typeof scopeOf>,
|
|
7818
|
+
agentAccountId: string | null = "acct-a",
|
|
7819
|
+
) => {
|
|
7820
|
+
const base = makeMockDeps();
|
|
7821
|
+
return createAdminUIApp(
|
|
7822
|
+
makeMockDeps({
|
|
7823
|
+
selfServe,
|
|
7824
|
+
callerScopeResolver: scope,
|
|
7825
|
+
agentService: {
|
|
7826
|
+
...base.agentService,
|
|
7827
|
+
getDetail: async (id: string) => {
|
|
7828
|
+
const detail = await base.agentService.getDetail(id);
|
|
7829
|
+
return detail && { ...detail, accountId: agentAccountId };
|
|
7830
|
+
},
|
|
7831
|
+
},
|
|
7832
|
+
}),
|
|
7833
|
+
);
|
|
7834
|
+
};
|
|
7835
|
+
const callerCookie = (isAdmin = false) =>
|
|
7836
|
+
makeSessionCookie(SESSION_SECRET, "google-sub-caller", CALLER, isAdmin);
|
|
7811
7837
|
|
|
7812
|
-
|
|
7838
|
+
// Every management POST (UI actions) and GET (setup wizard).
|
|
7839
|
+
const postRoutes: Array<[string, Record<string, string>]> = [
|
|
7813
7840
|
["settings", { restrictSlackToMembers: "true" }],
|
|
7814
7841
|
["members", { email: "new@example.com" }],
|
|
7815
7842
|
["members/delete", { memberId: "m1" }],
|
|
7816
7843
|
["delete", {}],
|
|
7844
|
+
["envs", { key: "A", value: "b" }],
|
|
7845
|
+
["envs/delete", { key: "A" }],
|
|
7846
|
+
["repos/add", { repo: "org/repo" }],
|
|
7847
|
+
["repos/delete", { repo: "org/repo" }],
|
|
7848
|
+
["review-author-allowlist/add", { author: "someone" }],
|
|
7849
|
+
["review-author-allowlist/delete", { author: "someone" }],
|
|
7850
|
+
["patch-author-allowlist/add", { author: "someone" }],
|
|
7851
|
+
["patch-author-allowlist/delete", { author: "someone" }],
|
|
7852
|
+
["crons", { name: "n", schedule: "* * * * *", prompt: "p" }],
|
|
7853
|
+
["crons/c1/toggle", {}],
|
|
7854
|
+
["crons/c1/update", { schedule: "* * * * *" }],
|
|
7855
|
+
["crons/c1/delete", {}],
|
|
7856
|
+
["tools", { name: "t" }],
|
|
7857
|
+
["tools/t1/toggle", {}],
|
|
7858
|
+
["tools/t1/delete", {}],
|
|
7859
|
+
["marketplaces", { name: "x", source: "a/b" }],
|
|
7860
|
+
["marketplaces/delete", { marketplaceId: "mk1" }],
|
|
7861
|
+
["plugins", { spec: "x" }],
|
|
7862
|
+
["plugins/delete", { spec: "x" }],
|
|
7863
|
+
["tokens", { label: "l" }],
|
|
7864
|
+
["tokens/t1/revoke", {}],
|
|
7865
|
+
["sync-manifest", {}],
|
|
7866
|
+
["connect-slack", {}],
|
|
7867
|
+
["connect-github", {}],
|
|
7817
7868
|
];
|
|
7818
7869
|
|
|
7819
|
-
for (const [path, fields] of
|
|
7820
|
-
it(`
|
|
7821
|
-
const
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
selfServe: selfServe(true),
|
|
7825
|
-
callerScopeResolver: scopedTo([AGENT_ID]),
|
|
7826
|
-
}),
|
|
7870
|
+
for (const [path, fields] of postRoutes) {
|
|
7871
|
+
it(`member gets 403 on POST /admin/agents/:id/${path}`, async () => {
|
|
7872
|
+
const res = await makeApp(scopeOf("acct-a", "member")).request(
|
|
7873
|
+
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7874
|
+
form(fields, await callerCookie()),
|
|
7827
7875
|
);
|
|
7828
|
-
|
|
7829
|
-
...form(fields),
|
|
7830
|
-
headers: {
|
|
7831
|
-
...form(fields).headers,
|
|
7832
|
-
Cookie: `admin_session=${cookie}`,
|
|
7833
|
-
},
|
|
7834
|
-
});
|
|
7835
|
-
expect(res.status).not.toBe(403);
|
|
7876
|
+
expect(res.status).toBe(403);
|
|
7836
7877
|
});
|
|
7837
7878
|
|
|
7838
|
-
it(`
|
|
7839
|
-
const
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
selfServe: selfServe(true),
|
|
7843
|
-
callerScopeResolver: scopedTo(["some-other-agent"]),
|
|
7844
|
-
}),
|
|
7879
|
+
it(`other-account owner gets 403 on POST /admin/agents/:id/${path}`, async () => {
|
|
7880
|
+
const res = await makeApp(scopeOf("acct-b", "owner")).request(
|
|
7881
|
+
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7882
|
+
form(fields, await callerCookie()),
|
|
7845
7883
|
);
|
|
7846
|
-
const res = await app.request(`/admin/agents/${AGENT_ID}/${path}`, {
|
|
7847
|
-
...form(fields),
|
|
7848
|
-
headers: {
|
|
7849
|
-
...form(fields).headers,
|
|
7850
|
-
Cookie: `admin_session=${cookie}`,
|
|
7851
|
-
},
|
|
7852
|
-
});
|
|
7853
7884
|
expect(res.status).toBe(403);
|
|
7854
7885
|
});
|
|
7855
7886
|
|
|
7856
|
-
it(`flag off:
|
|
7857
|
-
const
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
selfServe: selfServe(false),
|
|
7861
|
-
callerScopeResolver: scopedTo([AGENT_ID]),
|
|
7862
|
-
}),
|
|
7887
|
+
it(`flag off (no account on scope): owner gets 403 on POST /admin/agents/:id/${path}`, async () => {
|
|
7888
|
+
const res = await makeApp(scopeOf(null, "owner")).request(
|
|
7889
|
+
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7890
|
+
form(fields, await callerCookie()),
|
|
7863
7891
|
);
|
|
7864
|
-
const res = await app.request(`/admin/agents/${AGENT_ID}/${path}`, {
|
|
7865
|
-
...form(fields),
|
|
7866
|
-
headers: {
|
|
7867
|
-
...form(fields).headers,
|
|
7868
|
-
Cookie: `admin_session=${cookie}`,
|
|
7869
|
-
},
|
|
7870
|
-
});
|
|
7871
7892
|
expect(res.status).toBe(403);
|
|
7872
7893
|
});
|
|
7873
7894
|
}
|
|
7874
7895
|
|
|
7875
|
-
for (const [
|
|
7876
|
-
[
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7896
|
+
for (const path of ["settings", "members", "members/delete", "delete"]) {
|
|
7897
|
+
const fields = Object.fromEntries(postRoutes)[path] ?? {};
|
|
7898
|
+
it(`owner of the agent's account is not blocked on POST /admin/agents/:id/${path}`, async () => {
|
|
7899
|
+
const res = await makeApp(scopeOf("acct-a", "owner")).request(
|
|
7900
|
+
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7901
|
+
form(fields, await callerCookie()),
|
|
7902
|
+
);
|
|
7903
|
+
expect(res.status).not.toBe(403);
|
|
7904
|
+
});
|
|
7905
|
+
|
|
7906
|
+
it(`platform admin is not blocked on POST /admin/agents/:id/${path}`, async () => {
|
|
7907
|
+
const res = await makeApp(scopeOf("acct-b", "member")).request(
|
|
7908
|
+
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7909
|
+
form(fields, await callerCookie(true)),
|
|
7886
7910
|
);
|
|
7887
|
-
|
|
7911
|
+
expect(res.status).not.toBe(403);
|
|
7912
|
+
});
|
|
7913
|
+
}
|
|
7914
|
+
|
|
7915
|
+
it("member gets 403 on the setup page but keeps read access to the agent pages", async () => {
|
|
7916
|
+
const headers = { Cookie: `admin_session=${await callerCookie()}` };
|
|
7917
|
+
const app = makeApp(scopeOf("acct-a", "member"));
|
|
7918
|
+
expect(
|
|
7919
|
+
(await app.request(`/admin/agents/${AGENT_ID}/setup`, { headers }))
|
|
7920
|
+
.status,
|
|
7921
|
+
).toBe(403);
|
|
7922
|
+
expect(
|
|
7923
|
+
(await app.request(`/admin/agents/${AGENT_ID}`, { headers })).status,
|
|
7924
|
+
).toBe(200);
|
|
7925
|
+
expect(
|
|
7926
|
+
(await app.request(`/admin/agents/${AGENT_ID}/access`, { headers }))
|
|
7927
|
+
.status,
|
|
7928
|
+
).toBe(200);
|
|
7929
|
+
});
|
|
7930
|
+
|
|
7931
|
+
it("member keeps chat access to the agent", async () => {
|
|
7932
|
+
const headers = { Cookie: `admin_session=${await callerCookie()}` };
|
|
7933
|
+
const res = await makeApp(scopeOf("acct-a", "member")).request(
|
|
7934
|
+
`/admin/chat?agentId=${AGENT_ID}`,
|
|
7935
|
+
{ headers },
|
|
7936
|
+
);
|
|
7937
|
+
expect(res.status).not.toBe(403);
|
|
7938
|
+
});
|
|
7939
|
+
|
|
7940
|
+
for (const [label, scope, admin, shown] of [
|
|
7941
|
+
["member", scopeOf("acct-a", "member"), false, false],
|
|
7942
|
+
["other-account owner", scopeOf("acct-b", "owner"), false, false],
|
|
7943
|
+
["owner of the agent's account", scopeOf("acct-a", "owner"), false, true],
|
|
7944
|
+
["platform admin", scopeOf("acct-a", "member"), true, true],
|
|
7945
|
+
] as const) {
|
|
7946
|
+
it(`agent detail for ${label} ${shown ? "renders" : "hides"} the management controls`, async () => {
|
|
7947
|
+
const headers = {
|
|
7948
|
+
Cookie: `admin_session=${await callerCookie(admin)}`,
|
|
7949
|
+
};
|
|
7950
|
+
const app = makeApp(scope);
|
|
7888
7951
|
const res = await app.request(`/admin/agents/${AGENT_ID}`, { headers });
|
|
7889
7952
|
const accessRes = await app.request(`/admin/agents/${AGENT_ID}/access`, {
|
|
7890
7953
|
headers,
|