rleland 2003/08/16 21:21:05 Modified: validator/src/test/org/apache/commons/validator EmailTest.java Log: Bug 22124 Add tests so Email validation will fail. These tests test for all special characters allowed in the users part of the email. Both serverside java and javascript need to be fixed. Revision Changes Path 1.17 +73 -17 jakarta-commons/validator/src/test/org/apache/commons/validator/EmailTest.java Index: EmailTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/EmailTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- EmailTest.java 12 Aug 2003 00:29:34 -0000 1.16 +++ EmailTest.java 17 Aug 2003 04:21:05 -0000 1.17 @@ -7,7 +7,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999-2003 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written - * permission of the Apache Group. + * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -77,6 +77,7 @@ * * @author David Winterfeldt * @author David Graham + * @author Rob Leland * @version $Revision$ $Date$ */ public class EmailTest extends TestCase { @@ -200,8 +201,12 @@ info.setValue("[EMAIL PROTECTED]"); valueTest(info, true); - info.setValue("[EMAIL PROTECTED]"); - valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, false); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, false); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); } @@ -241,15 +246,66 @@ /** * Tests the email validation with commas. */ - public void testEmailWithCommas() throws ValidatorException { - ValueBean info = new ValueBean(); - info.setValue("joe,[EMAIL PROTECTED]"); - valueTest(info, false); - info.setValue("[EMAIL PROTECTED],che.org"); - valueTest(info, false); - info.setValue("[EMAIL PROTECTED],rg"); - valueTest(info, false); - } + + public void testEmailWithCommas() throws ValidatorException { + ValueBean info = new ValueBean(); + info.setValue("[EMAIL PROTECTED],che.org"); + valueTest(info, false); + info.setValue("[EMAIL PROTECTED],rg"); + valueTest(info, false); + info.setValue("[EMAIL PROTECTED],org"); + valueTest(info, false); + + } + + /** + * Write this test according to parts of RFC, as opposed to the type of character + * that is being tested. + * According to RFC 1738 a user name can be composed of the following : + * *[alpha | digit | "$" | "-" | "_" | "." | "+" | "!" | "*" | "'" | "(" | ")" | "," | "%" hex hex | ";" | "?" | "&" | "=" ] + + * @throws ValidatorException + */ + public void testEmailUserName() throws ValidatorException { + ValueBean info = new ValueBean(); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("joe'@apache.org"); + valueTest(info, true); + info.setValue("joe(@apache.org"); + valueTest(info, true); + info.setValue("joe)@apache.org"); + valueTest(info, true); + info.setValue("joe,@apache.org"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("joe;@apache.org"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + info.setValue("joe&@apache.org"); + valueTest(info, true); + info.setValue("[EMAIL PROTECTED]"); + valueTest(info, true); + + } + + /** * Utlity class to run a test on a value.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]