diff --git a/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala b/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala index 9674df8b0..47e7851b6 100644 --- a/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala +++ b/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala @@ -371,10 +371,15 @@ class MembershipService( def EmailValidation(email: String): Result[Unit] = { val emailDomains = validDomains.valid_domains - val emailRegex = if(emailDomains.mkString(",").contains("*")){ - ("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString(",").replaceAllLiterally("*","[A-Za-z0-9.]*").replaceAllLiterally(",","|") + "$").r - } else { - ("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString("|") + "$").r + val emailRegex = if(emailDomains.isEmpty){ + """^[a-zA-Z0-9\.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$""".r + } + else { + if (emailDomains.mkString(",").contains("*")) { + ("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString(",").replaceAllLiterally("*", "[A-Za-z0-9.]*").replaceAllLiterally(",", "|") + "$").r + } else { + ("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString("|") + "$").r + } } Option(email) match { case Some(value) if (emailRegex.findFirstIn(value) == None) => diff --git a/modules/api/src/test/scala/vinyldns/api/domain/membership/MembershipServiceSpec.scala b/modules/api/src/test/scala/vinyldns/api/domain/membership/MembershipServiceSpec.scala index 3bbce7fa7..d83d30104 100644 --- a/modules/api/src/test/scala/vinyldns/api/domain/membership/MembershipServiceSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/domain/membership/MembershipServiceSpec.scala @@ -290,11 +290,12 @@ class MembershipServiceSpec doReturn(IO.pure(Some(okUser))).when(mockUserRepo).getUser("ok") doReturn(result(EmailValidationError("fail"))) .when(underTest) - .EmailValidation(email = "test@test.com") + .EmailValidation(email = "test@ok.com") - val error = underTest.createGroup(groupInfo.copy(email = "test@test.com"), okAuth).value.unsafeRunSync().swap.toOption.get + val error = underTest.createGroup(groupInfo.copy(email = "test@ok.com"), okAuth).value.unsafeRunSync().swap.toOption.get error shouldBe a[EmailValidationError] + println(error) } }