mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Prevent error when switching accounts
This commit is contained in:
parent
137027e421
commit
68975e6627
@ -86,4 +86,12 @@ export async function forgetWebId(provider: Provider, oidcInteraction: Interacti
|
||||
delete session.accountId;
|
||||
await session.persist();
|
||||
}
|
||||
|
||||
// If a client previously successfully completed an interaction a grant will have been created.
|
||||
// If the same session gets reused to authenticate with a different WebID,
|
||||
// we need to first delete the previous grant as the oidc-provider will try to reuse it.
|
||||
if (oidcInteraction.grantId) {
|
||||
const grant = await provider.Grant.find(oidcInteraction.grantId);
|
||||
await grant?.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -85,14 +85,31 @@ describe('InteractionUtil', (): void => {
|
||||
persist: jest.fn(),
|
||||
}),
|
||||
},
|
||||
Grant: {
|
||||
find: jest.fn().mockResolvedValue({
|
||||
destroy: jest.fn(),
|
||||
}),
|
||||
},
|
||||
} as any;
|
||||
});
|
||||
|
||||
it('removes the accountId from the session.', async(): Promise<void> => {
|
||||
await expect(forgetWebId(provider, oidcInteraction)).resolves.toBeUndefined();
|
||||
expect(provider.Session.find).toHaveBeenCalledTimes(1);
|
||||
expect(provider.Session.find).toHaveBeenLastCalledWith('cookie');
|
||||
const session = await (provider.Session.find as jest.Mock).mock.results[0].value;
|
||||
expect(session.accountId).toBeUndefined();
|
||||
expect(session.persist).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('deletes the grant if there is one associated to the session.', async(): Promise<void> => {
|
||||
delete oidcInteraction.session;
|
||||
oidcInteraction.grantId = 'grantId';
|
||||
await expect(forgetWebId(provider, oidcInteraction)).resolves.toBeUndefined();
|
||||
expect(provider.Grant.find).toHaveBeenCalledTimes(1);
|
||||
expect(provider.Grant.find).toHaveBeenLastCalledWith('grantId');
|
||||
const grant = await (provider.Grant.find as jest.Mock).mock.results[0].value;
|
||||
expect(grant.destroy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user