Files
outline/plugins/oidc/server/auth/resolveProviderId.test.ts
Tom Moor 32b0f94d5a fix: Prefer OIDC provider record matching the configured hostname (#14389)
* fix: Prefer OIDC provider record matching the configured hostname

* test: Cover OIDC provider identifier resolution
2026-10-29 17:58:28 -04:00

52 lines
1.5 KiB
TypeScript

import { AuthenticationProvider } from "@server/models";
import { buildTeam } from "@server/test/factories";
import { resolveProviderId } from "./resolveProviderId";
describe("resolveProviderId", () => {
const hostname = "auth.example.com";
const domain = "legacy.example.org";
it("should return the hostname when there is no team", async () => {
expect(await resolveProviderId(undefined, hostname, domain)).toEqual(
hostname
);
});
it("should prefer the record for the configured hostname", async () => {
const team = await buildTeam({
authenticationProviders: [
{ name: "oidc", providerId: domain },
{ name: "oidc", providerId: hostname },
],
});
expect(await resolveProviderId(team.id, hostname, domain)).toEqual(
hostname
);
const providerIds = (
await AuthenticationProvider.findAll({
where: { name: "oidc", teamId: team.id },
})
).map((provider) => provider.providerId);
expect(providerIds.sort()).toEqual([hostname, domain].sort());
});
it("should move the identifier of an existing record to the hostname", async () => {
const team = await buildTeam({
authenticationProviders: [{ name: "oidc", providerId: domain }],
});
expect(await resolveProviderId(team.id, hostname, domain)).toEqual(
hostname
);
const providers = await AuthenticationProvider.findAll({
where: { name: "oidc", teamId: team.id },
});
expect(providers.map((provider) => provider.providerId)).toEqual([
hostname,
]);
});
});