mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* 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>
73 lines
2.1 KiB
TypeScript
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);
|
|
});
|
|
});
|
|
});
|