From 091febe6b0df10293927007dfb367e0c934dfb5f Mon Sep 17 00:00:00 2001 From: sabrina-konrad-lee-hmrc <108811386+sabrina-konrad-lee-hmrc@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:47:09 +0100 Subject: [PATCH] GG-7233 --- app/config/GuiceModule.scala | 1 - app/services/UserInfoService.scala | 9 +-------- test/controllers/UserInfoControllerSpec.scala | 20 ------------------- test/services/UserInfoServiceSpec.scala | 12 ++--------- 4 files changed, 3 insertions(+), 39 deletions(-) diff --git a/app/config/GuiceModule.scala b/app/config/GuiceModule.scala index 5e7cba4..abf1ec1 100644 --- a/app/config/GuiceModule.scala +++ b/app/config/GuiceModule.scala @@ -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]) diff --git a/app/services/UserInfoService.scala b/app/services/UserInfoService.scala index f373dcb..a717cc7 100644 --- a/app/services/UserInfoService.scala +++ b/app/services/UserInfoService.scala @@ -33,7 +33,6 @@ trait UserInfoService { class LiveUserInfoService @Inject() ( @Named("v1Connector") v1AuthConnector: AuthConnector, - @Named("v2Connector") v2AuthConnector: AuthConnector, userInfoTransformer: UserInfoTransformer, thirdPartyDelegatedAuthorityConnector: ThirdPartyDelegatedAuthorityConnector )(implicit ec: ExecutionContext) @@ -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 @@ -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 = { @@ -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) diff --git a/test/controllers/UserInfoControllerSpec.scala b/test/controllers/UserInfoControllerSpec.scala index 4a8819a..f4ace7a 100644 --- a/test/controllers/UserInfoControllerSpec.scala +++ b/test/controllers/UserInfoControllerSpec.scala @@ -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) @@ -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())) diff --git a/test/services/UserInfoServiceSpec.scala b/test/services/UserInfoServiceSpec.scala index d5aca5f..70c4278 100644 --- a/test/services/UserInfoServiceSpec.scala +++ b/test/services/UserInfoServiceSpec.scala @@ -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 @@ -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 { @@ -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 - } } }