Merge pull request #7946 from overleaf/msm-settings-domain-blocklist

[Settings] domain blocklist for email autocompletion

GitOrigin-RevId: 62444f0f903ce3feae585c84c9f01164eac42a1f
This commit is contained in:
Timothée Alby 2022-05-16 10:03:16 +02:00 committed by Copybot
parent 920a5921c7
commit 8c611a8f49
3 changed files with 82 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import {
} from 'react'
import { getJSON } from '../../../../../infrastructure/fetch-json'
import useAbortController from '../../../../../shared/hooks/use-abort-controller'
import domainBlocklist from '../../../domain-blocklist'
const LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
@ -91,6 +92,9 @@ function Input({ onChange }: InputProps) {
if (!(data && data[0])) {
return
}
if (domainBlocklist.has(data[0].hostname)) {
return
}
const hostname = data[0]?.hostname
if (hostname) {
domainCache.set(match.domain, data[0])

View file

@ -0,0 +1,61 @@
const domainBlocklist = new Set(['overleaf.com'])
const commonTLDs = [
'br',
'cn',
'co',
'co.jp',
'co.uk',
'com',
'com.au',
'de',
'fr',
'in',
'info',
'io',
'net',
'no',
'ru',
'se',
'us',
'com.tw',
'com.br',
'pl',
'it',
'co.in',
'com.mx',
] as const
const commonDomains = [
'gmail',
'googlemail',
'icloud',
'me',
'yahoo',
'ymail',
'yahoomail',
'hotmail',
'live',
'msn',
'outlook',
'gmx',
'mail',
'aol',
'163',
'mac',
'qq',
'o2',
'libero',
'126',
'protonmail',
'yandex',
'yeah',
'web',
'foxmail',
] as const
for (const domain of commonDomains) {
for (const tld of commonTLDs) {
domainBlocklist.add(`${domain}.${tld}`)
}
}
export default domainBlocklist

View file

@ -189,6 +189,23 @@ describe('<AddEmailInput/>', function () {
})
})
describe('when there is a match for a blocklisted domain', function () {
beforeEach(function () {
const blockedInstitution = [
{ university: { id: 1 }, hostname: 'overleaf.com' },
]
fetchMock.get('express:/institutions/domains', blockedInstitution)
fireEvent.change(screen.getByRole('textbox'), {
target: { value: 'user@o' },
})
})
it('should not render the suggestion', async function () {
await fetchMock.flush(true)
expect(screen.queryByText('user@overleaf.com')).to.be.null
})
})
describe('while waiting for a response', function () {
beforeEach(async function () {
// type an initial suggestion