@app-vitals/agent-admin 1.107.5 → 1.108.1
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/admin-access.real.e2e.ts +77 -68
- package/e2e/real/agent-management.real.e2e.ts +165 -143
- package/e2e/real/owner-access.real.e2e.ts +228 -212
- package/openapi.platform.json +127 -6
- package/package.json +2 -2
- package/src/account-created-notifier.ts +1 -1
- package/src/account-onboarding.integration.test.ts +69 -0
- package/src/account-onboarding.ts +29 -3
- package/src/account-repo-lookup-api.integration.test.ts +163 -0
- package/src/account-repo-lookup-api.ts +106 -0
- package/src/account-repo-lookup.ts +89 -0
- package/src/account-trial-expiry-sweeper.ts +1 -1
- package/src/accounts-api.integration.test.ts +5 -2
- package/src/accounts-api.smoke.test.ts +21 -5
- package/src/accounts-api.ts +12 -15
- package/src/admin-boot-config.ts +2 -0
- package/src/admin-boot-config.unit.test.ts +27 -0
- package/src/admin-boot.ts +18 -10
- package/src/admin-spec.ts +6 -0
- package/src/admin-ui-account.smoke.test.ts +7 -3
- package/src/admin-ui-account.ts +10 -15
- package/src/admin-ui-accounts.smoke.test.ts +4 -4
- package/src/admin-ui-accounts.ts +7 -11
- package/src/admin-ui-settings-nav-context.smoke.test.ts +24 -0
- package/src/admin-ui-settings.smoke.test.ts +17 -1
- package/src/admin-ui.smoke.test.ts +168 -2
- package/src/admin-ui.ts +39 -26
- package/src/agent-management-access.integration.test.ts +18 -6
- package/src/agent-manifest.ts +2 -1
- package/src/agent-provisioner.integration.test.ts +10 -10
- package/src/agent-provisioner.ts +10 -1
- package/src/agent-provisioner.unit.test.ts +110 -36
- package/src/agent-templates-api.integration.test.ts +23 -5
- package/src/agent-templates-api.ts +11 -8
- package/src/caller-scope.integration.test.ts +8 -6
- package/src/caller-scope.ts +32 -26
- package/src/caller-scope.unit.test.ts +15 -11
- package/src/openapi-schemas.ts +22 -0
- package/src/platform-routes.ts +14 -2
- package/src/platform-routes.unit.test.ts +2 -0
|
@@ -41,3 +41,30 @@ describe("buildProvisioner pod label configuration", () => {
|
|
|
41
41
|
).toThrow("reserved key");
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe("buildProvisioner tenant pod restrictions", () => {
|
|
46
|
+
const config = (env: Record<string, string>) =>
|
|
47
|
+
(
|
|
48
|
+
buildProvisioner(
|
|
49
|
+
{ SHIPWRIGHT_K8S_PROVISIONING: "enabled", ...env },
|
|
50
|
+
{} as AgentTokenService,
|
|
51
|
+
) as unknown as { config: { tenantPodRestrictions?: boolean } }
|
|
52
|
+
).config;
|
|
53
|
+
|
|
54
|
+
it("are on only when SHIPWRIGHT_SELF_SERVE_ENABLED is exactly enabled", () => {
|
|
55
|
+
expect(
|
|
56
|
+
config({ SHIPWRIGHT_SELF_SERVE_ENABLED: "enabled" })
|
|
57
|
+
.tenantPodRestrictions,
|
|
58
|
+
).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it.each(["", "true", "disabled"])(
|
|
62
|
+
"are off for SHIPWRIGHT_SELF_SERVE_ENABLED=%p and when unset",
|
|
63
|
+
(value) => {
|
|
64
|
+
expect(
|
|
65
|
+
config({ SHIPWRIGHT_SELF_SERVE_ENABLED: value }).tenantPodRestrictions,
|
|
66
|
+
).toBe(false);
|
|
67
|
+
expect(config({}).tenantPodRestrictions).toBe(false);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
});
|
package/src/admin-boot.ts
CHANGED
|
@@ -127,6 +127,7 @@ import { HttpChatClient } from "./http-chat-client.ts";
|
|
|
127
127
|
import { HttpOktaAuthClient } from "./okta-auth-client.ts";
|
|
128
128
|
import { mountPlatformApis } from "./platform-routes.ts";
|
|
129
129
|
import { parsePodServiceAccountConfig } from "./pod-service-account-config.ts";
|
|
130
|
+
import { AccountRepoLookupService } from "./account-repo-lookup.ts";
|
|
130
131
|
import { PrincipalLookupService } from "./principal-lookup.ts";
|
|
131
132
|
import { createAdminPrismaClient } from "./prisma-client.ts";
|
|
132
133
|
import { isPushEnabled } from "./push-sender.ts";
|
|
@@ -240,15 +241,14 @@ export async function startAdmin(
|
|
|
240
241
|
const agentPluginService = new AgentPluginService(prisma);
|
|
241
242
|
const agentMarketplaceService = new AgentMarketplaceService(prisma);
|
|
242
243
|
const agentMemberService = new AgentMemberService(prisma);
|
|
243
|
-
// Account-aware caller scope (SSP-2.1).
|
|
244
|
-
//
|
|
244
|
+
// Account-aware caller scope (SSP-2.1). Owners get their account's agents
|
|
245
|
+
// whether or not self-serve signup is enabled.
|
|
245
246
|
const accountService = new AccountService(prisma);
|
|
246
247
|
const callerScopeResolver = createCallerScopeResolver(
|
|
247
248
|
callerScopeDepsFromServices({
|
|
248
249
|
accountService,
|
|
249
250
|
agentMemberService,
|
|
250
251
|
}),
|
|
251
|
-
process.env.SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled",
|
|
252
252
|
);
|
|
253
253
|
const agentChatTokenService = new AgentChatTokenService(prisma);
|
|
254
254
|
const agentCronRunStatsService = new AgentCronRunStatsService(prisma);
|
|
@@ -296,8 +296,9 @@ export async function startAdmin(
|
|
|
296
296
|
.then((v) => v.trim())
|
|
297
297
|
.catch(() => "0.0.0");
|
|
298
298
|
const adminApiKeys = parseAdminApiKeys(process.env.SHIPWRIGHT_ADMIN_API_KEYS);
|
|
299
|
-
// Self-serve
|
|
300
|
-
//
|
|
299
|
+
// Self-serve config (SSP-1.3), read once at startup. `enabled` controls only
|
|
300
|
+
// open signup (an unknown verified user creating an account); the tenant pod
|
|
301
|
+
// restrictions read the same env var in buildProvisioner.
|
|
301
302
|
const selfServe = parseSelfServeConfig(process.env);
|
|
302
303
|
// Account status transitions → cron lockdown/restore (SSP-8.2). Shared by
|
|
303
304
|
// the /accounts PATCH handler, the admin UI and the account sweepers.
|
|
@@ -620,6 +621,12 @@ export async function startAdmin(
|
|
|
620
621
|
adminApiKeys,
|
|
621
622
|
agentTokenService,
|
|
622
623
|
},
|
|
624
|
+
accountRepoLookup: {
|
|
625
|
+
lookup: new AccountRepoLookupService(prisma),
|
|
626
|
+
sessionSecret,
|
|
627
|
+
adminApiKeys,
|
|
628
|
+
agentTokenService,
|
|
629
|
+
},
|
|
623
630
|
templates: {
|
|
624
631
|
templateService,
|
|
625
632
|
callerScopeResolver,
|
|
@@ -803,11 +810,12 @@ export async function startAdmin(
|
|
|
803
810
|
}
|
|
804
811
|
|
|
805
812
|
// Account trial sweepers (SSP-8.2) — the account-level counterparts of the
|
|
806
|
-
// two per-agent sweepers above (which keep running unchanged).
|
|
807
|
-
//
|
|
808
|
-
// per-agent pair: hourly warning, minutely
|
|
809
|
-
// HERE, never inside an app factory. No
|
|
810
|
-
|
|
813
|
+
// two per-agent sweepers above (which keep running unchanged). Accounts
|
|
814
|
+
// exist whether or not self-serve signup is enabled, so they always run.
|
|
815
|
+
// Same cadences as the per-agent pair: hourly warning, minutely
|
|
816
|
+
// expiry/lockdown. Registered HERE, never inside an app factory. No
|
|
817
|
+
// deleteAgentFully call anywhere.
|
|
818
|
+
{
|
|
811
819
|
const accountTrialWarningSweeper = new AccountTrialWarningSweeper({
|
|
812
820
|
accounts: accountService,
|
|
813
821
|
agentEnvService,
|
package/src/admin-spec.ts
CHANGED
|
@@ -130,6 +130,12 @@ export function buildPlatformAdminSpec(): AdminOpenApiDocument {
|
|
|
130
130
|
adminApiKeys,
|
|
131
131
|
agentTokenService: { validate: async () => null },
|
|
132
132
|
},
|
|
133
|
+
accountRepoLookup: {
|
|
134
|
+
lookup: {} as never,
|
|
135
|
+
sessionSecret: SESSION_SECRET,
|
|
136
|
+
adminApiKeys,
|
|
137
|
+
agentTokenService: { validate: async () => null },
|
|
138
|
+
},
|
|
133
139
|
templates: {
|
|
134
140
|
templateService: {} as never,
|
|
135
141
|
callerScopeResolver: async () => ({ kind: "all" }),
|
|
@@ -153,12 +153,16 @@ function post(
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
describe("/admin/account", () => {
|
|
156
|
-
it("
|
|
156
|
+
it("serves the page and invites with the self-serve flag off", async () => {
|
|
157
157
|
const { app } = setup({ enabled: false });
|
|
158
|
-
|
|
158
|
+
const res = await app.request("/admin/account", {
|
|
159
|
+
headers: { "x-test-user-email": "owner@x.com" },
|
|
160
|
+
});
|
|
161
|
+
expect(res.status).toBe(200);
|
|
162
|
+
expect(await res.text()).toContain("Acme");
|
|
159
163
|
expect(
|
|
160
164
|
(await post(app, "/admin/account/invite", { email: "a@b.co" })).status,
|
|
161
|
-
).toBe(404);
|
|
165
|
+
).not.toBe(404);
|
|
162
166
|
});
|
|
163
167
|
|
|
164
168
|
it("returns 404 for a signed-in user without an account", async () => {
|
package/src/admin-ui-account.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account.ts
|
|
3
|
-
* GET/POST /admin/account —
|
|
4
|
-
*
|
|
3
|
+
* GET/POST /admin/account — account management (SSP-3.2): name, quota,
|
|
4
|
+
* members, pending invites. Owners manage; members are read-only.
|
|
5
5
|
*
|
|
6
|
-
* Registered into admin-ui.ts's app via registerAccountRoutes().
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Registered into admin-ui.ts's app via registerAccountRoutes(). Every route
|
|
7
|
+
* 404s for signed-in users with no account. Independent of the self-serve
|
|
8
|
+
* setting.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { Context, Hono, MiddlewareHandler } from "hono";
|
|
@@ -22,8 +22,11 @@ import type { AdminUIEnv } from "./admin-ui.ts";
|
|
|
22
22
|
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
23
23
|
|
|
24
24
|
export interface AccountRouteDeps {
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Ignored: these routes no longer depend on the self-serve
|
|
27
|
+
* setting. Kept optional so existing callers keep compiling.
|
|
28
|
+
*/
|
|
29
|
+
enabled?: boolean;
|
|
27
30
|
requireAuth: MiddlewareHandler<AdminUIEnv>;
|
|
28
31
|
accounts: Pick<AccountService, "getByMemberEmail" | "update" | "countAgents">;
|
|
29
32
|
members: Pick<
|
|
@@ -45,14 +48,6 @@ export function registerAccountRoutes(
|
|
|
45
48
|
): void {
|
|
46
49
|
const notFound = () => new Response("Not Found", { status: 404 });
|
|
47
50
|
|
|
48
|
-
// Flag-off 404s before auth so the route is indistinguishable from absent.
|
|
49
|
-
app.use(`${ACCOUNT_PATH}`, async (_c, next) =>
|
|
50
|
-
deps.enabled ? next() : notFound(),
|
|
51
|
-
);
|
|
52
|
-
app.use(`${ACCOUNT_PATH}/*`, async (_c, next) =>
|
|
53
|
-
deps.enabled ? next() : notFound(),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
51
|
async function render(
|
|
57
52
|
c: Context<AdminUIEnv>,
|
|
58
53
|
account: Account,
|
|
@@ -279,15 +279,15 @@ describe("/admin/accounts", () => {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
-
it("
|
|
282
|
+
it("serves every route to admins with the self-serve flag off", async () => {
|
|
283
283
|
const { app } = setup({ enabled: false });
|
|
284
284
|
expect(
|
|
285
285
|
(await app.request("/admin/accounts", { headers: ADMIN })).status,
|
|
286
|
-
).toBe(
|
|
286
|
+
).toBe(200);
|
|
287
287
|
expect(
|
|
288
288
|
(await app.request("/admin/accounts/a1", { headers: ADMIN })).status,
|
|
289
|
-
).toBe(
|
|
290
|
-
expect((await post(app, "/admin/accounts/a1/suspend", {})).status).toBe(
|
|
289
|
+
).toBe(200);
|
|
290
|
+
expect((await post(app, "/admin/accounts/a1/suspend", {})).status).not.toBe(
|
|
291
291
|
404,
|
|
292
292
|
);
|
|
293
293
|
});
|
package/src/admin-ui-accounts.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-accounts.ts
|
|
3
3
|
* GET/POST /admin/accounts[/:id] — platform-admin account management
|
|
4
|
-
* (SSP-5.2). Admin only (403 otherwise)
|
|
5
|
-
*
|
|
4
|
+
* (SSP-5.2). Admin only (403 otherwise), independent of the self-serve
|
|
5
|
+
* setting. Status and trial edits go through AccountLifecycle (SSP-8.2), so
|
|
6
6
|
* suspend locks down the account's crons and reactivate restores them.
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -30,8 +30,11 @@ import type { AgentService } from "./agents.ts";
|
|
|
30
30
|
import { UnprocessableEntityError } from "./errors.ts";
|
|
31
31
|
|
|
32
32
|
export interface AdminAccountsRouteDeps {
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Ignored: these routes no longer depend on the self-serve
|
|
35
|
+
* setting. Kept optional so existing callers keep compiling.
|
|
36
|
+
*/
|
|
37
|
+
enabled?: boolean;
|
|
35
38
|
requireAuth: MiddlewareHandler<AdminUIEnv>;
|
|
36
39
|
accounts: Pick<
|
|
37
40
|
AccountService,
|
|
@@ -62,13 +65,6 @@ export function registerAdminAccountsRoutes(
|
|
|
62
65
|
const notFound = () => new Response("Not Found", { status: 404 });
|
|
63
66
|
const forbidden = () => new Response("Forbidden", { status: 403 });
|
|
64
67
|
|
|
65
|
-
app.use(ADMIN_ACCOUNTS_PATH, async (_c, next) =>
|
|
66
|
-
deps.enabled ? next() : notFound(),
|
|
67
|
-
);
|
|
68
|
-
app.use(`${ADMIN_ACCOUNTS_PATH}/*`, async (_c, next) =>
|
|
69
|
-
deps.enabled ? next() : notFound(),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
68
|
const requireAdmin: MiddlewareHandler<AdminUIEnv> = async (c, next) =>
|
|
73
69
|
c.var.isAdmin === true ? next() : forbidden();
|
|
74
70
|
|
|
@@ -146,6 +146,30 @@ describe("contract: nav item present iff its route is registered", () => {
|
|
|
146
146
|
path: SETTINGS_ACCOUNTS_PATH,
|
|
147
147
|
present: true,
|
|
148
148
|
},
|
|
149
|
+
{
|
|
150
|
+
name: "Accounts on, self-serve off",
|
|
151
|
+
deps: {
|
|
152
|
+
selfServe: { ...selfServe, enabled: false },
|
|
153
|
+
accountServices: accountServices("admin@example.com"),
|
|
154
|
+
},
|
|
155
|
+
path: SETTINGS_ACCOUNTS_PATH,
|
|
156
|
+
present: true,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "Accounts on, no self-serve config",
|
|
160
|
+
deps: { accountServices: accountServices("admin@example.com") },
|
|
161
|
+
path: SETTINGS_ACCOUNTS_PATH,
|
|
162
|
+
present: true,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "Account page, self-serve off",
|
|
166
|
+
deps: {
|
|
167
|
+
selfServe: { ...selfServe, enabled: false },
|
|
168
|
+
accountServices: accountServices("admin@example.com"),
|
|
169
|
+
},
|
|
170
|
+
path: SETTINGS_ACCOUNT_PATH,
|
|
171
|
+
present: true,
|
|
172
|
+
},
|
|
149
173
|
{
|
|
150
174
|
name: "Accounts off",
|
|
151
175
|
deps: {},
|
|
@@ -81,7 +81,8 @@ describe("GET /admin/settings", () => {
|
|
|
81
81
|
headers: { cookie: await userCookie() },
|
|
82
82
|
});
|
|
83
83
|
expect(res.status).toBe(302);
|
|
84
|
-
|
|
84
|
+
// Account comes first for an owner, with or without self-serve signup.
|
|
85
|
+
expect(res.headers.get("location")).toBe("/admin/account");
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
it("lands an account member on Notifications (ACM-7.2)", async () => {
|
|
@@ -239,6 +240,21 @@ describe("GET /admin/settings with accounts (SGL-2.3)", () => {
|
|
|
239
240
|
expect(res.headers.get("location")).toBe("/admin/account");
|
|
240
241
|
});
|
|
241
242
|
|
|
243
|
+
it("lands an account owner on Account with self-serve off", async () => {
|
|
244
|
+
const app = createAdminUIApp(
|
|
245
|
+
makeMockDeps({
|
|
246
|
+
templateService,
|
|
247
|
+
selfServe: { ...selfServe, enabled: false },
|
|
248
|
+
accountServices: memberAccounts("m@acme.com"),
|
|
249
|
+
} as never),
|
|
250
|
+
);
|
|
251
|
+
const res = await app.request("/admin/settings", {
|
|
252
|
+
headers: { cookie: await userCookie("m@acme.com") },
|
|
253
|
+
});
|
|
254
|
+
expect(res.status).toBe(302);
|
|
255
|
+
expect(res.headers.get("location")).toBe("/admin/account");
|
|
256
|
+
});
|
|
257
|
+
|
|
242
258
|
it("lands an account member on Notifications, not Account (ACM-7.2)", async () => {
|
|
243
259
|
const app = createAdminUIApp(
|
|
244
260
|
makeMockDeps({
|
|
@@ -613,7 +613,77 @@ describe("admin UI — Google callback self-serve signup (SSP-3.1)", () => {
|
|
|
613
613
|
expect(notified).toEqual([]);
|
|
614
614
|
});
|
|
615
615
|
|
|
616
|
-
it("flag off: unknown email still gets 403 and
|
|
616
|
+
it("flag off: unknown email still gets 403 and no account is created", async () => {
|
|
617
|
+
const calls: string[] = [];
|
|
618
|
+
const app = createAdminUIApp(
|
|
619
|
+
makeMockDeps({
|
|
620
|
+
googleClient: identity(),
|
|
621
|
+
selfServe: { ...enabled, enabled: false },
|
|
622
|
+
accountOnboarding: {
|
|
623
|
+
provisionForEmail: async () => {
|
|
624
|
+
calls.push("provision");
|
|
625
|
+
return { kind: "created", accountId: "acc-1" };
|
|
626
|
+
},
|
|
627
|
+
joinForEmail: async (email) => {
|
|
628
|
+
calls.push(`join:${email}`);
|
|
629
|
+
return null;
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
}),
|
|
633
|
+
);
|
|
634
|
+
const res = await app.request(callbackRequest(nonce));
|
|
635
|
+
expect(res.status).toBe(403);
|
|
636
|
+
expect(res.headers.get("Set-Cookie") ?? "").not.toContain("admin_session=");
|
|
637
|
+
expect(calls).toEqual(["join:new.user@example.com"]);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it("flag off: an invited email joins its account and signs in, without a notification", async () => {
|
|
641
|
+
const notified: unknown[] = [];
|
|
642
|
+
let provisioned = false;
|
|
643
|
+
const app = createAdminUIApp(
|
|
644
|
+
makeMockDeps({
|
|
645
|
+
googleClient: identity(),
|
|
646
|
+
selfServe: { ...enabled, enabled: false },
|
|
647
|
+
accountOnboarding: {
|
|
648
|
+
provisionForEmail: async () => {
|
|
649
|
+
provisioned = true;
|
|
650
|
+
return { kind: "created", accountId: "acc-1" };
|
|
651
|
+
},
|
|
652
|
+
joinForEmail: async () => ({ kind: "joined", accountId: "acc-1" }),
|
|
653
|
+
},
|
|
654
|
+
accountCreatedNotifier: async (info) => {
|
|
655
|
+
notified.push(info);
|
|
656
|
+
},
|
|
657
|
+
}),
|
|
658
|
+
);
|
|
659
|
+
const res = await app.request(callbackRequest(nonce));
|
|
660
|
+
expect(res.status).toBe(302);
|
|
661
|
+
expect(res.headers.get("Location")).toBe("/admin/agents");
|
|
662
|
+
expect(res.headers.get("Set-Cookie")).toContain("admin_session=");
|
|
663
|
+
expect(provisioned).toBe(false);
|
|
664
|
+
expect(notified).toEqual([]);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it("flag off: an existing account owner with no agent memberships signs in", async () => {
|
|
668
|
+
const app = createAdminUIApp(
|
|
669
|
+
makeMockDeps({
|
|
670
|
+
googleClient: identity(),
|
|
671
|
+
selfServe: { ...enabled, enabled: false },
|
|
672
|
+
accountOnboarding: {
|
|
673
|
+
provisionForEmail: async () => {
|
|
674
|
+
throw new Error("must not create");
|
|
675
|
+
},
|
|
676
|
+
joinForEmail: async () => ({ kind: "existing", accountId: "acc-1" }),
|
|
677
|
+
},
|
|
678
|
+
}),
|
|
679
|
+
);
|
|
680
|
+
const res = await app.request(callbackRequest(nonce));
|
|
681
|
+
expect(res.status).toBe(302);
|
|
682
|
+
expect(res.headers.get("Location")).toBe("/admin/agents");
|
|
683
|
+
expect(res.headers.get("Set-Cookie")).toContain("admin_session=");
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
it("flag off: onboarding without joinForEmail keeps the 403", async () => {
|
|
617
687
|
let called = false;
|
|
618
688
|
const app = createAdminUIApp(
|
|
619
689
|
makeMockDeps({
|
|
@@ -632,6 +702,25 @@ describe("admin UI — Google callback self-serve signup (SSP-3.1)", () => {
|
|
|
632
702
|
expect(called).toBe(false);
|
|
633
703
|
});
|
|
634
704
|
|
|
705
|
+
it("flag off: a join failure redirects to server_error without a session", async () => {
|
|
706
|
+
const app = createAdminUIApp(
|
|
707
|
+
makeMockDeps({
|
|
708
|
+
googleClient: identity(),
|
|
709
|
+
selfServe: { ...enabled, enabled: false },
|
|
710
|
+
accountOnboarding: {
|
|
711
|
+
provisionForEmail: async () => ({ kind: "created", accountId: "a" }),
|
|
712
|
+
joinForEmail: async () => {
|
|
713
|
+
throw new Error("db down");
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
}),
|
|
717
|
+
);
|
|
718
|
+
const res = await app.request(callbackRequest(nonce));
|
|
719
|
+
expect(res.status).toBe(302);
|
|
720
|
+
expect(res.headers.get("Location")).toContain("error=server_error");
|
|
721
|
+
expect(res.headers.get("Set-Cookie") ?? "").not.toContain("admin_session=");
|
|
722
|
+
});
|
|
723
|
+
|
|
635
724
|
it("flag on: unverified email creates nothing", async () => {
|
|
636
725
|
let called = false;
|
|
637
726
|
const app = createAdminUIApp(
|
|
@@ -7884,7 +7973,7 @@ describe("admin UI — agent management is limited to admins and account owners"
|
|
|
7884
7973
|
expect(res.status).toBe(403);
|
|
7885
7974
|
});
|
|
7886
7975
|
|
|
7887
|
-
it(`
|
|
7976
|
+
it(`owner with no account on the scope gets 403 on POST /admin/agents/:id/${path}`, async () => {
|
|
7888
7977
|
const res = await makeApp(scopeOf(null, "owner")).request(
|
|
7889
7978
|
`/admin/agents/${AGENT_ID}/${path}`,
|
|
7890
7979
|
form(fields, await callerCookie()),
|
|
@@ -8217,3 +8306,80 @@ describe("admin UI — admin sign-in ensures an AccountMember", () => {
|
|
|
8217
8306
|
expect(emails).toEqual(["dev@localhost"]);
|
|
8218
8307
|
});
|
|
8219
8308
|
});
|
|
8309
|
+
|
|
8310
|
+
// ─── Agents list account features do not depend on the self-serve flag ─────
|
|
8311
|
+
|
|
8312
|
+
describe("admin UI — agents list account features, self-serve off and on", () => {
|
|
8313
|
+
const OWNER = "owner@example.com";
|
|
8314
|
+
const agent = {
|
|
8315
|
+
id: AGENT_ID,
|
|
8316
|
+
name: "Test Agent",
|
|
8317
|
+
slackId: "U123456",
|
|
8318
|
+
selfHosted: false,
|
|
8319
|
+
specialty: "coding",
|
|
8320
|
+
accountId: "acct-a",
|
|
8321
|
+
createdAt: new Date("2024-01-01"),
|
|
8322
|
+
updatedAt: new Date("2024-01-01"),
|
|
8323
|
+
};
|
|
8324
|
+
const makeApp = (enabled: boolean) => {
|
|
8325
|
+
const base = makeMockDeps();
|
|
8326
|
+
return createAdminUIApp(
|
|
8327
|
+
makeMockDeps({
|
|
8328
|
+
selfServe: {
|
|
8329
|
+
enabled,
|
|
8330
|
+
defaultMaxAgents: 0,
|
|
8331
|
+
contactEmail: "quota@example.com",
|
|
8332
|
+
},
|
|
8333
|
+
callerScopeResolver: async () => ({
|
|
8334
|
+
kind: "scoped" as const,
|
|
8335
|
+
accountId: "acct-a",
|
|
8336
|
+
agentIds: [AGENT_ID],
|
|
8337
|
+
role: "owner" as const,
|
|
8338
|
+
}),
|
|
8339
|
+
agentService: {
|
|
8340
|
+
...base.agentService,
|
|
8341
|
+
listAll: async () => [agent],
|
|
8342
|
+
listByIds: async () => [agent],
|
|
8343
|
+
} as never,
|
|
8344
|
+
accountServices: {
|
|
8345
|
+
accounts: {
|
|
8346
|
+
getByMemberEmail: async (email: string) =>
|
|
8347
|
+
email === OWNER
|
|
8348
|
+
? { id: "acct-a", name: "Acme Co", maxAgents: 0 }
|
|
8349
|
+
: null,
|
|
8350
|
+
listWithCounts: async () => [{ id: "acct-a", name: "Acme Co" }],
|
|
8351
|
+
},
|
|
8352
|
+
members: { getByEmail: async () => null },
|
|
8353
|
+
} as never,
|
|
8354
|
+
}),
|
|
8355
|
+
);
|
|
8356
|
+
};
|
|
8357
|
+
|
|
8358
|
+
for (const enabled of [false, true]) {
|
|
8359
|
+
const label = enabled ? "on" : "off";
|
|
8360
|
+
|
|
8361
|
+
it(`self-serve ${label}: admins see the Account column`, async () => {
|
|
8362
|
+
const res = await makeApp(enabled).request("/admin/agents", {
|
|
8363
|
+
headers: { Cookie: `admin_session=${await makeSessionCookie()}` },
|
|
8364
|
+
});
|
|
8365
|
+
expect(res.status).toBe(200);
|
|
8366
|
+
const body = await res.text();
|
|
8367
|
+
expect(body).toContain("<th>Account</th>");
|
|
8368
|
+
expect(body).toContain('href="/admin/accounts/acct-a"');
|
|
8369
|
+
});
|
|
8370
|
+
|
|
8371
|
+
it(`self-serve ${label}: an owner of a zero-limit account sees the contact notice`, async () => {
|
|
8372
|
+
const cookie = await makeSessionCookie(
|
|
8373
|
+
SESSION_SECRET,
|
|
8374
|
+
"google-sub-owner",
|
|
8375
|
+
OWNER,
|
|
8376
|
+
false,
|
|
8377
|
+
);
|
|
8378
|
+
const res = await makeApp(enabled).request("/admin/agents", {
|
|
8379
|
+
headers: { Cookie: `admin_session=${cookie}` },
|
|
8380
|
+
});
|
|
8381
|
+
expect(res.status).toBe(200);
|
|
8382
|
+
expect(await res.text()).toContain("quota@example.com");
|
|
8383
|
+
});
|
|
8384
|
+
}
|
|
8385
|
+
});
|
package/src/admin-ui.ts
CHANGED
|
@@ -494,13 +494,21 @@ export interface AdminUIDeps {
|
|
|
494
494
|
appBaseUrl: string;
|
|
495
495
|
/** Enable the /admin/dev-login route. Hard-blocked in production regardless of this value. */
|
|
496
496
|
devAuthEnabled?: boolean;
|
|
497
|
-
/**
|
|
497
|
+
/**
|
|
498
|
+
* Resolved self-serve config (SSP-1.3). `enabled` controls only open signup
|
|
499
|
+
* (an unknown verified Google user creating an account); `contactEmail` is
|
|
500
|
+
* shown on the agent-limit notices.
|
|
501
|
+
*/
|
|
498
502
|
selfServe?: SelfServeConfig;
|
|
499
503
|
/**
|
|
500
|
-
* First-login account
|
|
501
|
-
*
|
|
504
|
+
* First-login account resolution (SSP-3.1), consulted by the Google callback
|
|
505
|
+
* only, for a verified email with no AgentMember rows. Signup on
|
|
506
|
+
* (selfServe.enabled): provisionForEmail (join, existing or create). Signup
|
|
507
|
+
* off: joinForEmail (join or existing, never create); without it the
|
|
508
|
+
* caller gets 403. Absent → 403.
|
|
502
509
|
*/
|
|
503
|
-
accountOnboarding?: Pick<AccountOnboardingService, "provisionForEmail"
|
|
510
|
+
accountOnboarding?: Pick<AccountOnboardingService, "provisionForEmail"> &
|
|
511
|
+
Partial<Pick<AccountOnboardingService, "joinForEmail">>;
|
|
504
512
|
/**
|
|
505
513
|
* GHE-1.4: the GHE-1.3 /github-enterprise API app's `request`. Optional
|
|
506
514
|
* (additive): when absent the Settings page and its nav entry are not
|
|
@@ -548,8 +556,9 @@ export interface AdminUIDeps {
|
|
|
548
556
|
creator?: MemberCreator;
|
|
549
557
|
}) => Promise<EnsureAccountMemberResult>;
|
|
550
558
|
/**
|
|
551
|
-
* Account page + nav services (SSP-3.2)
|
|
552
|
-
* absent → no /admin/account routes
|
|
559
|
+
* Account page + nav services (SSP-3.2), independent of the self-serve
|
|
560
|
+
* setting; absent → no /admin/account(s) routes, no nav entry, no quota
|
|
561
|
+
* notice and no Account column.
|
|
553
562
|
*/
|
|
554
563
|
accountServices?: {
|
|
555
564
|
accounts: Pick<
|
|
@@ -1032,7 +1041,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1032
1041
|
devAuthEnabled,
|
|
1033
1042
|
});
|
|
1034
1043
|
|
|
1035
|
-
const accountNavEnabled =
|
|
1044
|
+
const accountNavEnabled = accountServices !== undefined;
|
|
1036
1045
|
|
|
1037
1046
|
const settingsNav = buildSettingsNav({
|
|
1038
1047
|
githubEnterprise: Boolean(githubEnterpriseApi),
|
|
@@ -1064,7 +1073,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1064
1073
|
if (user) {
|
|
1065
1074
|
const role = await resolveNavRole(user.email, user.isAdmin === true);
|
|
1066
1075
|
nav = filterSettingsNavForRole(settingsNav, role);
|
|
1067
|
-
if (
|
|
1076
|
+
if (accountServices) {
|
|
1068
1077
|
const account = await accountServices.accounts
|
|
1069
1078
|
.getByMemberEmail(user.email)
|
|
1070
1079
|
.catch(() => null);
|
|
@@ -1186,7 +1195,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1186
1195
|
c: Context<AdminUIEnv, any>,
|
|
1187
1196
|
userInfo: { sub: string; email?: string; email_verified?: boolean },
|
|
1188
1197
|
returnTo: string | undefined,
|
|
1189
|
-
opts: {
|
|
1198
|
+
opts: { accountSignIn?: boolean } = {},
|
|
1190
1199
|
): Promise<Response> {
|
|
1191
1200
|
if (!userInfo.email) {
|
|
1192
1201
|
return c.redirect("/admin/login?error=auth_failed", 302);
|
|
@@ -1208,21 +1217,26 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1208
1217
|
userInfo.email.toLowerCase(),
|
|
1209
1218
|
);
|
|
1210
1219
|
if (memberships.length === 0) {
|
|
1211
|
-
//
|
|
1212
|
-
//
|
|
1213
|
-
//
|
|
1214
|
-
const onboarding = accountOnboarding;
|
|
1215
|
-
|
|
1220
|
+
// SSP-3.1: a verified Google email with no AgentMember rows signs in
|
|
1221
|
+
// through its account: an existing membership, else a pending invite,
|
|
1222
|
+
// else (signup on only) a new account. Okta keeps the existing 403.
|
|
1223
|
+
const onboarding = opts.accountSignIn ? accountOnboarding : undefined;
|
|
1224
|
+
const resolveAccount =
|
|
1225
|
+
selfServe?.enabled === true
|
|
1226
|
+
? onboarding?.provisionForEmail.bind(onboarding)
|
|
1227
|
+
: onboarding?.joinForEmail?.bind(onboarding);
|
|
1228
|
+
if (!resolveAccount) {
|
|
1216
1229
|
return new Response("Forbidden", { status: 403 });
|
|
1217
1230
|
}
|
|
1218
1231
|
const email = userInfo.email.toLowerCase();
|
|
1219
|
-
let result: Awaited<ReturnType<typeof
|
|
1232
|
+
let result: Awaited<ReturnType<typeof resolveAccount>>;
|
|
1220
1233
|
try {
|
|
1221
|
-
result = await
|
|
1234
|
+
result = await resolveAccount(email);
|
|
1222
1235
|
} catch (err) {
|
|
1223
|
-
console.error("[admin]
|
|
1236
|
+
console.error("[admin] account sign-in resolution failed", err);
|
|
1224
1237
|
return c.redirect("/admin/login?error=server_error", 302);
|
|
1225
1238
|
}
|
|
1239
|
+
if (!result) return new Response("Forbidden", { status: 403 });
|
|
1226
1240
|
if (result.kind !== "existing") {
|
|
1227
1241
|
console.log(
|
|
1228
1242
|
JSON.stringify({
|
|
@@ -1476,7 +1490,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1476
1490
|
return c.redirect("/admin/login?error=auth_failed", 302);
|
|
1477
1491
|
}
|
|
1478
1492
|
|
|
1479
|
-
return completeLogin(c, userInfo, returnTo, {
|
|
1493
|
+
return completeLogin(c, userInfo, returnTo, { accountSignIn: true });
|
|
1480
1494
|
});
|
|
1481
1495
|
|
|
1482
1496
|
app.get("/admin/auth/okta", (c) => {
|
|
@@ -1613,17 +1627,18 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1613
1627
|
// SSP-3.2: a zero-quota account sees a request-a-trial message and a
|
|
1614
1628
|
// disabled create button instead of the create CTA.
|
|
1615
1629
|
let zeroQuotaContactEmail: string | undefined;
|
|
1616
|
-
if (
|
|
1630
|
+
if (accountServices) {
|
|
1617
1631
|
const account = await accountServices.accounts.getByMemberEmail(
|
|
1618
1632
|
c.var.userEmail,
|
|
1619
1633
|
);
|
|
1620
1634
|
if (account && account.maxAgents === 0) {
|
|
1621
|
-
zeroQuotaContactEmail =
|
|
1635
|
+
zeroQuotaContactEmail =
|
|
1636
|
+
selfServe?.contactEmail ?? DEFAULT_SELF_SERVE_CONTACT_EMAIL;
|
|
1622
1637
|
}
|
|
1623
1638
|
}
|
|
1624
|
-
// SSP-5.2: admins get an Account column
|
|
1639
|
+
// SSP-5.2: admins get an Account column.
|
|
1625
1640
|
let accountNames: Map<string, string> | undefined;
|
|
1626
|
-
if (c.var.isAdmin &&
|
|
1641
|
+
if (c.var.isAdmin && accountServices) {
|
|
1627
1642
|
accountNames = new Map(
|
|
1628
1643
|
(await accountServices.accounts.listWithCounts()).map((a) => [
|
|
1629
1644
|
a.id,
|
|
@@ -4572,7 +4587,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4572
4587
|
|
|
4573
4588
|
app.get("/admin/provision", (c) => c.redirect("/admin/agents/new", 302));
|
|
4574
4589
|
|
|
4575
|
-
// ─── Member management (admin, or
|
|
4590
|
+
// ─── Member management (platform admin, or the owner of the agent's account) ───
|
|
4576
4591
|
|
|
4577
4592
|
app.post("/admin/agents/:id/members", requireAuth, async (c) => {
|
|
4578
4593
|
const agentId = c.req.param("id");
|
|
@@ -4663,7 +4678,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4663
4678
|
c.var.isAdmin === true,
|
|
4664
4679
|
);
|
|
4665
4680
|
let nav = settingsNav;
|
|
4666
|
-
if (
|
|
4681
|
+
if (accountServices) {
|
|
4667
4682
|
const account = await accountServices.accounts
|
|
4668
4683
|
.getByMemberEmail(c.var.userEmail)
|
|
4669
4684
|
.catch(() => null);
|
|
@@ -4733,14 +4748,12 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4733
4748
|
|
|
4734
4749
|
if (accountServices) {
|
|
4735
4750
|
registerAccountRoutes(app, {
|
|
4736
|
-
enabled: accountNavEnabled,
|
|
4737
4751
|
requireAuth,
|
|
4738
4752
|
settingsNav,
|
|
4739
4753
|
...accountServices,
|
|
4740
4754
|
html,
|
|
4741
4755
|
});
|
|
4742
4756
|
registerAdminAccountsRoutes(app, {
|
|
4743
|
-
enabled: accountNavEnabled,
|
|
4744
4757
|
requireAuth,
|
|
4745
4758
|
settingsNav,
|
|
4746
4759
|
...accountServices,
|