mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 20:11:32 +02:00
* [web] double down on validating email addresses * [web] normalize emails in captcha middleware * [web] add support for regex based allow-list for skipping captcha * [web] skip captcha for trusted users on all actions GitOrigin-RevId: a994ebf6b74e80f462d2dab1fe5113bbffa676a9
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const { expect } = require('chai')
|
|
const {
|
|
parseEmail,
|
|
} = require('../../../../app/src/Features/Helpers/EmailHelper')
|
|
|
|
describe('EmailHelper', function () {
|
|
it('should parse a single email', function () {
|
|
const address = 'test@example.com'
|
|
const expected = 'test@example.com'
|
|
expect(parseEmail(address)).to.equal(expected)
|
|
expect(parseEmail(address, true)).to.equal(expected)
|
|
})
|
|
|
|
it('should parse a valid email address', function () {
|
|
const address = '"Test Person" <test@example.com>'
|
|
const expected = 'test@example.com'
|
|
expect(parseEmail(address)).to.equal(null)
|
|
expect(parseEmail(address, true)).to.equal(expected)
|
|
})
|
|
|
|
it('should return null for garbage input', function () {
|
|
const cases = [
|
|
undefined,
|
|
null,
|
|
'',
|
|
42,
|
|
['test@example.com'],
|
|
{},
|
|
{ length: 42 },
|
|
{ trim: true, match: true },
|
|
{ toString: true },
|
|
]
|
|
for (const input of cases) {
|
|
expect(parseEmail(input)).to.equal(null, input)
|
|
expect(parseEmail(input, true)).to.equal(null, input)
|
|
}
|
|
})
|
|
|
|
it('should return null for an invalid single email', function () {
|
|
const address = 'testexample.com'
|
|
expect(parseEmail(address)).to.equal(null)
|
|
expect(parseEmail(address, true)).to.equal(null)
|
|
})
|
|
|
|
it('should return null for an invalid email address', function () {
|
|
const address = '"Test Person" test@example.com>'
|
|
expect(parseEmail(address)).to.equal(null)
|
|
expect(parseEmail(address, true)).to.equal(null)
|
|
})
|
|
|
|
it('should return null for a group of addresses', function () {
|
|
const address = 'Group name:test1@example.com,test2@example.com;'
|
|
expect(parseEmail(address)).to.equal(null)
|
|
expect(parseEmail(address, true)).to.equal(null)
|
|
})
|
|
})
|