mirror of
https://github.com/outline/outline.git
synced 2026-12-03 01:59:03 +03:00
MCP clients can send an https URL as their client_id. The server fetches the metadata document at that URL and caches one team-less client row per URL, so MCP works on the root domain without dynamic registration. Closes #14010
103 lines
3.2 KiB
TypeScript
103 lines
3.2 KiB
TypeScript
import { Scope } from "@shared/types";
|
|
import { OAuthAuthentication, OAuthAuthorizationCode } from "@server/models";
|
|
import {
|
|
buildOAuthAuthentication,
|
|
buildOAuthAuthorizationCode,
|
|
buildMetadataDocumentOAuthClient,
|
|
buildOAuthClient,
|
|
buildUser,
|
|
} from "@server/test/factories";
|
|
import RevokeDynamicOAuthClientsTask from "./RevokeDynamicOAuthClientsTask";
|
|
|
|
describe("RevokeDynamicOAuthClientsTask", () => {
|
|
it("should revoke tokens and codes held by dynamic clients", async () => {
|
|
const user = await buildUser();
|
|
const client = await buildOAuthClient({
|
|
teamId: user.teamId,
|
|
createdById: null,
|
|
});
|
|
const authentication = await buildOAuthAuthentication({
|
|
user,
|
|
oauthClientId: client.id,
|
|
scope: [Scope.Read],
|
|
});
|
|
const code = await buildOAuthAuthorizationCode({
|
|
userId: user.id,
|
|
oauthClientId: client.id,
|
|
});
|
|
|
|
const task = new RevokeDynamicOAuthClientsTask();
|
|
await task.perform({ teamId: user.teamId });
|
|
|
|
expect(await OAuthAuthentication.findByPk(authentication.id)).toBeNull();
|
|
expect(await OAuthAuthorizationCode.findByPk(code.id)).toBeNull();
|
|
});
|
|
|
|
it("should not revoke tokens held by user created clients", async () => {
|
|
const user = await buildUser();
|
|
const client = await buildOAuthClient({ teamId: user.teamId });
|
|
const authentication = await buildOAuthAuthentication({
|
|
user,
|
|
oauthClientId: client.id,
|
|
scope: [Scope.Read],
|
|
});
|
|
|
|
const task = new RevokeDynamicOAuthClientsTask();
|
|
await task.perform({ teamId: user.teamId });
|
|
|
|
expect(
|
|
await OAuthAuthentication.findByPk(authentication.id)
|
|
).not.toBeNull();
|
|
});
|
|
|
|
it("should not revoke tokens held by dynamic clients in another team", async () => {
|
|
const user = await buildUser();
|
|
const other = await buildUser();
|
|
const client = await buildOAuthClient({
|
|
teamId: other.teamId,
|
|
createdById: null,
|
|
});
|
|
const authentication = await buildOAuthAuthentication({
|
|
user: other,
|
|
oauthClientId: client.id,
|
|
scope: [Scope.Read],
|
|
});
|
|
|
|
const task = new RevokeDynamicOAuthClientsTask();
|
|
await task.perform({ teamId: user.teamId });
|
|
|
|
expect(
|
|
await OAuthAuthentication.findByPk(authentication.id)
|
|
).not.toBeNull();
|
|
});
|
|
|
|
it("should revoke metadata document grants held only by users in the team", async () => {
|
|
const user = await buildUser();
|
|
const other = await buildUser();
|
|
const client = await buildMetadataDocumentOAuthClient();
|
|
const authentication = await buildOAuthAuthentication({
|
|
user,
|
|
oauthClientId: client.id,
|
|
scope: [Scope.Read],
|
|
});
|
|
const otherAuthentication = await buildOAuthAuthentication({
|
|
user: other,
|
|
oauthClientId: client.id,
|
|
scope: [Scope.Read],
|
|
});
|
|
const code = await buildOAuthAuthorizationCode({
|
|
userId: user.id,
|
|
oauthClientId: client.id,
|
|
});
|
|
|
|
const task = new RevokeDynamicOAuthClientsTask();
|
|
await task.perform({ teamId: user.teamId });
|
|
|
|
expect(await OAuthAuthentication.findByPk(authentication.id)).toBeNull();
|
|
expect(await OAuthAuthorizationCode.findByPk(code.id)).toBeNull();
|
|
expect(
|
|
await OAuthAuthentication.findByPk(otherAuthentication.id)
|
|
).not.toBeNull();
|
|
});
|
|
});
|