Skip to content

Commit

Permalink
DLS-4425: [RP] Play 2.8 upgrade. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rambabu-posa authored Nov 15, 2021
1 parent 5ca3714 commit 017715f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import play.api.Configuration
import play.api.mvc.{Call, RequestHeader, Result, Results}
import uk.gov.hmrc.helptosavetestadminfrontend.controllers.routes
import uk.gov.hmrc.helptosavetestadminfrontend.util.Logging
import uk.gov.hmrc.whitelist.{AkamaiWhitelistFilter => AkamaiAllowListFilter}
import uk.gov.hmrc.allowlist.AkamaiAllowlistFilter

import scala.concurrent.Future

class AllowListFilter @Inject()(configuration: Configuration, val mat: Materializer) extends AkamaiAllowListFilter with Logging {
class AllowListFilter @Inject()(configuration: Configuration, val mat: Materializer) extends AkamaiAllowlistFilter with Logging {

override def whitelist: Seq[String] =
override def allowlist: Seq[String] =
configuration.underlying.get[List[String]]("http-header-ip-whitelist").value

override def excludedPaths: Seq[Call] = Seq(forbiddenCall, healthCheckCall)
override def excludedPaths: Seq[Call] = Seq(forbiddenCall)

// This is the `Call` used in the `Redirect` when an IP is present in the header
// of the HTTP request but is not in the allowList
Expand All @@ -44,13 +44,11 @@ class AllowListFilter @Inject()(configuration: Configuration, val mat: Materiali
Future.successful(Results.Redirect(forbiddenCall))
}

val forbiddenCall: Call = Call("GET", routes.ForbiddenController.forbidden().url)

val healthCheckCall: Call = Call("GET", uk.gov.hmrc.play.health.routes.HealthController.ping().url)
val forbiddenCall: Call = Call("GET", routes.ForbiddenController.forbidden.url)

override def apply(f: (RequestHeader) Future[Result])(rh: RequestHeader): Future[Result] = {
rh.headers.get(trueClient).foreach{ ip
if (!whitelist.contains(ip)) {
if (!allowlist.contains(ip)) {
logger.warn(s"SuspiciousActivity: Received request from non-allowListed ip $ip")
}
}
Expand Down
13 changes: 4 additions & 9 deletions app/uk/gov/hmrc/helptosavetestadminfrontend/config/Filters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,18 @@ import configs.syntax._
import play.api.Configuration
import play.api.http.HttpFilters
import play.api.mvc.EssentialFilter
import uk.gov.hmrc.play.bootstrap.frontend.filters.FrontendFilters

@Singleton
class Filters @Inject()(
configuration: Configuration,
allowListFilter: AllowListFilter,
frontendFilters: FrontendFilters
configuration: Configuration,
allowListFilter: AllowListFilter
) extends HttpFilters {

val allowListFilterEnabled: Boolean =
configuration.underlying.get[List[String]]("http-header-ip-whitelist").value.nonEmpty

override val filters: Seq[EssentialFilter] =
if (allowListFilterEnabled) {
frontendFilters.filters :+ allowListFilter
} else {
frontendFilters.filters
}
if (allowListFilterEnabled) Seq(allowListFilter)
else Seq.empty

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<h1>Available Functions</h1>

<ul>
<li><a href="@routes.VerifiedEmailsController.specifyEmailsToDelete()">Delete Emails</a></li><br>
<li><a href="@routes.VerifiedEmailsController.specifyEmailsToDelete">Delete Emails</a></li><br>
<li><a href="@routes.HelpToSaveApiController.getCheckEligibilityPage()">Check Eligibility</a></li><br>
<li><a href="@routes.HelpToSaveApiController.getCreateAccountPage()">Create Account</a></li><br>
<li><a href="@routes.HelpToSaveApiController.getAccountPage()">Get Account</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*@

@import uk.gov.hmrc.helptosavetestadminfrontend.views.html.govuk_wrapper
@import uk.gov.hmrc.play.views.html.layouts.{Sidebar, MainContentHeader, Article}

@this(govukWrapper: govuk_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@main_template(title = "Hello from help-to-save-test-admin-frontend", bodyClasses = None) {

@uiForm(uk.gov.hmrc.helptosavetestadminfrontend.controllers.routes.VerifiedEmailsController.deleteVerifiedEmails(), 'class -> "group subsection--wide") {
@uiForm(uk.gov.hmrc.helptosavetestadminfrontend.controllers.routes.VerifiedEmailsController.deleteVerifiedEmails, 'class -> "group subsection--wide") {
@input_text(
id = "emails",
name = "emails",
Expand Down
66 changes: 25 additions & 41 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,33 @@ val appName = "help-to-save-test-admin-frontend"

lazy val appDependencies: Seq[ModuleID] = dependencies ++ testDependencies()

val akkaVersion = "2.5.23"

val akkaHttpVersion = "10.0.15"


dependencyOverrides += "com.typesafe.akka" %% "akka-stream" % akkaVersion

dependencyOverrides += "com.typesafe.akka" %% "akka-protobuf" % akkaVersion

dependencyOverrides += "com.typesafe.akka" %% "akka-slf4j" % akkaVersion

dependencyOverrides += "com.typesafe.akka" %% "akka-actor" % akkaVersion

dependencyOverrides += "com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion

val dependencies = Seq(
ws,
"uk.gov.hmrc" %% "bootstrap-frontend-play-26" % "5.2.0",
"uk.gov.hmrc" %% "govuk-template" % "5.66.0-play-26",
"uk.gov.hmrc" %% "play-ui" % "9.2.0-play-26",
"uk.gov.hmrc" %% "play-health" % "3.16.0-play-26",
"uk.gov.hmrc" %% "simple-reactivemongo" % "8.0.0-play-26",
"uk.gov.hmrc" %% "play-whitelist-filter" % "3.4.0-play-26",
"uk.gov.hmrc" %% "totp-generator" % "0.22.0",
"com.github.kxbmap" %% "configs" % "0.6.1",
"org.typelevel" %% "cats-core" % "2.2.0",
"org.jsoup" % "jsoup" % "1.13.1",
"org.mongodb.scala" %% "mongo-scala-driver" % "4.2.3",
compilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.3" cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % "1.7.3" % Provided cross CrossVersion.full
"uk.gov.hmrc" %% "bootstrap-frontend-play-28" % "5.12.0",
"uk.gov.hmrc" %% "govuk-template" % "5.72.0-play-28",
"uk.gov.hmrc" %% "play-ui" % "9.5.0-play-28",
"uk.gov.hmrc" %% "simple-reactivemongo" % "8.0.0-play-28",
"uk.gov.hmrc" %% "play-allowlist-filter" % "1.0.0-play-28",
"uk.gov.hmrc" %% "totp-generator" % "0.22.0",
"com.github.kxbmap" %% "configs" % "0.6.1",
"org.typelevel" %% "cats-core" % "2.2.0",
"org.jsoup" % "jsoup" % "1.13.1",
"org.mongodb.scala" %% "mongo-scala-driver" % "4.2.3",
compilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.5" cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % "1.7.5" % Provided cross CrossVersion.full
)

def testDependencies(scope: String = "test") = Seq(
"uk.gov.hmrc" %% "bootstrap-test-play-26" % "5.2.0" % scope,
"uk.gov.hmrc" %% "service-integration-test" % "1.1.0-play-26" % scope,
"uk.gov.hmrc" %% "domain" % "5.11.0-play-26" % scope,
"uk.gov.hmrc" %% "stub-data-generator" % "0.5.3" % scope,
"uk.gov.hmrc" %% "reactivemongo-test" % "5.0.0-play-26" % scope,
"org.scalatest" %% "scalatest" % "3.2.8" % scope,
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % scope,
"com.vladsch.flexmark" % "flexmark-all" % "0.35.10" % scope,
"com.typesafe.play" %% "play-test" % PlayVersion.current % scope,
"org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % scope
"uk.gov.hmrc" %% "bootstrap-test-play-28" % "5.12.0" % scope,
"uk.gov.hmrc" %% "service-integration-test" % "1.1.0-play-28" % scope,
"uk.gov.hmrc" %% "domain" % "6.2.0-play-28" % scope,
"uk.gov.hmrc" %% "stub-data-generator" % "0.5.3" % scope,
"uk.gov.hmrc" %% "reactivemongo-test" % "5.0.0-play-28" % scope,
"org.scalatest" %% "scalatest" % "3.2.9" % scope,
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % scope,
"com.vladsch.flexmark" % "flexmark-all" % "0.35.10" % scope,
"com.typesafe.play" %% "play-test" % PlayVersion.current % scope,
"org.scalamock" %% "scalamock-scalatest-support" % "3.6.0" % scope
)

lazy val plugins: Seq[Plugins] = Seq.empty
Expand All @@ -59,10 +43,10 @@ lazy val scoverageSettings = {
Seq(
// Semicolon-separated list of regexs matching classes to exclude
ScoverageKeys.coverageExcludedPackages := "<empty>;Reverse.*;.*(uk.gov.hmrc.helptosavetestadminfrontend.config|forms|util|views.*);.*(AuthService|BuildInfo|Routes).*",
ScoverageKeys.coverageMinimum := 10,
ScoverageKeys.coverageMinimumStmtTotal := 10,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true,
parallelExecution in Test := false
Test / parallelExecution := false
)
}

Expand All @@ -78,7 +62,7 @@ lazy val microservice = Project(appName, file("."))
.settings(PlayKeys.playDefaultPort := 7007)
.settings(
libraryDependencies ++= appDependencies,
evictionWarningOptions in update := EvictionWarningOptions.default.withWarnScalaVersionEviction(false)
update / evictionWarningOptions := EvictionWarningOptions.default.withWarnScalaVersionEviction(false)
)
.settings(resolvers ++= Seq(
Resolver.jcenterRepo,
Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ appName="help-to-save-test-admin-frontend"
play.http.router=prod.Routes

# to learn why this was included: /display/TEC/2016/03/14/Setting+Security+Headers+in+frontend+services
play.filters.headers.contentSecurityPolicy = "default-src 'self' 'unsafe-inline' localhost:9000 localhost:9032 localhost:9250 data:; img-src *"
play.filters.csp.CSPFilter = "default-src 'self' 'unsafe-inline' localhost:9000 localhost:9032 localhost:9250 data:; img-src *"

# An ApplicationLoader that uses Guice to bootstrap the application.
play.application.loader = "uk.gov.hmrc.play.bootstrap.ApplicationLoader"
Expand Down
7 changes: 4 additions & 3 deletions conf/prod.routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Add all the application routes to the app.routes file
-> /help-to-save-test-admin-frontend app.Routes
-> / health.Routes
-> /template template.Routes
-> /help-to-save-test-admin-frontend app.Routes
-> / health.Routes
-> /template template.Routes

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.4.9
sbt.version=1.5.2
17 changes: 6 additions & 11 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ resolvers += "HMRC Releases" at "https://artefacts.tax.service.gov.uk/artifactor
resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.gov.uk/maven2"
resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.0.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.1.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-bobby" % "3.4.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.23")

addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.8.0")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.5.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.1.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-bobby" % "3.4.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8" exclude ("org.slf4j", "slf4j-simple"))
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.8.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
41 changes: 4 additions & 37 deletions test/config/FiltersSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,34 @@

package config

import akka.stream.Materializer
import com.kenshoo.play.metrics.MetricsFilter
import controllers.TestSupport
import play.api.Configuration
import play.api.mvc.EssentialFilter
import play.filters.csrf.CSRFFilter
import play.filters.headers.SecurityHeadersFilter
import uk.gov.hmrc.helptosavetestadminfrontend.config.{Filters, AllowListFilter}
import uk.gov.hmrc.play.bootstrap.frontend.filters.crypto.SessionCookieCryptoFilter
import uk.gov.hmrc.play.bootstrap.frontend.filters.deviceid.DeviceIdFilter
import uk.gov.hmrc.play.bootstrap.frontend.filters.{FrontendAuditFilter, FrontendFilters, HeadersFilter, SessionIdFilter, SessionTimeoutFilter}
import uk.gov.hmrc.helptosavetestadminfrontend.config.{AllowListFilter, Filters}
import uk.gov.hmrc.play.bootstrap.frontend.filters.SessionIdFilter
import uk.gov.hmrc.play.bootstrap.filters._

class FiltersSpec extends TestSupport {

// can't use scalamock for CacheControlFilter since a logging statement during class
// construction requires a parameter from the CacheControlConfig. Using scalamock
// reuslts in a NullPointerException since no CacheControlConfig is there
val mockCacheControllerFilter = new CacheControlFilter(CacheControlConfig(), mock[Materializer])

val mockMDCFilter = new MDCFilter(fakeApplication.materializer, fakeApplication.configuration, "")
val mockAllowlistFilter = mock[uk.gov.hmrc.play.bootstrap.frontend.filters.AllowlistFilter]

val mockSessionIdFilter =mock[SessionIdFilter]

class TestableFrontendFilters extends FrontendFilters(
stub[Configuration],
stub[LoggingFilter],
stub[HeadersFilter],
stub[SecurityHeadersFilter],
stub[FrontendAuditFilter],
stub[MetricsFilter],
stub[DeviceIdFilter],
stub[CSRFFilter],
stub[SessionCookieCryptoFilter],
stub[SessionTimeoutFilter],
mockCacheControllerFilter,
mockMDCFilter,
mockAllowlistFilter,
mockSessionIdFilter
) {
lazy val enableSecurityHeaderFilter: Boolean = false
override val filters: Seq[EssentialFilter] = Seq()
}

val frontendFilters = new TestableFrontendFilters
val allowListFilter = mock[AllowListFilter]

"Filters" must {

"include the allowList filter if the allowList from config is non empty" in {
val config = Configuration("http-header-ip-whitelist" List("1.2.3"))

val filters = new Filters(config, allowListFilter, frontendFilters)
val filters = new Filters(config, allowListFilter)
filters.filters shouldBe Seq(allowListFilter)
}

"not include the allowList filter if the allowList from config is empty" in {
val config = Configuration("http-header-ip-whitelist" List())

val filters = new Filters(config, allowListFilter, frontendFilters)
val filters = new Filters(config, allowListFilter)
filters.filters shouldBe Seq()
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/TestSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ trait TestSupport extends UnitSpec with MockFactory with BeforeAndAfterAll with
|
|
""".stripMargin)
) ++ additionalConfig)
).withFallback(additionalConfig)
)
.build()
}

Expand Down

0 comments on commit 017715f

Please sign in to comment.