Files
outline/server/queues/tasks/CleanupOAuthAuthorizationCodeTask.test.ts
T
Tom Moor a06671e8ce OAuth provider (#8884)
This PR contains the necessary work to make Outline an OAuth provider including:

- OAuth app registration
- OAuth app management
- Private / public apps (Public in cloud only)
- Full OAuth 2.0 spec compatible authentication flow
- Granular scopes
- User token management screen in settings
- Associated API endpoints for programatic access
2025-05-03 19:40:18 -04:00

38 lines
1.2 KiB
TypeScript

import { subMonths } from "date-fns";
import { OAuthAuthorizationCode } from "@server/models";
import { buildOAuthAuthorizationCode } from "@server/test/factories";
import CleanupOAuthAuthorizationCodeTask from "./CleanupOAuthAuthorizationCodeTask";
const codeExists = async (code: OAuthAuthorizationCode) => {
const found = await OAuthAuthorizationCode.findByPk(code.id);
return !!found;
};
describe("CleanupOAuthAuthorizationCodeTask", () => {
it("should delete authorization codes expired more than one month ago", async () => {
const brandNewCode = await buildOAuthAuthorizationCode({
expiresAt: new Date(),
});
const oldCode = await buildOAuthAuthorizationCode({
expiresAt: subMonths(new Date(), 2),
});
const task = new CleanupOAuthAuthorizationCodeTask();
await task.perform();
expect(await codeExists(brandNewCode)).toBe(true);
expect(await codeExists(oldCode)).toBe(false);
});
it("should not delete codes that expired less than one month ago", async () => {
const recentCode = await buildOAuthAuthorizationCode({
expiresAt: new Date(),
});
const task = new CleanupOAuthAuthorizationCodeTask();
await task.perform();
expect(await codeExists(recentCode)).toBe(true);
});
});