@email-utils/validator-syntax 0.0.1-9 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/Readme.md +1 -1
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/dist/fixtures.cjs +2112 -0
- package/dist/fixtures.cjs.map +1 -0
- package/dist/fixtures.d.cts +121 -0
- package/dist/fixtures.d.mts +121 -0
- package/dist/fixtures.mjs +2103 -0
- package/dist/fixtures.mjs.map +1 -0
- package/dist/index.cjs +2141 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +87 -0
- package/dist/index.d.mts +87 -0
- package/dist/index.mjs +2138 -0
- package/dist/index.mjs.map +1 -0
- package/dist/result-BZjmlevS.d.cts +100 -0
- package/dist/result-BZjmlevS.d.mts +100 -0
- package/package.json +62 -73
- package/.babelrc +0 -8
- package/.eslintignore +0 -5
- package/.nvmrc +0 -1
- package/.nycrc.json +0 -11
- package/@types/index.d.ts +0 -30
- package/Readme.old.md +0 -103
- package/bin/tag.sh +0 -21
- package/dist/index.js +0 -272
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -342
- package/test/index.test.ts +0 -1612
- package/tsconfig.json +0 -22
package/test/index.test.ts
DELETED
|
@@ -1,1612 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai'
|
|
2
|
-
import { describe, it } from 'mocha'
|
|
3
|
-
import EmailSyntaxValidator from '../src'
|
|
4
|
-
|
|
5
|
-
const requiresPrintable = [
|
|
6
|
-
{
|
|
7
|
-
email: 'disposablestyleemailwith+symbol@example.com',
|
|
8
|
-
description: 'Emails with symbols',
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
email: 'username+tag+sorting@example.com',
|
|
12
|
-
description: 'Emails with tags and sorting',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
email: 'test/test@test.com',
|
|
16
|
-
description: 'Emails with slashes',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
email: 'mailhost.com!username@example.org',
|
|
20
|
-
description: 'Emails with bangified host routes',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
email: 'user%example.com@example.org',
|
|
24
|
-
description: 'Emails with % escaped mail routes',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
email: 'disposablestyleemailwith+symbol@example.com',
|
|
28
|
-
description: 'Emails with symbols',
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
email: 'username+tag+sorting@example.com',
|
|
32
|
-
description: 'Emails with tags and sorting',
|
|
33
|
-
},
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
const alwaysValidEmails = [
|
|
37
|
-
{
|
|
38
|
-
email: 'simple@example.com',
|
|
39
|
-
description: 'Simple emails',
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
email: 'x@example.com',
|
|
44
|
-
description: 'Emails with a single letter local',
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
// This scenario has to be extremely rare and is very difficult to setup. Ignoring for now.
|
|
48
|
-
// {
|
|
49
|
-
// // eslint-disable-next-line max-len, no-useless-escape
|
|
50
|
-
// email:
|
|
51
|
-
// '"very.(),:;<>[]".VERY."very@\\ "very".unusual"@strange.example.com',
|
|
52
|
-
// description: 'Emails with a very unusual set of characters',
|
|
53
|
-
//
|
|
54
|
-
// },
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
email: 'admin@test.co',
|
|
58
|
-
description: 'Email with short Top Level Domain',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
email: 'test@gmail.com',
|
|
62
|
-
description: 'Gmail emails',
|
|
63
|
-
},
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
const requiresSpacesSurroundedByQuote = [
|
|
67
|
-
{
|
|
68
|
-
email: '" "@example.org',
|
|
69
|
-
description: 'Email with space between quotes for username',
|
|
70
|
-
},
|
|
71
|
-
]
|
|
72
|
-
|
|
73
|
-
const requiresDoublePeriodsInQuotes = [
|
|
74
|
-
{
|
|
75
|
-
email: '"john..doe"@example.com',
|
|
76
|
-
description: 'Emails with 2 dots together in the local when in quotes',
|
|
77
|
-
},
|
|
78
|
-
]
|
|
79
|
-
|
|
80
|
-
const requiresUppercaseLetters = [
|
|
81
|
-
{
|
|
82
|
-
email: 'tesT@example.com',
|
|
83
|
-
description: 'Emails with uppercase letters',
|
|
84
|
-
},
|
|
85
|
-
]
|
|
86
|
-
|
|
87
|
-
const requiresNumbers = [
|
|
88
|
-
{
|
|
89
|
-
email: 'test1@example.com',
|
|
90
|
-
description: 'Emails with numbers',
|
|
91
|
-
},
|
|
92
|
-
]
|
|
93
|
-
|
|
94
|
-
const requiresPeriods = [
|
|
95
|
-
{
|
|
96
|
-
email: 'very.common@example.com',
|
|
97
|
-
description: 'Emails with periods',
|
|
98
|
-
},
|
|
99
|
-
]
|
|
100
|
-
|
|
101
|
-
const requiresQuotes = [
|
|
102
|
-
{
|
|
103
|
-
email: '"justactually"@example.com',
|
|
104
|
-
description: 'Emails with quotes',
|
|
105
|
-
},
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
const requiresPeriodsAndQuotes = [
|
|
109
|
-
{
|
|
110
|
-
email: 'just."actually".right@example.com',
|
|
111
|
-
description: 'Emails with internal quotes that are surrounded by periods',
|
|
112
|
-
},
|
|
113
|
-
]
|
|
114
|
-
|
|
115
|
-
const requiresLocalHyphens = [
|
|
116
|
-
{
|
|
117
|
-
email: 'fully-qualified-domain@example.com',
|
|
118
|
-
description: 'Emails with fully qualified domains',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
email: 'otheremail-with-hyphen@example.com',
|
|
122
|
-
description: 'Emails with hyphens',
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
email: 'user-@example.org',
|
|
126
|
-
description:
|
|
127
|
-
'Emails that end in non-alphanumeric characters that are in the allowed printable characters',
|
|
128
|
-
},
|
|
129
|
-
]
|
|
130
|
-
|
|
131
|
-
const requiresHyphens = [
|
|
132
|
-
{
|
|
133
|
-
email: 'example-indeed@strange-example.com',
|
|
134
|
-
description: 'Emails with a hyphenated domain',
|
|
135
|
-
},
|
|
136
|
-
]
|
|
137
|
-
|
|
138
|
-
const requiresDomainHyphens = [
|
|
139
|
-
{
|
|
140
|
-
email: 'exampleindeed@strange-example.com',
|
|
141
|
-
description: 'Emails with a hyphenated domain',
|
|
142
|
-
},
|
|
143
|
-
]
|
|
144
|
-
|
|
145
|
-
const requiresNoTldCheck = [
|
|
146
|
-
{
|
|
147
|
-
email: 'test@example.thisisnotavalidtld',
|
|
148
|
-
description: 'Emails that are non-icann tlds',
|
|
149
|
-
},
|
|
150
|
-
]
|
|
151
|
-
|
|
152
|
-
const requiresNoDomainNameLengthCheck = [
|
|
153
|
-
{
|
|
154
|
-
email: 'james@g.com',
|
|
155
|
-
description:
|
|
156
|
-
'Emails with periods that are less than 1 chars from the domain beginning',
|
|
157
|
-
},
|
|
158
|
-
]
|
|
159
|
-
|
|
160
|
-
const requiresNoTldLengthCheck = [
|
|
161
|
-
{
|
|
162
|
-
email: 'james@google.c',
|
|
163
|
-
description:
|
|
164
|
-
'Emails with periods that are less than 2 chars from the end of the domain',
|
|
165
|
-
},
|
|
166
|
-
]
|
|
167
|
-
|
|
168
|
-
function runValidations(validations, emailValidator, expected) {
|
|
169
|
-
for (let v = 0; v < validations.length; v++) {
|
|
170
|
-
const validation = validations[v]
|
|
171
|
-
|
|
172
|
-
it(`${validation.description} are valid (${validation.email})`, async () =>
|
|
173
|
-
expect(await emailValidator.validate(validation.email)).to.equal(
|
|
174
|
-
expected
|
|
175
|
-
))
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
describe('Check valid emails. | Base config.', async () => {
|
|
180
|
-
const emailValidator = new EmailSyntaxValidator()
|
|
181
|
-
|
|
182
|
-
const validations = [
|
|
183
|
-
...alwaysValidEmails,
|
|
184
|
-
...requiresSpacesSurroundedByQuote,
|
|
185
|
-
...requiresDoublePeriodsInQuotes,
|
|
186
|
-
...requiresUppercaseLetters,
|
|
187
|
-
...requiresNumbers,
|
|
188
|
-
...requiresPeriods,
|
|
189
|
-
...requiresPrintable,
|
|
190
|
-
...requiresQuotes,
|
|
191
|
-
...requiresPeriodsAndQuotes,
|
|
192
|
-
...requiresLocalHyphens,
|
|
193
|
-
...requiresDomainHyphens,
|
|
194
|
-
...requiresHyphens,
|
|
195
|
-
]
|
|
196
|
-
|
|
197
|
-
runValidations(validations, emailValidator, true)
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
describe('Check invalid emails. | Base config.', async () => {
|
|
201
|
-
const emailValidator = new EmailSyntaxValidator()
|
|
202
|
-
|
|
203
|
-
const emailWOAt = 'Abc.example.com'
|
|
204
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
205
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
206
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
207
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
208
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
209
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
210
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
211
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
212
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
213
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
214
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
215
|
-
false
|
|
216
|
-
))
|
|
217
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
218
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
219
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
220
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
221
|
-
'this is"notallowed@example.com'
|
|
222
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
223
|
-
expect(
|
|
224
|
-
await emailValidator.validate(
|
|
225
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
226
|
-
)
|
|
227
|
-
).to.equal(false))
|
|
228
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
229
|
-
'this still"not\\allowed@example.com'
|
|
230
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
231
|
-
expect(
|
|
232
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
233
|
-
).to.equal(false))
|
|
234
|
-
const emailWTooLongLocal =
|
|
235
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
236
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
237
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
238
|
-
const emailWUnderscoredDomain =
|
|
239
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
240
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
241
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
242
|
-
false
|
|
243
|
-
))
|
|
244
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
245
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
246
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
247
|
-
const emailWODomainPeriod = 'james@google'
|
|
248
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
249
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
250
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
251
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
252
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
253
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
254
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
255
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
256
|
-
false
|
|
257
|
-
))
|
|
258
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
259
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
260
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
261
|
-
false
|
|
262
|
-
))
|
|
263
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
264
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
265
|
-
expect(
|
|
266
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
267
|
-
).to.equal(false))
|
|
268
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
269
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
270
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
271
|
-
false
|
|
272
|
-
))
|
|
273
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
274
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
275
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
276
|
-
false
|
|
277
|
-
))
|
|
278
|
-
const doubleDotBeforeAt = 'john..doe@example.com'
|
|
279
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
280
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
281
|
-
|
|
282
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
283
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
284
|
-
expect(
|
|
285
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
286
|
-
).to.equal(false))
|
|
287
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
288
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
289
|
-
expect(
|
|
290
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
291
|
-
).to.equal(false))
|
|
292
|
-
const doubleDotAfterAt = 'john.doe@example..com'
|
|
293
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
294
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
295
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
296
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
297
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
298
|
-
false
|
|
299
|
-
))
|
|
300
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
301
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
302
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
303
|
-
|
|
304
|
-
const percentEscapedMailRoute = 'user%example@example.org'
|
|
305
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
306
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
307
|
-
false
|
|
308
|
-
))
|
|
309
|
-
|
|
310
|
-
const emailWTLD = 'admin@mailserver1'
|
|
311
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
312
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
describe('Check valid emails. | W/Out spaces surrounded by quotes.', async () => {
|
|
316
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
317
|
-
local: {
|
|
318
|
-
spaces: false,
|
|
319
|
-
},
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
const validations = [
|
|
323
|
-
...alwaysValidEmails,
|
|
324
|
-
...requiresDoublePeriodsInQuotes,
|
|
325
|
-
...requiresUppercaseLetters,
|
|
326
|
-
...requiresNumbers,
|
|
327
|
-
...requiresPeriods,
|
|
328
|
-
...requiresPrintable,
|
|
329
|
-
...requiresQuotes,
|
|
330
|
-
...requiresPeriodsAndQuotes,
|
|
331
|
-
...requiresLocalHyphens,
|
|
332
|
-
...requiresDomainHyphens,
|
|
333
|
-
...requiresHyphens,
|
|
334
|
-
]
|
|
335
|
-
|
|
336
|
-
runValidations(validations, emailValidator, true)
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
describe('Check valid emails. | W/Out uppercase letters.', async () => {
|
|
340
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
341
|
-
local: {
|
|
342
|
-
alphaUpper: false,
|
|
343
|
-
},
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
const validations = [
|
|
347
|
-
...alwaysValidEmails,
|
|
348
|
-
...requiresSpacesSurroundedByQuote,
|
|
349
|
-
...requiresDoublePeriodsInQuotes,
|
|
350
|
-
...requiresNumbers,
|
|
351
|
-
...requiresPeriods,
|
|
352
|
-
...requiresPrintable,
|
|
353
|
-
...requiresQuotes,
|
|
354
|
-
...requiresPeriodsAndQuotes,
|
|
355
|
-
...requiresLocalHyphens,
|
|
356
|
-
...requiresDomainHyphens,
|
|
357
|
-
...requiresHyphens,
|
|
358
|
-
]
|
|
359
|
-
|
|
360
|
-
runValidations(validations, emailValidator, true)
|
|
361
|
-
})
|
|
362
|
-
|
|
363
|
-
describe('Check invalid emails. | W/Out uppercase letters, and lowercasing.', async () => {
|
|
364
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
365
|
-
local: {
|
|
366
|
-
alphaUpper: false,
|
|
367
|
-
},
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
const emailWOAt = 'Abc.example.com'
|
|
371
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
372
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
373
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
374
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
375
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
376
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
377
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
378
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
379
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
380
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
381
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
382
|
-
false
|
|
383
|
-
))
|
|
384
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
385
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
386
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
387
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
388
|
-
'this is"notallowed@example.com'
|
|
389
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
390
|
-
expect(
|
|
391
|
-
await emailValidator.validate(
|
|
392
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
393
|
-
)
|
|
394
|
-
).to.equal(false))
|
|
395
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
396
|
-
'this still"not\\allowed@example.com'
|
|
397
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
398
|
-
expect(
|
|
399
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
400
|
-
).to.equal(false))
|
|
401
|
-
const emailWTooLongLocal =
|
|
402
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
403
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
404
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
405
|
-
const emailWUnderscoredDomain =
|
|
406
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
407
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
408
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
409
|
-
false
|
|
410
|
-
))
|
|
411
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
412
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
413
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
414
|
-
const emailWODomainPeriod = 'james@google'
|
|
415
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
416
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
417
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
418
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
419
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
420
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
421
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
422
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
423
|
-
false
|
|
424
|
-
))
|
|
425
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
426
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
427
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
428
|
-
false
|
|
429
|
-
))
|
|
430
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
431
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
432
|
-
expect(
|
|
433
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
434
|
-
).to.equal(false))
|
|
435
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
436
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
437
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
438
|
-
false
|
|
439
|
-
))
|
|
440
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
441
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
442
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
443
|
-
false
|
|
444
|
-
))
|
|
445
|
-
const doubleDotBeforeAt = 'john..doe@example.com'
|
|
446
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
447
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
448
|
-
|
|
449
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
450
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
451
|
-
expect(
|
|
452
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
453
|
-
).to.equal(false))
|
|
454
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
455
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
456
|
-
expect(
|
|
457
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
458
|
-
).to.equal(false))
|
|
459
|
-
const doubleDotAfterAt = 'john.doe@example..com'
|
|
460
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
461
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
462
|
-
|
|
463
|
-
const uppercasedEmail = 'tesT@example.com'
|
|
464
|
-
it(`Emails with uppercase letters when sanitize.lowercase is false and local.alphaUpper is false are invalid. (${uppercasedEmail})`, async () =>
|
|
465
|
-
expect(await emailValidator.validate(uppercasedEmail)).to.equal(false))
|
|
466
|
-
|
|
467
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
468
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
469
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
470
|
-
false
|
|
471
|
-
))
|
|
472
|
-
|
|
473
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
474
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
475
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
476
|
-
|
|
477
|
-
const percentEscapedMailRoute = 'user%example@example.org'
|
|
478
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
479
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
480
|
-
false
|
|
481
|
-
))
|
|
482
|
-
|
|
483
|
-
const emailWTLD = 'admin@mailserver1'
|
|
484
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
485
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
describe('Check valid emails. | W/Out lowercase letters.', async () => {
|
|
489
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
490
|
-
local: {
|
|
491
|
-
alphaLower: false,
|
|
492
|
-
},
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
const validations = [
|
|
496
|
-
...alwaysValidEmails,
|
|
497
|
-
...requiresSpacesSurroundedByQuote,
|
|
498
|
-
...requiresDoublePeriodsInQuotes,
|
|
499
|
-
...requiresUppercaseLetters,
|
|
500
|
-
...requiresNumbers,
|
|
501
|
-
...requiresPeriods,
|
|
502
|
-
...requiresPrintable,
|
|
503
|
-
...requiresQuotes,
|
|
504
|
-
...requiresPeriodsAndQuotes,
|
|
505
|
-
...requiresLocalHyphens,
|
|
506
|
-
...requiresDomainHyphens,
|
|
507
|
-
...requiresHyphens,
|
|
508
|
-
]
|
|
509
|
-
|
|
510
|
-
runValidations(
|
|
511
|
-
validations.map((validation) => ({
|
|
512
|
-
...validation,
|
|
513
|
-
email: validation.email.toUpperCase(),
|
|
514
|
-
})),
|
|
515
|
-
emailValidator,
|
|
516
|
-
true
|
|
517
|
-
)
|
|
518
|
-
})
|
|
519
|
-
|
|
520
|
-
describe('Check invalid emails. | W/Out lowercase letters.', async () => {
|
|
521
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
522
|
-
local: {
|
|
523
|
-
alphaLower: false,
|
|
524
|
-
},
|
|
525
|
-
sanitize: {
|
|
526
|
-
lowercase: false,
|
|
527
|
-
},
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
const emailWOAt = 'Abc.example.com'.toUpperCase()
|
|
531
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
532
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
533
|
-
const emailWAtFirst = '@Abc.example.com'.toUpperCase()
|
|
534
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
535
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
536
|
-
const emailWMultiAts = 'A@b@c@example.com'.toUpperCase()
|
|
537
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
538
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
539
|
-
const emailWUnquotedSpecialChars =
|
|
540
|
-
'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'.toUpperCase()
|
|
541
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
542
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
543
|
-
false
|
|
544
|
-
))
|
|
545
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'.toUpperCase()
|
|
546
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
547
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
548
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
549
|
-
'this is"notallowed@example.com'.toUpperCase()
|
|
550
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
551
|
-
expect(
|
|
552
|
-
await emailValidator.validate(
|
|
553
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
554
|
-
)
|
|
555
|
-
).to.equal(false))
|
|
556
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
557
|
-
'this still"not\\allowed@example.com'.toUpperCase()
|
|
558
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
559
|
-
expect(
|
|
560
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
561
|
-
).to.equal(false))
|
|
562
|
-
const emailWTooLongLocal =
|
|
563
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'.toUpperCase()
|
|
564
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
565
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
566
|
-
const emailWUnderscoredDomain =
|
|
567
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'.toUpperCase()
|
|
568
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
569
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
570
|
-
false
|
|
571
|
-
))
|
|
572
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'.toUpperCase()
|
|
573
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
574
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
575
|
-
const emailWODomainPeriod = 'james@google'.toUpperCase()
|
|
576
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
577
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
578
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
579
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
580
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
581
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
582
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
583
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
584
|
-
false
|
|
585
|
-
))
|
|
586
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'.toUpperCase()
|
|
587
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
588
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
589
|
-
false
|
|
590
|
-
))
|
|
591
|
-
const emailWSpaceButOnlyQuoteBefore =
|
|
592
|
-
'james" richards@google.com'.toUpperCase()
|
|
593
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
594
|
-
expect(
|
|
595
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
596
|
-
).to.equal(false))
|
|
597
|
-
const emailWInvalidDomainChars = 'james@cb$.com'.toUpperCase()
|
|
598
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
599
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
600
|
-
false
|
|
601
|
-
))
|
|
602
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'.toUpperCase()
|
|
603
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
604
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
605
|
-
false
|
|
606
|
-
))
|
|
607
|
-
const doubleDotBeforeAt = 'john..doe@example.com'.toUpperCase()
|
|
608
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
609
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
610
|
-
|
|
611
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'.toUpperCase()
|
|
612
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
613
|
-
expect(
|
|
614
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
615
|
-
).to.equal(false))
|
|
616
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods =
|
|
617
|
-
'"john"..doe@example.com'.toUpperCase()
|
|
618
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
619
|
-
expect(
|
|
620
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
621
|
-
).to.equal(false))
|
|
622
|
-
const doubleDotAfterAt = 'john.doe@example..com'.toUpperCase()
|
|
623
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
624
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
625
|
-
|
|
626
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'.toUpperCase()
|
|
627
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
628
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
629
|
-
false
|
|
630
|
-
))
|
|
631
|
-
|
|
632
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
633
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
634
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
635
|
-
|
|
636
|
-
const percentEscapedMailRoute = 'user%example@example.org'
|
|
637
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
638
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
639
|
-
false
|
|
640
|
-
))
|
|
641
|
-
|
|
642
|
-
const emailWTLD = 'admin@mailserver1'
|
|
643
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
644
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
645
|
-
})
|
|
646
|
-
|
|
647
|
-
describe('Check valid emails. | W/Out numbers.', async () => {
|
|
648
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
649
|
-
local: {
|
|
650
|
-
numeric: false,
|
|
651
|
-
},
|
|
652
|
-
})
|
|
653
|
-
|
|
654
|
-
const validations = [
|
|
655
|
-
...alwaysValidEmails,
|
|
656
|
-
...requiresSpacesSurroundedByQuote,
|
|
657
|
-
...requiresDoublePeriodsInQuotes,
|
|
658
|
-
...requiresUppercaseLetters,
|
|
659
|
-
...requiresPeriods,
|
|
660
|
-
...requiresPrintable,
|
|
661
|
-
...requiresQuotes,
|
|
662
|
-
...requiresPeriodsAndQuotes,
|
|
663
|
-
...requiresLocalHyphens,
|
|
664
|
-
...requiresDomainHyphens,
|
|
665
|
-
...requiresHyphens,
|
|
666
|
-
]
|
|
667
|
-
|
|
668
|
-
runValidations(validations, emailValidator, true)
|
|
669
|
-
})
|
|
670
|
-
|
|
671
|
-
describe('Check invalid emails. | W/Out numbers.', async () => {
|
|
672
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
673
|
-
local: {
|
|
674
|
-
numeric: false,
|
|
675
|
-
},
|
|
676
|
-
})
|
|
677
|
-
|
|
678
|
-
const emailWNumbers = 'simple1@example.com'
|
|
679
|
-
it(`Valid emails with numbers are invalid. (${emailWNumbers})`, async () =>
|
|
680
|
-
expect(await emailValidator.validate(emailWNumbers)).to.equal(false))
|
|
681
|
-
const emailWOAt = 'Abc.example.com'
|
|
682
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
683
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
684
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
685
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
686
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
687
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
688
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
689
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
690
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
691
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
692
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
693
|
-
false
|
|
694
|
-
))
|
|
695
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
696
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
697
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
698
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
699
|
-
'this is"notallowed@example.com'
|
|
700
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
701
|
-
expect(
|
|
702
|
-
await emailValidator.validate(
|
|
703
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
704
|
-
)
|
|
705
|
-
).to.equal(false))
|
|
706
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
707
|
-
'this still"not\\allowed@example.com'
|
|
708
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
709
|
-
expect(
|
|
710
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
711
|
-
).to.equal(false))
|
|
712
|
-
const emailWTooLongLocal =
|
|
713
|
-
'uayuYfBgRktoqVPCAJLhkcyVHFsZygReesttpNWTTiETtbQFfDUMZjyCdeaEhcotf+x@example.com'
|
|
714
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
715
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
716
|
-
const emailWUnderscoredDomain =
|
|
717
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
718
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
719
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
720
|
-
false
|
|
721
|
-
))
|
|
722
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
723
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
724
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
725
|
-
const emailWODomainPeriod = 'james@google'
|
|
726
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
727
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
728
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
729
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
730
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
731
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
732
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
733
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
734
|
-
false
|
|
735
|
-
))
|
|
736
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
737
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
738
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
739
|
-
false
|
|
740
|
-
))
|
|
741
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
742
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
743
|
-
expect(
|
|
744
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
745
|
-
).to.equal(false))
|
|
746
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
747
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
748
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
749
|
-
false
|
|
750
|
-
))
|
|
751
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
752
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
753
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
754
|
-
false
|
|
755
|
-
))
|
|
756
|
-
const doubleDotBeforeAt = 'john..doe@example.com'
|
|
757
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
758
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
759
|
-
|
|
760
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
761
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
762
|
-
expect(
|
|
763
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
764
|
-
).to.equal(false))
|
|
765
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
766
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
767
|
-
expect(
|
|
768
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
769
|
-
).to.equal(false))
|
|
770
|
-
const doubleDotAfterAt = 'john.doe@example..com'
|
|
771
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
772
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
773
|
-
|
|
774
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
775
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
776
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
777
|
-
false
|
|
778
|
-
))
|
|
779
|
-
|
|
780
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
781
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
782
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
783
|
-
|
|
784
|
-
const percentEscapedMailRoute = 'user%example@example.org'
|
|
785
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
786
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
787
|
-
false
|
|
788
|
-
))
|
|
789
|
-
|
|
790
|
-
const emailWTLD = 'admin@mailserver1'
|
|
791
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
792
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
793
|
-
})
|
|
794
|
-
|
|
795
|
-
describe('Check valid emails. | W/Out periods.', async () => {
|
|
796
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
797
|
-
local: {
|
|
798
|
-
period: false,
|
|
799
|
-
},
|
|
800
|
-
})
|
|
801
|
-
|
|
802
|
-
const validations = [
|
|
803
|
-
...alwaysValidEmails,
|
|
804
|
-
...requiresSpacesSurroundedByQuote,
|
|
805
|
-
...requiresUppercaseLetters,
|
|
806
|
-
...requiresNumbers,
|
|
807
|
-
...requiresPrintable,
|
|
808
|
-
...requiresQuotes,
|
|
809
|
-
...requiresLocalHyphens,
|
|
810
|
-
...requiresDomainHyphens,
|
|
811
|
-
...requiresHyphens,
|
|
812
|
-
]
|
|
813
|
-
|
|
814
|
-
runValidations(validations, emailValidator, true)
|
|
815
|
-
})
|
|
816
|
-
|
|
817
|
-
describe('Check invalid emails. | W/Out periods.', async () => {
|
|
818
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
819
|
-
local: {
|
|
820
|
-
period: false,
|
|
821
|
-
doublePeriodsInQuotes: false,
|
|
822
|
-
},
|
|
823
|
-
})
|
|
824
|
-
|
|
825
|
-
const periodEmail = 'very.common@example.com'
|
|
826
|
-
it(`Emails with periods are invalid. (${periodEmail})`, async () =>
|
|
827
|
-
expect(await emailValidator.validate(periodEmail)).to.equal(false))
|
|
828
|
-
const emailWOAt = 'Abc+example.com'
|
|
829
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
830
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
831
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
832
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
833
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
834
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
835
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
836
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
837
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
838
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
839
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
840
|
-
false
|
|
841
|
-
))
|
|
842
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
843
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
844
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
845
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
846
|
-
'this is"notallowed@example.com'
|
|
847
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
848
|
-
expect(
|
|
849
|
-
await emailValidator.validate(
|
|
850
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
851
|
-
)
|
|
852
|
-
).to.equal(false))
|
|
853
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
854
|
-
'this still"not\\allowed@example.com'
|
|
855
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
856
|
-
expect(
|
|
857
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
858
|
-
).to.equal(false))
|
|
859
|
-
const emailWTooLongLocal =
|
|
860
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
861
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
862
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
863
|
-
const emailWUnderscoredDomain =
|
|
864
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
865
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
866
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
867
|
-
false
|
|
868
|
-
))
|
|
869
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
870
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
871
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
872
|
-
const emailWODomainPeriod = 'james@google'
|
|
873
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
874
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
875
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
876
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
877
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
878
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
879
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
880
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
881
|
-
false
|
|
882
|
-
))
|
|
883
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
884
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
885
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
886
|
-
false
|
|
887
|
-
))
|
|
888
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
889
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
890
|
-
expect(
|
|
891
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
892
|
-
).to.equal(false))
|
|
893
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
894
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
895
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
896
|
-
false
|
|
897
|
-
))
|
|
898
|
-
|
|
899
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
900
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
901
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
902
|
-
false
|
|
903
|
-
))
|
|
904
|
-
|
|
905
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
906
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
907
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
908
|
-
|
|
909
|
-
const percentEscapedMailRoute = 'user%example@example.org'
|
|
910
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
911
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
912
|
-
false
|
|
913
|
-
))
|
|
914
|
-
|
|
915
|
-
const emailWTLD = 'admin@mailserver1'
|
|
916
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
917
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
918
|
-
})
|
|
919
|
-
|
|
920
|
-
describe('Check valid emails. | W/Out printable chars.', async () => {
|
|
921
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
922
|
-
local: {
|
|
923
|
-
printable: false,
|
|
924
|
-
},
|
|
925
|
-
})
|
|
926
|
-
|
|
927
|
-
const validations = [
|
|
928
|
-
...alwaysValidEmails,
|
|
929
|
-
...requiresSpacesSurroundedByQuote,
|
|
930
|
-
...requiresDoublePeriodsInQuotes,
|
|
931
|
-
...requiresUppercaseLetters,
|
|
932
|
-
...requiresNumbers,
|
|
933
|
-
...requiresPeriods,
|
|
934
|
-
...requiresQuotes,
|
|
935
|
-
...requiresPeriodsAndQuotes,
|
|
936
|
-
...requiresLocalHyphens,
|
|
937
|
-
...requiresDomainHyphens,
|
|
938
|
-
...requiresHyphens,
|
|
939
|
-
]
|
|
940
|
-
|
|
941
|
-
runValidations(validations, emailValidator, true)
|
|
942
|
-
})
|
|
943
|
-
|
|
944
|
-
describe('Check valid emails. | W/Out quotes.', async () => {
|
|
945
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
946
|
-
local: {
|
|
947
|
-
quote: false,
|
|
948
|
-
},
|
|
949
|
-
})
|
|
950
|
-
|
|
951
|
-
const validations = [
|
|
952
|
-
...alwaysValidEmails,
|
|
953
|
-
...requiresUppercaseLetters,
|
|
954
|
-
...requiresNumbers,
|
|
955
|
-
...requiresPeriods,
|
|
956
|
-
...requiresPrintable,
|
|
957
|
-
...requiresLocalHyphens,
|
|
958
|
-
...requiresDomainHyphens,
|
|
959
|
-
...requiresHyphens,
|
|
960
|
-
]
|
|
961
|
-
|
|
962
|
-
runValidations(validations, emailValidator, true)
|
|
963
|
-
})
|
|
964
|
-
|
|
965
|
-
describe('Check valid emails. | W/Out hyphens in local.', async () => {
|
|
966
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
967
|
-
local: {
|
|
968
|
-
hyphen: false,
|
|
969
|
-
},
|
|
970
|
-
})
|
|
971
|
-
|
|
972
|
-
const validations = [
|
|
973
|
-
...alwaysValidEmails,
|
|
974
|
-
...requiresSpacesSurroundedByQuote,
|
|
975
|
-
...requiresDoublePeriodsInQuotes,
|
|
976
|
-
...requiresUppercaseLetters,
|
|
977
|
-
...requiresNumbers,
|
|
978
|
-
...requiresPeriods,
|
|
979
|
-
...requiresPrintable,
|
|
980
|
-
...requiresQuotes,
|
|
981
|
-
...requiresPeriodsAndQuotes,
|
|
982
|
-
...requiresDomainHyphens,
|
|
983
|
-
]
|
|
984
|
-
|
|
985
|
-
runValidations(validations, emailValidator, true)
|
|
986
|
-
})
|
|
987
|
-
|
|
988
|
-
describe('Check valid emails. | W/Out hyphens in domain.', async () => {
|
|
989
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
990
|
-
domain: {
|
|
991
|
-
hyphen: false,
|
|
992
|
-
},
|
|
993
|
-
})
|
|
994
|
-
|
|
995
|
-
const validations = [
|
|
996
|
-
...alwaysValidEmails,
|
|
997
|
-
...requiresSpacesSurroundedByQuote,
|
|
998
|
-
...requiresDoublePeriodsInQuotes,
|
|
999
|
-
...requiresUppercaseLetters,
|
|
1000
|
-
...requiresNumbers,
|
|
1001
|
-
...requiresPeriods,
|
|
1002
|
-
...requiresPrintable,
|
|
1003
|
-
...requiresQuotes,
|
|
1004
|
-
...requiresPeriodsAndQuotes,
|
|
1005
|
-
...requiresLocalHyphens,
|
|
1006
|
-
]
|
|
1007
|
-
|
|
1008
|
-
runValidations(validations, emailValidator, true)
|
|
1009
|
-
})
|
|
1010
|
-
|
|
1011
|
-
// describe('Check invalid emails. | W/Out printable chars, spaces, quotes, or hyphens in domain.', async () => {
|
|
1012
|
-
// const emailValidator = new EmailSyntaxValidator({
|
|
1013
|
-
// local: {
|
|
1014
|
-
// printable: false,
|
|
1015
|
-
// // space: false,
|
|
1016
|
-
// // quote: false,
|
|
1017
|
-
// },
|
|
1018
|
-
// // domain: {
|
|
1019
|
-
// // hyphen: false,
|
|
1020
|
-
// // },
|
|
1021
|
-
// })
|
|
1022
|
-
|
|
1023
|
-
// const emailWOAt = 'Abc.example.com'
|
|
1024
|
-
// it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
1025
|
-
// expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
1026
|
-
// const emailWAtFirst = '@Abc.example.com'
|
|
1027
|
-
// it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
1028
|
-
// expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
1029
|
-
// const emailWMultiAts = 'A@b@c@example.com'
|
|
1030
|
-
// it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
1031
|
-
// expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
1032
|
-
// const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
1033
|
-
// it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
1034
|
-
// expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
1035
|
-
// false
|
|
1036
|
-
// ))
|
|
1037
|
-
// const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
1038
|
-
// it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
1039
|
-
// expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
1040
|
-
// const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
1041
|
-
// 'this is"notallowed@example.com'
|
|
1042
|
-
// it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
1043
|
-
// expect(
|
|
1044
|
-
// await emailValidator.validate(
|
|
1045
|
-
// emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
1046
|
-
// )
|
|
1047
|
-
// ).to.equal(false))
|
|
1048
|
-
// const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
1049
|
-
// 'this still"not\\allowed@example.com'
|
|
1050
|
-
// it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
1051
|
-
// expect(
|
|
1052
|
-
// await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
1053
|
-
// ).to.equal(false))
|
|
1054
|
-
// const emailWTooLongLocal =
|
|
1055
|
-
// '1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
1056
|
-
// it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
1057
|
-
// expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
1058
|
-
// const emailWUnderscoredDomain =
|
|
1059
|
-
// 'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
1060
|
-
// it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
1061
|
-
// expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
1062
|
-
// false
|
|
1063
|
-
// ))
|
|
1064
|
-
// const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
1065
|
-
// it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
1066
|
-
// expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
1067
|
-
// const emailWODomainPeriod = 'james@google'
|
|
1068
|
-
// it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
1069
|
-
// expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
1070
|
-
// const emailWPeriodNearEnd = 'james@google.c'
|
|
1071
|
-
// it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
1072
|
-
// expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
1073
|
-
// const emailWPeriodNearBeginning = 'james@g.com'
|
|
1074
|
-
// it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
1075
|
-
// expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
1076
|
-
// false
|
|
1077
|
-
// ))
|
|
1078
|
-
// const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
1079
|
-
// it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
1080
|
-
// expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
1081
|
-
// false
|
|
1082
|
-
// ))
|
|
1083
|
-
// const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
1084
|
-
// it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
1085
|
-
// expect(
|
|
1086
|
-
// await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
1087
|
-
// ).to.equal(false))
|
|
1088
|
-
// const emailWInvalidDomainChars = 'james@cb$.com'
|
|
1089
|
-
// it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
1090
|
-
// expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
1091
|
-
// false
|
|
1092
|
-
// ))
|
|
1093
|
-
// const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
1094
|
-
// it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
1095
|
-
// expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
1096
|
-
// false
|
|
1097
|
-
// ))
|
|
1098
|
-
// const doubleDotBeforeAt = 'john..doe@example.com'
|
|
1099
|
-
// it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
1100
|
-
// expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
1101
|
-
|
|
1102
|
-
// const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
1103
|
-
// it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
1104
|
-
// expect(
|
|
1105
|
-
// await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
1106
|
-
// ).to.equal(false))
|
|
1107
|
-
// const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
1108
|
-
// it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
1109
|
-
// expect(
|
|
1110
|
-
// await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
1111
|
-
// ).to.equal(false))
|
|
1112
|
-
// const doubleDotAfterAt = 'john.doe@example..com'
|
|
1113
|
-
// it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
1114
|
-
// expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
1115
|
-
// const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
1116
|
-
// it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
1117
|
-
// expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
1118
|
-
// false
|
|
1119
|
-
// ))
|
|
1120
|
-
|
|
1121
|
-
// const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
1122
|
-
// it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
1123
|
-
// expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
1124
|
-
|
|
1125
|
-
// const percentEscapedMailRouteLocalhost = 'user%example@example.org'
|
|
1126
|
-
// it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRouteLocalhost})`, async () =>
|
|
1127
|
-
// expect(
|
|
1128
|
-
// await emailValidator.validate(percentEscapedMailRouteLocalhost)
|
|
1129
|
-
// ).to.equal(false))
|
|
1130
|
-
|
|
1131
|
-
// const localEndingInNonAlphaNum = 'user-@example.org'
|
|
1132
|
-
// it(`Emails that end in non-alphanumeric characters are invalid. (${localEndingInNonAlphaNum})`, async () =>
|
|
1133
|
-
// expect(await emailValidator.validate(localEndingInNonAlphaNum)).to.equal(
|
|
1134
|
-
// false
|
|
1135
|
-
// ))
|
|
1136
|
-
|
|
1137
|
-
// const percentEscapedMailRoute = 'user%example.com@example.org'
|
|
1138
|
-
// it(`Emails with % escaped mail routes are invalid. (${percentEscapedMailRoute})`, async () =>
|
|
1139
|
-
// expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
1140
|
-
// false
|
|
1141
|
-
// ))
|
|
1142
|
-
|
|
1143
|
-
// const bangifiedHostRoute = 'mailhost.com!username@example.org'
|
|
1144
|
-
// it(`Emails with bangified host routes are invalid. (${bangifiedHostRoute})`, async () =>
|
|
1145
|
-
// expect(await emailValidator.validate(bangifiedHostRoute)).to.equal(false))
|
|
1146
|
-
|
|
1147
|
-
// const emailWInternalQuoteWDotsAround = 'just."not".right@example.com'
|
|
1148
|
-
// it(`Emails with quotes that are surrounded by periods are invalid. (${emailWInternalQuoteWDotsAround})`, async () =>
|
|
1149
|
-
// expect(
|
|
1150
|
-
// await emailValidator.validate(emailWInternalQuoteWDotsAround)
|
|
1151
|
-
// ).to.equal(false))
|
|
1152
|
-
|
|
1153
|
-
// const emailWSpaceBetweenQuotes = '" "@example.org'
|
|
1154
|
-
// it(`Email with space between quotes for username are invalid. (${emailWSpaceBetweenQuotes})`, async () =>
|
|
1155
|
-
// expect(await emailValidator.validate(emailWSpaceBetweenQuotes)).to.equal(
|
|
1156
|
-
// false
|
|
1157
|
-
// ))
|
|
1158
|
-
|
|
1159
|
-
// const doubleDotBeforeAtWQuote = '"john..doe"@example.com'
|
|
1160
|
-
// it(`Emails with 2 dots together in the local are invalid when in quotes. (${doubleDotBeforeAtWQuote})`, async () =>
|
|
1161
|
-
// expect(await emailValidator.validate(doubleDotBeforeAtWQuote)).to.equal(
|
|
1162
|
-
// false
|
|
1163
|
-
// ))
|
|
1164
|
-
|
|
1165
|
-
// const emailWSymbol = 'disposable.style.email.with+symbol@example.com'
|
|
1166
|
-
// it(`Emails with symbols are invalid. (${emailWSymbol})`, async () =>
|
|
1167
|
-
// expect(await emailValidator.validate(emailWSymbol)).to.equal(false))
|
|
1168
|
-
// const emailWHyphen = 'other.email-with-hyphen@example.com'
|
|
1169
|
-
// it(`Emails with hyphens are invalid. (${emailWHyphen})`, async () =>
|
|
1170
|
-
// expect(await emailValidator.validate(emailWHyphen)).to.equal(false))
|
|
1171
|
-
// const emailWFQD = 'fully-qualified-domain@example.com'
|
|
1172
|
-
// it(`Emails with fully qualified domains are invalid. (${emailWFQD})`, async () =>
|
|
1173
|
-
// expect(await emailValidator.validate(emailWFQD)).to.equal(false))
|
|
1174
|
-
// const emailWTag = 'user.name+tag+sorting@example.com'
|
|
1175
|
-
// it(`Emails with tags and sorting are invalid. (${emailWTag})`, async () =>
|
|
1176
|
-
// expect(await emailValidator.validate(emailWTag)).to.equal(false))
|
|
1177
|
-
// const emailWHyphenDomain = 'example-indeed@strange-example.com'
|
|
1178
|
-
// it(`Emails with a hyphenated domain are invalid. (${emailWHyphenDomain})`, async () =>
|
|
1179
|
-
// expect(await emailValidator.validate(emailWHyphenDomain)).to.equal(false))
|
|
1180
|
-
|
|
1181
|
-
// const emailWSlash = 'test/test@test.com'
|
|
1182
|
-
// it(`Emails with slashes are invalid. (${emailWSlash})`, async () =>
|
|
1183
|
-
// expect(await emailValidator.validate(emailWSlash)).to.equal(false))
|
|
1184
|
-
|
|
1185
|
-
// const emailWTLD = 'admin@mailserver1'
|
|
1186
|
-
// it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
1187
|
-
// expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
1188
|
-
// })
|
|
1189
|
-
|
|
1190
|
-
describe('Check valid emails. | W/Out tld check.', async () => {
|
|
1191
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1192
|
-
domain: {
|
|
1193
|
-
tld: false,
|
|
1194
|
-
// charsBeforeDot: -1,
|
|
1195
|
-
// charsAfterDot: -1,
|
|
1196
|
-
},
|
|
1197
|
-
})
|
|
1198
|
-
|
|
1199
|
-
const validations = [
|
|
1200
|
-
...alwaysValidEmails,
|
|
1201
|
-
...requiresSpacesSurroundedByQuote,
|
|
1202
|
-
...requiresDoublePeriodsInQuotes,
|
|
1203
|
-
...requiresUppercaseLetters,
|
|
1204
|
-
...requiresNumbers,
|
|
1205
|
-
...requiresPeriods,
|
|
1206
|
-
...requiresPrintable,
|
|
1207
|
-
...requiresQuotes,
|
|
1208
|
-
...requiresPeriodsAndQuotes,
|
|
1209
|
-
...requiresLocalHyphens,
|
|
1210
|
-
...requiresDomainHyphens,
|
|
1211
|
-
...requiresHyphens,
|
|
1212
|
-
...requiresNoTldCheck,
|
|
1213
|
-
]
|
|
1214
|
-
|
|
1215
|
-
runValidations(validations, emailValidator, true)
|
|
1216
|
-
})
|
|
1217
|
-
|
|
1218
|
-
describe("Check valid emails. | W/Out length check of domain's name.", async () => {
|
|
1219
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1220
|
-
domain: {
|
|
1221
|
-
charsBeforeDot: -1,
|
|
1222
|
-
},
|
|
1223
|
-
})
|
|
1224
|
-
|
|
1225
|
-
const validations = [
|
|
1226
|
-
...alwaysValidEmails,
|
|
1227
|
-
...requiresSpacesSurroundedByQuote,
|
|
1228
|
-
...requiresDoublePeriodsInQuotes,
|
|
1229
|
-
...requiresUppercaseLetters,
|
|
1230
|
-
...requiresNumbers,
|
|
1231
|
-
...requiresPeriods,
|
|
1232
|
-
...requiresPrintable,
|
|
1233
|
-
...requiresQuotes,
|
|
1234
|
-
...requiresPeriodsAndQuotes,
|
|
1235
|
-
...requiresLocalHyphens,
|
|
1236
|
-
...requiresDomainHyphens,
|
|
1237
|
-
...requiresHyphens,
|
|
1238
|
-
...requiresNoDomainNameLengthCheck,
|
|
1239
|
-
]
|
|
1240
|
-
|
|
1241
|
-
runValidations(validations, emailValidator, true)
|
|
1242
|
-
})
|
|
1243
|
-
|
|
1244
|
-
describe('Check valid emails. | W/Out length check of tld.', async () => {
|
|
1245
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1246
|
-
domain: {
|
|
1247
|
-
tld: false,
|
|
1248
|
-
charsAfterDot: -1,
|
|
1249
|
-
},
|
|
1250
|
-
})
|
|
1251
|
-
|
|
1252
|
-
const validations = [
|
|
1253
|
-
...alwaysValidEmails,
|
|
1254
|
-
...requiresSpacesSurroundedByQuote,
|
|
1255
|
-
...requiresDoublePeriodsInQuotes,
|
|
1256
|
-
...requiresUppercaseLetters,
|
|
1257
|
-
...requiresNumbers,
|
|
1258
|
-
...requiresPeriods,
|
|
1259
|
-
...requiresPrintable,
|
|
1260
|
-
...requiresQuotes,
|
|
1261
|
-
...requiresPeriodsAndQuotes,
|
|
1262
|
-
...requiresLocalHyphens,
|
|
1263
|
-
...requiresDomainHyphens,
|
|
1264
|
-
...requiresHyphens,
|
|
1265
|
-
...requiresNoTldLengthCheck,
|
|
1266
|
-
...requiresNoTldCheck,
|
|
1267
|
-
]
|
|
1268
|
-
|
|
1269
|
-
runValidations(validations, emailValidator, true)
|
|
1270
|
-
})
|
|
1271
|
-
|
|
1272
|
-
describe('Check invalid emails. | W/Out character length of domain.', async () => {
|
|
1273
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1274
|
-
domain: {
|
|
1275
|
-
tld: false,
|
|
1276
|
-
charsBeforeDot: -1,
|
|
1277
|
-
charsAfterDot: -1,
|
|
1278
|
-
},
|
|
1279
|
-
})
|
|
1280
|
-
|
|
1281
|
-
const emailWOAt = 'Abc.example.com'
|
|
1282
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
1283
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
1284
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
1285
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
1286
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
1287
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
1288
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
1289
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
1290
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
1291
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
1292
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
1293
|
-
false
|
|
1294
|
-
))
|
|
1295
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
1296
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
1297
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
1298
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
1299
|
-
'this is"notallowed@example.com'
|
|
1300
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
1301
|
-
expect(
|
|
1302
|
-
await emailValidator.validate(
|
|
1303
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
1304
|
-
)
|
|
1305
|
-
).to.equal(false))
|
|
1306
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
1307
|
-
'this still"not\\allowed@example.com'
|
|
1308
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
1309
|
-
expect(
|
|
1310
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
1311
|
-
).to.equal(false))
|
|
1312
|
-
const emailWTooLongLocal =
|
|
1313
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
1314
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
1315
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
1316
|
-
const emailWUnderscoredDomain =
|
|
1317
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
1318
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
1319
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
1320
|
-
false
|
|
1321
|
-
))
|
|
1322
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
1323
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
1324
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
1325
|
-
const emailWODomainPeriod = 'james@google'
|
|
1326
|
-
it(`Emails without a period in the domain are invalid. (${emailWODomainPeriod})`, async () =>
|
|
1327
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(false))
|
|
1328
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
1329
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
1330
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
1331
|
-
false
|
|
1332
|
-
))
|
|
1333
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
1334
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
1335
|
-
expect(
|
|
1336
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
1337
|
-
).to.equal(false))
|
|
1338
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
1339
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
1340
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
1341
|
-
false
|
|
1342
|
-
))
|
|
1343
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
1344
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
1345
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
1346
|
-
false
|
|
1347
|
-
))
|
|
1348
|
-
const doubleDotBeforeAt = 'john..doe@example.com'
|
|
1349
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
1350
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
1351
|
-
|
|
1352
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
1353
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
1354
|
-
expect(
|
|
1355
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
1356
|
-
).to.equal(false))
|
|
1357
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
1358
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
1359
|
-
expect(
|
|
1360
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
1361
|
-
).to.equal(false))
|
|
1362
|
-
const doubleDotAfterAt = 'john.doe@example..com'
|
|
1363
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
1364
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
1365
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
1366
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
1367
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
1368
|
-
false
|
|
1369
|
-
))
|
|
1370
|
-
|
|
1371
|
-
const percentEscapedMailRouteLocalhost = 'user%example@example.org'
|
|
1372
|
-
it(`Emails with % escaped mail routes that are localhost are invalid. (${percentEscapedMailRouteLocalhost})`, async () =>
|
|
1373
|
-
expect(
|
|
1374
|
-
await emailValidator.validate(percentEscapedMailRouteLocalhost)
|
|
1375
|
-
).to.equal(false))
|
|
1376
|
-
|
|
1377
|
-
const emailWTLD = 'admin@mailserver1'
|
|
1378
|
-
it(`Localhost domains are invalid. (${emailWTLD})`, async () =>
|
|
1379
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(false))
|
|
1380
|
-
})
|
|
1381
|
-
|
|
1382
|
-
describe('Check valid emails. | Localhost domains valid.', async () => {
|
|
1383
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1384
|
-
domain: {
|
|
1385
|
-
localhost: true,
|
|
1386
|
-
},
|
|
1387
|
-
})
|
|
1388
|
-
|
|
1389
|
-
const simpleEmail = 'simple@example.com'
|
|
1390
|
-
it(`Simple emails are valid. (${simpleEmail})`, async () =>
|
|
1391
|
-
expect(await emailValidator.validate(simpleEmail)).to.equal(true))
|
|
1392
|
-
const periodEmail = 'very.common@example.com'
|
|
1393
|
-
it(`Emails with periods are valid. (${periodEmail})`, async () =>
|
|
1394
|
-
expect(await emailValidator.validate(periodEmail)).to.equal(true))
|
|
1395
|
-
const emailWSymbol = 'disposable.style.email.with+symbol@example.com'
|
|
1396
|
-
it(`Emails with symbols are valid. (${emailWSymbol})`, async () =>
|
|
1397
|
-
expect(await emailValidator.validate(emailWSymbol)).to.equal(true))
|
|
1398
|
-
const emailWHyphen = 'other.email-with-hyphen@example.com'
|
|
1399
|
-
it(`Emails with hyphens are valid. (${emailWHyphen})`, async () =>
|
|
1400
|
-
expect(await emailValidator.validate(emailWHyphen)).to.equal(true))
|
|
1401
|
-
const emailWFQD = 'fully-qualified-domain@example.com'
|
|
1402
|
-
it(`Emails with fully qualified domains are valid. (${emailWFQD})`, async () =>
|
|
1403
|
-
expect(await emailValidator.validate(emailWFQD)).to.equal(true))
|
|
1404
|
-
const emailWTag = 'user.name+tag+sorting@example.com'
|
|
1405
|
-
it(`Emails with tags and sorting are valid. (${emailWTag})`, async () =>
|
|
1406
|
-
expect(await emailValidator.validate(emailWTag)).to.equal(true))
|
|
1407
|
-
const emailWSingleLetterLocal = 'x@example.com'
|
|
1408
|
-
it(`Emails with a single letter local are valid. (${emailWSingleLetterLocal})`, async () =>
|
|
1409
|
-
expect(await emailValidator.validate(emailWSingleLetterLocal)).to.equal(
|
|
1410
|
-
true
|
|
1411
|
-
))
|
|
1412
|
-
const emailWHyphenDomain = 'example-indeed@strange-example.com'
|
|
1413
|
-
it(`Emails with a hyphenated domain are valid. (${emailWHyphenDomain})`, async () =>
|
|
1414
|
-
expect(await emailValidator.validate(emailWHyphenDomain)).to.equal(true))
|
|
1415
|
-
const emailWTLD = 'admin@mailserver1'
|
|
1416
|
-
it(`Localhost domains are valid. (${emailWTLD})`, async () =>
|
|
1417
|
-
expect(await emailValidator.validate(emailWTLD)).to.equal(true))
|
|
1418
|
-
|
|
1419
|
-
const emailWSlash = 'test/test@test.com'
|
|
1420
|
-
it(`Emails with slashes are valid. (${emailWSlash})`, async () =>
|
|
1421
|
-
expect(await emailValidator.validate(emailWSlash)).to.equal(true))
|
|
1422
|
-
|
|
1423
|
-
const emailWShortTLD = 'admin@test.co'
|
|
1424
|
-
it(`Email with short Top Level Domain are valid. (${emailWShortTLD})`, async () =>
|
|
1425
|
-
expect(await emailValidator.validate(emailWShortTLD)).to.equal(true))
|
|
1426
|
-
const emailWSpaceBetweenQuotes = '" "@example.org'
|
|
1427
|
-
it(`Email with space between quotes for username are valid. (${emailWSpaceBetweenQuotes})`, async () =>
|
|
1428
|
-
expect(await emailValidator.validate(emailWSpaceBetweenQuotes)).to.equal(
|
|
1429
|
-
true
|
|
1430
|
-
))
|
|
1431
|
-
|
|
1432
|
-
const doubleDotBeforeAtWQuote = '"john..doe"@example.com'
|
|
1433
|
-
it(`Emails with 2 dots together in the local are valid when in quotes. (${doubleDotBeforeAtWQuote})`, async () =>
|
|
1434
|
-
expect(await emailValidator.validate(doubleDotBeforeAtWQuote)).to.equal(
|
|
1435
|
-
true
|
|
1436
|
-
))
|
|
1437
|
-
|
|
1438
|
-
const emailWInternalQuoteWDots = 'just."not".right@example.com'
|
|
1439
|
-
it(`Emails with quotes that are surrounded by periods are valid. (${emailWInternalQuoteWDots})`, async () =>
|
|
1440
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
1441
|
-
true
|
|
1442
|
-
))
|
|
1443
|
-
|
|
1444
|
-
const bangifiedHostRoute = 'mailhost!username@example.org'
|
|
1445
|
-
it(`Emails with bangified host routes are valid. (${bangifiedHostRoute})`, async () =>
|
|
1446
|
-
expect(await emailValidator.validate(bangifiedHostRoute)).to.equal(true))
|
|
1447
|
-
|
|
1448
|
-
const percentEscapedMailRoute = 'user%example.com@example.org'
|
|
1449
|
-
it(`Emails with % escaped mail routes are valid. (${percentEscapedMailRoute})`, async () =>
|
|
1450
|
-
expect(await emailValidator.validate(percentEscapedMailRoute)).to.equal(
|
|
1451
|
-
true
|
|
1452
|
-
))
|
|
1453
|
-
|
|
1454
|
-
const localEndingInNonAlphaNum = 'user-@example.org'
|
|
1455
|
-
it(`Emails that end in non-alphanumeric characters that are in the allowed printable characters are valid. (${localEndingInNonAlphaNum})`, async () =>
|
|
1456
|
-
expect(await emailValidator.validate(localEndingInNonAlphaNum)).to.equal(
|
|
1457
|
-
true
|
|
1458
|
-
))
|
|
1459
|
-
|
|
1460
|
-
const gmailEmail = 'test@gmail.com'
|
|
1461
|
-
it(`Gmail emails are valid. (${gmailEmail})`, async () =>
|
|
1462
|
-
expect(await emailValidator.validate(gmailEmail)).to.equal(true))
|
|
1463
|
-
const emailWODomainPeriod = 'james@google'
|
|
1464
|
-
it(`Emails without a period in the domain are valid. (${emailWODomainPeriod})`, async () =>
|
|
1465
|
-
expect(await emailValidator.validate(emailWODomainPeriod)).to.equal(true))
|
|
1466
|
-
|
|
1467
|
-
const percentEscapedMailRouteLocalhost = 'user%example@example.org'
|
|
1468
|
-
it(`Emails with % escaped mail routes that are localhost are valid. (${percentEscapedMailRouteLocalhost})`, async () =>
|
|
1469
|
-
expect(
|
|
1470
|
-
await emailValidator.validate(percentEscapedMailRouteLocalhost)
|
|
1471
|
-
).to.equal(true))
|
|
1472
|
-
})
|
|
1473
|
-
|
|
1474
|
-
describe('Check invalid emails. | Localhost domains valid.', async () => {
|
|
1475
|
-
const emailValidator = new EmailSyntaxValidator({
|
|
1476
|
-
domain: {
|
|
1477
|
-
localhost: true,
|
|
1478
|
-
},
|
|
1479
|
-
})
|
|
1480
|
-
|
|
1481
|
-
const emailWOAt = 'Abc.example.com'
|
|
1482
|
-
it(`Emails without at symbol are invalid. (${emailWOAt})`, async () =>
|
|
1483
|
-
expect(await emailValidator.validate(emailWOAt)).to.equal(false))
|
|
1484
|
-
const emailWAtFirst = '@Abc.example.com'
|
|
1485
|
-
it(`Emails with the at symbol at the beginning are invalid. (${emailWAtFirst})`, async () =>
|
|
1486
|
-
expect(await emailValidator.validate(emailWAtFirst)).to.equal(false))
|
|
1487
|
-
const emailWMultiAts = 'A@b@c@example.com'
|
|
1488
|
-
it(`Emails with multiple ats are invalid. (${emailWMultiAts})`, async () =>
|
|
1489
|
-
expect(await emailValidator.validate(emailWMultiAts)).to.equal(false))
|
|
1490
|
-
const emailWUnquotedSpecialChars = 'a"b(c)d,e:f;g<h>i[j\\k]l@example.com'
|
|
1491
|
-
it(`Emails with unquoted special chars are invalid. (${emailWUnquotedSpecialChars})`, async () =>
|
|
1492
|
-
expect(await emailValidator.validate(emailWUnquotedSpecialChars)).to.equal(
|
|
1493
|
-
false
|
|
1494
|
-
))
|
|
1495
|
-
const emailWQuoteButNoDots = 'just"not"right@example.com'
|
|
1496
|
-
it(`Emails with quotes that are not the only thing but not seperated by dots are invalid. (${emailWQuoteButNoDots})`, async () =>
|
|
1497
|
-
expect(await emailValidator.validate(emailWQuoteButNoDots)).to.equal(false))
|
|
1498
|
-
const emailWSpacesQuotesBackslashOutsideQuotesNoBackslash =
|
|
1499
|
-
'this is"notallowed@example.com'
|
|
1500
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes and not proceeded by a backslash are invalid. (${emailWSpacesQuotesBackslashOutsideQuotesNoBackslash})`, async () =>
|
|
1501
|
-
expect(
|
|
1502
|
-
await emailValidator.validate(
|
|
1503
|
-
emailWSpacesQuotesBackslashOutsideQuotesNoBackslash
|
|
1504
|
-
)
|
|
1505
|
-
).to.equal(false))
|
|
1506
|
-
const emailWSpacesQuotesBackslashOutsideQuotes =
|
|
1507
|
-
'this still"not\\allowed@example.com'
|
|
1508
|
-
it(`Emails with spaces, quotes, and backslashes outside of a quotes are invalid. (${emailWSpacesQuotesBackslashOutsideQuotes})`, async () =>
|
|
1509
|
-
expect(
|
|
1510
|
-
await emailValidator.validate(emailWSpacesQuotesBackslashOutsideQuotes)
|
|
1511
|
-
).to.equal(false))
|
|
1512
|
-
const emailWTooLongLocal =
|
|
1513
|
-
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'
|
|
1514
|
-
it(`Emails with more than 64 chars are invalid. (${emailWTooLongLocal})`, async () =>
|
|
1515
|
-
expect(await emailValidator.validate(emailWTooLongLocal)).to.equal(false))
|
|
1516
|
-
const emailWUnderscoredDomain =
|
|
1517
|
-
'i_like_underscore@but_its_not_allowed_in_this_part.example.com'
|
|
1518
|
-
it(`Emails with underscores in the domain are invalid. (${emailWUnderscoredDomain})`, async () =>
|
|
1519
|
-
expect(await emailValidator.validate(emailWUnderscoredDomain)).to.equal(
|
|
1520
|
-
false
|
|
1521
|
-
))
|
|
1522
|
-
const emailWIconCharacters = 'QA☕CHOCOLATE☕@test.com'
|
|
1523
|
-
it(`Emails with icon characters invalid. (${emailWIconCharacters})`, async () =>
|
|
1524
|
-
expect(await emailValidator.validate(emailWIconCharacters)).to.equal(false))
|
|
1525
|
-
const emailWPeriodNearEnd = 'james@google.c'
|
|
1526
|
-
it(`Emails with periods that are less than 2 chars from the end of the domain are invalid. (${emailWPeriodNearEnd})`, async () =>
|
|
1527
|
-
expect(await emailValidator.validate(emailWPeriodNearEnd)).to.equal(false))
|
|
1528
|
-
const emailWPeriodNearBeginning = 'james@g.com'
|
|
1529
|
-
it(`Emails with periods that are less than 1 chars from the domain beginning are invalid. (${emailWPeriodNearBeginning})`, async () =>
|
|
1530
|
-
expect(await emailValidator.validate(emailWPeriodNearBeginning)).to.equal(
|
|
1531
|
-
false
|
|
1532
|
-
))
|
|
1533
|
-
const emailWSpaceButNoQuotes = 'james richards@google.com'
|
|
1534
|
-
it(`Emails with spaces but no quotes are invalid. (${emailWSpaceButNoQuotes})`, async () =>
|
|
1535
|
-
expect(await emailValidator.validate(emailWSpaceButNoQuotes)).to.equal(
|
|
1536
|
-
false
|
|
1537
|
-
))
|
|
1538
|
-
const emailWSpaceButOnlyQuoteBefore = 'james" richards@google.com'
|
|
1539
|
-
it(`Emails with spaces but only a quote before or after are invlaid. (${emailWSpaceButOnlyQuoteBefore})`, async () =>
|
|
1540
|
-
expect(
|
|
1541
|
-
await emailValidator.validate(emailWSpaceButOnlyQuoteBefore)
|
|
1542
|
-
).to.equal(false))
|
|
1543
|
-
const emailWInvalidDomainChars = 'james@cb$.com'
|
|
1544
|
-
it(`Emails with invalid chars in the domain are invalid. (${emailWInvalidDomainChars})`, async () =>
|
|
1545
|
-
expect(await emailValidator.validate(emailWInvalidDomainChars)).to.equal(
|
|
1546
|
-
false
|
|
1547
|
-
))
|
|
1548
|
-
const emailWQuoteButMissingDots = 'just."not"right@example.com'
|
|
1549
|
-
it(`Emails with quotes that are not the only thing but are missing some of the dots that should surround quotes are invalid. (${emailWQuoteButMissingDots})`, async () =>
|
|
1550
|
-
expect(await emailValidator.validate(emailWQuoteButMissingDots)).to.equal(
|
|
1551
|
-
false
|
|
1552
|
-
))
|
|
1553
|
-
const doubleDotBeforeAt = 'john..doe@example.com'
|
|
1554
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAt})`, async () =>
|
|
1555
|
-
expect(await emailValidator.validate(doubleDotBeforeAt)).to.equal(false))
|
|
1556
|
-
|
|
1557
|
-
const doubleDotBeforeAtAndOneQuote = '"john..doe@example.com'
|
|
1558
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndOneQuote})`, async () =>
|
|
1559
|
-
expect(
|
|
1560
|
-
await emailValidator.validate(doubleDotBeforeAtAndOneQuote)
|
|
1561
|
-
).to.equal(false))
|
|
1562
|
-
const doubleDotBeforeAtAndTwoQuotesBeforePeriods = '"john"..doe@example.com'
|
|
1563
|
-
it(`Emails with 2 dots together in the local are invalid unless quoted. (${doubleDotBeforeAtAndTwoQuotesBeforePeriods})`, async () =>
|
|
1564
|
-
expect(
|
|
1565
|
-
await emailValidator.validate(doubleDotBeforeAtAndTwoQuotesBeforePeriods)
|
|
1566
|
-
).to.equal(false))
|
|
1567
|
-
const doubleDotAfterAt = 'john.doe@example..com'
|
|
1568
|
-
it(`Emails with 2 dots together after the at are invalid. (${doubleDotAfterAt})`, async () =>
|
|
1569
|
-
expect(await emailValidator.validate(doubleDotAfterAt)).to.equal(false))
|
|
1570
|
-
const emailWInternalQuoteWDots = 'just."not."right@example.com'
|
|
1571
|
-
it(`Emails with quotes that have periods next to them but are not onside are invalid. (${emailWInternalQuoteWDots})`, async () =>
|
|
1572
|
-
expect(await emailValidator.validate(emailWInternalQuoteWDots)).to.equal(
|
|
1573
|
-
false
|
|
1574
|
-
))
|
|
1575
|
-
const emailInvalidTld = 'test@example.thisisnotavalidtld'
|
|
1576
|
-
it(`Emails that are non-icann tlds invalid. (${emailInvalidTld})`, async () =>
|
|
1577
|
-
expect(await emailValidator.validate(emailInvalidTld)).to.equal(false))
|
|
1578
|
-
})
|
|
1579
|
-
|
|
1580
|
-
describe('Check run time for 1000 emails.', async () => {
|
|
1581
|
-
const emailValidator = new EmailSyntaxValidator()
|
|
1582
|
-
|
|
1583
|
-
const validEmail = 'test@google.com'
|
|
1584
|
-
const maxTime = 20
|
|
1585
|
-
it(`Valid emails run 1000 times should take less than ${maxTime} milliseconds.`, async () => {
|
|
1586
|
-
const startTime = performance.now()
|
|
1587
|
-
const promises = []
|
|
1588
|
-
for (let i = 0; i < 1000; i += 1) {
|
|
1589
|
-
promises.push(emailValidator.validate(validEmail))
|
|
1590
|
-
}
|
|
1591
|
-
await Promise.all(promises)
|
|
1592
|
-
const endTime = performance.now()
|
|
1593
|
-
|
|
1594
|
-
console.log(`Valid emails took ${endTime - startTime} milliseconds`)
|
|
1595
|
-
|
|
1596
|
-
return expect(endTime - startTime).to.be.below(maxTime)
|
|
1597
|
-
})
|
|
1598
|
-
const invalidEmail = 'invalid@cb$.com'
|
|
1599
|
-
it(`Invalid emails run 1000 times should take less than ${maxTime} milliseconds.`, async () => {
|
|
1600
|
-
const startTime = performance.now()
|
|
1601
|
-
const promises = []
|
|
1602
|
-
for (let i = 0; i < 1000; i += 1) {
|
|
1603
|
-
promises.push(emailValidator.validate(invalidEmail))
|
|
1604
|
-
}
|
|
1605
|
-
await Promise.all(promises)
|
|
1606
|
-
const endTime = performance.now()
|
|
1607
|
-
|
|
1608
|
-
console.log(`Invalid emails took ${endTime - startTime} milliseconds`)
|
|
1609
|
-
|
|
1610
|
-
return expect(endTime - startTime).to.be.below(maxTime)
|
|
1611
|
-
})
|
|
1612
|
-
})
|