@app-vitals/agent-admin 1.107.2 → 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/e2e/real/seed.ts +0 -1
- package/package.json +2 -2
- package/prisma/client/internal/class.ts +4 -4
- package/prisma/client/internal/prismaNamespace.ts +1 -5
- package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -5
- package/prisma/client/models/AgentMember.ts +26 -61
- package/prisma/client/models/ChatThreadWatch.ts +19 -47
- package/prisma/client/models/PushSubscription.ts +15 -43
- package/prisma/client/models/UserNotificationPrefs.ts +38 -66
- package/prisma/migrations/20261130000000_drop_email_key_columns/migration.sql +49 -0
- package/prisma/schema/schema.prisma +11 -15
- package/src/account-member-removal.integration.test.ts +31 -44
- package/src/account-members.ts +4 -6
- package/src/account-onboarding.ts +2 -5
- package/src/account-onboarding.unit.test.ts +71 -0
- package/src/accounts.ts +1 -3
- package/src/admin-dev-login.smoke.test.ts +1 -1
- package/src/admin-local-agent.smoke.test.ts +28 -6
- package/src/admin-ui-agent-members.smoke.test.ts +31 -7
- package/src/admin-ui-pages.ts +23 -1
- package/src/admin-ui-pages.unit.test.ts +17 -0
- package/src/admin-ui.fixtures.ts +1 -1
- package/src/admin-ui.smoke.test.ts +163 -100
- package/src/admin-ui.ts +132 -55
- package/src/agent-cron-run-stats.smoke.test.ts +1 -1
- package/src/agent-deletion.integration.test.ts +1 -1
- package/src/agent-management-access.integration.test.ts +269 -0
- package/src/agent-members.integration.test.ts +14 -10
- package/src/agent-members.ts +28 -18
- package/src/agents-api.integration.test.ts +2 -2
- package/src/agents-api.smoke.test.ts +68 -13
- package/src/agents-api.ts +2 -0
- package/src/agents.integration.test.ts +1 -2
- package/src/api-auth.ts +31 -1
- package/src/api-auth.unit.test.ts +106 -6
- package/src/api.smoke.test.ts +1 -1
- package/src/caller-scope.ts +21 -0
- package/src/caller-scope.unit.test.ts +39 -0
- package/src/chat.smoke.test.ts +68 -14
- package/src/drop-email-key-columns-migration.integration.test.ts +141 -0
- package/src/ensure-account-member.integration.test.ts +17 -232
- package/src/ensure-account-member.ts +0 -5
- package/src/github-enterprise-client.unit.test.ts +62 -2
- package/src/member-rows.ts +24 -0
- package/src/member-rows.unit.test.ts +48 -0
- package/src/principals-api.integration.test.ts +3 -2
- package/src/push-service.integration.test.ts +7 -12
- package/src/push-service.ts +28 -39
- package/src/push-service.unit.test.ts +8 -8
- package/src/slack-provisioning.integration.test.ts +1 -1
- package/src/user-notification-prefs.integration.test.ts +5 -16
- package/src/user-notification-prefs.ts +12 -18
- package/scripts/backfill-member-id.ts +0 -50
- package/src/member-id-backfill.integration.test.ts +0 -167
- package/src/member-id-backfill.ts +0 -253
- package/src/member-id-backfill.unit.test.ts +0 -12
- package/src/member-id-stamp.ts +0 -68
- package/src/member-id-stamp.unit.test.ts +0 -81
|
@@ -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)", () => {
|
package/src/admin-ui.fixtures.ts
CHANGED
|
@@ -1302,7 +1302,7 @@ describe("admin UI — authenticated pages", () => {
|
|
|
1302
1302
|
id: "m1",
|
|
1303
1303
|
agentId: AGENT_ID,
|
|
1304
1304
|
email,
|
|
1305
|
-
memberId:
|
|
1305
|
+
memberId: "member-1",
|
|
1306
1306
|
createdAt: new Date(),
|
|
1307
1307
|
},
|
|
1308
1308
|
]
|
|
@@ -1313,7 +1313,7 @@ describe("admin UI — authenticated pages", () => {
|
|
|
1313
1313
|
id: "m1",
|
|
1314
1314
|
agentId: AGENT_ID,
|
|
1315
1315
|
email: MEMBER_EMAIL,
|
|
1316
|
-
memberId:
|
|
1316
|
+
memberId: "member-1",
|
|
1317
1317
|
createdAt: new Date(),
|
|
1318
1318
|
}),
|
|
1319
1319
|
remove: async () => {},
|
|
@@ -2888,7 +2888,7 @@ describe("admin UI — member access control", () => {
|
|
|
2888
2888
|
id: "m1",
|
|
2889
2889
|
agentId: AGENT_ID,
|
|
2890
2890
|
email,
|
|
2891
|
-
memberId:
|
|
2891
|
+
memberId: "member-1",
|
|
2892
2892
|
createdAt: new Date(),
|
|
2893
2893
|
},
|
|
2894
2894
|
]
|
|
@@ -2899,7 +2899,7 @@ describe("admin UI — member access control", () => {
|
|
|
2899
2899
|
id: "m1",
|
|
2900
2900
|
agentId: AGENT_ID,
|
|
2901
2901
|
email: MEMBER_EMAIL,
|
|
2902
|
-
memberId:
|
|
2902
|
+
memberId: "member-1",
|
|
2903
2903
|
createdAt: new Date(),
|
|
2904
2904
|
}),
|
|
2905
2905
|
remove: async () => {},
|
|
@@ -3042,7 +3042,7 @@ describe("admin UI — member access control", () => {
|
|
|
3042
3042
|
id: "m1",
|
|
3043
3043
|
agentId: AGENT_ID,
|
|
3044
3044
|
email: MEMBER_EMAIL,
|
|
3045
|
-
memberId:
|
|
3045
|
+
memberId: "member-1",
|
|
3046
3046
|
createdAt: new Date(),
|
|
3047
3047
|
},
|
|
3048
3048
|
]
|
|
@@ -3052,7 +3052,7 @@ describe("admin UI — member access control", () => {
|
|
|
3052
3052
|
id: "m1",
|
|
3053
3053
|
agentId: AGENT_ID,
|
|
3054
3054
|
email: MEMBER_EMAIL,
|
|
3055
|
-
memberId:
|
|
3055
|
+
memberId: "member-1",
|
|
3056
3056
|
createdAt: new Date(),
|
|
3057
3057
|
}),
|
|
3058
3058
|
remove: async () => {},
|
|
@@ -3199,7 +3199,7 @@ describe("admin UI — member access control", () => {
|
|
|
3199
3199
|
id: "m1",
|
|
3200
3200
|
agentId: AGENT_ID,
|
|
3201
3201
|
email: MEMBER_EMAIL,
|
|
3202
|
-
memberId:
|
|
3202
|
+
memberId: "member-1",
|
|
3203
3203
|
createdAt: new Date(),
|
|
3204
3204
|
},
|
|
3205
3205
|
]
|
|
@@ -3209,7 +3209,7 @@ describe("admin UI — member access control", () => {
|
|
|
3209
3209
|
id: "m1",
|
|
3210
3210
|
agentId: AGENT_ID,
|
|
3211
3211
|
email: MEMBER_EMAIL,
|
|
3212
|
-
memberId:
|
|
3212
|
+
memberId: "member-1",
|
|
3213
3213
|
createdAt: new Date(),
|
|
3214
3214
|
}),
|
|
3215
3215
|
remove: async () => {},
|
|
@@ -3687,7 +3687,7 @@ describe("admin UI — member management routes", () => {
|
|
|
3687
3687
|
id: "m-new",
|
|
3688
3688
|
agentId,
|
|
3689
3689
|
email,
|
|
3690
|
-
memberId:
|
|
3690
|
+
memberId: "member-1",
|
|
3691
3691
|
createdAt: new Date(),
|
|
3692
3692
|
};
|
|
3693
3693
|
},
|
|
@@ -3782,7 +3782,7 @@ describe("admin UI — member management routes", () => {
|
|
|
3782
3782
|
id: "m1",
|
|
3783
3783
|
agentId: AGENT_ID,
|
|
3784
3784
|
email: "member@example.com",
|
|
3785
|
-
memberId:
|
|
3785
|
+
memberId: "member-1",
|
|
3786
3786
|
createdAt: new Date(),
|
|
3787
3787
|
}),
|
|
3788
3788
|
remove: async (_agentId: string, memberId: string) => {
|
|
@@ -3848,7 +3848,7 @@ describe("admin UI — marketplaces (PMK-1.5)", () => {
|
|
|
3848
3848
|
id: "m1",
|
|
3849
3849
|
agentId: AGENT_ID,
|
|
3850
3850
|
email,
|
|
3851
|
-
memberId:
|
|
3851
|
+
memberId: "member-1",
|
|
3852
3852
|
createdAt: new Date(),
|
|
3853
3853
|
},
|
|
3854
3854
|
]
|
|
@@ -3858,7 +3858,7 @@ describe("admin UI — marketplaces (PMK-1.5)", () => {
|
|
|
3858
3858
|
id: "m1",
|
|
3859
3859
|
agentId: AGENT_ID,
|
|
3860
3860
|
email: MEMBER,
|
|
3861
|
-
memberId:
|
|
3861
|
+
memberId: "member-1",
|
|
3862
3862
|
createdAt: new Date(),
|
|
3863
3863
|
}),
|
|
3864
3864
|
remove: async () => {},
|
|
@@ -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(
|
|
@@ -4087,7 +4087,7 @@ describe("admin UI — plugin add/remove (PUI-1.2)", () => {
|
|
|
4087
4087
|
id: "m1",
|
|
4088
4088
|
agentId: AGENT_ID,
|
|
4089
4089
|
email,
|
|
4090
|
-
memberId:
|
|
4090
|
+
memberId: "member-1",
|
|
4091
4091
|
createdAt: new Date(),
|
|
4092
4092
|
},
|
|
4093
4093
|
]
|
|
@@ -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
|
|
|
@@ -7025,7 +7027,7 @@ describe("admin UI — Slack access settings route (restrictSlackToMembers)", ()
|
|
|
7025
7027
|
id: "m1",
|
|
7026
7028
|
agentId: AGENT_ID,
|
|
7027
7029
|
email: "member@example.com",
|
|
7028
|
-
memberId:
|
|
7030
|
+
memberId: "member-1",
|
|
7029
7031
|
createdAt: new Date("2024-01-01"),
|
|
7030
7032
|
},
|
|
7031
7033
|
],
|
|
@@ -7288,7 +7290,7 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7288
7290
|
id: "m1",
|
|
7289
7291
|
agentId: AGENT_ID,
|
|
7290
7292
|
email: OKTA_MEMBER_EMAIL,
|
|
7291
|
-
memberId:
|
|
7293
|
+
memberId: "member-1",
|
|
7292
7294
|
createdAt: new Date(),
|
|
7293
7295
|
},
|
|
7294
7296
|
]
|
|
@@ -7299,7 +7301,7 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7299
7301
|
id: "m1",
|
|
7300
7302
|
agentId: AGENT_ID,
|
|
7301
7303
|
email: OKTA_MEMBER_EMAIL,
|
|
7302
|
-
memberId:
|
|
7304
|
+
memberId: "member-1",
|
|
7303
7305
|
createdAt: new Date(),
|
|
7304
7306
|
}),
|
|
7305
7307
|
remove: async () => {},
|
|
@@ -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",
|
|
@@ -7409,7 +7411,7 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7409
7411
|
id: "m1",
|
|
7410
7412
|
agentId: AGENT_ID,
|
|
7411
7413
|
email,
|
|
7412
|
-
memberId:
|
|
7414
|
+
memberId: "member-1",
|
|
7413
7415
|
createdAt: new Date(),
|
|
7414
7416
|
},
|
|
7415
7417
|
]
|
|
@@ -7420,7 +7422,7 @@ describe("admin UI — Okta-authenticated access control", () => {
|
|
|
7420
7422
|
id: "m1",
|
|
7421
7423
|
agentId: AGENT_ID,
|
|
7422
7424
|
email: OKTA_MEMBER_EMAIL,
|
|
7423
|
-
memberId:
|
|
7425
|
+
memberId: "member-1",
|
|
7424
7426
|
createdAt: new Date(),
|
|
7425
7427
|
}),
|
|
7426
7428
|
remove: async () => {},
|
|
@@ -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,
|