R21.3: delete the unreachable registered-app resolution path
The runtime app-registration writer (POST /v1/apps) was deleted in an earlier pass because it minted a client_secret nobody verified. This pass kept resolveAppProfile's registered-app fallback and listAppProfiles on the theory that AppSlug is an open string and dynamic registration was a live extension point. Soul falsified that: every HTTP route enumerates the four built-in slugs in its own JSON schema (app.ts's `enum: [...appSlugs]` at every appSlug param/body field), so a registered row could never be resolved from a request. With the writer already gone, this was unreachable code behind a dead writer -- delete it rather than keep authenticating a door nobody can open. Deleted: src/app-registry.ts entirely (resolveAppProfile, listAppProfiles, isBuiltInApp, registeredAppToProfile, returnOriginsFromRedirectUris); StoredRegisteredApp and the findRegisteredApp/listRegisteredApps HeimdallStore methods (store/types.ts); their InMemoryStore and PostgresStore implementations, including seedRegisteredApp and mapRegisteredApp; the registered_apps table (store/schema.ts now drops it on any store built before this schema); tests/app-registry.test.ts. Every call site (app.ts x5, claims.ts, private-command-plane.ts) now calls the existing built-in-only getAppProfile (app-profiles.ts) directly -- sync, no store needed. If dynamic app registration is wanted later it returns as a designed, authenticated feature, not by resurrecting this vestige. Net -305 lines against the prior commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
3427bdda1e
commit
e21659cd31
11 changed files with 33 additions and 338 deletions
|
|
@ -178,8 +178,13 @@ const ghostlightProfile: AppProfile = {
|
|||
};
|
||||
|
||||
/**
|
||||
* Profiles that ship with Heimdall. These are seed data, not special cases:
|
||||
* a registered app produces the same shape and is evaluated by the same code.
|
||||
* Profiles that ship with Heimdall. This is the whole set: runtime app
|
||||
* registration (POST /v1/apps, and the `registered_apps` table it fed) was
|
||||
* deleted with the caller-identity cut (R21.3) after Soul showed it was
|
||||
* unreachable dead code — every HTTP route already enumerates these four
|
||||
* slugs in its own JSON schema, so a registered row could never be resolved
|
||||
* from a request. A future app with a genuine dynamic-registration need adds
|
||||
* that back as a designed, authenticated feature, not by resurrecting this.
|
||||
*/
|
||||
export const builtInAppProfiles: Record<AppSlug, AppProfile> = {
|
||||
repixelizer: repixelizerProfile,
|
||||
|
|
@ -190,11 +195,6 @@ export const builtInAppProfiles: Record<AppSlug, AppProfile> = {
|
|||
|
||||
export const appProfiles = builtInAppProfiles;
|
||||
|
||||
/**
|
||||
* Built-in profiles only, and it can miss: an app registered at runtime is
|
||||
* resolved through the registry, which needs a store. Callers with a store
|
||||
* should prefer resolveAppProfile.
|
||||
*/
|
||||
export function getAppProfile(appSlug: AppSlug): AppProfile | undefined {
|
||||
return appProfiles[appSlug];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
// App profile resolution: built-in profiles plus whatever is provisioned
|
||||
// directly in the `registered_apps` table.
|
||||
//
|
||||
// This used to also own runtime registration (POST /v1/apps): a caller
|
||||
// self-registered a profile and got back a client_secret nobody ever
|
||||
// verified. That HTTP surface, its validation, and the minted secret are
|
||||
// gone (the caller-identity cut). `registered_apps` remains a profile store
|
||||
// beneath the built-in profiles; a row is now provisioned by direct SQL
|
||||
// against Postgres (or InMemoryStore.seedRegisteredApp for tests), not by an
|
||||
// app calling Heimdall.
|
||||
|
||||
import { builtInAppProfiles, type AppProfile } from "./app-profiles.js";
|
||||
import { type HeimdallStore, type StoredRegisteredApp } from "./store/types.js";
|
||||
|
||||
export function isBuiltInApp(slug: string): boolean {
|
||||
return Object.hasOwn(builtInAppProfiles, slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* A registered app's `redirectUris` is the same "where may this app send a
|
||||
* browser back to" data a runtime registration used to validate; it becomes
|
||||
* the profile's return-origin allowlist. An unparseable entry is dropped
|
||||
* rather than widening the allowlist with garbage.
|
||||
*/
|
||||
function returnOriginsFromRedirectUris(redirectUris: string[]): string[] {
|
||||
const origins = new Set<string>();
|
||||
for (const uri of redirectUris) {
|
||||
try {
|
||||
origins.add(new URL(uri).origin);
|
||||
} catch {
|
||||
// Dropped: an unparseable redirect URI cannot name a trustworthy origin.
|
||||
}
|
||||
}
|
||||
return [...origins];
|
||||
}
|
||||
|
||||
export function registeredAppToProfile(app: StoredRegisteredApp): AppProfile {
|
||||
return {
|
||||
slug: app.slug,
|
||||
displayName: app.displayName,
|
||||
profileVersion: app.profileVersion,
|
||||
identityProviders: app.identityProviders,
|
||||
entitlementSources: app.entitlementSources,
|
||||
managedConnectionProviders: app.managedConnectionProviders,
|
||||
capabilities: app.capabilities,
|
||||
allowedReturnOrigins: returnOriginsFromRedirectUris(app.redirectUris),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Built-ins first, so a shipped app cannot be shadowed even if a row for it
|
||||
* somehow exists.
|
||||
*/
|
||||
export async function resolveAppProfile(store: HeimdallStore, slug: string): Promise<AppProfile | null> {
|
||||
const builtIn = builtInAppProfiles[slug as keyof typeof builtInAppProfiles];
|
||||
if (builtIn) return builtIn;
|
||||
const registered = await store.findRegisteredApp(slug);
|
||||
return registered ? registeredAppToProfile(registered) : null;
|
||||
}
|
||||
|
||||
export async function listAppProfiles(store: HeimdallStore): Promise<AppProfile[]> {
|
||||
const registered = await store.listRegisteredApps();
|
||||
return [
|
||||
...Object.values(builtInAppProfiles),
|
||||
...registered.filter((app) => !isBuiltInApp(app.slug)).map(registeredAppToProfile),
|
||||
];
|
||||
}
|
||||
15
src/app.ts
15
src/app.ts
|
|
@ -24,7 +24,6 @@ import {
|
|||
} from "./contracts.js";
|
||||
import { issueAccessClaim, type IssueAccessClaimInput } from "./claims.js";
|
||||
import { builtInAppProfiles, getAppProfile, isAllowedReturnOrigin, serializeAppProfile, supportsProvider } from "./app-profiles.js";
|
||||
import { listAppProfiles, resolveAppProfile } from "./app-registry.js";
|
||||
import { renderBrowserHandoffPage } from "./browser-handoff.js";
|
||||
import { type HeimdallConfig, loadConfig } from "./config.js";
|
||||
import { createTokenCustody, type TokenCustody } from "./custody.js";
|
||||
|
|
@ -429,7 +428,7 @@ async function evaluateStoredEntitlements(options: {
|
|||
entitlementPolicies: OAuthEntitlementPolicy[];
|
||||
now: string;
|
||||
}): Promise<string[]> {
|
||||
const profile = await resolveAppProfile(options.store, options.appSlug);
|
||||
const profile = getAppProfile(options.appSlug);
|
||||
if (!profile) {
|
||||
throw new Error(`Unknown app '${options.appSlug}'.`);
|
||||
}
|
||||
|
|
@ -530,8 +529,8 @@ export async function startOAuthFlow(
|
|||
trustedBrowserAttemptId?: string;
|
||||
}
|
||||
): Promise<HandlerResult> {
|
||||
const { config, keys, store } = ctx;
|
||||
const profile = await resolveAppProfile(store, input.appSlug);
|
||||
const { config, keys } = ctx;
|
||||
const profile = getAppProfile(input.appSlug);
|
||||
if (!profile) {
|
||||
return { statusCode: 404, body: { error: "unknown_app", detail: `No app '${input.appSlug}' is registered.` } };
|
||||
}
|
||||
|
|
@ -768,7 +767,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
app.get("/.well-known/heimdall-configuration", async () => buildDiscovery(config));
|
||||
|
||||
app.get("/v1/apps", async () => ({
|
||||
apps: (await listAppProfiles(store)).map(serializeAppProfile),
|
||||
apps: Object.values(builtInAppProfiles).map(serializeAppProfile),
|
||||
}));
|
||||
|
||||
app.get<{ Params: { appSlug: AppSlug } }>(
|
||||
|
|
@ -786,7 +785,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const profile = await resolveAppProfile(store, request.params.appSlug);
|
||||
const profile = getAppProfile(request.params.appSlug);
|
||||
if (!profile) {
|
||||
reply.code(404);
|
||||
return { error: "unknown_app", detail: `No app '${request.params.appSlug}' is registered.` };
|
||||
|
|
@ -1539,7 +1538,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const profile = await resolveAppProfile(store, request.params.appSlug);
|
||||
const profile = getAppProfile(request.params.appSlug);
|
||||
if (!profile) {
|
||||
reply.code(404);
|
||||
return { error: "unknown_app", detail: `No app '${request.params.appSlug}' is registered.` };
|
||||
|
|
@ -1690,7 +1689,7 @@ export async function buildApp(options: BuildAppOptions = {}): Promise<FastifyIn
|
|||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const profile = await resolveAppProfile(store, request.params.appSlug);
|
||||
const profile = getAppProfile(request.params.appSlug);
|
||||
if (!profile) {
|
||||
reply.code(404);
|
||||
return { error: "unknown_app", detail: `No app '${request.params.appSlug}' is registered.` };
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ import {
|
|||
type LinkedIdentityInput,
|
||||
type RefreshTokenPayload,
|
||||
} from "./contracts.js";
|
||||
import { evaluateSharedCapabilities, type AppProfile } from "./app-profiles.js";
|
||||
import { resolveAppProfile } from "./app-registry.js";
|
||||
import { evaluateSharedCapabilities, getAppProfile, type AppProfile } from "./app-profiles.js";
|
||||
import { type HeimdallConfig } from "./config.js";
|
||||
import { identityFacts } from "./facts.js";
|
||||
import { signJwt, type RuntimeKeyMaterial } from "./signing.js";
|
||||
|
|
@ -75,7 +74,7 @@ export async function issueAccessClaim(options: {
|
|||
store: HeimdallStore;
|
||||
input: IssueAccessClaimInput;
|
||||
}): Promise<IssuedAccessClaimResult> {
|
||||
const profile = await resolveAppProfile(options.store, options.input.appSlug);
|
||||
const profile = getAppProfile(options.input.appSlug);
|
||||
if (!profile) {
|
||||
// An unregistered audience must not receive a signed claim: the token
|
||||
// would name an app no verifier can resolve a profile for.
|
||||
|
|
|
|||
|
|
@ -9,12 +9,11 @@ import {
|
|||
import { type FastifyInstance } from "fastify";
|
||||
import { getHeimdallRuntimeContext, refreshAppSession, startOAuthFlow, verifyRefreshToken } from "./app.js";
|
||||
import { callerFromOpenedEnvelope } from "./app-caller.js";
|
||||
import { resolveAppProfile } from "./app-registry.js";
|
||||
import { getAppProfile } from "./app-profiles.js";
|
||||
import { executeHeimdallAccessPlugin, HEIMDALL_ACCESS_PLUGIN_ID, type EvePluginAbiRequest } from "./access-plugin.js";
|
||||
import { isAppSlug, oauthModes, providers, type AppSlug, type OAuthEntitlementPolicy, type OAuthMode, type Provider } from "./contracts.js";
|
||||
import { type HeimdallConfig } from "./config.js";
|
||||
import { openPrivateEnvelope, sealPrivateEnvelope, type HeimdallPrivateEnvelope } from "./private-command-security.js";
|
||||
import { type HeimdallStore } from "./store/types.js";
|
||||
|
||||
export const HEIMDALL_PRIVATE_COMMAND_SERVICE = "heimdall.private.commands";
|
||||
export const HEIMDALL_PRIVATE_ENVELOPE_SCHEMA = "heimdall.private_command_envelope.v1";
|
||||
|
|
@ -228,7 +227,7 @@ async function refreshAuth(
|
|||
// handler function the HTTP route uses rather than forging the HTTP header
|
||||
// back at itself.
|
||||
const context = getHeimdallRuntimeContext(app);
|
||||
await requireEntitlementPolicyIfProfileDemandsIt(context.store, appSlug, entitlementPolicy, "refresh");
|
||||
await requireEntitlementPolicyIfProfileDemandsIt(appSlug, entitlementPolicy, "refresh");
|
||||
const result = await refreshAppSession(context, appSlug, callerFromOpenedEnvelope(appSlug), {
|
||||
refreshToken,
|
||||
...(entitlementPolicy ? { entitlementPolicy } : {}),
|
||||
|
|
@ -264,7 +263,7 @@ async function beginAuth(
|
|||
if (!providers.includes(provider) || !oauthModes.includes(mode) || !returnTo) throw new Error("Auth begin payload is incomplete.");
|
||||
const entitlementPolicy = parseEntitlementPolicy(payload.entitlementPolicy);
|
||||
const store = getHeimdallRuntimeContext(app).store;
|
||||
await requireEntitlementPolicyIfProfileDemandsIt(store, appSlug, entitlementPolicy, "authentication");
|
||||
await requireEntitlementPolicyIfProfileDemandsIt(appSlug, entitlementPolicy, "authentication");
|
||||
const now = new Date();
|
||||
const attempt = await store.createAuthAttempt({
|
||||
handle: randomUUID(),
|
||||
|
|
@ -392,12 +391,11 @@ function parseEntitlementPolicy(value: unknown): OAuthEntitlementPolicy | undefi
|
|||
* need declares it in its profile instead of adding another branch.
|
||||
*/
|
||||
async function requireEntitlementPolicyIfProfileDemandsIt(
|
||||
store: HeimdallStore,
|
||||
appSlug: AppSlug,
|
||||
entitlementPolicy: OAuthEntitlementPolicy | undefined,
|
||||
action: "authentication" | "refresh",
|
||||
): Promise<void> {
|
||||
const profile = await resolveAppProfile(store, appSlug);
|
||||
const profile = getAppProfile(appSlug);
|
||||
const requiredKind = profile?.requiredEntitlementPolicyKind;
|
||||
if (requiredKind && entitlementPolicy?.kind !== requiredKind) {
|
||||
throw new Error(`${appSlug} ${action} requires its caller-owned ${requiredKind} policy.`);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import {
|
|||
type StoredAuthCompletion,
|
||||
type StoredCapabilityGrant,
|
||||
type StoredLinkedIdentity,
|
||||
type StoredRegisteredApp,
|
||||
type StoredSession,
|
||||
type StoredPrivateCommandReceipt,
|
||||
type UpsertLinkedIdentityInput,
|
||||
|
|
@ -38,7 +37,6 @@ function isGrantActive(grant: StoredCapabilityGrant, appSlug: AppSlug, at: strin
|
|||
}
|
||||
|
||||
export class InMemoryStore implements HeimdallStore {
|
||||
private readonly registeredApps = new Map<string, StoredRegisteredApp>();
|
||||
private readonly accounts = new Map<string, StoredAccount>();
|
||||
private readonly linkedIdentities = new Map<string, StoredLinkedIdentity>();
|
||||
private readonly grants = new Map<string, StoredCapabilityGrant>();
|
||||
|
|
@ -50,27 +48,6 @@ export class InMemoryStore implements HeimdallStore {
|
|||
private readonly entitlementSnapshots = new Map<string, CreateEntitlementSnapshotInput>();
|
||||
private readonly auditEvents = new Map<string, CreateAuditEventInput>();
|
||||
|
||||
/**
|
||||
* Test/ops seam only — not part of HeimdallStore. There is no production
|
||||
* writer for `registered_apps` anymore; a real deployment provisions a row
|
||||
* directly against Postgres. This lets fixtures exercise resolveAppProfile's
|
||||
* non-built-in branch the same way.
|
||||
*/
|
||||
seedRegisteredApp(record: StoredRegisteredApp): void {
|
||||
this.registeredApps.set(record.slug, structuredClone(record));
|
||||
}
|
||||
|
||||
async findRegisteredApp(slug: string): Promise<StoredRegisteredApp | null> {
|
||||
const record = this.registeredApps.get(slug);
|
||||
return record ? structuredClone(record) : null;
|
||||
}
|
||||
|
||||
async listRegisteredApps(): Promise<StoredRegisteredApp[]> {
|
||||
return [...this.registeredApps.values()]
|
||||
.sort((left, right) => left.slug.localeCompare(right.slug))
|
||||
.map((record) => structuredClone(record));
|
||||
}
|
||||
|
||||
async ensureSchema(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { randomUUID } from "node:crypto";
|
||||
import { Pool, type PoolClient, type QueryResultRow } from "pg";
|
||||
import { type CapabilityDefinition } from "../capability-rules.js";
|
||||
import { type AppSlug, type HeimdallAuthAttemptStatus, type LinkedIdentityInput, type Provider } from "../contracts.js";
|
||||
import { CREATE_SCHEMA_SQL } from "./schema.js";
|
||||
import {
|
||||
|
|
@ -18,7 +17,6 @@ import {
|
|||
type StoredAuthCompletion,
|
||||
type StoredCapabilityGrant,
|
||||
type StoredLinkedIdentity,
|
||||
type StoredRegisteredApp,
|
||||
type StoredSession,
|
||||
type StoredPrivateCommandReceipt,
|
||||
type UpsertLinkedIdentityInput,
|
||||
|
|
@ -63,19 +61,6 @@ interface GrantRow extends QueryResultRow {
|
|||
updated_at: string;
|
||||
}
|
||||
|
||||
interface RegisteredAppRow extends QueryResultRow {
|
||||
slug: string;
|
||||
display_name: string;
|
||||
profile_version: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
identity_providers: Provider[];
|
||||
entitlement_sources: Provider[];
|
||||
managed_connection_providers: Provider[];
|
||||
capabilities_json: CapabilityDefinition[];
|
||||
redirect_uris: string[];
|
||||
}
|
||||
|
||||
interface SessionRow extends QueryResultRow {
|
||||
id: string;
|
||||
account_id: string;
|
||||
|
|
@ -302,28 +287,6 @@ function mapAuthAttemptRow(row: AuthAttemptRow): StoredAuthAttempt {
|
|||
export class PostgresStore implements HeimdallStore {
|
||||
constructor(private readonly pool: Pick<Pool, "query" | "end">) {}
|
||||
|
||||
// There is no production writer for registered_apps anymore (the
|
||||
// caller-identity cut deleted the runtime registration surface that minted
|
||||
// a client_secret nobody verified). A row can still be provisioned by
|
||||
// direct SQL against this table; findRegisteredApp/listRegisteredApps below
|
||||
// keep reading it as a profile source beneath the built-in profiles.
|
||||
|
||||
async findRegisteredApp(slug: string): Promise<StoredRegisteredApp | null> {
|
||||
const result = await this.pool.query<RegisteredAppRow>(
|
||||
`SELECT * FROM registered_apps WHERE slug = $1`,
|
||||
[slug],
|
||||
);
|
||||
const row = result.rows[0];
|
||||
return row ? mapRegisteredApp(row) : null;
|
||||
}
|
||||
|
||||
async listRegisteredApps(): Promise<StoredRegisteredApp[]> {
|
||||
const result = await this.pool.query<RegisteredAppRow>(
|
||||
`SELECT * FROM registered_apps ORDER BY slug ASC`,
|
||||
);
|
||||
return result.rows.map(mapRegisteredApp);
|
||||
}
|
||||
|
||||
async ensureSchema(): Promise<void> {
|
||||
await this.pool.query(CREATE_SCHEMA_SQL);
|
||||
}
|
||||
|
|
@ -834,18 +797,3 @@ export function createPostgresStore(databaseUrl: string): HeimdallStore {
|
|||
});
|
||||
return new PostgresStore(pool);
|
||||
}
|
||||
|
||||
function mapRegisteredApp(row: RegisteredAppRow): StoredRegisteredApp {
|
||||
return {
|
||||
slug: row.slug,
|
||||
displayName: row.display_name,
|
||||
profileVersion: row.profile_version,
|
||||
createdAt: new Date(row.created_at).toISOString(),
|
||||
updatedAt: new Date(row.updated_at).toISOString(),
|
||||
identityProviders: row.identity_providers,
|
||||
entitlementSources: row.entitlement_sources,
|
||||
managedConnectionProviders: row.managed_connection_providers,
|
||||
capabilities: row.capabilities_json,
|
||||
redirectUris: row.redirect_uris,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,11 @@
|
|||
export const CREATE_SCHEMA_SQL = `
|
||||
CREATE TABLE IF NOT EXISTS registered_apps (
|
||||
slug TEXT PRIMARY KEY,
|
||||
display_name TEXT NOT NULL,
|
||||
profile_version TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
identity_providers JSONB NOT NULL,
|
||||
entitlement_sources JSONB NOT NULL,
|
||||
managed_connection_providers JSONB NOT NULL,
|
||||
capabilities_json JSONB NOT NULL,
|
||||
redirect_uris JSONB NOT NULL
|
||||
);
|
||||
|
||||
-- Runtime app registration (POST /v1/apps) minted a client_secret_hash that
|
||||
-- nothing ever verified. Deleted with the caller-identity cut; drop the
|
||||
-- column on any store built before this schema too.
|
||||
ALTER TABLE registered_apps DROP COLUMN IF EXISTS client_secret_hash;
|
||||
-- nothing ever verified, and the registered_apps table it fed was
|
||||
-- unreachable dead code even after that writer was deleted: every HTTP route
|
||||
-- already enumerates the four built-in app slugs in its own JSON schema, so a
|
||||
-- registered row could never be resolved from a request (R21.3). Drop the
|
||||
-- table on any store built before this schema too.
|
||||
DROP TABLE IF EXISTS registered_apps;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id TEXT PRIMARY KEY,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { type CapabilityDefinition } from "../capability-rules.js";
|
||||
import {
|
||||
type AppSlug,
|
||||
type HeimdallAuthAttemptStatus,
|
||||
|
|
@ -7,27 +6,6 @@ import {
|
|||
type Provider,
|
||||
} from "../contracts.js";
|
||||
|
||||
/**
|
||||
* An app registered at runtime.
|
||||
*
|
||||
* The built-in profiles are seed data of the same shape; nothing here is
|
||||
* special-cased for them. There is no runtime registration authority anymore
|
||||
* (deleted with the auth-hole cut: a minted client_secret nobody verified);
|
||||
* this remains a profile store consulted by resolveAppProfile.
|
||||
*/
|
||||
export interface StoredRegisteredApp {
|
||||
slug: string;
|
||||
displayName: string;
|
||||
profileVersion: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
identityProviders: Provider[];
|
||||
entitlementSources: Provider[];
|
||||
managedConnectionProviders: Provider[];
|
||||
capabilities: CapabilityDefinition[];
|
||||
redirectUris: string[];
|
||||
}
|
||||
|
||||
export interface StoredAccount {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
|
|
@ -225,16 +203,6 @@ export interface StoredPrivateCommandReceipt {
|
|||
export type CreatePrivateCommandReceiptInput = StoredPrivateCommandReceipt;
|
||||
|
||||
export interface HeimdallStore {
|
||||
/**
|
||||
* There is no runtime writer for this table anymore (the caller-identity
|
||||
* cut deleted the registration surface that minted a client_secret nobody
|
||||
* verified). A profile row can still be provisioned directly against the
|
||||
* store outside the app, which is how the InMemoryStore test double and any
|
||||
* future ops-side seeding populate it; `resolveAppProfile` keeps consulting
|
||||
* it below the built-in profiles.
|
||||
*/
|
||||
findRegisteredApp(slug: string): Promise<StoredRegisteredApp | null>;
|
||||
listRegisteredApps(): Promise<StoredRegisteredApp[]>;
|
||||
ensureSchema(): Promise<void>;
|
||||
close(): Promise<void>;
|
||||
createAccount(input: CreateAccountInput): Promise<StoredAccount>;
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { isBuiltInApp, listAppProfiles, resolveAppProfile } from "../src/app-registry.js";
|
||||
import { evaluateCapabilityRules } from "../src/capability-rules.js";
|
||||
import { type CapabilityDefinition } from "../src/capability-rules.js";
|
||||
import { entitlementFacts, grantFacts, identityFacts } from "../src/facts.js";
|
||||
import { InMemoryStore } from "../src/store/in-memory.js";
|
||||
import { type StoredRegisteredApp } from "../src/store/types.js";
|
||||
|
||||
const registeredApp = (overrides: Partial<StoredRegisteredApp> = {}): StoredRegisteredApp => ({
|
||||
slug: "erycina",
|
||||
displayName: "Erycina",
|
||||
profileVersion: "2026-01-01",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
identityProviders: ["discord"],
|
||||
entitlementSources: [],
|
||||
managedConnectionProviders: [],
|
||||
capabilities: [
|
||||
{ key: "viewer_access", mode: "shared", summary: "Signed-in viewer.", anyOf: [identityFacts.authenticated] },
|
||||
] as CapabilityDefinition[],
|
||||
redirectUris: ["https://erycina.example/auth/callback"],
|
||||
...overrides,
|
||||
});
|
||||
|
||||
let store: InMemoryStore;
|
||||
beforeEach(() => {
|
||||
store = new InMemoryStore();
|
||||
});
|
||||
|
||||
/**
|
||||
* There is no runtime registration authority anymore (deleted with the
|
||||
* caller-identity cut: registerApp minted a client_secret nobody verified,
|
||||
* and validateAppRegistration/AppRegistrationRequest/RegistrationProblem/
|
||||
* AppRegistrationError went with it). `registered_apps` remains a profile
|
||||
* store consulted below the built-in profiles; a real deployment provisions
|
||||
* a row directly against Postgres, and `seedRegisteredApp` is the equivalent
|
||||
* test/ops seam on the in-memory store.
|
||||
*/
|
||||
describe("resolveAppProfile", () => {
|
||||
it("resolves a registered app", async () => {
|
||||
store.seedRegisteredApp(registeredApp());
|
||||
const profile = await resolveAppProfile(store, "erycina");
|
||||
|
||||
expect(profile?.displayName).toBe("Erycina");
|
||||
});
|
||||
|
||||
it("resolves a built-in app without touching storage", async () => {
|
||||
expect((await resolveAppProfile(store, "bifrost"))?.displayName).toBe("Bifrost");
|
||||
});
|
||||
|
||||
it("returns null for an app nobody registered", async () => {
|
||||
expect(await resolveAppProfile(store, "nope")).toBeNull();
|
||||
});
|
||||
|
||||
it("a built-in cannot be shadowed even if a row exists for it", async () => {
|
||||
// The built-in lookup runs first; a row written by some other path
|
||||
// cannot hijack a shipped audience.
|
||||
store.seedRegisteredApp(registeredApp({ slug: "bifrost", displayName: "Impostor" }));
|
||||
|
||||
expect((await resolveAppProfile(store, "bifrost"))?.displayName).toBe("Bifrost");
|
||||
});
|
||||
});
|
||||
|
||||
describe("a registered profile evaluates like a built-in", () => {
|
||||
it("grants capabilities through the same evaluator", async () => {
|
||||
store.seedRegisteredApp(
|
||||
registeredApp({
|
||||
capabilities: [
|
||||
{ key: "member_access", mode: "shared", summary: "member", anyOf: [entitlementFacts.appAccess, grantFacts.globalMember] },
|
||||
{ key: "post_create", mode: "shared", summary: "post", anyOf: ["member_access"] },
|
||||
] as CapabilityDefinition[],
|
||||
}),
|
||||
);
|
||||
const profile = await resolveAppProfile(store, "erycina");
|
||||
|
||||
expect(evaluateCapabilityRules(profile!.capabilities, new Set([grantFacts.globalMember]))).toEqual([
|
||||
"member_access",
|
||||
"post_create",
|
||||
]);
|
||||
expect(evaluateCapabilityRules(profile!.capabilities, new Set([identityFacts.authenticated]))).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("listAppProfiles", () => {
|
||||
it("lists built-ins alongside registered apps", async () => {
|
||||
store.seedRegisteredApp(registeredApp());
|
||||
const slugs = (await listAppProfiles(store)).map((profile) => profile.slug);
|
||||
|
||||
expect(slugs).toContain("bifrost");
|
||||
expect(slugs).toContain("erycina");
|
||||
});
|
||||
|
||||
it("lists each app once", async () => {
|
||||
store.seedRegisteredApp(registeredApp());
|
||||
const slugs = (await listAppProfiles(store)).map((profile) => profile.slug);
|
||||
|
||||
expect(new Set(slugs).size).toBe(slugs.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isBuiltInApp", () => {
|
||||
it("knows the shipped profiles", () => {
|
||||
expect(isBuiltInApp("repixelizer")).toBe(true);
|
||||
expect(isBuiltInApp("erycina")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -318,23 +318,13 @@ describe("isAllowedReturnOrigin: origin comparison, not string matching", () =>
|
|||
expect(isAllowedReturnOrigin({ ...profile, allowedReturnOrigins: [] }, "https://repixelizer.gamecult.org/")).toBe(false);
|
||||
});
|
||||
|
||||
it("a registered app with no parseable redirect URIs cannot start a flow through HTTP at all (slug enum) and gets an empty allowlist", async () => {
|
||||
const store = new InMemoryStore();
|
||||
store.seedRegisteredApp({
|
||||
slug: "newapp",
|
||||
displayName: "New",
|
||||
profileVersion: "1",
|
||||
identityProviders: ["discord"],
|
||||
entitlementSources: [],
|
||||
managedConnectionProviders: [],
|
||||
capabilities: [],
|
||||
redirectUris: ["garbage"],
|
||||
clientSecretHash: "x",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
} as never);
|
||||
const app = await buildApp({ config: testConfig(), store, oauthRuntimes: { discord: identityByCodeRuntime() } });
|
||||
resources.push(app);
|
||||
// The registered-app path this test covered (seedRegisteredApp,
|
||||
// resolveAppProfile's non-built-in branch) was deleted in R21.3: every HTTP
|
||||
// route already enumerates the four built-in slugs in its own JSON schema,
|
||||
// so a registered row could never be reached over HTTP in the first place.
|
||||
// An unknown slug is now refused by that schema directly.
|
||||
it("an unknown appSlug cannot start a flow through HTTP at all (slug enum)", async () => {
|
||||
const { app } = await harness();
|
||||
const started = await start(app, { appSlug: "newapp", mode: "sign_in", returnTo: "https://anything.example/" });
|
||||
expect(started.statusCode).toBe(400);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue