Delete the runtime app registration surface (R7, fork 3)
registerApp minted a client_secret whose hash nothing ever verified (six routes gate on the shared-secret caller-identity check, not on registration); registered_apps sits empty on the live host. Deleted: POST /v1/apps, getRegistrationSecret, config.appRegistrationSecret, registerApp/ hashClientSecret/verifyClientSecret, the client_secret_hash column (dropped idempotently on startup, same as it is created), and tests/app-registration-endpoint.test.ts. registered_apps and resolveAppProfile stay as a profile store; app-registry.test.ts fixtures that used registerApp purely to seed a profile now write through store.registerApp directly, the same primitive the built-in-shadow test already used.
This commit is contained in:
parent
326f613ffe
commit
776565effd
9 changed files with 45 additions and 376 deletions
|
|
@ -1,195 +0,0 @@
|
|||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { type FastifyInstance } from "fastify";
|
||||
|
||||
import { buildApp } from "../src/app.js";
|
||||
import { type HeimdallConfig } from "../src/config.js";
|
||||
import { identityFacts } from "../src/facts.js";
|
||||
|
||||
const REGISTRATION_SECRET = "operator-registration-secret";
|
||||
|
||||
function createTestConfig(overrides: Partial<HeimdallConfig> = {}): HeimdallConfig {
|
||||
return {
|
||||
serviceName: "heimdall",
|
||||
host: "127.0.0.1",
|
||||
port: 4100,
|
||||
workspaceRoot: ".",
|
||||
dataRoot: "./.heimdall-data",
|
||||
cultCachePath: "./.heimdall-data/cultcache/heimdall.service.cc",
|
||||
publicBaseUrl: "https://heimdall.test",
|
||||
issuer: "https://heimdall.test",
|
||||
daemonId: "test-heimdall",
|
||||
idunnRudpHealth: undefined,
|
||||
idunnHealthContract: "heimdall.cultnet-rudp-provider-health",
|
||||
providerHealthIdentityPath: "./.heimdall-data/provider-health-identity.cc",
|
||||
sessionTtlSeconds: 3600,
|
||||
refreshTtlSeconds: 60 * 60 * 24 * 30,
|
||||
stateTtlSeconds: 600,
|
||||
completionTtlSeconds: 300,
|
||||
bootstrapSigningPrivateKeyOnMissing: false,
|
||||
tokenEncryptionKeyBase64: Buffer.alloc(32, 7).toString("base64"),
|
||||
appSharedSecrets: {},
|
||||
appBackendCallbacks: {},
|
||||
storage: { backend: "memory", applySchemaOnStartup: true },
|
||||
providers: {
|
||||
discord: { clientId: "discord-client", clientSecret: "discord-secret" },
|
||||
patreon: { clientId: "patreon-client", clientSecret: "patreon-secret" },
|
||||
github: { clientId: "github-client", clientSecret: "github-secret" },
|
||||
twitch: { clientId: "twitch-client", clientSecret: "twitch-secret" },
|
||||
youtube: { clientId: "youtube-client", clientSecret: "youtube-secret" },
|
||||
spotify: { clientId: "spotify-client", clientSecret: "spotify-secret" },
|
||||
},
|
||||
...overrides,
|
||||
} as HeimdallConfig;
|
||||
}
|
||||
|
||||
const registration = {
|
||||
slug: "erycina",
|
||||
displayName: "Erycina",
|
||||
identityProviders: ["discord"],
|
||||
redirectUris: ["https://erycina.test/auth/callback"],
|
||||
capabilities: [
|
||||
{ key: "viewer_access", mode: "shared", summary: "Signed-in viewer.", anyOf: [identityFacts.authenticated] },
|
||||
],
|
||||
};
|
||||
|
||||
const apps: FastifyInstance[] = [];
|
||||
afterEach(async () => {
|
||||
while (apps.length > 0) await apps.pop()!.close();
|
||||
});
|
||||
|
||||
async function buildOpenInstance(): Promise<FastifyInstance> {
|
||||
const app = await buildApp({ config: createTestConfig({ appRegistrationSecret: REGISTRATION_SECRET }) });
|
||||
apps.push(app);
|
||||
return app;
|
||||
}
|
||||
|
||||
describe("POST /v1/apps", () => {
|
||||
it("is closed on an instance with no registration secret configured", async () => {
|
||||
// A fresh instance must not be accidentally open. Heimdall is an OAuth
|
||||
// provider; an open registration endpoint lets anyone create a client that
|
||||
// starts provider flows under this instance's identity.
|
||||
const app = await buildApp({ config: createTestConfig() });
|
||||
apps.push(app);
|
||||
|
||||
const response = await app.inject({ method: "POST", url: "/v1/apps", payload: registration });
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
expect(response.json().error).toBe("registration_closed");
|
||||
});
|
||||
|
||||
it("refuses a request with no registration secret", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({ method: "POST", url: "/v1/apps", payload: registration });
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it("refuses a request with the wrong registration secret", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": "not-it" },
|
||||
payload: registration,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it("registers an app and returns an RFC 7591 shaped response", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": REGISTRATION_SECRET },
|
||||
payload: registration,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(201);
|
||||
const body = response.json();
|
||||
expect(body.client_id).toBe("erycina");
|
||||
expect(body.client_secret).toBeTruthy();
|
||||
expect(body.client_name).toBe("Erycina");
|
||||
expect(body.redirect_uris).toEqual(["https://erycina.test/auth/callback"]);
|
||||
expect(typeof body.client_id_issued_at).toBe("number");
|
||||
});
|
||||
|
||||
it("rejects an invalid registration with the problems that caused it", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": REGISTRATION_SECRET },
|
||||
payload: { ...registration, slug: "bifrost" },
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json().error).toBe("invalid_client_metadata");
|
||||
expect(JSON.stringify(response.json().problems)).toMatch(/reserved by a built-in/);
|
||||
});
|
||||
|
||||
it("rejects a capability rule naming a fact Heimdall does not produce", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": REGISTRATION_SECRET },
|
||||
payload: {
|
||||
...registration,
|
||||
capabilities: [{ key: "admin", mode: "shared", summary: "x", anyOf: ["invented.superuser"] }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(JSON.stringify(response.json().problems)).toMatch(/Unknown term/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("app discovery after registration", () => {
|
||||
it("lists a registered app alongside the built-ins", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": REGISTRATION_SECRET },
|
||||
payload: registration,
|
||||
});
|
||||
|
||||
const listed = (await app.inject({ method: "GET", url: "/v1/apps" })).json();
|
||||
const slugs = listed.apps.map((profile: { slug: string }) => profile.slug);
|
||||
|
||||
expect(slugs).toContain("erycina");
|
||||
expect(slugs).toContain("bifrost");
|
||||
});
|
||||
|
||||
it("serves a registered app's profile by slug", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps",
|
||||
headers: { "x-heimdall-registration-secret": REGISTRATION_SECRET },
|
||||
payload: registration,
|
||||
});
|
||||
|
||||
const response = await app.inject({ method: "GET", url: "/v1/apps/erycina" });
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().displayName).toBe("Erycina");
|
||||
});
|
||||
|
||||
it("404s an app nobody registered, rather than serving an empty profile", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({ method: "GET", url: "/v1/apps/nobody" });
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
expect(response.json().error).toBe("unknown_app");
|
||||
});
|
||||
|
||||
it("still serves the built-in profiles", async () => {
|
||||
const app = await buildOpenInstance();
|
||||
const response = await app.inject({ method: "GET", url: "/v1/apps/repixelizer" });
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().slug).toBe("repixelizer");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
AppRegistrationError,
|
||||
hashClientSecret,
|
||||
isBuiltInApp,
|
||||
listAppProfiles,
|
||||
registerApp,
|
||||
resolveAppProfile,
|
||||
validateAppRegistration,
|
||||
verifyClientSecret,
|
||||
type AppRegistrationRequest,
|
||||
} from "../src/app-registry.js";
|
||||
import { evaluateCapabilityRules } from "../src/capability-rules.js";
|
||||
import { type Provider } from "../src/contracts.js";
|
||||
import { entitlementFacts, grantFacts, identityFacts } from "../src/facts.js";
|
||||
import { InMemoryStore } from "../src/store/in-memory.js";
|
||||
|
||||
|
|
@ -31,6 +28,28 @@ beforeEach(() => {
|
|||
store = new InMemoryStore();
|
||||
});
|
||||
|
||||
/**
|
||||
* There is no runtime registration authority anymore (deleted with the
|
||||
* caller-identity cut: registerApp minted a client_secret nobody verified).
|
||||
* `registered_apps` remains a profile store, so tests that need a resolvable
|
||||
* profile write the row directly through the store primitive, the same way
|
||||
* production code would seed one outside the deleted HTTP surface.
|
||||
*/
|
||||
async function seedRegisteredApp(overrides: Partial<AppRegistrationRequest> = {}, registeredAt = "2026-01-01T00:00:00.000Z") {
|
||||
const req = request(overrides);
|
||||
return store.registerApp({
|
||||
slug: req.slug,
|
||||
displayName: req.displayName.trim(),
|
||||
profileVersion: req.profileVersion?.trim() || registeredAt.slice(0, 10),
|
||||
registeredAt,
|
||||
identityProviders: req.identityProviders as Provider[],
|
||||
entitlementSources: (req.entitlementSources ?? []) as Provider[],
|
||||
managedConnectionProviders: (req.managedConnectionProviders ?? []) as Provider[],
|
||||
capabilities: req.capabilities,
|
||||
redirectUris: req.redirectUris,
|
||||
});
|
||||
}
|
||||
|
||||
describe("validateAppRegistration", () => {
|
||||
it("accepts a well-formed registration", () => {
|
||||
expect(validateAppRegistration(request())).toEqual([]);
|
||||
|
|
@ -100,45 +119,9 @@ describe("validateAppRegistration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("registerApp", () => {
|
||||
it("stores the app and returns a secret exactly once", async () => {
|
||||
const { app, clientSecret } = await registerApp(store, request());
|
||||
|
||||
expect(app.slug).toBe("erycina");
|
||||
expect(clientSecret).toBeTruthy();
|
||||
// The secret is returned, never stored.
|
||||
expect(app).not.toHaveProperty("clientSecret");
|
||||
expect(app.clientSecretHash).toBe(hashClientSecret(clientSecret));
|
||||
});
|
||||
|
||||
it("refuses an invalid registration rather than storing a broken profile", async () => {
|
||||
await expect(registerApp(store, request({ slug: "bifrost" }))).rejects.toBeInstanceOf(AppRegistrationError);
|
||||
expect(await store.findRegisteredApp("bifrost")).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps the original creation time when an app re-registers", async () => {
|
||||
const first = await registerApp(store, request(), "2026-01-01T00:00:00.000Z");
|
||||
const second = await registerApp(store, request({ displayName: "Erycina v2" }), "2026-06-01T00:00:00.000Z");
|
||||
|
||||
expect(second.app.createdAt).toBe(first.app.createdAt);
|
||||
expect(second.app.updatedAt).toBe("2026-06-01T00:00:00.000Z");
|
||||
expect(second.app.displayName).toBe("Erycina v2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("verifyClientSecret", () => {
|
||||
it("accepts the issued secret and rejects anything else", async () => {
|
||||
const { app, clientSecret } = await registerApp(store, request());
|
||||
|
||||
expect(verifyClientSecret(clientSecret, app.clientSecretHash)).toBe(true);
|
||||
expect(verifyClientSecret("not-the-secret", app.clientSecretHash)).toBe(false);
|
||||
expect(verifyClientSecret(clientSecret, null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAppProfile", () => {
|
||||
it("resolves a registered app", async () => {
|
||||
await registerApp(store, request());
|
||||
await seedRegisteredApp();
|
||||
const profile = await resolveAppProfile(store, "erycina");
|
||||
|
||||
expect(profile?.displayName).toBe("Erycina");
|
||||
|
|
@ -165,7 +148,6 @@ describe("resolveAppProfile", () => {
|
|||
managedConnectionProviders: [],
|
||||
capabilities: [],
|
||||
redirectUris: [],
|
||||
clientSecretHash: null,
|
||||
});
|
||||
|
||||
expect((await resolveAppProfile(store, "bifrost"))?.displayName).toBe("Bifrost");
|
||||
|
|
@ -174,15 +156,12 @@ describe("resolveAppProfile", () => {
|
|||
|
||||
describe("a registered profile evaluates like a built-in", () => {
|
||||
it("grants capabilities through the same evaluator", async () => {
|
||||
await registerApp(
|
||||
store,
|
||||
request({
|
||||
capabilities: [
|
||||
{ key: "member_access", mode: "shared", summary: "member", anyOf: [entitlementFacts.appAccess, grantFacts.globalMember] },
|
||||
{ key: "post_create", mode: "shared", summary: "post", anyOf: ["member_access"] },
|
||||
],
|
||||
}),
|
||||
);
|
||||
await seedRegisteredApp({
|
||||
capabilities: [
|
||||
{ key: "member_access", mode: "shared", summary: "member", anyOf: [entitlementFacts.appAccess, grantFacts.globalMember] },
|
||||
{ key: "post_create", mode: "shared", summary: "post", anyOf: ["member_access"] },
|
||||
],
|
||||
});
|
||||
const profile = await resolveAppProfile(store, "erycina");
|
||||
|
||||
expect(evaluateCapabilityRules(profile!.capabilities, new Set([grantFacts.globalMember]))).toEqual([
|
||||
|
|
@ -195,7 +174,7 @@ describe("a registered profile evaluates like a built-in", () => {
|
|||
|
||||
describe("listAppProfiles", () => {
|
||||
it("lists built-ins alongside registered apps", async () => {
|
||||
await registerApp(store, request());
|
||||
await seedRegisteredApp();
|
||||
const slugs = (await listAppProfiles(store)).map((profile) => profile.slug);
|
||||
|
||||
expect(slugs).toContain("bifrost");
|
||||
|
|
@ -203,7 +182,7 @@ describe("listAppProfiles", () => {
|
|||
});
|
||||
|
||||
it("lists each app once", async () => {
|
||||
await registerApp(store, request());
|
||||
await seedRegisteredApp();
|
||||
const slugs = (await listAppProfiles(store)).map((profile) => profile.slug);
|
||||
|
||||
expect(new Set(slugs).size).toBe(slugs.length);
|
||||
|
|
|
|||
Loading…
Reference in a new issue