1 | /*
|
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | * contributor license agreements. See the NOTICE file distributed with
|
---|
4 | * this work for additional information regarding copyright ownership.
|
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | * (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | * See the License for the specific language governing permissions and
|
---|
15 | * limitations under the License.
|
---|
16 | */
|
---|
17 | package org.openstreetmap.josm.data.validation.routines;
|
---|
18 |
|
---|
19 | import static org.junit.Assert.assertEquals;
|
---|
20 | import static org.junit.Assert.assertFalse;
|
---|
21 | import static org.junit.Assert.assertTrue;
|
---|
22 |
|
---|
23 | import org.junit.Before;
|
---|
24 | import org.junit.Ignore;
|
---|
25 | import org.junit.Test;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Performs Validation Test for e-mail validations.
|
---|
29 | *
|
---|
30 | *
|
---|
31 | * @version $Revision: 1723573 $
|
---|
32 | */
|
---|
33 | public class EmailValidatorTest {
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The key used to retrieve the set of validation
|
---|
37 | * rules from the xml file.
|
---|
38 | */
|
---|
39 | protected static String FORM_KEY = "emailForm";
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The key used to retrieve the validator action.
|
---|
43 | */
|
---|
44 | protected static String ACTION = "email";
|
---|
45 |
|
---|
46 | private EmailValidator validator;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Setup
|
---|
50 | */
|
---|
51 | @Before
|
---|
52 | public void setUp() {
|
---|
53 | validator = EmailValidator.getInstance();
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Tests the e-mail validation.
|
---|
58 | */
|
---|
59 | @Test
|
---|
60 | public void testEmail() {
|
---|
61 | assertTrue(validator.isValid("jsmith@apache.org"));
|
---|
62 | assertFalse(validator.isValid(null));
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Tests the email validation with numeric domains.
|
---|
67 | */
|
---|
68 | @Test
|
---|
69 | public void testEmailWithNumericAddress() {
|
---|
70 | assertTrue(validator.isValid("someone@[216.109.118.76]"));
|
---|
71 | assertTrue(validator.isValid("someone@yahoo.com"));
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Tests the e-mail validation.
|
---|
76 | */
|
---|
77 | @Test
|
---|
78 | public void testEmailExtension() {
|
---|
79 | assertTrue(validator.isValid("jsmith@apache.org"));
|
---|
80 |
|
---|
81 | assertTrue(validator.isValid("jsmith@apache.com"));
|
---|
82 |
|
---|
83 | assertTrue(validator.isValid("jsmith@apache.net"));
|
---|
84 |
|
---|
85 | assertTrue(validator.isValid("jsmith@apache.info"));
|
---|
86 |
|
---|
87 | assertFalse(validator.isValid("jsmith@apache."));
|
---|
88 |
|
---|
89 | assertFalse(validator.isValid("jsmith@apache.c"));
|
---|
90 |
|
---|
91 | assertTrue(validator.isValid("someone@yahoo.museum"));
|
---|
92 |
|
---|
93 | assertFalse(validator.isValid("someone@yahoo.mu-seum"));
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Tests the e-mail validation with a dash in
|
---|
98 | * the address.
|
---|
99 | */
|
---|
100 | @Test
|
---|
101 | public void testEmailWithDash() {
|
---|
102 | assertTrue(validator.isValid("andy.noble@data-workshop.com"));
|
---|
103 |
|
---|
104 | assertFalse(validator.isValid("andy-noble@data-workshop.-com"));
|
---|
105 |
|
---|
106 | assertFalse(validator.isValid("andy-noble@data-workshop.c-om"));
|
---|
107 |
|
---|
108 | assertFalse(validator.isValid("andy-noble@data-workshop.co-m"));
|
---|
109 | }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Tests the e-mail validation with a dot at the end of
|
---|
113 | * the address.
|
---|
114 | */
|
---|
115 | @Test
|
---|
116 | public void testEmailWithDotEnd() {
|
---|
117 | assertFalse(validator.isValid("andy.noble@data-workshop.com."));
|
---|
118 | }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Tests the e-mail validation with an RCS-noncompliant character in
|
---|
122 | * the address.
|
---|
123 | */
|
---|
124 | @Test
|
---|
125 | public void testEmailWithBogusCharacter() {
|
---|
126 |
|
---|
127 | assertFalse(validator.isValid("andy.noble@\u008fdata-workshop.com"));
|
---|
128 |
|
---|
129 | // The ' character is valid in an email username.
|
---|
130 | assertTrue(validator.isValid("andy.o'reilly@data-workshop.com"));
|
---|
131 |
|
---|
132 | // But not in the domain name.
|
---|
133 | assertFalse(validator.isValid("andy@o'reilly.data-workshop.com"));
|
---|
134 |
|
---|
135 | // The + character is valid in an email username.
|
---|
136 | assertTrue(validator.isValid("foo+bar@i.am.not.in.us.example.com"));
|
---|
137 |
|
---|
138 | // But not in the domain name
|
---|
139 | assertFalse(validator.isValid("foo+bar@example+3.com"));
|
---|
140 |
|
---|
141 | // Domains with only special characters aren't allowed (VALIDATOR-286)
|
---|
142 | assertFalse(validator.isValid("test@%*.com"));
|
---|
143 | assertFalse(validator.isValid("test@^&#.com"));
|
---|
144 | }
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Non-regression test for VALIDATOR-315
|
---|
148 | */
|
---|
149 | @Test
|
---|
150 | public void testVALIDATOR_315() {
|
---|
151 | assertFalse(validator.isValid("me@at&t.net"));
|
---|
152 | assertTrue(validator.isValid("me@att.net")); // Make sure TLD is not the cause of the failure
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Non-regression test for VALIDATOR-278
|
---|
157 | */
|
---|
158 | @Test
|
---|
159 | public void testVALIDATOR_278() {
|
---|
160 | assertFalse(validator.isValid("someone@-test.com")); // hostname starts with dash/hyphen
|
---|
161 | assertFalse(validator.isValid("someone@test-.com")); // hostname ends with dash/hyphen
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Non-regression test for VALIDATOR-235
|
---|
166 | */
|
---|
167 | @Test
|
---|
168 | public void testValidator235() {
|
---|
169 | String version = System.getProperty("java.version");
|
---|
170 | if (version.compareTo("1.6") < 0) {
|
---|
171 | System.out.println("Cannot run Unicode IDN tests");
|
---|
172 | return; // Cannot run the test
|
---|
173 | }
|
---|
174 | assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"));
|
---|
175 | assertTrue("президент.рф should validate", validator.isValid("someone@президент.рф"));
|
---|
176 | assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
|
---|
177 | assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
|
---|
178 | assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
|
---|
179 | assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Tests the email validation with commas.
|
---|
184 | */
|
---|
185 | @Test
|
---|
186 | public void testEmailWithCommas() {
|
---|
187 | assertFalse(validator.isValid("joeblow@apa,che.org"));
|
---|
188 |
|
---|
189 | assertFalse(validator.isValid("joeblow@apache.o,rg"));
|
---|
190 |
|
---|
191 | assertFalse(validator.isValid("joeblow@apache,org"));
|
---|
192 | }
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Tests the email validation with spaces.
|
---|
196 | */
|
---|
197 | @Test
|
---|
198 | public void testEmailWithSpaces() {
|
---|
199 | assertFalse(validator.isValid("joeblow @apache.org")); // TODO - this should be valid?
|
---|
200 |
|
---|
201 | assertFalse(validator.isValid("joeblow@ apache.org"));
|
---|
202 |
|
---|
203 | assertTrue(validator.isValid(" joeblow@apache.org")); // TODO - this should be valid?
|
---|
204 |
|
---|
205 | assertTrue(validator.isValid("joeblow@apache.org "));
|
---|
206 |
|
---|
207 | assertFalse(validator.isValid("joe blow@apache.org "));
|
---|
208 |
|
---|
209 | assertFalse(validator.isValid("joeblow@apa che.org "));
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Tests the email validation with ascii control characters.
|
---|
214 | * (i.e. Ascii chars 0 - 31 and 127)
|
---|
215 | */
|
---|
216 | @Test
|
---|
217 | public void testEmailWithControlChars() {
|
---|
218 | for (char c = 0; c < 32; c++) {
|
---|
219 | assertFalse("Test control char " + ((int) c), validator.isValid("foo" + c + "bar@domain.com"));
|
---|
220 | }
|
---|
221 | assertFalse("Test control char 127", validator.isValid("foo" + ((char) 127) + "bar@domain.com"));
|
---|
222 | }
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Test that @localhost and @localhost.localdomain
|
---|
226 | * addresses are declared as valid when requested.
|
---|
227 | */
|
---|
228 | @Test
|
---|
229 | public void testEmailLocalhost() {
|
---|
230 | // Check the default is not to allow
|
---|
231 | EmailValidator noLocal = EmailValidator.getInstance(false);
|
---|
232 | EmailValidator allowLocal = EmailValidator.getInstance(true);
|
---|
233 | assertEquals(validator, noLocal);
|
---|
234 |
|
---|
235 | // Depends on the validator
|
---|
236 | assertTrue(
|
---|
237 | "@localhost.localdomain should be accepted but wasn't",
|
---|
238 | allowLocal.isValid("joe@localhost.localdomain")
|
---|
239 | );
|
---|
240 | assertTrue(
|
---|
241 | "@localhost should be accepted but wasn't",
|
---|
242 | allowLocal.isValid("joe@localhost")
|
---|
243 | );
|
---|
244 |
|
---|
245 | assertFalse(
|
---|
246 | "@localhost.localdomain should be accepted but wasn't",
|
---|
247 | noLocal.isValid("joe@localhost.localdomain")
|
---|
248 | );
|
---|
249 | assertFalse(
|
---|
250 | "@localhost should be accepted but wasn't",
|
---|
251 | noLocal.isValid("joe@localhost")
|
---|
252 | );
|
---|
253 | }
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * VALIDATOR-296 - A / or a ! is valid in the user part,
|
---|
257 | * but not in the domain part
|
---|
258 | */
|
---|
259 | @Test
|
---|
260 | public void testEmailWithSlashes() {
|
---|
261 | assertTrue(
|
---|
262 | "/ and ! valid in username",
|
---|
263 | validator.isValid("joe!/blow@apache.org")
|
---|
264 | );
|
---|
265 | assertFalse(
|
---|
266 | "/ not valid in domain",
|
---|
267 | validator.isValid("joe@ap/ache.org")
|
---|
268 | );
|
---|
269 | assertFalse(
|
---|
270 | "! not valid in domain",
|
---|
271 | validator.isValid("joe@apac!he.org")
|
---|
272 | );
|
---|
273 | }
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Write this test according to parts of RFC, as opposed to the type of character
|
---|
277 | * that is being tested.
|
---|
278 | */
|
---|
279 | @Test
|
---|
280 | public void testEmailUserName() {
|
---|
281 |
|
---|
282 | assertTrue(validator.isValid("joe1blow@apache.org"));
|
---|
283 |
|
---|
284 | assertTrue(validator.isValid("joe$blow@apache.org"));
|
---|
285 |
|
---|
286 | assertTrue(validator.isValid("joe-@apache.org"));
|
---|
287 |
|
---|
288 | assertTrue(validator.isValid("joe_@apache.org"));
|
---|
289 |
|
---|
290 | assertTrue(validator.isValid("joe+@apache.org")); // + is valid unquoted
|
---|
291 |
|
---|
292 | assertTrue(validator.isValid("joe!@apache.org")); // ! is valid unquoted
|
---|
293 |
|
---|
294 | assertTrue(validator.isValid("joe*@apache.org")); // * is valid unquoted
|
---|
295 |
|
---|
296 | assertTrue(validator.isValid("joe'@apache.org")); // ' is valid unquoted
|
---|
297 |
|
---|
298 | assertTrue(validator.isValid("joe%45@apache.org")); // % is valid unquoted
|
---|
299 |
|
---|
300 | assertTrue(validator.isValid("joe?@apache.org")); // ? is valid unquoted
|
---|
301 |
|
---|
302 | assertTrue(validator.isValid("joe&@apache.org")); // & ditto
|
---|
303 |
|
---|
304 | assertTrue(validator.isValid("joe=@apache.org")); // = ditto
|
---|
305 |
|
---|
306 | assertTrue(validator.isValid("+joe@apache.org")); // + is valid unquoted
|
---|
307 |
|
---|
308 | assertTrue(validator.isValid("!joe@apache.org")); // ! is valid unquoted
|
---|
309 |
|
---|
310 | assertTrue(validator.isValid("*joe@apache.org")); // * is valid unquoted
|
---|
311 |
|
---|
312 | assertTrue(validator.isValid("'joe@apache.org")); // ' is valid unquoted
|
---|
313 |
|
---|
314 | assertTrue(validator.isValid("%joe45@apache.org")); // % is valid unquoted
|
---|
315 |
|
---|
316 | assertTrue(validator.isValid("?joe@apache.org")); // ? is valid unquoted
|
---|
317 |
|
---|
318 | assertTrue(validator.isValid("&joe@apache.org")); // & ditto
|
---|
319 |
|
---|
320 | assertTrue(validator.isValid("=joe@apache.org")); // = ditto
|
---|
321 |
|
---|
322 | assertTrue(validator.isValid("+@apache.org")); // + is valid unquoted
|
---|
323 |
|
---|
324 | assertTrue(validator.isValid("!@apache.org")); // ! is valid unquoted
|
---|
325 |
|
---|
326 | assertTrue(validator.isValid("*@apache.org")); // * is valid unquoted
|
---|
327 |
|
---|
328 | assertTrue(validator.isValid("'@apache.org")); // ' is valid unquoted
|
---|
329 |
|
---|
330 | assertTrue(validator.isValid("%@apache.org")); // % is valid unquoted
|
---|
331 |
|
---|
332 | assertTrue(validator.isValid("?@apache.org")); // ? is valid unquoted
|
---|
333 |
|
---|
334 | assertTrue(validator.isValid("&@apache.org")); // & ditto
|
---|
335 |
|
---|
336 | assertTrue(validator.isValid("=@apache.org")); // = ditto
|
---|
337 |
|
---|
338 |
|
---|
339 | //UnQuoted Special characters are invalid
|
---|
340 |
|
---|
341 | assertFalse(validator.isValid("joe.@apache.org")); // . not allowed at end of local part
|
---|
342 |
|
---|
343 | assertFalse(validator.isValid(".joe@apache.org")); // . not allowed at start of local part
|
---|
344 |
|
---|
345 | assertFalse(validator.isValid(".@apache.org")); // . not allowed alone
|
---|
346 |
|
---|
347 | assertTrue(validator.isValid("joe.ok@apache.org")); // . allowed embedded
|
---|
348 |
|
---|
349 | assertFalse(validator.isValid("joe..ok@apache.org")); // .. not allowed embedded
|
---|
350 |
|
---|
351 | assertFalse(validator.isValid("..@apache.org")); // .. not allowed alone
|
---|
352 |
|
---|
353 | assertFalse(validator.isValid("joe(@apache.org"));
|
---|
354 |
|
---|
355 | assertFalse(validator.isValid("joe)@apache.org"));
|
---|
356 |
|
---|
357 | assertFalse(validator.isValid("joe,@apache.org"));
|
---|
358 |
|
---|
359 | assertFalse(validator.isValid("joe;@apache.org"));
|
---|
360 |
|
---|
361 |
|
---|
362 | //Quoted Special characters are valid
|
---|
363 | assertTrue(validator.isValid("\"joe.\"@apache.org"));
|
---|
364 |
|
---|
365 | assertTrue(validator.isValid("\".joe\"@apache.org"));
|
---|
366 |
|
---|
367 | assertTrue(validator.isValid("\"joe+\"@apache.org"));
|
---|
368 |
|
---|
369 | assertTrue(validator.isValid("\"joe!\"@apache.org"));
|
---|
370 |
|
---|
371 | assertTrue(validator.isValid("\"joe*\"@apache.org"));
|
---|
372 |
|
---|
373 | assertTrue(validator.isValid("\"joe'\"@apache.org"));
|
---|
374 |
|
---|
375 | assertTrue(validator.isValid("\"joe(\"@apache.org"));
|
---|
376 |
|
---|
377 | assertTrue(validator.isValid("\"joe)\"@apache.org"));
|
---|
378 |
|
---|
379 | assertTrue(validator.isValid("\"joe,\"@apache.org"));
|
---|
380 |
|
---|
381 | assertTrue(validator.isValid("\"joe%45\"@apache.org"));
|
---|
382 |
|
---|
383 | assertTrue(validator.isValid("\"joe;\"@apache.org"));
|
---|
384 |
|
---|
385 | assertTrue(validator.isValid("\"joe?\"@apache.org"));
|
---|
386 |
|
---|
387 | assertTrue(validator.isValid("\"joe&\"@apache.org"));
|
---|
388 |
|
---|
389 | assertTrue(validator.isValid("\"joe=\"@apache.org"));
|
---|
390 |
|
---|
391 | assertTrue(validator.isValid("\"..\"@apache.org"));
|
---|
392 |
|
---|
393 | // escaped quote character valid in quoted string
|
---|
394 | assertTrue(validator.isValid("\"john\\\"doe\"@apache.org"));
|
---|
395 |
|
---|
396 | assertTrue(validator.isValid("john56789.john56789.john56789.john56789.john56789.john56789.john@example.com"));
|
---|
397 |
|
---|
398 | assertFalse(validator.isValid("john56789.john56789.john56789.john56789.john56789.john56789.john5@example.com"));
|
---|
399 |
|
---|
400 | assertTrue(validator.isValid("\\>escape\\\\special\\^characters\\<@example.com"));
|
---|
401 |
|
---|
402 | assertTrue(validator.isValid("Abc\\@def@example.com"));
|
---|
403 |
|
---|
404 | assertFalse(validator.isValid("Abc@def@example.com"));
|
---|
405 |
|
---|
406 | assertTrue(validator.isValid("space\\ monkey@example.com"));
|
---|
407 | }
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * These test values derive directly from RFC 822 &
|
---|
411 | * Mail::RFC822::Address & RFC::RFC822::Address perl test.pl
|
---|
412 | * For traceability don't combine these test values with other tests.
|
---|
413 | */
|
---|
414 | private static final ResultPair[] testEmailFromPerl = {
|
---|
415 | new ResultPair("abigail@example.com", true),
|
---|
416 | new ResultPair("abigail@example.com ", true),
|
---|
417 | new ResultPair(" abigail@example.com", true),
|
---|
418 | new ResultPair("abigail @example.com ", true),
|
---|
419 | new ResultPair("*@example.net", true),
|
---|
420 | new ResultPair("\"\\\"\"@foo.bar", true),
|
---|
421 | new ResultPair("fred&barny@example.com", true),
|
---|
422 | new ResultPair("---@example.com", true),
|
---|
423 | new ResultPair("foo-bar@example.net", true),
|
---|
424 | new ResultPair("\"127.0.0.1\"@[127.0.0.1]", true),
|
---|
425 | new ResultPair("Abigail <abigail@example.com>", true),
|
---|
426 | new ResultPair("Abigail<abigail@example.com>", true),
|
---|
427 | new ResultPair("Abigail<@a,@b,@c:abigail@example.com>", true),
|
---|
428 | new ResultPair("\"This is a phrase\"<abigail@example.com>", true),
|
---|
429 | new ResultPair("\"Abigail \"<abigail@example.com>", true),
|
---|
430 | new ResultPair("\"Joe & J. Harvey\" <example @Org>", true),
|
---|
431 | new ResultPair("Abigail <abigail @ example.com>", true),
|
---|
432 | new ResultPair("Abigail made this < abigail @ example . com >", true),
|
---|
433 | new ResultPair("Abigail(the bitch)@example.com", true),
|
---|
434 | new ResultPair("Abigail <abigail @ example . (bar) com >", true),
|
---|
435 | new ResultPair("Abigail < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
|
---|
436 | new ResultPair("Abigail (foo) (((baz)(nested) (comment)) ! ) < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
|
---|
437 | new ResultPair("Abigail <abigail(fo\\(o)@example.com>", true),
|
---|
438 | new ResultPair("Abigail <abigail(fo\\)o)@example.com> ", true),
|
---|
439 | new ResultPair("(foo) abigail@example.com", true),
|
---|
440 | new ResultPair("abigail@example.com (foo)", true),
|
---|
441 | new ResultPair("\"Abi\\\"gail\" <abigail@example.com>", true),
|
---|
442 | new ResultPair("abigail@[example.com]", true),
|
---|
443 | new ResultPair("abigail@[exa\\[ple.com]", true),
|
---|
444 | new ResultPair("abigail@[exa\\]ple.com]", true),
|
---|
445 | new ResultPair("\":sysmail\"@ Some-Group. Some-Org", true),
|
---|
446 | new ResultPair("Muhammed.(I am the greatest) Ali @(the)Vegas.WBA", true),
|
---|
447 | new ResultPair("mailbox.sub1.sub2@this-domain", true),
|
---|
448 | new ResultPair("sub-net.mailbox@sub-domain.domain", true),
|
---|
449 | new ResultPair("name:;", true),
|
---|
450 | new ResultPair("':;", true),
|
---|
451 | new ResultPair("name: ;", true),
|
---|
452 | new ResultPair("Alfred Neuman <Neuman@BBN-TENEXA>", true),
|
---|
453 | new ResultPair("Neuman@BBN-TENEXA", true),
|
---|
454 | new ResultPair("\"George, Ted\" <Shared@Group.Arpanet>", true),
|
---|
455 | new ResultPair("Wilt . (the Stilt) Chamberlain@NBA.US", true),
|
---|
456 | new ResultPair("Cruisers: Port@Portugal, Jones@SEA;", true),
|
---|
457 | new ResultPair("$@[]", true),
|
---|
458 | new ResultPair("*()@[]", true),
|
---|
459 | new ResultPair("\"quoted ( brackets\" ( a comment )@example.com", true),
|
---|
460 | new ResultPair("\"Joe & J. Harvey\"\\x0D\\x0A <ddd\\@ Org>", true),
|
---|
461 | new ResultPair("\"Joe &\\x0D\\x0A J. Harvey\" <ddd \\@ Org>", true),
|
---|
462 | new ResultPair("Gourmets: Pompous Person <WhoZiWhatZit\\@Cordon-Bleu>,\\x0D\\x0A" +
|
---|
463 | " Childs\\@WGBH.Boston, \"Galloping Gourmet\"\\@\\x0D\\x0A" +
|
---|
464 | " ANT.Down-Under (Australian National Television),\\x0D\\x0A" +
|
---|
465 | " Cheapie\\@Discount-Liquors;", true),
|
---|
466 | new ResultPair(" Just a string", false),
|
---|
467 | new ResultPair("string", false),
|
---|
468 | new ResultPair("(comment)", false),
|
---|
469 | new ResultPair("()@example.com", false),
|
---|
470 | new ResultPair("fred(&)barny@example.com", false),
|
---|
471 | new ResultPair("fred\\ barny@example.com", false),
|
---|
472 | new ResultPair("Abigail <abi gail @ example.com>", false),
|
---|
473 | new ResultPair("Abigail <abigail(fo(o)@example.com>", false),
|
---|
474 | new ResultPair("Abigail <abigail(fo)o)@example.com>", false),
|
---|
475 | new ResultPair("\"Abi\"gail\" <abigail@example.com>", false),
|
---|
476 | new ResultPair("abigail@[exa]ple.com]", false),
|
---|
477 | new ResultPair("abigail@[exa[ple.com]", false),
|
---|
478 | new ResultPair("abigail@[exaple].com]", false),
|
---|
479 | new ResultPair("abigail@", false),
|
---|
480 | new ResultPair("@example.com", false),
|
---|
481 | new ResultPair("phrase: abigail@example.com abigail@example.com ;", false),
|
---|
482 | new ResultPair("invalid�char@example.com", false)
|
---|
483 | };
|
---|
484 |
|
---|
485 | /**
|
---|
486 | * Write this test based on perl Mail::RFC822::Address
|
---|
487 | * which takes its example email address directly from RFC822
|
---|
488 | *
|
---|
489 | * FIXME This test fails so disable it with a leading _ for 1.1.4 release.
|
---|
490 | * The real solution is to fix the email parsing.
|
---|
491 | */
|
---|
492 | @Ignore("This test fails so disable it for 1.1.4 release. The real solution is to fix the email parsing")
|
---|
493 | @Test
|
---|
494 | public void testEmailFromPerl() {
|
---|
495 | for (int index = 0; index < testEmailFromPerl.length; index++) {
|
---|
496 | String item = testEmailFromPerl[index].item;
|
---|
497 | if (testEmailFromPerl[index].valid) {
|
---|
498 | assertTrue("Should be OK: "+item, validator.isValid(item));
|
---|
499 | } else {
|
---|
500 | assertFalse("Should fail: "+item, validator.isValid(item));
|
---|
501 | }
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | /**
|
---|
506 | * Non-regression test for VALIDATOR-293
|
---|
507 | */
|
---|
508 | @Test
|
---|
509 | public void testValidator293() {
|
---|
510 | assertTrue(validator.isValid("abc-@abc.com"));
|
---|
511 | assertTrue(validator.isValid("abc_@abc.com"));
|
---|
512 | assertTrue(validator.isValid("abc-def@abc.com"));
|
---|
513 | assertTrue(validator.isValid("abc_def@abc.com"));
|
---|
514 | assertFalse(validator.isValid("abc@abc_def.com"));
|
---|
515 | }
|
---|
516 |
|
---|
517 | /**
|
---|
518 | * Non-regression test for VALIDATOR-365
|
---|
519 | */
|
---|
520 | @Test
|
---|
521 | public void testValidator365() {
|
---|
522 | assertFalse(validator.isValid(
|
---|
523 | "Loremipsumdolorsitametconsecteturadipiscingelit.Nullavitaeligulamattisrhoncusnuncegestasmattisleo."+
|
---|
524 | "Donecnonsapieninmagnatristiquedictumaacturpis.Fusceorciduifacilisisutsapieneuconsequatpharetralectus."+
|
---|
525 | "Quisqueenimestpulvinarutquamvitaeportamattisex.Nullamquismaurisplaceratconvallisjustoquisportamauris."+
|
---|
526 | "Innullalacusconvalliseufringillautvenenatissitametdiam.Maecenasluctusligulascelerisquepulvinarfeugiat."+
|
---|
527 | "Sedmolestienullaaliquetorciluctusidpharetranislfinibus.Suspendissemalesuadatinciduntduisitametportaarcusollicitudinnec."+
|
---|
528 | "Donecetmassamagna.Curabitururnadiampretiumveldignissimporttitorfringillaeuneque."+
|
---|
529 | "Duisantetelluspharetraidtinciduntinterdummolestiesitametfelis.Utquisquamsitametantesagittisdapibusacnonodio."+
|
---|
530 | "Namrutrummolestiediamidmattis.Cumsociisnatoquepenatibusetmagnisdisparturientmontesnasceturridiculusmus."+
|
---|
531 | "Morbiposueresedmetusacconsectetur.Etiamquisipsumvitaejustotempusmaximus.Sedultriciesplaceratvolutpat."+
|
---|
532 | "Integerlacuslectusmaximusacornarequissagittissitametjusto."+
|
---|
533 | "Cumsociisnatoquepenatibusetmagnisdisparturientmontesnasceturridiculusmus.Maecenasindictumpurussedrutrumex.Nullafacilisi."+
|
---|
534 | "Integerfinibusfinibusmietpharetranislfaucibusvel.Maecenasegetdolorlacinialobortisjustovelullamcorpersem."+
|
---|
535 | "Vivamusaliquetpurusidvariusornaresapienrisusrutrumnisitinciduntmollissemnequeidmetus."+
|
---|
536 | "Etiamquiseleifendpurus.Nuncfelisnuncscelerisqueiddignissimnecfinibusalibero."+
|
---|
537 | "Nuncsemperenimnequesitamethendreritpurusfacilisisac.Maurisdapibussemperfelisdignissimgravida."+
|
---|
538 | "Aeneanultricesblanditnequealiquamfinibusodioscelerisqueac.Aliquamnecmassaeumaurisfaucibusfringilla."+
|
---|
539 | "Etiamconsequatligulanisisitametaliquamnibhtemporquis.Nuncinterdumdignissimnullaatsodalesarcusagittiseu."+
|
---|
540 | "Proinpharetrametusneclacuspulvinarsedvolutpatliberoornare.Sedligulanislpulvinarnonlectuseublanditfacilisisante."+
|
---|
541 | "Sedmollisnislalacusauctorsuscipit.Inhachabitasseplateadictumst.Phasellussitametvelittemporvenenatisfeliseuegestasrisus."+
|
---|
542 | "Aliquameteratsitametnibhcommodofinibus.Morbiefficiturodiovelpulvinariaculis."+
|
---|
543 | "Aeneantemporipsummassaaconsecteturturpisfaucibusultrices.Praesentsodalesmaurisquisportafermentum."+
|
---|
544 | "Etiamnisinislvenenatisvelauctorutullamcorperinjusto.Proinvelligulaerat.Phasellusvestibulumgravidamassanonfeugiat."+
|
---|
545 | "Maecenaspharetraeuismodmetusegetefficitur.Suspendisseamet@gmail.com"));
|
---|
546 | }
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * Tests the e-mail validation with a user at a TLD
|
---|
550 | *
|
---|
551 | * http://tools.ietf.org/html/rfc5321#section-2.3.5
|
---|
552 | * (In the case of a top-level domain used by itself in an
|
---|
553 | * email address, a single string is used without any dots)
|
---|
554 | */
|
---|
555 | @Test
|
---|
556 | public void testEmailAtTLD() {
|
---|
557 | EmailValidator val = EmailValidator.getInstance(false, true);
|
---|
558 | assertTrue(val.isValid("test@com"));
|
---|
559 | }
|
---|
560 |
|
---|
561 | /**
|
---|
562 | * Non-regression test for VALIDATOR-359
|
---|
563 | */
|
---|
564 | @Test
|
---|
565 | public void testValidator359() {
|
---|
566 | EmailValidator val = EmailValidator.getInstance(false, true);
|
---|
567 | assertFalse(val.isValid("test@.com"));
|
---|
568 | }
|
---|
569 |
|
---|
570 | /**
|
---|
571 | * Non-regression test for VALIDATOR-374
|
---|
572 | */
|
---|
573 | @Test
|
---|
574 | public void testValidator374() {
|
---|
575 | assertTrue(validator.isValid("abc@school.school"));
|
---|
576 | }
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Unit test of {@link EmailValidator#getValidatorName}.
|
---|
580 | */
|
---|
581 | @Test
|
---|
582 | public void testValidatorName() {
|
---|
583 | assertEquals("Email validator", EmailValidator.getInstance().getValidatorName());
|
---|
584 | }
|
---|
585 | }
|
---|