mirror of
https://github.com/VinylDNS/vinyldns
synced 2025-08-30 13:58:15 +00:00
code changes when domain is empty
This commit is contained in:
parent
c18b6c59d4
commit
a40ec652f4
@ -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) =>
|
||||
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user