From 72b67dbc181a0c9bbedfbf3276274fd81a2784e7 Mon Sep 17 00:00:00 2001 From: sabrina-konrad-lee-hmrc <108811386+sabrina-konrad-lee-hmrc@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:32:33 +0100 Subject: [PATCH 1/3] GG-7233-yaml removed yaml config --- app/controllers/UserInfoController.scala | 2 - app/services/UserInfoService.scala | 2 +- conf/application.conf | 8 - public/api/conf/1.1/application.yaml | 360 ----------------------- public/api/conf/1.1/docs/overview.md | 1 - public/api/conf/1.1/docs/scopes.md | 11 - 6 files changed, 1 insertion(+), 383 deletions(-) delete mode 100644 public/api/conf/1.1/application.yaml delete mode 100644 public/api/conf/1.1/docs/overview.md delete mode 100644 public/api/conf/1.1/docs/scopes.md diff --git a/app/controllers/UserInfoController.scala b/app/controllers/UserInfoController.scala index ec0fc9c..21ddbad 100644 --- a/app/controllers/UserInfoController.scala +++ b/app/controllers/UserInfoController.scala @@ -33,7 +33,6 @@ import scala.concurrent.ExecutionContext sealed trait Version case object Version_1_0 extends Version -case object Version_1_1 extends Version object Version { def fromAcceptHeader(header: Option[String]): Version = @@ -42,7 +41,6 @@ object Version { // integration test using scalaj.http which inject "Accept" header with default values if you don't provide any so we need a case when empty string is like missing Accept Header case Some("") => Version_1_0 case Some("application/vnd.hmrc.1.0+json") => Version_1_0 - case Some("application/vnd.hmrc.1.1+json") => Version_1_1 case _ => throw new IllegalArgumentException("Valid version not supplied") } } diff --git a/app/services/UserInfoService.scala b/app/services/UserInfoService.scala index 97d8afe..f373dcb 100644 --- a/app/services/UserInfoService.scala +++ b/app/services/UserInfoService.scala @@ -21,7 +21,7 @@ import uk.gov.hmrc.auth.core.Enrolments import uk.gov.hmrc.http.Authorization import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier, UnauthorizedException} import connectors._ -import controllers.{Version, Version_1_0, Version_1_1} +import controllers.{Version, Version_1_0} import data.UserInfoGenerator import domain._ diff --git a/conf/application.conf b/conf/application.conf index ad24b91..92927a2 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -136,14 +136,6 @@ api.access.version { } endpointsEnabled = true } - 1_1 { - type = PRIVATE - status = BETA - allow-list { - applicationIds.0 = 649def0f-3ed3-4df5-8ae1-3e687a9143ea - } - endpointsEnabled = false - } } diff --git a/public/api/conf/1.1/application.yaml b/public/api/conf/1.1/application.yaml deleted file mode 100644 index 385140e..0000000 --- a/public/api/conf/1.1/application.yaml +++ /dev/null @@ -1,360 +0,0 @@ -openapi: 3.0.3 -info: - title: User Information - description: >- - Access to user information is controlled through scopes. Each access token (OAuth 2.0 Bearer Token) is associated with a set of scopes at login. When a request is made for user information, only information belonging to the provided scopes is returned. The information is returned in the form of claims, which sometimes are simple fields and sometimes objects that contain further fields. - Here is a list of supported scopes and the claims they contain. The details of each claim, including any contained fields, is documented further down. - * 'profile': given_name, middle_name, family_name, birthdate - * 'address': address - * 'email': email - * 'openid:hmrc-enrolments': hmrc_enrolments - * 'openid:government-gateway': government_gateway - * 'openid:mdtp': mdtp - * 'openid:gov-uk-identifiers': uk_gov_nino - contact: {} - version: '1.1' -servers: -- url: https://api.service.hmrc.gov.uk/ - variables: {} -security: - - userRestricted: - - "openid" -paths: - /userinfo/: - get: - tags: - - userinfo - summary: Get user information - description: Retrieves OpenID Connect compliant information about the signed-in user - operationId: Getuserinformation - parameters: - - $ref: '#/components/parameters/authorizationHeader' - - $ref: '#/components/parameters/acceptHeader' - responses: - '200': - description: '' - headers: {} - content: - application/json: - schema: - allOf: - - $ref: '#/components/schemas/Userinforesponse' - - example: - given_name: John - family_name: Smith - middle_name: Scott - address: - formatted: >- - 221B Baker Street - London - NW1 9NT - Great Britain - postal_code: NW1 9NT - country: Great Britain - country_code: GB - email: John.Smith@abc.uk - birthdate: 1950-01-01 - uk_gov_nino: AA000003D - hmrc_enrolments: - - key: IR-SA - identifiers: - - key: UTR - value: '174371121' - state: activated - government_gateway: - user_id: '019283' - roles: - - User - affinity_group: Individual - user_name: John - agent_code: 123456-abc - agent_friendly_name: AC Accounting - agent_id: AC - gateway_token: token-value-1234 - unread_message_count: 0 - profile_uri: https://www.ete.tax.service.gov.uk/manage/user/0001111 - group_profile_uri: https://www.ete.tax.service.gov.uk/manage/group/1110000 - mdtp: - device_id: device_id-12345 - session_id: session_id_123455 - examples: - example-1: - value: - given_name: John - family_name: Smith - middle_name: Scott - address: - formatted: >- - 221B Baker Street - London - NW1 9NT - Great Britain - postal_code: NW1 9NT - country: Great Britain - country_code: GB - email: John.Smith@abc.uk - birthdate: 1950-01-01 - uk_gov_nino: AA000003D - hmrc_enrolments: - - key: IR-SA - identifiers: - - key: UTR - value: '174371121' - state: activated - government_gateway: - user_id: '019283' - roles: - - User - affinity_group: Individual - user_name: John - agent_code: 123456-abc - agent_friendly_name: AC Accounting - agent_id: AC - gateway_token: token-value-1234 - unread_message_count: 0 - profile_uri: https://www.ete.tax.service.gov.uk/manage/user/0001111 - group_profile_uri: https://www.ete.tax.service.gov.uk/manage/group/1110000 - mdtp: - device_id: device_id-12345 - session_id: session_id_123455 - '403': - description: '' - headers: {} - content: - application/json: - schema: - allOf: - - $ref: '#/components/schemas/errorResponse' - - example: - code: FORBIDDEN - examples: - BadRequest: - description: Forbidden operation - value: - code: FORBIDDEN - deprecated: false -components: - parameters: - acceptHeader: - name: Accept - in: header - description: "Specifies the response format and the version of the API to be used. For example: application/vnd.hmrc.2.0+json" - schema: - type: string - enum: [ - "application/vnd.hmrc.2.0+json", - "application/vnd.hmrc.2.0+xml" - ] - required: true - authorizationHeader: - name: Authorization - in: header - description: "An OAuth 2.0 Bearer Token" - schema: - type: string - required: true - schemas: - errorResponse: - title: errorResponse - required: - - code - type: object - properties: - code: - type: string - Address: - title: Address - type: object - properties: - formatted: - type: string - description: End-user's mailing address, formatted for display or use on a mailing label. - example: >- - 221B Baker Street - London - NW1 9NT - Great Britain - postal_code: - type: string - description: End-user's Zip code or postal code. - example: NW1 9NT - country: - type: string - description: End-user's country name. - example: Great Britain - country_code: - type: string - description: ISO 3166 Alpha-2-code of a given country - example: GB - GovernmentGateway: - title: GovernmentGateway - type: object - properties: - user_id: - type: string - description: Cred id - example: '1012345' - roles: - type: array - items: - type: string - description: List of user's roles - user_name: - type: string - description: Government Gateway user name - example: Bob - affinity_group: - type: string - description: User affinity group - example: Individual - agent_code: - type: string - description: Agent code - example: 123456-abc - agent_friendly_name: - type: string - description: Agent friendly name - example: AC Accounting - agent_id: - type: string - description: Agent id - example: AC - gateway_token: - type: string - description: Government gateway token - example: '123456789' - unread_message_count: - type: integer - description: Unread message count - format: int32 - example: 234 - profile_uri: - type: string - description: The manage user details for the current user - example: https://www.ete.tax.service.gov.uk/manage/user/0001111 - group_profile_uri: - type: string - description: The manage group details for the current user - example: https://www.ete.tax.service.gov.uk/manage/group/1110000 - description: Legacy properties based on government gateway input. - HmrcEnrolment: - title: HmrcEnrolment - required: - - key - - identifiers - - state - type: object - properties: - key: - type: string - description: HMRC service name. - example: IR-SA - identifiers: - type: array - items: - $ref: '#/components/schemas/Identifier' - description: End-user's identifiers associated to this HMRC service. - example: - - key: UTR - value: '174371121' - state: - allOf: - - $ref: '#/components/schemas/State' - - description: End-user's HMRC enrolment status. - Identifier: - title: Identifier - required: - - key - - value - type: object - properties: - key: - type: string - example: UTR - value: - type: string - example: '174371121' - Mdtp: - title: Mdtp - type: object - properties: - device_id: - type: string - description: Device id - example: '3012345' - session_id: - type: string - description: Session id - example: '2012345' - description: Mdtp information based on government gateway input - State: - title: State - enum: - - awaitingActivation - - activated - - Active - - Activated - - pending - - givenToAgent - type: string - description: End-user's HMRC enrolment status. - Userinforesponse: - title: Userinforesponse - type: object - properties: - given_name: - type: string - description: End-user's first name. - example: Thomas - middle_name: - type: string - description: End user's middle name. - example: A. - family_name: - type: string - description: End-user's last name. - example: Delgado - email: - type: string - description: User email - example: Cling.Eastwood@wildwest.com - birthdate: - type: string - description: End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format. - example: 1996-08-10 - uk_gov_nino: - type: string - description: End-User's National Insurance Number. - example: AA000003D - address: - $ref: '#/components/schemas/Address' - hmrc_enrolments: - type: array - items: - $ref: '#/components/schemas/HmrcEnrolment' - description: End-user's HMRC enrolments. - mdtp: - allOf: - - $ref: '#/components/schemas/Mdtp' - - description: Mdtp information based on government gateway input - government_gateway: - allOf: - - $ref: '#/components/schemas/GovernmentGateway' - - description: Legacy properties based on government gateway input. - description: User Info - securitySchemes: - userRestricted: - type: oauth2 - description: | - HMRC supports OAuth 2.0 for authenticating user restricted API requests using an OAuth 2.0 Bearer Token in the AUTHORIZATION header. - See https://developer.service.hmrc.gov.uk/api-documentation/docs/authorisation/user-restricted-endpoints for details. - flows: - authorizationCode: - authorizationUrl: https://api.service.hmrc.gov.uk/oauth/authorize - tokenUrl: https://api.service.hmrc.gov.uk/oauth/token - refreshUrl: https://api.service.hmrc.gov.uk/oauth/refresh - scopes: - "openid": openid -tags: -- name: userinfo - description: '' diff --git a/public/api/conf/1.1/docs/overview.md b/public/api/conf/1.1/docs/overview.md deleted file mode 100644 index 01f707e..0000000 --- a/public/api/conf/1.1/docs/overview.md +++ /dev/null @@ -1 +0,0 @@ -The User Information API provides information about the signed-in user, in an OpenID Connect compliant format. diff --git a/public/api/conf/1.1/docs/scopes.md b/public/api/conf/1.1/docs/scopes.md deleted file mode 100644 index e407ac2..0000000 --- a/public/api/conf/1.1/docs/scopes.md +++ /dev/null @@ -1,11 +0,0 @@ -Access to user information is controlled through scopes. Each access token (OAuth 2.0 Bearer Token) is associated with a set of scopes at login. When a request is made for user information, only information belonging to the provided scopes is returned. The information is returned in the form of claims, which sometimes are simple fields and sometimes objects that contain further fields. - -Here is a list of supported scopes and the claims they contain. The details of each claim, including any contained fields, is documented further down. - -* 'profile': given_name, middle_name, familiy_name, birthdate -* 'address': address -* 'email': email -* 'openid:hmrc-enrolments': hmrc_enrolments -* 'openid:government-gateway': government_gateway -* 'openid:mdtp': mdtp -* 'openid:gov-uk-identifiers': uk_gov_nino 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 2/3] 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 - } } } From 3cb24abc87d9cf09520e8d130518f54288c9cbbd Mon Sep 17 00:00:00 2001 From: sabrina-konrad-lee-hmrc <108811386+sabrina-konrad-lee-hmrc@users.noreply.github.com> Date: Wed, 16 Aug 2023 12:42:08 +0100 Subject: [PATCH 3/3] GG-7233-yaml removed yaml --- app/config/GuiceModule.scala | 3 +- app/connectors/AuthConnector.scala | 5 -- app/connectors/AuthV2UserDetailsFetcher.scala | 68 ------------------- app/services/UserInfoService.scala | 2 +- it/UserInfoServiceISpec.scala | 68 ------------------- it/stubs/AuthStub.scala | 27 +------- test/services/UserInfoServiceSpec.scala | 61 ++++++++++------- 7 files changed, 38 insertions(+), 196 deletions(-) delete mode 100644 app/connectors/AuthV2UserDetailsFetcher.scala diff --git a/app/config/GuiceModule.scala b/app/config/GuiceModule.scala index abf1ec1..91966af 100644 --- a/app/config/GuiceModule.scala +++ b/app/config/GuiceModule.scala @@ -28,8 +28,7 @@ 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]).to(classOf[AuthConnectorV2]) + bind(classOf[AuthConnector]).to(classOf[AuthConnectorV1]) bind(classOf[HttpClient]).to(classOf[DefaultHttpClient]) bind(classOf[UserInfoService]).annotatedWith(Names.named("live")).to(classOf[LiveUserInfoService]) bind(classOf[UserInfoService]).annotatedWith(Names.named("sandbox")).to(classOf[SandboxUserInfoService]) diff --git a/app/connectors/AuthConnector.scala b/app/connectors/AuthConnector.scala index b3a4933..3fa0524 100644 --- a/app/connectors/AuthConnector.scala +++ b/app/connectors/AuthConnector.scala @@ -77,8 +77,3 @@ import scala.concurrent.{ExecutionContext, Future} class AuthConnectorV1 @Inject() (val appContext: AppContext, val http: CorePost)(implicit val executionContext: ExecutionContext) extends AuthConnector with AuthV1UserDetailsFetcher - -@Singleton -class AuthConnectorV2 @Inject() (val appContext: AppContext, val http: CorePost)(implicit val executionContext: ExecutionContext) - extends AuthConnector - with AuthV2UserDetailsFetcher diff --git a/app/connectors/AuthV2UserDetailsFetcher.scala b/app/connectors/AuthV2UserDetailsFetcher.scala deleted file mode 100644 index 8569361..0000000 --- a/app/connectors/AuthV2UserDetailsFetcher.scala +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package connectors - -import uk.gov.hmrc.auth.core.AuthorisedFunctions -import uk.gov.hmrc.auth.core.retrieve.v2.Retrievals -import uk.gov.hmrc.auth.core.retrieve.~ -import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException} -import domain.UserDetails - -import scala.concurrent.{ExecutionContext, Future} - -trait AuthV2UserDetailsFetcher extends UserDetailsFetcher { - self: AuthorisedFunctions => - - def fetchDetails()(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Option[UserDetails]] = { - authorised() - .retrieve( - Retrievals.allUserDetails and Retrievals.mdtpInformation and Retrievals.gatewayInformation and Retrievals.profile and Retrievals.groupProfile - ) { - case credentials ~ maybeName ~ birthDate ~ postCode ~ email ~ affinityGroup ~ agentCode ~ agentInformation ~ - credentialRole ~ description ~ groupId ~ mdtp ~ gatewayInformation ~ profile ~ groupProfile => - Future.successful( - Some( - UserDetails( - authProviderId = credentials.map(_.providerId), - authProviderType = credentials.map(_.providerType), - name = maybeName.flatMap(_.name), - lastName = maybeName.flatMap(_.lastName), - dateOfBirth = birthDate, - postCode = postCode, - email = email, - affinityGroup = affinityGroup.map(_.toString()), - agentCode = agentCode, - agentFriendlyName = agentInformation.agentFriendlyName, - credentialRole = credentialRole.map(_.toString), - description = description, - groupIdentifier = groupId, - agentId = agentInformation.agentId, - gatewayInformation = gatewayInformation, - mdtpInformation = mdtp, - profile = profile, - groupProfile = groupProfile - ) - ) - ) - case _ => Future.successful(None) - } - .recover { case e: NotFoundException => - None - } - } - -} diff --git a/app/services/UserInfoService.scala b/app/services/UserInfoService.scala index a717cc7..58a59a2 100644 --- a/app/services/UserInfoService.scala +++ b/app/services/UserInfoService.scala @@ -32,7 +32,7 @@ trait UserInfoService { } class LiveUserInfoService @Inject() ( - @Named("v1Connector") v1AuthConnector: AuthConnector, + v1AuthConnector: AuthConnector, userInfoTransformer: UserInfoTransformer, thirdPartyDelegatedAuthorityConnector: ThirdPartyDelegatedAuthorityConnector )(implicit ec: ExecutionContext) diff --git a/it/UserInfoServiceISpec.scala b/it/UserInfoServiceISpec.scala index 94405e4..8de7721 100644 --- a/it/UserInfoServiceISpec.scala +++ b/it/UserInfoServiceISpec.scala @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.github.fge.jsonschema.core.report.LogLevel import com.github.fge.jsonschema.main.JsonSchemaFactory import config.{FeatureSwitch, UserInfoFeatureSwitches} -import controllers.Version_1_1 import domain._ import java.time.LocalDate import play.api.libs.json.Json @@ -380,73 +379,6 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart json shouldBe Json.toJson(userInfo_v1) } - Scenario("fetch user profile v2") { - - Given( - "A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'openid:hmrc-enrolments', 'openid:mdtp'," + - "'email' and 'openid:government-gateway' scopes" - ) - willReturnScopesForAuthBearerToken( - authBearerToken, - Set( - "openid", - "profile", - "address", - "openid:gov-uk-identifiers", - "openid:hmrc-enrolments", - "openid:government-gateway", - "email", - "agentInformation", - "openid:mdtp" - ) - ) - willAuthoriseWith(200) - - And("The Auth token has a NINO") - willReturnAuthorityWith(Nino(nino)) - - And("The authority has enrolments") - willReturnEnrolmentsWith() - - And("The auth will authorise DES contains user information for the NINO") - willFindUser( - Some(desUserInfo), - Some(AgentInformation(government_gateway_v1.agent_id, government_gateway_v1.agent_code, government_gateway_v1.agent_friendly_name)), - Some(Credentials("1304372065861347", "")), - Some(uk.gov.hmrc.auth.core.retrieve.Name(Some("Bob"), None)), - Some(Email(email)), - Some(AffinityGroup.Individual), - Some(User), - Some(authMdtp), - Some(gatewayInformation), - Some(10), - Some("some_url"), - Some("some_other_url"), - Version_1_1 - ) - - When("We request the user information") - val result = Http(s"$serviceUrl") - .options(HttpOptions.readTimeout(1000000), HttpOptions.connTimeout(1000000)) - .headers(Seq("Authorization" -> s"Bearer $authBearerToken", "Accept" -> "application/vnd.hmrc.1.1+json", "token" -> "ggToken")) - .asString - - val validator = JsonSchemaFactory.byDefault().getValidator - val mapper = new ObjectMapper - val schema = mapper.readTree(Paths.get(getClass.getResource("1.1/schemas/userinfo.json").toURI).toFile) - val json = Json.parse(result.body) - - val report = validator.validate(schema, mapper.readTree(json.toString())) - - Then("The user information is returned") - result.code shouldBe 200 - - import scala.jdk.CollectionConverters._ - assert(report.isSuccess, report.asScala.filter(_.getLogLevel == LogLevel.ERROR).map(m => m)) - - json shouldBe Json.toJson(userInfo_v2) - } - Scenario("fetch user profile without family name") { Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers' and 'openid:hmrc-enrolments' scopes") diff --git a/it/stubs/AuthStub.scala b/it/stubs/AuthStub.scala index d5d8a31..34b834d 100644 --- a/it/stubs/AuthStub.scala +++ b/it/stubs/AuthStub.scala @@ -23,7 +23,7 @@ import uk.gov.hmrc.auth.core.retrieve._ import uk.gov.hmrc.auth.core.retrieve.v2.{Retrievals => V2Retrievals} import uk.gov.hmrc.auth.core.{AffinityGroup, CredentialRole} import uk.gov.hmrc.domain.Nino -import controllers.{Version, Version_1_0, Version_1_1} +import controllers.{Version, Version_1_0} import domain.{DesUserInfo, _} import com.github.ghik.silencer.silent @@ -173,31 +173,6 @@ import com.github.ghik.silencer.silent .withStatus(200) ) ) - case Version_1_1 => - stubFor( - post(urlPathEqualTo(s"/auth/authorise")) - .withRequestBody( - equalToJson( - Json - .obj( - "authorise" -> JsArray(), - "retrieve" -> JsArray( - (V2Retrievals.allUserDetails - and V2Retrievals.mdtpInformation - and V2Retrievals.gatewayInformation - and V2Retrievals.profile - and V2Retrievals.groupProfile).propertyNames.map(JsString) - ) - ) - .toString() - ) - ) - .willReturn( - aResponse() - .withBody(v11response.toString()) - .withStatus(200) - ) - ) } stubFor( diff --git a/test/services/UserInfoServiceSpec.scala b/test/services/UserInfoServiceSpec.scala index 70c4278..2c792e2 100644 --- a/test/services/UserInfoServiceSpec.scala +++ b/test/services/UserInfoServiceSpec.scala @@ -93,13 +93,20 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { "requests all available data" in new Setup { val scopes = Set("openid", "address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "email", "openid:government-gateway") - given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) - given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) - given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Some(enrolments)) - given(mockAuthConnector.fetchDesUserInfo()(headers, implicitly)).willReturn(Some(desUserInfo)) + given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(eqTo(authBearerToken))(eqTo(headers), any[ExecutionContext])).willReturn(scopes) + given(mockAuthConnector.fetchAuthority()(eqTo(headers), any[ExecutionContext])).willReturn(Some(authority)) + given(mockAuthConnector.fetchEnrolments()(eqTo(headers), any[ExecutionContext])).willReturn(Some(enrolments)) + given(mockAuthConnector.fetchDesUserInfo()(eqTo(headers), any[ExecutionContext])).willReturn(Some(desUserInfo)) when(mockAuthConnector.fetchUserDetails()(eqTo(headers), any[ExecutionContext])).thenReturn(Future.successful(Some(userDetails))) - given(mockUserInfoTransformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) - .willReturn(any[UserInfo], any[UserInfo]) + given( + mockUserInfoTransformer.transform(eqTo(scopes), + eqTo(Some(authority)), + eqTo(Some(desUserInfo)), + eqTo(Some(enrolments)), + eqTo(Some(userDetails)) + ) + ) + .willReturn(UserInfo()) await(liveInfoService.fetchUserInfo(Version_1_0)) @@ -109,12 +116,11 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { verify(mockAuthConnector).fetchUserDetails()(any[HeaderCarrier], any[ExecutionContext]) } - "should fail with BadRequestException when the NINO is not in the authority and a scope that requires a NINO is requested" in new Setup { + "should fail with BadRequestException when the NINO is not in the authority and a scope that requires a NINO is requested UNICORN" in new Setup { val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments") - given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) - given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Future(Some(authority.copy(nino = None)))) - given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Future(None)) - when(mockAuthConnector.fetchUserDetails()(eqTo(headers), any[ExecutionContext])).thenReturn(Future.successful(Some(userDetails))) + given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(eqTo(authBearerToken))(eqTo(headers), any[ExecutionContext])).willReturn(scopes) + given(mockAuthConnector.fetchAuthority()(eqTo(headers), any[ExecutionContext])).willReturn(Future(Some(authority.copy(nino = None)))) + given(mockAuthConnector.fetchEnrolments()(eqTo(headers), any[ExecutionContext])).willReturn(Future(None)) a[BadRequestException] should be thrownBy await(liveInfoService.fetchUserInfo(Version_1_0)) } @@ -122,48 +128,51 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { "does not request DES::fetchUserInfo when the scopes does not contain 'address' nor 'profile'" in new Setup { val scopes = Set("openid:gov-uk-identifiers", "openid:hmrc-enrolments") - given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) - given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) - given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Future(Some(enrolments))) - given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) - given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) + given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(eqTo(authBearerToken))(eqTo(headers), any[ExecutionContext])).willReturn(scopes) + given(mockAuthConnector.fetchAuthority()(eqTo(headers), any[ExecutionContext])).willReturn(Some(authority)) + given(mockAuthConnector.fetchEnrolments()(eqTo(headers), any[ExecutionContext])).willReturn(Future(Some(enrolments))) + given(mockUserInfoTransformer.transform(eqTo(scopes), eqTo(Some(authority)), eqTo(None), eqTo(Some(enrolments)), eqTo(None))) + .willReturn(UserInfo()) await(liveInfoService.fetchUserInfo(Version_1_0)) verify(mockAuthConnector, never).fetchDesUserInfo()(any[HeaderCarrier], any[ExecutionContext]) verify(mockAuthConnector).fetchEnrolments() + verify(mockAuthConnector, never).fetchUserDetails()(any[HeaderCarrier], any[ExecutionContext]) } "does not request AUTH::fetchNino nor DES::fetchUserInfo when the scopes does not contain 'address' nor 'profile' nor 'openid:gov-uk-identifiers'" in new Setup { val scopes = Set("openid:hmrc-enrolments") - given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) + given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(eqTo(authBearerToken))(eqTo(headers), any[ExecutionContext])).willReturn(scopes) - given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) - given(mockAuthConnector.fetchEnrolments()(headers, implicitly)).willReturn(Some(enrolments)) - given(mockUserInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) - given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) + given(mockAuthConnector.fetchAuthority()(eqTo(headers), any[ExecutionContext])).willReturn(Some(authority)) + given(mockAuthConnector.fetchEnrolments()(eqTo(headers), any[ExecutionContext])).willReturn(Some(enrolments)) + given(mockUserInfoTransformer.transform(eqTo(scopes), eqTo(Some(authority)), eqTo(None), eqTo(Some(enrolments)), eqTo(None))) + .willReturn(UserInfo()) await(liveInfoService.fetchUserInfo(Version_1_0)) verify(mockAuthConnector, never).fetchDesUserInfo()(any[HeaderCarrier], any[ExecutionContext]) verify(mockAuthConnector).fetchEnrolments() + verify(mockAuthConnector, never).fetchUserDetails()(any[HeaderCarrier], any[ExecutionContext]) } "does not request AUTH::fetchEnrolments when the scopes does not contain 'openid:hmrc-enrolments'" in new Setup { val scopes = Set("address", "profile", "openid:gov-uk-identifiers") - given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers, implicitly)).willReturn(scopes) + given(mockThirdPartyDelegatedAuthorityConnector.fetchScopes(eqTo(authBearerToken))(eqTo(headers), any[ExecutionContext])).willReturn(scopes) - given(mockAuthConnector.fetchAuthority()(headers, implicitly)).willReturn(Some(authority)) - given(mockAuthConnector.fetchDesUserInfo()(headers, implicitly)).willReturn(None) - given(mockUserInfoTransformer.transform(scopes, Some(authority), None, None, None)).willReturn(any[UserInfo], any[UserInfo]) - given(mockAuthConnector.fetchUserDetails()(headers, implicitly)).willReturn(Future.successful(Some(userDetails))) + given(mockAuthConnector.fetchAuthority()(eqTo(headers), any[ExecutionContext])).willReturn(Some(authority)) + given(mockAuthConnector.fetchDesUserInfo()(eqTo(headers), any[ExecutionContext])).willReturn(None) + given(mockUserInfoTransformer.transform(eqTo(scopes), eqTo(Some(authority)), eqTo(None), eqTo(None), eqTo(None))) + .willReturn(UserInfo()) await(liveInfoService.fetchUserInfo(Version_1_0)) verify(mockAuthConnector, never).fetchEnrolments()(any[HeaderCarrier], any[ExecutionContext]) verify(mockAuthConnector).fetchDesUserInfo()(any[HeaderCarrier], any[ExecutionContext]) + verify(mockAuthConnector, never).fetchUserDetails()(any[HeaderCarrier], any[ExecutionContext]) } }