Skip to content

Commit

Permalink
GG-7233
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrina-konrad-lee-hmrc committed Aug 11, 2023
1 parent 72b67db commit 091febe
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 39 deletions.
1 change: 0 additions & 1 deletion app/config/GuiceModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import uk.gov.hmrc.play.bootstrap.config.ControllerConfig
class GuiceModule(val environment: Environment, val configuration: Configuration) extends AbstractModule {
override def configure() = {
bind(classOf[AuthConnector]).annotatedWith(Names.named("v1Connector")).to(classOf[AuthConnectorV1])
bind(classOf[AuthConnector]).annotatedWith(Names.named("v2Connector")).to(classOf[AuthConnectorV2])
bind(classOf[AuthConnector]).to(classOf[AuthConnectorV2])
bind(classOf[HttpClient]).to(classOf[DefaultHttpClient])
bind(classOf[UserInfoService]).annotatedWith(Names.named("live")).to(classOf[LiveUserInfoService])
Expand Down
9 changes: 1 addition & 8 deletions app/services/UserInfoService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ trait UserInfoService {

class LiveUserInfoService @Inject() (
@Named("v1Connector") v1AuthConnector: AuthConnector,
@Named("v2Connector") v2AuthConnector: AuthConnector,
userInfoTransformer: UserInfoTransformer,
thirdPartyDelegatedAuthorityConnector: ThirdPartyDelegatedAuthorityConnector
)(implicit ec: ExecutionContext)
Expand All @@ -47,11 +46,6 @@ class LiveUserInfoService @Inject() (
case None => Future.failed(new UnauthorizedException("Bearer token is required"))
}

val userDetailsFetcher = version match {
case Version_1_0 => v1AuthConnector.fetchUserDetails()
case Version_1_1 => v2AuthConnector.fetchUserDetails()
}

scopes flatMap { scopes =>
def getMaybeForScopes[T](maybeScopes: Set[String], allScopes: Set[String], f: => Future[Option[T]]): Future[Option[T]] = {
if ((maybeScopes intersect allScopes).nonEmpty) f
Expand All @@ -63,7 +57,7 @@ class LiveUserInfoService @Inject() (
val maybeAuthority = getMaybeForScopes(scopesForAuthority, scopes, v1AuthConnector.fetchAuthority())

val scopesForUserDetails = Set("openid:government-gateway", "email", "openid:mdtp")
def maybeUserDetails = getMaybeForScopes[UserDetails](scopesForUserDetails, scopes, userDetailsFetcher)
def maybeUserDetails = getMaybeForScopes[UserDetails](scopesForUserDetails, scopes, v1AuthConnector.fetchUserDetails())

val scopesForDes = Set("profile", "address")
def maybeDesUserInfo = {
Expand Down Expand Up @@ -94,7 +88,6 @@ class SandboxUserInfoService @Inject() (userInfoGenerator: UserInfoGenerator) ex
override def fetchUserInfo(version: Version)(implicit hc: HeaderCarrier): Future[UserInfo] = {
val generator: UserInfo = version match {
case Version_1_0 => userInfoGenerator.userInfoV1_0()
case Version_1_1 => userInfoGenerator.userInfoV1_1()
case _ => UserInfo()
}
Future.successful(generator)
Expand Down
20 changes: 0 additions & 20 deletions test/controllers/UserInfoControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: Executio
jsonBodyOf(result) shouldBe Json.toJson(userInfoV1)
}

"retrieve user information v1.1" in new Setup {

given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_1))(any[HeaderCarrier])).willReturn(userInfoV11)

val result = await(sandboxController.userInfo()(FakeRequest().withHeaders("Accept" -> "application/vnd.hmrc.1.1+json")))

status(result) shouldBe 200
jsonBodyOf(result) shouldBe Json.toJson(userInfoV11)
}

"fail with 406 (Not Acceptable) if version headers not present" in new Setup {

given(mockSandboxUserInfoService.fetchUserInfo(eqTo(Version_1_0))(any[HeaderCarrier])).willReturn(userInfoV1)
Expand All @@ -120,16 +110,6 @@ class UserInfoControllerSpec(implicit val cc: ControllerComponents, ex: Executio
jsonBodyOf(result) shouldBe Json.toJson(userInfoV1)
}

"retrieve user information v1.1" in new Setup {

given(mockLiveUserInfoService.fetchUserInfo(eqTo(Version_1_1))(any[HeaderCarrier])).willReturn(userInfoV11)

val result = await(liveController.userInfo()(FakeRequest().withHeaders("Accept" -> "application/vnd.hmrc.1.1+json")))

status(result) shouldBe 200
jsonBodyOf(result) shouldBe Json.toJson(userInfoV11)
}

"fail with 406 (Not Acceptable) if version headers not present" in new Setup {

val result = await(liveController.userInfo()(FakeRequest()))
Expand Down
12 changes: 2 additions & 10 deletions test/services/UserInfoServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package services

import connectors.{AuthConnector, AuthConnectorV1, ThirdPartyDelegatedAuthorityConnector}
import controllers.{Version_1_0, Version_1_1}
import controllers.Version_1_0
import data.UserInfoGenerator
import domain._
import org.mockito.BDDMockito.given
Expand Down Expand Up @@ -85,7 +85,7 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures {

val sandboxInfoService = new SandboxUserInfoService(mockUserInfoGenerator)
val liveInfoService =
new LiveUserInfoService(mockAuthConnector, mockAuthConnector, mockUserInfoTransformer, mockThirdPartyDelegatedAuthorityConnector)
new LiveUserInfoService(mockAuthConnector, mockUserInfoTransformer, mockThirdPartyDelegatedAuthorityConnector)
}

"LiveUserInfoService" should {
Expand Down Expand Up @@ -175,13 +175,5 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures {

result shouldBe userInfo
}

"return generated UserInfo v1.1" in new Setup {
given(mockUserInfoGenerator.userInfoV1_1()).willReturn(userInfo)

val result = await(sandboxInfoService.fetchUserInfo(Version_1_1))

result shouldBe userInfo
}
}
}

0 comments on commit 091febe

Please sign in to comment.