2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-30 22:05:21 +00:00

code changes when domain is empty

This commit is contained in:
ssranjani06
2023-01-18 14:02:01 +05:30
parent c18b6c59d4
commit a40ec652f4
2 changed files with 12 additions and 6 deletions

View File

@@ -371,10 +371,15 @@ class MembershipService(
def EmailValidation(email: String): Result[Unit] = { def EmailValidation(email: String): Result[Unit] = {
val emailDomains = validDomains.valid_domains val emailDomains = validDomains.valid_domains
val emailRegex = if(emailDomains.mkString(",").contains("*")){ val emailRegex = if(emailDomains.isEmpty){
("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString(",").replaceAllLiterally("*","[A-Za-z0-9.]*").replaceAllLiterally(",","|") + "$").r """^[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 { }
("^[A-Za-z0-9._%+-]+@" + emailDomains.mkString("|") + "$").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 { Option(email) match {
case Some(value) if (emailRegex.findFirstIn(value) == None) => case Some(value) if (emailRegex.findFirstIn(value) == None) =>

View File

@@ -290,11 +290,12 @@ class MembershipServiceSpec
doReturn(IO.pure(Some(okUser))).when(mockUserRepo).getUser("ok") doReturn(IO.pure(Some(okUser))).when(mockUserRepo).getUser("ok")
doReturn(result(EmailValidationError("fail"))) doReturn(result(EmailValidationError("fail")))
.when(underTest) .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] error shouldBe a[EmailValidationError]
println(error)
} }
} }