Files
outline/server/models/oauth/OAuthAuthentication.test.ts
Tom MoorandClaude Fable 5.1 a577d5c2c8 fix: Validate API key and OAuth scopes at the model layer (#13664)
* fix: Validate API key scopes with Sequelize-level validators

* test: Add API regression tests for duplicate OAuth redirect URIs

* fix: Preserve wildcard scope and guard non-string redirect URIs

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 23:10:32 -04:00

73 lines
2.1 KiB
TypeScript

import { Scope } from "@shared/types";
import { buildOAuthAuthentication, buildUser } from "@server/test/factories";
describe("OAuthAuthentication", () => {
describe("scope", () => {
it("should reject malformed scopes", async () => {
const user = await buildUser();
await expect(
buildOAuthAuthentication({
user,
scope: ["documents:read,documents:write"],
})
).rejects.toThrow("Scope must be a valid API scope");
});
});
describe("canAccess", () => {
it("should allow MCP access for scoped tokens", async () => {
const user = await buildUser();
const authentication = await buildOAuthAuthentication({
user,
scope: [Scope.Read],
});
expect(authentication.canAccess("/mcp")).toBe(true);
expect(authentication.canAccess("/mcp/")).toBe(true);
});
it("should deny MCP access for tokens with empty scope", async () => {
const user = await buildUser();
const authentication = await buildOAuthAuthentication({
user,
scope: [],
});
expect(authentication.canAccess("/mcp")).toBe(false);
});
it("should deny MCP access when no scope is well-formed", async () => {
const user = await buildUser();
const authentication = await buildOAuthAuthentication({
user,
scope: [Scope.Read],
});
authentication.scope = ["documents:read,documents:write"];
expect(authentication.canAccess("/mcp")).toBe(false);
});
it("should always allow the revoke endpoint", async () => {
const user = await buildUser();
const authentication = await buildOAuthAuthentication({
user,
scope: [Scope.Read],
});
expect(authentication.canAccess("/oauth/revoke")).toBe(true);
});
it("should check scopes for API paths", async () => {
const user = await buildUser();
const authentication = await buildOAuthAuthentication({
user,
scope: [Scope.Read],
});
expect(authentication.canAccess("/api/documents.list")).toBe(true);
expect(authentication.canAccess("/api/documents.update")).toBe(false);
});
});
});