Files
outline/server/routes/auth/index.test.ts
2026-01-10 16:29:44 +00:00

47 lines
1.4 KiB
TypeScript

import { buildUser, buildCollection } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("auth/redirect", () => {
it("should redirect to home", async () => {
const user = await buildUser();
const res = await server.get(
`/auth/redirect?token=${user.getTransferToken()}`,
{
redirect: "manual",
}
);
expect(res.status).toEqual(302);
expect(res.headers.get("location")).not.toBeNull();
expect(res.headers.get("location")!.endsWith("/home")).toBeTruthy();
});
it("should redirect to first collection", async () => {
const collection = await buildCollection();
const user = await buildUser({
teamId: collection.teamId,
});
const res = await server.get(
`/auth/redirect?token=${user.getTransferToken()}`,
{
redirect: "manual",
}
);
expect(res.status).toEqual(302);
expect(res.headers.get("location")).not.toBeNull();
expect(res.headers.get("location")!.includes(collection.path)).toBeTruthy();
});
it("should prevent token extension by rejecting JWT tokens", async () => {
const user = await buildUser();
const jwtToken = user.getJwtToken();
const res = await server.get(`/auth/redirect?token=${jwtToken}`, {
redirect: "manual",
});
expect(res.status).toEqual(401);
});
});