feat(hub): add idempotent service registration

This commit is contained in:
DCCONSTRUCTIONS
2026-08-10 16:53:47 +03:00
parent 24d01fc813
commit 64624293a8
7 changed files with 494 additions and 51 deletions
@@ -122,6 +122,71 @@ describe("computeEffectiveAccess", () => {
expect(result.source).toBe("user");
});
it("supports a personal client without making the service globally available", () => {
const personalClient: Client = {
...client,
id: "client_personal_a",
type: "person",
name: "Личный контур пользователя",
};
const personalMembership: ClientMembership = {
...membership,
id: "membership_personal_a",
clientId: personalClient.id,
};
const result = computeEffectiveAccess({
...baseInput,
client: personalClient,
membership: personalMembership,
userGroups: [],
grants: [grant("client", personalClient.id)],
});
expect(result.allowed).toBe(true);
expect(result.source).toBe("client");
});
it("isolates an open-pool user grant from other users in the same pool", () => {
const publicPoolClient: Client = {
...client,
id: "client_public_pool",
name: "Открытый контур",
};
const publicPoolMembership: ClientMembership = {
...membership,
id: "membership_public_pool_a",
clientId: publicPoolClient.id,
};
const granted = computeEffectiveAccess({
...baseInput,
client: publicPoolClient,
membership: publicPoolMembership,
userGroups: [],
grants: [grant("user", user.id)],
});
const otherUser: LauncherUser = {
...user,
id: "user_b",
email: "other@example.ru",
};
const isolated = computeEffectiveAccess({
...baseInput,
client: publicPoolClient,
user: otherUser,
membership: {
...publicPoolMembership,
id: "membership_public_pool_b",
userId: otherUser.id,
},
userGroups: [],
grants: [grant("user", user.id)],
});
expect(granted.allowed).toBe(true);
expect(granted.source).toBe("user");
expect(isolated.allowed).toBe(false);
});
it("deny exception overrides user grant", () => {
const result = computeEffectiveAccess({
...baseInput,
@@ -133,6 +198,26 @@ describe("computeEffectiveAccess", () => {
expect(result.source).toBe("exception");
});
it.each(["hidden", "disabled"] as const)("blocks a %s service even when a grant exists", (status) => {
const result = computeEffectiveAccess({
...baseInput,
service: { ...service, status },
grants: [grant("client", client.id)],
});
expect(result.allowed).toBe(false);
expect(result.visible).toBe(false);
});
it("ignores an inactive entitlement", () => {
const result = computeEffectiveAccess({
...baseInput,
grants: [{ ...grant("client", client.id), status: "disabled" }],
});
expect(result.allowed).toBe(false);
});
it("maintenance service is visible but openEnabled is false", () => {
const result = computeEffectiveAccess({
...baseInput,
@@ -81,6 +81,28 @@ describe("assistant-ready Launcher admin routes", () => {
expect(block).toContain("scopeAdminMutationResult");
});
it("keeps generic service registration root-guarded and idempotent", () => {
const block = sourceBlock(
'app.put("/api/admin/services/registrations/:serviceSlug"',
'app.patch("/api/admin/services/reorder"'
);
expect(block).toContain("requireLauncherAdmin");
expect(block).toContain("requireRootLauncherAdmin");
expect(block).toContain("sendAdminIdempotentJson");
expect(block).toContain("controlPlaneStore.ensureService");
});
it("keeps service grants idempotent and outside the assistant gateway allowlist", () => {
const block = sourceBlock('app.post("/api/admin/access/grants"', 'app.post("/api/admin/access/exceptions"');
const allowlistBlock = sourceBlock("const assistantGatewayAdminRouteAllowlist = [", "];",);
expect(block).toContain("sendAdminIdempotentJson");
expect(block).toContain("controlPlaneStore.upsertGrant");
expect(allowlistBlock).not.toContain("/api/admin/services/registrations");
expect(allowlistBlock).not.toContain("/api/admin/access/grants");
});
it("keeps hard delete routes outside assistant-ready routes and root-guarded where available", () => {
const userDeleteBlock = sourceBlock('app.delete("/api/admin/users/:userId"', 'app.post("/api/admin/users/:userId/provision-authentik"');