From 0ea8df63fe7e78d1a8cd032abcd0197b0bc5bba2 Mon Sep 17 00:00:00 2001 From: ShivangiShah42 <177633426+ShivangiShah42@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:45:01 +0000 Subject: [PATCH] DLS-11277 : Logs added for invalid email address --- .../hmrc/cbcr/emailaddress/EmailAddress.scala | 17 +++++++++++------ project/plugins.sbt | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/uk/gov/hmrc/cbcr/emailaddress/EmailAddress.scala b/app/uk/gov/hmrc/cbcr/emailaddress/EmailAddress.scala index e784537..0593cd0 100644 --- a/app/uk/gov/hmrc/cbcr/emailaddress/EmailAddress.scala +++ b/app/uk/gov/hmrc/cbcr/emailaddress/EmailAddress.scala @@ -17,10 +17,11 @@ 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 @@ -28,13 +29,13 @@ 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 @@ -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 } @@ -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 } } diff --git a/project/plugins.sbt b/project/plugins.sbt index 378c0b2..fed9c35 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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")