Merge pull request #29332 from overleaf/as-sso-prevent-double-linking

[web] Prevent users from attempting to link to the same SSO institution twice

GitOrigin-RevId: 7e708eadc9f9aedc2007cb83f7f48df83561fa84
This commit is contained in:
MoxAmber
2025-10-30 09:06:42 +00:00
committed by Copybot
parent a29864ef86
commit e473010d46
2 changed files with 44 additions and 1 deletions
@@ -289,6 +289,32 @@ describe('<EmailsSection />', function () {
await screen.findByRole('button', { name: 'Link accounts and add email' })
})
it('prevents user from linking to same SSO institution twice', async function () {
fetchMock.get('/user/emails?ensureAffiliation=true', [
{ email: 'bar@autocomplete.edu', samlProviderId: '1234' },
])
render(<EmailsSection />)
const button = await screen.findByRole<HTMLButtonElement>('button', {
name: 'Add another email',
})
await fetchMock.callHistory.flush(true)
fetchMock.removeRoutes().clearHistory()
fetchMock.get('express:/institutions/domains', institutionDomainData)
await userEvent.click(button)
const input = screen.getByRole('textbox', { name: 'Email' })
fireEvent.change(input, {
target: { value: 'baz@autocomplete.edu' },
})
await screen.findByText(
'This institution is already linked with your account via another email address.'
)
})
it('adds new email address with existing institution and custom departments', async function () {
const country = 'Germany'
const customDepartment = 'Custom department'