Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ with SimpleName {
case _ => false
}

def variations: Seq[String] = value +: Nino.validSuffixes.map(value + _)

}

object NinoWithoutSuffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ with RequestAwareLogging {
suppliedClientIdKey
else
clientIdKey
Some(in(key, clientIds.flatMap(expandNinoSuffixes).map(encryptedString): _*))
Some(in(key, clientIds.map(getValidNinoWithoutSuffixOrClientId).map(encryptedString): _*))
}
else
None,
Expand Down Expand Up @@ -265,7 +265,7 @@ with RequestAwareLogging {
suppliedClientIdKey
else
clientIdKey,
clientIds.map(_.replaceAll(" ", "")).flatMap(expandNinoSuffixes).map(encryptedString): _*
clientIds.map(_.replaceAll(" ", "")).map(getValidNinoWithoutSuffixOrClientId).map(encryptedString): _*
)
)
)
Expand Down Expand Up @@ -306,8 +306,8 @@ with RequestAwareLogging {
)),
Some(equal(serviceKey, service)),
Some(or(
in(suppliedClientIdKey, expandNinoSuffixes(clientId).map(encryptedString): _*),
in(clientIdKey, expandNinoSuffixes(clientId).map(encryptedString): _*) // Some deauth requests target the MTDITID for ITSA
equal(suppliedClientIdKey, encryptedString(getValidNinoWithoutSuffixOrClientId(clientId))),
equal(clientIdKey, encryptedString(getValidNinoWithoutSuffixOrClientId(clientId))) // Some deauth requests target the MTDITID for ITSA
)),
optArn.map(a => equal(arnKey, a)),
invitationIdToIgnore
Expand Down Expand Up @@ -335,7 +335,7 @@ with RequestAwareLogging {
.updateOne(
and(
equal(arnKey, arn.value),
in(clientIdKey, expandNinoSuffixes(nino.value).map(encryptedString): _*),
equal(clientIdKey, encryptedString(nino.value)),
equal(serviceKey, service),
equal(statusKey, Codecs.toBson[InvitationStatus](PartialAuth))
),
Expand Down Expand Up @@ -484,10 +484,10 @@ with RequestAwareLogging {
.map(_.getModifiedCount == 1L)
}

private def expandNinoSuffixes(clientId: String): Seq[String] = {
private def getValidNinoWithoutSuffixOrClientId(clientId: String): String = {
clientId match {
case nino if NinoWithoutSuffix.isValid(nino) => NinoWithoutSuffix(nino).variations
case clientId => Seq(clientId)
case nino if NinoWithoutSuffix.isValid(nino) => NinoWithoutSuffix(nino).value
case clientId => clientId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ with RequestAwareLogging {
HMRCMTDIT,
HMRCMTDITSUPP
),
in("nino", nino.variations.map(encryptedString): _*),
equal("nino", encryptedString(nino.value)),
equal("arn", arn.value),
equal("active", true)
)
Expand All @@ -136,7 +136,7 @@ with RequestAwareLogging {

def findActiveForClient(nino: NinoWithoutSuffix): Future[Seq[PartialAuthRelationship]] = Mdc.preservingMdc {
collection
.find(and(in("nino", nino.variations.map(encryptedString): _*), equal("active", true)))
.find(and(equal("nino", encryptedString(nino.value)), equal("active", true)))
.toFuture()
}

Expand All @@ -149,7 +149,7 @@ with RequestAwareLogging {
.find(
and(
equal("service", serviceId),
in("nino", nino.variations.map(encryptedString): _*),
equal("nino", encryptedString(nino.value)),
equal("arn", arn.value),
equal("active", true)
)
Expand All @@ -159,7 +159,7 @@ with RequestAwareLogging {

def findAllForClient(nino: NinoWithoutSuffix): Future[Seq[PartialAuthRelationship]] = Mdc.preservingMdc {
collection
.find(in("nino", nino.variations.map(encryptedString): _*))
.find(equal("nino", encryptedString(nino.value)))
.toFuture()
}

Expand All @@ -169,7 +169,7 @@ with RequestAwareLogging {
.find(
and(
equal("service", HMRCMTDIT),
in("nino", NinoWithoutSuffix(nino).variations.map(encryptedString): _*),
equal("nino", encryptedString(NinoWithoutSuffix(nino).value)),
equal("active", true)
)
)
Expand All @@ -186,7 +186,7 @@ with RequestAwareLogging {
.updateOne(
and(
equal("service", serviceId),
in("nino", nino.variations.map(encryptedString): _*),
equal("nino", encryptedString(nino.value)),
equal("arn", arn.value),
equal("active", true)
),
Expand All @@ -206,7 +206,7 @@ with RequestAwareLogging {
.deleteOne(
and(
equal("service", serviceId),
in("nino", nino.variations.map(encryptedString): _*),
equal("nino", encryptedString(nino.value)),
equal("arn", arn.value),
equal("active", true)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ with RepositoryCleanupSupport {
Instant.parse("2020-02-02T00:00:00.000Z"),
"XARN1234567",
"HMRC-MTD-IT",
"SX579189D",
"SX579189",
active = true,
Instant.parse("2020-02-02T00:00:00.000Z")
)
Expand Down Expand Up @@ -118,7 +118,7 @@ with RepositoryCleanupSupport {
Instant.parse("2020-01-01T00:00:00.000Z"),
Arn("XARN1234567"),
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D")
NinoWithoutSuffix("SX579189")
).futureValue

intercept[RuntimeException](
Expand All @@ -127,7 +127,7 @@ with RepositoryCleanupSupport {
Instant.parse("2020-01-01T00:00:00.000Z"),
Arn("XARN1234567"),
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D")
NinoWithoutSuffix("SX579189")
))
)
}
Expand All @@ -140,7 +140,7 @@ with RepositoryCleanupSupport {
Instant.parse("2020-01-01T00:00:00.000Z"),
Arn("XARN1234567"),
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D")
NinoWithoutSuffix("SX579189")
))
)
}
Expand All @@ -160,7 +160,7 @@ with RepositoryCleanupSupport {
await(
repository.findActive(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
) shouldBe Some(partialAuth)
Expand All @@ -172,7 +172,7 @@ with RepositoryCleanupSupport {
await(
repository.findActive(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
) shouldBe None
Expand All @@ -184,7 +184,7 @@ with RepositoryCleanupSupport {
await(
repository.findActive(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
) shouldBe None
Expand All @@ -196,7 +196,7 @@ with RepositoryCleanupSupport {
await(
repository.findActive(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
) shouldBe None
Expand All @@ -207,7 +207,7 @@ with RepositoryCleanupSupport {

"retrieves records for a given nino" in {
await(repository.collection.insertOne(partialAuth).toFuture())
await(repository.findAllForClient(NinoWithoutSuffix("SX579189D"))) shouldBe Seq(partialAuth)
await(repository.findAllForClient(NinoWithoutSuffix("SX579189"))) shouldBe Seq(partialAuth)
}

"fail to retrieve records when none are found for the given nino" in {
Expand All @@ -223,23 +223,23 @@ with RepositoryCleanupSupport {
Instant.parse("2020-01-01T00:00:00.000Z"),
Arn("XARN1234567"),
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D")
NinoWithoutSuffix("SX579189")
)
)
await(repository.collection.countDocuments().toFuture()) shouldBe 1
await(
repository
.deauthorise(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567"),
Instant.parse("2020-01-01T00:00:00.000Z")
)
)
val result = await(
repository.findActive(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
)
Expand All @@ -253,7 +253,7 @@ with RepositoryCleanupSupport {
repository
.deauthorise(
"HMRC-MTD-VAT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567"),
Instant.parse("2020-01-01T00:00:00.000Z")
)
Expand All @@ -263,13 +263,14 @@ with RepositoryCleanupSupport {
}

"deleteActivePartialAuth" should {

"delete when active record exists" in {
await(repository.collection.insertOne(partialAuth).toFuture())

val result = await(
repository.deleteActivePartialAuth(
"HMRC-MTD-IT",
NinoWithoutSuffix("SX579189D"),
NinoWithoutSuffix("SX579189"),
Arn("XARN1234567")
)
)
Expand Down
32 changes: 17 additions & 15 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import sbt.*

object AppDependencies {
private val mongoVer = "2.10.0"

private val bootstrapVer = "10.3.0"
private val pekkoVersion = "1.0.3"
private val mongoVer = "2.10.0"
private val playVer = "play-30"
private val pekkoVer = "1.0.3"

val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-backend-play-30" % bootstrapVer,
"uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % mongoVer,
"org.typelevel" %% "cats-core" % "2.13.0",
"uk.gov.hmrc" %% "crypto-json-play-30" % "8.4.0",
"io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.0-pekko-1.0.x",
"uk.gov.hmrc" %% "domain-play-30" % "11.0.0"
"uk.gov.hmrc" %% s"bootstrap-backend-$playVer" % bootstrapVer,
"uk.gov.hmrc.mongo" %% s"hmrc-mongo-$playVer" % mongoVer,
"uk.gov.hmrc" %% s"domain-$playVer" % "11.0.0",
"uk.gov.hmrc" %% s"crypto-json-$playVer" % "8.4.0",
"org.typelevel" %% "cats-core" % "2.13.0",
"io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.0-pekko-1.0.x"
)

val test: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapVer % Test,
"org.scalatestplus.play" %% "scalatestplus-play" % "7.0.2" % Test,
"uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-30" % mongoVer % Test,
"org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
"org.apache.pekko" %% "pekko-actor-testkit-typed" % pekkoVersion % Test,
"org.scalacheck" %% "scalacheck" % "1.19.0" % Test
)
"uk.gov.hmrc" %% s"bootstrap-test-$playVer" % bootstrapVer,
"uk.gov.hmrc.mongo" %% s"hmrc-mongo-test-$playVer" % mongoVer,
"org.apache.pekko" %% "pekko-testkit" % pekkoVer,
"org.apache.pekko" %% "pekko-actor-testkit-typed" % pekkoVer,
"org.scalacheck" %% "scalacheck" % "1.19.0"
).map(_ % Test)
}
10 changes: 5 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts

ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always

addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.9")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.6.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.9")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.6.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.3.3")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
Expand Down