Files
outline/server/queues/tasks/ValidateSSOAccessTask.test.ts
T
Tom MoorandClaude Fable 5.1 abc47b442a feat: Sync group descriptions and re-sync groups on SSO validation (#13889)
* feat: Sync group descriptions and re-sync groups on SSO validation

- Sync group descriptions from group sync providers alongside names
- Lock name and description edits for externally synced groups at the
  API layer and in the edit dialog
- Move group sync into a SyncUserGroupsTask, scheduled from login and
  from ValidateSSOAccessTask after a fresh provider validation
- Add authenticationProviders.startGroupSync for providers that require
  an admin consent flow before group sync can be enabled

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: Make group sync setup generic and deduplicate sync jobs

- Expose groupSyncRequiresSetup from the provider list and use it in the
  settings scene instead of checking for the azure provider name
- Rename the setup redirect query param to groupSync
- Give SyncUserGroupsTask a job id per user authentication so concurrent
  syncs for the same authentication are not queued twice

* Use existing hook

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-25 19:49:26 -04:00

47 lines
1.6 KiB
TypeScript

import { subMinutes } from "date-fns";
import { UserAuthentication } from "@server/models";
import { buildUser } from "@server/test/factories";
import { mockTaskSchedule } from "@server/test/support";
import SyncUserGroupsTask from "./SyncUserGroupsTask";
import ValidateSSOAccessTask from "./ValidateSSOAccessTask";
async function setup({ lastValidatedAt }: { lastValidatedAt: Date }) {
const user = await buildUser();
const authentication = (await UserAuthentication.findOne({
where: { userId: user.id },
}))!;
await UserAuthentication.update(
{ lastValidatedAt },
{ where: { id: authentication.id }, hooks: false }
);
return { user, authentication };
}
describe("ValidateSSOAccessTask", () => {
const schedule = mockTaskSchedule();
it("should schedule a group sync after a fresh validation", async () => {
const { user, authentication } = await setup({
lastValidatedAt: subMinutes(new Date(), 10),
});
await new ValidateSSOAccessTask().perform({ userId: user.id });
expect(schedule).toHaveBeenCalledTimes(1);
expect(schedule.mock.instances[0]).toBeInstanceOf(SyncUserGroupsTask);
expect(schedule).toHaveBeenCalledWith(
{ userAuthenticationId: authentication.id },
{ jobId: `sync-user-groups:${authentication.id}` }
);
});
it("should not schedule a group sync when validation was skipped as recent", async () => {
const { user } = await setup({ lastValidatedAt: new Date() });
await new ValidateSSOAccessTask().perform({ userId: user.id });
expect(schedule).not.toHaveBeenCalled();
});
});