Files
outline/server/models/oauth/OAuthClient.test.ts
T
Tom Moor 0a5d03cc62 refactor: Simplify client ID metadata document handling
- Gate metadata document fetches on the MCP preference inside the helper
- Add isMCPClient getter and a shared client ID prefix constant
- Enforce the team/metadata document CHECK in both directions
- Index oauthClientId on OAuth token and code tables
- Reuse parseDomain, clamp and time helpers
2026-10-11 22:14:52 -04:00

65 lines
2.0 KiB
TypeScript

import { randomUUID } from "node:crypto";
import { OAuthClient } from "@server/models";
import {
buildMetadataDocumentOAuthClient,
buildOAuthClient,
buildTeam,
} from "@server/test/factories";
describe("OAuthClient", () => {
describe("isDCR and isCIMD", () => {
it("should identify a dynamically registered client", async () => {
const client = await buildOAuthClient({ createdById: null });
expect(client.isDCR).toBe(true);
expect(client.isCIMD).toBe(false);
expect(client.clientSecret).toBeTruthy();
expect(client.registrationAccessTokenHash).toBeTruthy();
});
it("should identify a user created client", async () => {
const client = await buildOAuthClient();
expect(client.isDCR).toBe(false);
expect(client.isCIMD).toBe(false);
expect(client.registrationAccessTokenHash).toBeNull();
});
it("should identify a metadata document client", async () => {
const clientId = `https://${randomUUID()}.example.com/client.json`;
const client = await buildMetadataDocumentOAuthClient({ clientId });
expect(client.isDCR).toBe(false);
expect(client.isCIMD).toBe(true);
expect(client.clientId).toEqual(clientId);
expect(client.clientSecret).toBeNull();
expect(client.registrationAccessTokenHash).toBeNull();
});
});
describe("constraints", () => {
it("should not allow a client without a team unless it uses a metadata document", async () => {
const client = await buildOAuthClient({ createdById: null });
await expect(
OAuthClient.update(
{ teamId: null },
{ where: { id: client.id }, hooks: false }
)
).rejects.toThrow();
});
it("should not allow a metadata document client to have a team", async () => {
const team = await buildTeam();
const client = await buildMetadataDocumentOAuthClient();
await expect(
OAuthClient.update(
{ teamId: team.id },
{ where: { id: client.id }, hooks: false }
)
).rejects.toThrow();
});
});
});