feat(admin): remove the SSO link of an account whose provider changed its subject

A sign-in with another subject of the same provider is refused, so an
account whose provider re-issued the subject (a migrated or rebuilt IdP, a
changed sub format) was locked out: editing the email, as the wiki advised,
never touched the stored link. The edit dialog now offers "Remove SSO link"
for other accounts while SSO is set up (DELETE /api/admin/users/:id/sso,
audit admin.user_sso_unlink). The next SSO sign-in links again under the
rules of a first one, so it still needs a verified, not self-set email.
The log line names the remedy, and the wiki tells the two refusals apart.

Fixes #3065
This commit is contained in:
Maurice
2026-11-12 15:39:21 +01:00
parent a3a4f7cf79
commit b53130ca0d
43 changed files with 415 additions and 9 deletions
@@ -357,6 +357,42 @@ describe('AdminController addons + sessions + jwt + defaults', () => {
});
});
describe('AdminController SSO unlink (#3065)', () => {
it('ADMIN-CTRL-SSO-001: audits a removed link and answers unlinked: true', async () => {
writeAudit.mockClear();
const unlinkUserSso = vi.fn().mockResolvedValue({ email: 'a@b.c', unlinked: true });
expect(await adminCtl(svc({ unlinkUserSso } as Partial<AdminService>)).unlinkUserSso(user, '4', req)).toEqual({
success: true,
unlinked: true,
});
expect(unlinkUserSso).toHaveBeenCalledWith('4', user.id);
expect(writeAudit).toHaveBeenCalledWith(
expect.objectContaining({ action: 'admin.user_sso_unlink', resource: '4', details: { targetUser: 'a@b.c' } }),
);
});
it('ADMIN-CTRL-SSO-002: writes no audit row when there was no link, and maps the self refusal', async () => {
writeAudit.mockClear();
expect(
await adminCtl(
svc({ unlinkUserSso: vi.fn().mockResolvedValue({ email: 'a@b.c', unlinked: false }) } as Partial<AdminService>),
).unlinkUserSso(user, '4', req),
).toEqual({ success: true, unlinked: false });
expect(writeAudit).not.toHaveBeenCalled();
expect(
await thrown(() =>
adminCtl(
svc({
unlinkUserSso: vi
.fn()
.mockRejectedValue(new DomainError(400, 'You cannot remove the SSO link of your own account')),
} as Partial<AdminService>),
).unlinkUserSso(user, '1', req),
),
).toEqual({ status: 400, body: { error: 'You cannot remove the SSO link of your own account' } });
});
});
describe('AdminController read-only getters', () => {
it('return service values verbatim', async () => {
expect(