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:
@@ -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) =>
|
||||||
|
@@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user