From 65bdcbdacc9e7db2ea9361ba7ada9dec5e6e02a9 Mon Sep 17 00:00:00 2001 From: Pierre Beitz Date: Thu, 22 Apr 2021 13:17:31 +0200 Subject: [PATCH] [JENKINS-65230] Remove the regexp check on emails --- .../plugins/advisor/utils/EmailValidator.java | 10 +------- .../casc/AdvisorRootConfiguratorTest.java | 2 +- .../advisor/utils/EmailValidatorTest.java | 25 +++---------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidator.java b/src/main/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidator.java index 7c3301a..65f053d 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidator.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidator.java @@ -20,14 +20,9 @@ private EmailValidator() { throw new UnsupportedOperationException("Cannot instantiate utility class"); } - static boolean isValid(@NonNull String email) { - Matcher matcher = PATTERN.matcher(email); - return matcher.matches(); - } - public static boolean isValidEmail(String value) { String emailAddress = EmailUtil.fixEmptyAndTrimAllSpaces(value); - return StringUtils.isNotBlank(emailAddress) && isValid(emailAddress); + return StringUtils.isNotBlank(emailAddress); } public static FormValidation validateEmail(String value) { @@ -39,9 +34,6 @@ public static FormValidation validateEmail(String value) { return FormValidation.error( "Email cannot contain illegal character ';' or ','. Consider using the CC fields if multiple recipients are required"); } - if (!isValid(emailAddress)) { - return FormValidation.error("Invalid email"); - } return FormValidation.ok(); } diff --git a/src/test/java/com/cloudbees/jenkins/plugins/advisor/casc/AdvisorRootConfiguratorTest.java b/src/test/java/com/cloudbees/jenkins/plugins/advisor/casc/AdvisorRootConfiguratorTest.java index afd25a7..cc1d20e 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/advisor/casc/AdvisorRootConfiguratorTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/advisor/casc/AdvisorRootConfiguratorTest.java @@ -332,7 +332,7 @@ public void testInstanceBadEmail() throws Exception { cc.add(new Scalar("onemore@mail.com")); cc.add(new Scalar("another@email.com")); m.put(CCS_ATTR, cc); - m.put(EMAIL_ATTR, "bad_email"); + m.put(EMAIL_ATTR, ""); m.put(NAG_DISABLED_ATTR, NAG_DISABLED); configurator.instance(m, context); diff --git a/src/test/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidatorTest.java b/src/test/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidatorTest.java index 4ce9992..6a14bc8 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidatorTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/advisor/utils/EmailValidatorTest.java @@ -14,17 +14,16 @@ public class EmailValidatorTest { @Test public void validEmails() { - assertTrue("simple email", EmailValidator.isValid("jdoe@acme.com")); - assertTrue("email with tag", EmailValidator.isValid("jdoe+advisor@acme.com")); + assertTrue("simple email", EmailValidator.isValidEmail("jdoe@acme.com")); + assertTrue("email with tag", EmailValidator.isValidEmail("jdoe+advisor@acme.com")); + assertTrue("JENKINS-65230 email", EmailValidator.isValidEmail("test.test-test@acme.com")); // Not supported //assertTrue("email with name", emailValidator.isValid("John Doe ")); } @Test public void invalidEmails() { - assertFalse("email is empty", EmailValidator.isValid("")); - assertFalse("not an email", EmailValidator.isValid("Not valid")); - assertFalse("email with not root DN", EmailValidator.isValid("jdoe@acme")); + assertFalse("email is empty", EmailValidator.isValidEmail("")); } @Test @@ -49,22 +48,6 @@ public void testDoCheckEmail() { formValidation = EmailValidator.validateEmail(email + ","); assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail(" foo@acme.com"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("Foo"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("Foo "); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("\"foo\"@acme.com"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("\"foo bar\"@acme.com"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("\"foo\\ \"@acme.com"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - formValidation = EmailValidator.validateEmail("\"foo\\ /\"@acme.com"); - assertEquals(FormValidation.Kind.ERROR, formValidation.kind); - - formValidation = EmailValidator.validateEmail(StringUtils.capitalize(email)); assertEquals(FormValidation.Kind.OK, formValidation.kind); formValidation = EmailValidator.validateEmail(email);