Skip to content

Commit

Permalink
Merge pull request #248 from hmrc/Shivangi/DLS-11277_email_address_va…
Browse files Browse the repository at this point in the history
…lidation_V2

DLS-11277 : Logs added for failed email validation
  • Loading branch information
ShivangiShah42 authored Dec 30, 2024
2 parents 4f0c70a + 0ea8df6 commit 67eadfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/uk/gov/hmrc/cbcr/emailaddress/EmailAddress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
package uk.gov.hmrc.cbcr.emailaddress

import com.google.inject.ImplementedBy
import play.api.Logger
import uk.gov.hmrc.cbcr.emailaddress.EmailAddressValidation.validEmail

import javax.naming.Context.{INITIAL_CONTEXT_FACTORY => ICF}
import javax.inject.Singleton
import javax.naming.Context.{INITIAL_CONTEXT_FACTORY => ICF}
import javax.naming.directory.InitialDirContext
import scala.jdk.CollectionConverters._
import scala.util.Try
import scala.util.matching.Regex

case class EmailAddress(value: String) extends StringValue {

lazy val obfuscated: ObfuscatedEmailAddress = ObfuscatedEmailAddress.apply(value)

val (mailbox, domain): (Mailbox, Domain) = value match {
case validEmail(m, d) => (Mailbox(m), Domain(d))
case invalidEmail => throw new IllegalArgumentException(s"'$invalidEmail' is not a valid email address")
case invalidEmail =>
throw new IllegalArgumentException(s"'$invalidEmail' is not a valid email address")
}

lazy val obfuscated: ObfuscatedEmailAddress = ObfuscatedEmailAddress.apply(value)

}
case class Mailbox(value: String) extends StringValue

Expand All @@ -46,6 +47,7 @@ case class Domain(value: String) extends StringValue {
}
@ImplementedBy(classOf[EmailAddressValidation])
trait EmailValidation {
lazy val logger: Logger = Logger(getClass)
def isValid(email: String): Boolean
}

Expand Down Expand Up @@ -75,7 +77,10 @@ class EmailAddressValidation extends EmailValidation {
def isValid(email: String): Boolean =
email match {
case validEmail(_, _) if isHostMailServer(EmailAddress(email).domain) => true
case _ => false
case _ =>
val obfuscatedEmail = EmailAddress(email).obfuscated
logger.error(s"Invalid email Address : $obfuscatedEmail ")
false
}
}

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts
Resolver.ivyStylePatterns)
resolvers += Resolver.jcenterRepo

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.playframework" %% "sbt-plugin" % "3.0.5")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
Expand Down

0 comments on commit 67eadfb

Please sign in to comment.