diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnector.scala b/app/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnector.scala index 2e431e9..a436d58 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnector.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnector.scala @@ -16,35 +16,31 @@ package uk.gov.hmrc.openidconnect.userinfo.connectors -import play.api.Logger import uk.gov.hmrc.auth.core.retrieve.{Retrievals, ~} -import uk.gov.hmrc.auth.core.{AuthorisedFunctions, PlayAuthConnector} +import uk.gov.hmrc.auth.core.{AuthorisedFunctions, Enrolments, PlayAuthConnector} +import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException} import uk.gov.hmrc.openidconnect.userinfo.config.WSHttp -import uk.gov.hmrc.openidconnect.userinfo.domain.{Authority, DesUserInfo, Enrolment, UserDetails} -import uk.gov.hmrc.play.auth.microservice.connectors.ConfidenceLevel._ +import uk.gov.hmrc.openidconnect.userinfo.domain.{Authority, DesUserInfo, UserDetails} import uk.gov.hmrc.play.config.ServicesConfig import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.{ExecutionContext, Future} -import uk.gov.hmrc.http.{CoreGet, HeaderCarrier, HttpReads, NotFoundException} +import scala.concurrent.Future trait AuthConnector extends AuthorisedFunctions { - val authBaseUrl: String - - val http: CoreGet + def fetchEnrolments()(implicit headerCarrier: HeaderCarrier): Future[Option[Enrolments]] = { + authorised().retrieve(Retrievals.allEnrolments) { + enrolments => Future.successful(Some(enrolments)) + }.recover { + case e: NotFoundException => None + } + } - def fetchEnrolments(auth: Authority)(implicit headerCarrier: HeaderCarrier): Future[Option[Seq[Enrolment]]] = { - auth.enrolments map { enrolmentsUri => - http.GET(s"$authBaseUrl$enrolmentsUri") map { response => - response.json.asOpt[Seq[Enrolment]] - } recover { - case e: NotFoundException => { - None - } - } - } getOrElse { - Logger.debug("No enrolment uri.") - Future.successful(None) + def fetchAuthority()(implicit headerCarrier: HeaderCarrier): Future[Option[Authority]] = { + authorised().retrieve(Retrievals.credentials and Retrievals.nino) { + case credentials ~ nino => Future.successful(Some(Authority(credentials.providerId, nino))) + case _ => Future.successful(None) + }.recover { + case e: NotFoundException => None } } @@ -64,33 +60,23 @@ trait AuthConnector extends AuthorisedFunctions { } } - def fetchDesUserInfo(auth: Authority)(implicit hc: HeaderCarrier): Future[Option[DesUserInfo]] = { + def fetchDesUserInfo()(implicit hc: HeaderCarrier): Future[Option[DesUserInfo]] = { val nothing = Future.successful(None) - if (auth.nino.isDefined) - authorised().retrieve(Retrievals.allItmpUserDetails) { - case name ~ dateOfBirth ~ address => - Future.successful(Some(DesUserInfo(name, dateOfBirth, address))) - case _ => nothing - }.recoverWith { - case ex: NotFoundException => nothing - } - else nothing - } - - def fetchAuthority()(implicit headerCarrier: HeaderCarrier): Future[Option[Authority]] = { - http.GET(s"$authBaseUrl/auth/authority") map { response => - response.json.asOpt[Authority] + authorised().retrieve(Retrievals.allItmpUserDetails) { + case name ~ dateOfBirth ~ address => + Future.successful(Some(DesUserInfo(name, dateOfBirth, address))) + case _ => nothing + }.recoverWith { + case ex: NotFoundException => nothing } } } object AuthConnector extends AuthConnector with ServicesConfig { - override lazy val authBaseUrl = baseUrl("auth") - override lazy val http = WSHttp - - override def authConnector = new PlayAuthConnector { - override val serviceUrl = baseUrl("auth") + override def authConnector: uk.gov.hmrc.auth.core.AuthConnector = ConcreteAuthConnector +} - override def http = WSHttp - } +object ConcreteAuthConnector extends PlayAuthConnector with ServicesConfig { + override val serviceUrl = baseUrl("auth") + override def http = WSHttp } \ No newline at end of file diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoController.scala b/app/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoController.scala index 84a2060..e02cff0 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoController.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoController.scala @@ -34,11 +34,11 @@ package uk.gov.hmrc.openidconnect.userinfo.controllers import play.api.libs.json.Json import uk.gov.hmrc.api.controllers.HeaderValidator +import uk.gov.hmrc.http.{BadRequestException, Upstream4xxResponse, Upstream5xxResponse} import uk.gov.hmrc.openidconnect.userinfo.services.{LiveUserInfoService, SandboxUserInfoService, UserInfoService} import uk.gov.hmrc.play.microservice.controller.BaseController import scala.concurrent.ExecutionContext.Implicits.global -import uk.gov.hmrc.http.{BadRequestException, Upstream4xxResponse, Upstream5xxResponse} trait UserInfoController extends BaseController with HeaderValidator { val service: UserInfoService diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/data/UserInfoGenerator.scala b/app/uk/gov/hmrc/openidconnect/userinfo/data/UserInfoGenerator.scala index 953e538..df23c8f 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/data/UserInfoGenerator.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/data/UserInfoGenerator.scala @@ -18,9 +18,9 @@ package uk.gov.hmrc.openidconnect.userinfo.data import org.joda.time._ import org.scalacheck.Gen -import uk.gov.hmrc.auth.core.retrieve.MdtpInformation +import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier} import uk.gov.hmrc.openidconnect.userinfo.config.UserInfoFeatureSwitches -import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, Enrolment, EnrolmentIdentifier, GovernmentGatewayDetails, Mdtp, UserInfo} +import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, GovernmentGatewayDetails, Mdtp, UserInfo} trait UserInfoGenerator { val firstNames = List(Some("Roland"), Some("Eddie"), Some("Susanna"), Some("Jake"), Some("Oy"), Some("Cuthbert"), Some("Alain"), Some("Jamie"), Some("Thomas"), Some("Susan"), Some("Randall"), None) @@ -53,7 +53,7 @@ trait UserInfoGenerator { def address = addressWithToggleableFeatures(UserInfoFeatureSwitches.addressLine5.isEnabled, UserInfoFeatureSwitches.countryCode.isEnabled) - val enrolments = Seq(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")))) + val enrolments = Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated")) val government_gateway: GovernmentGatewayDetails = GovernmentGatewayDetails(Some("32131"), Some(Seq("User")), Some("Chambers"),Some("affinityGroup"), Some("agent-code-12345"), Some("agent-id-12345"), Some("agent-friendly-name-12345"), Some("gateway-token-val"), Some(10)) val mdtp = Mdtp(deviceId, sessionId) diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/domain/Authority.scala b/app/uk/gov/hmrc/openidconnect/userinfo/domain/Authority.scala index c2cfa0b..b1bb455 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/domain/Authority.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/domain/Authority.scala @@ -16,10 +16,5 @@ package uk.gov.hmrc.openidconnect.userinfo.domain -case class Authority(credentialStrength: Option[String] = None, - confidenceLevel: Option[Int] = None, - nino: Option[String] = None, - userDetailsLink: Option[String] = None, - enrolments: Option[String] = None, - affinityGroup: Option[String] = None, - credId: Option[String] = None) \ No newline at end of file +case class Authority(credId: String, + nino: Option[String] = None) \ No newline at end of file diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/domain/Enrolment.scala b/app/uk/gov/hmrc/openidconnect/userinfo/domain/Enrolment.scala index c3de8c6..bb37b7c 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/domain/Enrolment.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/domain/Enrolment.scala @@ -16,14 +16,7 @@ package uk.gov.hmrc.openidconnect.userinfo.domain -case class EnrolmentIdentifier(key: String, value: String) - -case class Enrolment(key: String, - identifiers: Seq[EnrolmentIdentifier] = Seq(), - state: String = "Activated") { - - def isActivated = state.toLowerCase == "activated" -} +import uk.gov.hmrc.auth.core.Enrolment case object ActiveEnrolment { def unapply(enrolment: Enrolment): Option[String] = diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/domain/UserInfo.scala b/app/uk/gov/hmrc/openidconnect/userinfo/domain/UserInfo.scala index 56559b3..472c253 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/domain/UserInfo.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/domain/UserInfo.scala @@ -17,7 +17,8 @@ package uk.gov.hmrc.openidconnect.userinfo.domain import org.joda.time.LocalDate -import uk.gov.hmrc.auth.core.retrieve.{ItmpAddress, ItmpName, MdtpInformation} +import uk.gov.hmrc.auth.core.Enrolment +import uk.gov.hmrc.auth.core.retrieve.{ItmpAddress, ItmpName} case class Address(formatted: String, postal_code: Option[String], @@ -33,7 +34,7 @@ case class UserInfo(given_name: Option[String] = None, email: Option[String] = None, birthdate: Option[LocalDate] = None, uk_gov_nino: Option[String] = None, - hmrc_enrolments: Option[Seq[Enrolment]] = None, + hmrc_enrolments: Option[Set[Enrolment]] = None, government_gateway: Option[GovernmentGatewayDetails] = None, mdtp: Option[Mdtp] = None) diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/domain/package.scala b/app/uk/gov/hmrc/openidconnect/userinfo/domain/package.scala index d6d52b1..6af1f20 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/domain/package.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/domain/package.scala @@ -18,6 +18,7 @@ package uk.gov.hmrc.openidconnect.userinfo import play.api.libs.json._ import uk.gov.hmrc.auth.core.retrieve.{GatewayInformation, ItmpAddress, ItmpName, MdtpInformation} +import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier} import uk.gov.hmrc.http.Token package object domain { @@ -39,7 +40,6 @@ package object domain { implicit val dateReads = Reads.jodaDateReads("yyyy-MM-dd") implicit val dateWrites = Writes.jodaDateWrites("yyyy-MM-dd") implicit val addressFmt = Json.format[Address] - implicit val authorityFmt = Json.format[Authority] implicit val userInfoFmt = Json.format[UserInfo] implicit val apiAccessFmt = Json.format[APIAccess] } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilter.scala b/app/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilter.scala index 247cb47..6f94fe6 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilter.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilter.scala @@ -20,18 +20,18 @@ import controllers.Default.Unauthorized import play.api.libs.json.Json import play.api.mvc.{Filter, RequestHeader, Result} import play.api.routing.Router +import uk.gov.hmrc.auth.core.{AuthorisationException, AuthorisedFunctions} import uk.gov.hmrc.openidconnect.userinfo.config.{AuthParamsControllerConfiguration, ControllerConfiguration} +import uk.gov.hmrc.openidconnect.userinfo.connectors.ConcreteAuthConnector import uk.gov.hmrc.openidconnect.userinfo.controllers.ErrorUnauthorized -import uk.gov.hmrc.openidconnect.userinfo.services.AuthService +import uk.gov.hmrc.play.HeaderCarrierConverter import uk.gov.hmrc.play.auth.controllers.{AuthConfig, AuthParamsControllerConfig} +import uk.gov.hmrc.play.microservice.filters.MicroserviceFilterSupport import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future -import uk.gov.hmrc.http.HeaderCarrier -import uk.gov.hmrc.play.HeaderCarrierConverter -import uk.gov.hmrc.play.microservice.filters.MicroserviceFilterSupport -trait MicroserviceAuthFilter extends Filter { +trait MicroserviceAuthFilter extends Filter with AuthorisedFunctions { def apply(next: (RequestHeader) => Future[Result])(rh: RequestHeader): Future[Result] = { implicit val hc = HeaderCarrierConverter.fromHeadersAndSession(rh.headers) @@ -43,21 +43,22 @@ trait MicroserviceAuthFilter extends Filter { } authConfig(rh) match { - case Some(authConfig) => authService.isAuthorised().flatMap { - case true => next(rh) - case _ => Future.successful(Unauthorized(Json.toJson(ErrorUnauthorized()))) - } + case Some(authConfig) => + authorised() { + next(rh) + } recoverWith { + case e: AuthorisationException => Future.successful(Unauthorized(Json.toJson(ErrorUnauthorized()))) + } case _ => next(rh) } } - val authService: AuthService val authParamsConfig: AuthParamsControllerConfig def controllerNeedsAuth(controllerName: String): Boolean = ControllerConfiguration.paramsForController(controllerName).needsAuth } object MicroserviceAuthFilter extends MicroserviceAuthFilter with MicroserviceFilterSupport { - override lazy val authService = AuthService override lazy val authParamsConfig = AuthParamsControllerConfiguration + lazy val authConnector = ConcreteAuthConnector } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/services/AuthService.scala b/app/uk/gov/hmrc/openidconnect/userinfo/services/AuthService.scala deleted file mode 100644 index 14b45dc..0000000 --- a/app/uk/gov/hmrc/openidconnect/userinfo/services/AuthService.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 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 uk.gov.hmrc.openidconnect.userinfo.services - -import uk.gov.hmrc.openidconnect.userinfo.connectors.AuthConnector - -import scala.concurrent.ExecutionContext.Implicits.global -import uk.gov.hmrc.http.{ HeaderCarrier, Upstream4xxResponse } - -trait AuthService { - val authConnector: AuthConnector - - -// TODO - this is due to be replaced by auth-client wrapper finction on the controller method - PE-3211 - def isAuthorised()(implicit hc: HeaderCarrier) = { - authConnector.fetchAuthority().map { - case Some(auth) => true - case None => false - } recover { - case Upstream4xxResponse(_, 401, _, _) => false - } - } -} - -object AuthService extends AuthService { - override val authConnector = AuthConnector -} diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoService.scala b/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoService.scala index 15f7190..10bef74 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoService.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoService.scala @@ -16,6 +16,7 @@ package uk.gov.hmrc.openidconnect.userinfo.services +import uk.gov.hmrc.auth.core.Enrolments import uk.gov.hmrc.http.logging.Authorization import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier, UnauthorizedException} import uk.gov.hmrc.openidconnect.userinfo.connectors._ @@ -48,34 +49,23 @@ trait LiveUserInfoService extends UserInfoService { else Future.successful(None) } - def getMaybeByParamForScopes[I, O](maybeScopes: Set[String], allScopes: Set[String], param: I, f: I => Future[Option[O]]): Future[Option[O]] = { - if ((maybeScopes intersect allScopes).nonEmpty) f(param) - else Future.successful(None) - } - val scopesForAuthority = Set("openid:government-gateway", "email", "profile", "address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:mdtp") - val maybeAuthority = getMaybeForScopes(scopesForAuthority, scopes, authConnector.fetchAuthority) + val maybeAuthority = getMaybeForScopes(scopesForAuthority, scopes, authConnector.fetchAuthority()) + + val scopesForUserDetails = Set("openid:government-gateway", "email", "openid:mdtp") + def maybeUserDetails = getMaybeForScopes[UserDetails](scopesForUserDetails, scopes, authConnector.fetchUserDetails) val scopesForDes = Set("profile", "address") - val maybeDesUserInfo = maybeAuthority flatMap { authority => - val concreteAuthority = authority.getOrElse(Authority()) - getMaybeByParamForScopes[Authority, DesUserInfo](scopesForDes, scopes, concreteAuthority, - concreteAuthority.nino match { - case Some(_) => authConnector.fetchDesUserInfo - case _ => (_) => Future.failed(new BadRequestException("NINO not found for this user")) + def maybeDesUserInfo = { + getMaybeForScopes[DesUserInfo](scopesForDes, scopes, + maybeAuthority flatMap { + case Some(auth) if auth.nino.isDefined => authConnector.fetchDesUserInfo + case _ => Future.failed(new BadRequestException("NINO not found for this user")) } ) } - val scopesForUserDetails = Set("openid:government-gateway", "email", "openid:mdtp") - val maybeUserDetails = maybeAuthority flatMap { authority => - getMaybeByParamForScopes[Authority, UserDetails](scopesForUserDetails, scopes, authority.getOrElse(Authority()), _ => authConnector.fetchUserDetails) - } - - def maybeEnrolments = maybeAuthority flatMap { authority => - getMaybeByParamForScopes[Authority, Seq[Enrolment]](Set("openid:hmrc-enrolments"), scopes, - authority.getOrElse(Authority()), authConnector.fetchEnrolments) - } + def maybeEnrolments = getMaybeForScopes[Enrolments](Set("openid:hmrc-enrolments"), scopes, authConnector.fetchEnrolments) for { authority <- maybeAuthority @@ -83,7 +73,7 @@ trait LiveUserInfoService extends UserInfoService { desUserInfo <- maybeDesUserInfo userDetails <- maybeUserDetails } yield - userInfoTransformer.transform(scopes, desUserInfo, enrolments, authority, userDetails) + userInfoTransformer.transform(scopes, authority, desUserInfo, enrolments, userDetails) } } } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformer.scala b/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformer.scala index 74d13f6..ac87bc6 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformer.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformer.scala @@ -17,13 +17,14 @@ package uk.gov.hmrc.openidconnect.userinfo.services import org.joda.time.LocalDate +import uk.gov.hmrc.auth.core.Enrolments import uk.gov.hmrc.auth.core.retrieve.ItmpAddress import uk.gov.hmrc.openidconnect.userinfo.config.UserInfoFeatureSwitches -import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, Authority, DesUserInfo, Enrolment, GovernmentGatewayDetails, Mdtp, UserDetails, UserInfo} +import uk.gov.hmrc.openidconnect.userinfo.domain._ trait UserInfoTransformer { - def transform(scopes: Set[String], desUserInfo: Option[DesUserInfo], enrolments: Option[Seq[Enrolment]], authority: Option[Authority], userDetails: Option[UserDetails]): UserInfo = { + def transform(scopes: Set[String], authority: Option[Authority], desUserInfo: Option[DesUserInfo], enrolments: Option[Enrolments], userDetails: Option[UserDetails]): UserInfo = { def profile = if (scopes.contains("profile")) desUserInfo map (u => UserProfile(u.name.givenName, u.name.familyName, u.name.middleName, u.dateOfBirth)) else None @@ -34,7 +35,7 @@ trait UserInfoTransformer { } else None - val identifier = if (scopes.contains("openid:gov-uk-identifiers")) authority flatMap {a => a.nino map {n => n}} else None + val identifier = if (scopes.contains("openid:gov-uk-identifiers")) authority flatMap(_.nino) else None val userEnrolments = if (scopes.contains("openid:hmrc-enrolments")) enrolments else None @@ -54,7 +55,7 @@ trait UserInfoTransformer { email, profile.flatMap(_.birthDate), identifier, - userEnrolments, + userEnrolments.map(_.enrolments), ggInfo, mdtp) } @@ -70,7 +71,7 @@ trait UserInfoTransformer { val role = userDetails flatMap {_.credentialRole} val userName = userDetails flatMap {_.name} val credentialRoles = role.map(Seq(_)) - val credId = authority flatMap {_.credId} + val credId = authority map {_.credId} val agentCode = userDetails flatMap { _.agentCode} val agentFriendlyName = userDetails flatMap { _.agentFriendlyName} val agentId = userDetails flatMap { _.agentId} diff --git a/test/it/UserInfoServiceSpec.scala b/test/it/UserInfoServiceSpec.scala index 22d934b..2d59206 100644 --- a/test/it/UserInfoServiceSpec.scala +++ b/test/it/UserInfoServiceSpec.scala @@ -21,15 +21,15 @@ import java.nio.file.Paths import com.fasterxml.jackson.databind.ObjectMapper import com.github.fge.jsonschema.core.report.LogLevel import com.github.fge.jsonschema.main.JsonSchemaFactory +import com.github.tomakehurst.wiremock.client.RequestPatternBuilder import org.joda.time.LocalDate import org.scalatest.BeforeAndAfterAll import play.api.libs.json.Json -import uk.gov.hmrc.auth.core.{AffinityGroup, CredentialRole, _} import uk.gov.hmrc.auth.core.retrieve._ +import uk.gov.hmrc.auth.core.{AffinityGroup, _} import uk.gov.hmrc.domain.Nino import uk.gov.hmrc.openidconnect.userinfo.config.{FeatureSwitch, UserInfoFeatureSwitches} -import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, DesUserInfo, GovernmentGatewayDetails, Mdtp, UserInfo, Enrolment => UserInfoEnrolment, EnrolmentIdentifier => UserInfoEnrolmentIdentifier} -import uk.gov.hmrc.play.auth.microservice.connectors.ConfidenceLevel +import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, DesUserInfo, GovernmentGatewayDetails, Mdtp, UserInfo} import scalaj.http.Http @@ -49,7 +49,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { val ukCountryCode = 1 val desUserInfo = DesUserInfo(ItmpName(Some("John"), Some("A"), Some("Smith")), Some(LocalDate.parse("1980-01-01")), ItmpAddress(Some("1 Station Road"), Some("Town Centre"), Some("London"), Some("England"), Some("UK"), Some("NW1 6XE"), Some("GREAT BRITAIN"), Some("GB"))) - val enrolments = Seq(UserInfoEnrolment("IR-SA", List(UserInfoEnrolmentIdentifier("UTR", "174371121")))) + val enrolments = Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated")) val deviceId = "device-id-12345" val sessionId = "session-id-12345" val mdtp = Mdtp(deviceId, sessionId) @@ -120,6 +120,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid", "profile", "address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "agentInformation", "openid:mdtp")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) @@ -128,7 +129,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { authStub.willReturnEnrolmentsWith() And("The auth will authorise DES contains user information for the NINO") - authStub.willAuthorise(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, government_gateway.agent_friendly_name)), Some(Credentials("", "")), + authStub.willFindUser(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, government_gateway.agent_friendly_name)), Some(Credentials("1304372065861347", "")), Some(uk.gov.hmrc.auth.core.retrieve.Name(Some("Bob"), None)), Some(Email(email)), Some(AffinityGroup.Individual), Some(Admin), Some(authMdtp), Some(gatewayInformation), Some(10)) @@ -143,10 +144,12 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { val mapper = new ObjectMapper val schema = mapper.readTree(Paths.get(public10, "schemas", "userinfo.json").toFile) + println(result.body) val json = Json.parse(result.body) val report = validator.validate(schema, mapper.readTree(json.toString())) + System.out.println(authStub.stub.mock.find(RequestPatternBuilder.allRequests())) Then("The user information is returned") result.code shouldBe 200 @@ -161,6 +164,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers' and 'openid:hmrc-enrolments' scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid", "profile", "address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) @@ -169,7 +173,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { authStub.willReturnEnrolmentsWith() And("The auth will authorise and DES contains user information for the NINO") - authStub.willAuthorise(Some(desUserInfoWithoutFamilyName)) + authStub.willFindUser(Some(desUserInfoWithoutFamilyName)) When("We request the user information") @@ -188,12 +192,13 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers', 'email', 'openid:government-gateway' and 'openid:hmrc-enrolments' scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid", "profile", "address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) And("The auth will authorise and DES contains user information for the NINO") - authStub.willAuthorise(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, government_gateway.agent_friendly_name)), Some(Credentials("", "")), + authStub.willFindUser(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, government_gateway.agent_friendly_name)), Some(Credentials("", "")), Some(uk.gov.hmrc.auth.core.retrieve.Name(Some("Bob"), None)), Some(Email(email)), Some(AffinityGroup.Individual), Some(Admin), Some(authMdtp), Some(gatewayInformation), Some(10)) When("We request the user information") @@ -211,6 +216,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { Given("A Auth token with 'openid', 'profile', 'address', 'openid:gov-uk-identifiers' and 'openid:hmrc-enrolments' scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid", "profile", "address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) @@ -238,6 +244,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { Given("A Auth token with 'openid:hmrc-enrolments' scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid:hmrc-enrolments")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) @@ -262,6 +269,7 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { Given("A Auth token with 'openid:government-gateway' scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid:government-gateway")) + authStub.willAuthoriseWith(200) And("The Auth token has a NINO") authStub.willReturnAuthorityWith(Nino(nino)) @@ -270,8 +278,8 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { authStub.willReturnEnrolmentsWith() And("The auth will authorise DES contains user information for the NINO") - authStub.willAuthorise(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, - government_gateway.agent_friendly_name)), Some(Credentials("", "")), + authStub.willFindUser(Some(desUserInfo), Some(AgentInformation(government_gateway.agent_id, government_gateway.agent_code, + government_gateway.agent_friendly_name)), Some(Credentials("1304372065861347", "")), Some(uk.gov.hmrc.auth.core.retrieve.Name(Some("Bob"), None)), Some(Email(email)), Some(AffinityGroup.Individual), Some(Admin), None, gatewayInformation = Some(gatewayInformation), Some(10)) @@ -296,12 +304,8 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid:government-gateway", "openid:hmrc-enrolments", "address")) - And("All upstream services excluding user-info have valid reponse") - authStub.willAuthorise(Some(desUserInfo)) - And("Auth returns unauthorized") - authStub.willReturnAuthorityWith(401) - authStub.willReturnEnrolmentsWith(401) + authStub.willAuthoriseWith(401) When("We request the user information") val result = Http(s"$serviceUrl") @@ -317,14 +321,13 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { scenario("return 502 when Auth returns error") { val errorMsg = "auth error msg" - val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"GET of 'http://localhost:22221/auth/authority' returned 503. Response body: '$errorMsg'"}""" + val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"POST of 'http://localhost:22221/auth/authorise' returned 503. Response body: '$errorMsg'"}""" Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid:government-gateway", "openid:hmrc-enrolments", "address")) And("Auth returns unauthorized") - authStub.willReturnAuthorityWith(503, errorMsg) - authStub.willReturnEnrolmentsWith(503, errorMsg) + authStub.willAuthoriseWith(503, errorMsg) When("We request the user information") val result = Http(s"$serviceUrl") @@ -338,17 +341,13 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll { scenario("return 502 when Auth returns not found") { val errorMsg = "auth error msg" - val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"GET of 'http://localhost:22221/auth/authority' returned 404 (Not Found). Response body: '$errorMsg'"}""" + val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"POST of 'http://localhost:22221/auth/authorise' returned 404 (Not Found). Response body: '$errorMsg'"}""" Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes") thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken, Set("openid:government-gateway", "openid:hmrc-enrolments", "address")) - And("All upstream services excluding user-info have valid reponse") - authStub.willAuthorise(Some(desUserInfo)) - And("Auth returns not found") - authStub.willReturnAuthorityWith(404, errorMsg) - authStub.willReturnEnrolmentsWith(404, errorMsg) + authStub.willAuthoriseWith(404, errorMsg) When("We request the user information") val result = Http(s"$serviceUrl") diff --git a/test/it/stubs/AuthStub.scala b/test/it/stubs/AuthStub.scala index 252fe6b..58db945 100644 --- a/test/it/stubs/AuthStub.scala +++ b/test/it/stubs/AuthStub.scala @@ -18,9 +18,10 @@ package it.stubs import com.github.tomakehurst.wiremock.client.WireMock._ import it.{MockHost, Stub} +import org.skyscreamer.jsonassert.JSONCompareMode import play.api.libs.json._ import uk.gov.hmrc.auth.core.retrieve._ -import uk.gov.hmrc.auth.core.{AffinityGroup, CredentialRole} +import uk.gov.hmrc.auth.core.{AffinityGroup, CredentialRole, Enrolment} import uk.gov.hmrc.domain.Nino import uk.gov.hmrc.http.controllers.RestFormats.localDateFormats import uk.gov.hmrc.openidconnect.userinfo.domain.{DesUserInfo, _} @@ -34,36 +35,37 @@ object AuthStub extends Stub { .getOrElse(jsObject) } - def willReturnAuthorityWith(nino: Nino): Unit = { - val body = - s""" - |{ - | "credentialStrength:": "strong", - | "confidenceLevel": 0, - | "userDetailsLink": "http://localhost:22224/uri/to/userDetails", - | "nino": "${nino.nino}", - | "enrolments": "/auth/oid/2/enrolments", - | "affinityGroup": "Individual", - | "credId": "1304372065861347", - | "gatewayToken": "gateway-token-qwert" - |} - """.stripMargin - willReturnAuthorityWith(200, body) + def willAuthoriseWith(statusCode: Int, body: String = Json.obj().toString()): Unit = { + stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray() + ).toString(), JSONCompareMode.STRICT)) + .willReturn(aResponse().withBody(body).withStatus(statusCode)) + ) } - def willReturnAuthorityWith(statusCode: Int, body: String = ""): Unit = { - stub.mock.register(get(urlPathEqualTo(s"/auth/authority")) + def willReturnAuthorityWith(nino: Nino): Unit = { + val response = Json.obj( + "nino" -> nino, + "credentials" -> Json.obj("providerId" -> "1304372065861347", "providerType" -> "GG") + ) + stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray((Retrievals.credentials and Retrievals.nino).propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() - .withBody(body) - .withStatus(statusCode)) + .withBody(response.toString()) + .withStatus(200)) ) } - def willAuthorise(desUserInfo: Option[DesUserInfo] = None, agentInformation: Option[AgentInformation] = None, - credentials: Option[Credentials] = None, name: Option[Name] = None, email: Option[Email] = None, - affinityGroup: Option[AffinityGroup] = None, role: Option[CredentialRole] = None, - mdtp: Option[MdtpInformation] = None, gatewayInformation: Option[GatewayInformation] = None, - unreadMessageCount: Option[Int] = None): Unit = { + def willFindUser(desUserInfo: Option[DesUserInfo] = None, agentInformation: Option[AgentInformation] = None, + credentials: Option[Credentials] = None, name: Option[Name] = None, email: Option[Email] = None, + affinityGroup: Option[AffinityGroup] = None, role: Option[CredentialRole] = None, + mdtp: Option[MdtpInformation] = None, gatewayInformation: Option[GatewayInformation] = None, + unreadMessageCount: Option[Int] = None): Unit = { implicit val agentWrites = Json.writes[AgentInformation] implicit val credentialWrites = Json.writes[Credentials] implicit val nameWrites = Json.writes[Name] @@ -72,8 +74,7 @@ object AuthStub extends Stub { val jsonItmpName: Option[JsValue] = desUserInfo.map(d => Json.toJson(d.name)) val jsonAgent: Option[JsValue] = agentInformation.map(Json.toJson(_)) val jsonCredentials: Option[JsValue] = credentials.map(Json.toJson(_)) - val jsonName : Option[JsValue] = name.map(Json.toJson(_)) - val jsonEmail : Option[JsValue] = email.map(Json.toJson(_)) + val jsonName: Option[JsValue] = name.map(Json.toJson(_)) val jsonDob = desUserInfo.flatMap(_.dateOfBirth) val jsonMdtp: Option[JsValue] = mdtp.map(Json.toJson(_)) val jsonGatewayInformation: Option[JsValue] = gatewayInformation.map(Json.toJson(_)) @@ -94,40 +95,52 @@ object AuthStub extends Stub { .appendOptional("unreadMessageCount", unreadMessageCount.map(Json.toJson(_))) stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray((Retrievals.allUserDetails and Retrievals.mdtpInformation and Retrievals.gatewayInformation).propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() .withBody(response.toString()) .withStatus(200)) ) - } - def willNotFindUser(): Unit = { stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray(Retrievals.allItmpUserDetails.propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() - .withBody("{}") - .withStatus(404)) + .withBody(response.toString()) + .withStatus(200)) ) } - def willAuthoriseWithEmptyResponse: Unit = { + def willNotFindUser(): Unit = { stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray(Retrievals.allItmpUserDetails.propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() .withBody("{}") - .withStatus(200)) + .withStatus(404)) ) - } - def willNotAuthorise(statusCode: Int = 401): Unit = { stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray((Retrievals.allUserDetails and Retrievals.mdtpInformation and Retrievals.gatewayInformation).propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() - .withHeader("WWW-Authenticate", """MDTP detail="InsufficientConfidenceLevel"""") - .withStatus(statusCode)) + .withBody("{}") + .withStatus(404)) ) } def willReturnEnrolmentsWith(): Unit = { val body = s""" - |[ + |{"allEnrolments": [ | { | "key": "IR-SA", | "identifiers": [ @@ -138,13 +151,17 @@ object AuthStub extends Stub { | ], | "state": "Activated" | } - |] + |]} """.stripMargin willReturnEnrolmentsWith(200, body) } def willReturnEnrolmentsWith(statusCode: Int, body: String = ""): Unit = { - stub.mock.register(get(urlPathEqualTo(s"/auth/oid/2/enrolments")) + stub.mock.register(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray(Retrievals.allEnrolments.propertyNames.map(JsString)) + ).toString(), JSONCompareMode.STRICT)) .willReturn(aResponse() .withBody(body) .withStatus(statusCode))) diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/WireMockSugar.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/WireMockSugar.scala deleted file mode 100644 index 8c0e167..0000000 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/WireMockSugar.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2017 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 unit.uk.gov.hmrc.openidconnect.userinfo - -import java.util.concurrent.TimeUnit - -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.client.WireMock._ -import com.github.tomakehurst.wiremock.core.WireMockConfiguration._ -import org.scalatest.BeforeAndAfterAll -import org.scalatest.concurrent.{Eventually, IntegrationPatience, ScalaFutures} -import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication} - -import scala.concurrent.duration.FiniteDuration - -trait WireMockSugar extends UnitSpec with WithFakeApplication with Eventually with ScalaFutures - with IntegrationPatience with BeforeAndAfterAll with WiremockDSL { - - override implicit val defaultTimeout = FiniteDuration(100, TimeUnit.SECONDS) - - val WIREMOCK_PORT = 22222 - val stubHost = "localhost" - - protected val wiremockBaseUrl: String = s"http://$stubHost:$WIREMOCK_PORT" - private val wireMockServer = new WireMockServer(wireMockConfig().port(WIREMOCK_PORT)) - - override def beforeAll() = { - super.beforeAll() - wireMockServer.stop() - wireMockServer.start() - WireMock.configureFor(stubHost, WIREMOCK_PORT) - // the below stub is here so that the application finds the registration endpoint which is called on startup - stubFor(post(urlMatching("/registration")).willReturn(aResponse().withStatus(200))) - } - - override def afterAll() = { - super.afterAll() - wireMockServer.stop() - } -} diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnectorSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnectorSpec.scala deleted file mode 100644 index 8a149d8..0000000 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/AuthConnectorSpec.scala +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2017 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 unit.uk.gov.hmrc.openidconnect.userinfo.connectors - -import com.github.tomakehurst.wiremock.client.WireMock._ -import org.scalatest.mock.MockitoSugar -import uk.gov.hmrc.openidconnect.userinfo.config.WSHttp -import uk.gov.hmrc.openidconnect.userinfo.connectors.AuthConnector -import uk.gov.hmrc.openidconnect.userinfo.domain.{Authority, Enrolment, EnrolmentIdentifier} -import uk.gov.hmrc.play.auth.microservice.connectors.ConfidenceLevel -import uk.gov.hmrc.play.auth.microservice.connectors.ConfidenceLevel._ -import unit.uk.gov.hmrc.openidconnect.userinfo.WireMockSugar -import uk.gov.hmrc.http.{ HeaderCarrier, HttpGet } - -class AuthConnectorSpec extends WireMockSugar { - - "fetchEnrolments" should { - val authority = Authority(Some("weak"), Some(200), Some("AA111111A"), Some("/uri/to/userDetails"), - Some("/uri/to/enrolments"), Some("Individual")) - "return the authority enrolments" in new TestAuthConnector(wiremockBaseUrl) { - given().get(urlPathEqualTo("/uri/to/enrolments")).returns(enrolmentsJson()) - fetchEnrolments(authority).futureValue shouldBe Some(Seq(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121"))))) - } - - "return None when there is no URI for enrolments" in new TestAuthConnector(wiremockBaseUrl) { - fetchEnrolments(authority.copy(enrolments = None)).futureValue shouldBe None - } - - "return None when there are no enrolments at all" in new TestAuthConnector(wiremockBaseUrl) { - given().get(urlPathEqualTo("/uri/to/enrolments")).returns("{}") - fetchEnrolments(authority).futureValue shouldBe None - } - } - - "fetchAuthority" should { - "return the authority with some GG fields" in new TestAuthConnector(wiremockBaseUrl) { - given().get(urlPathEqualTo("/auth/authority")).returns(authorityJson(L200)) - fetchAuthority().futureValue shouldBe Some(Authority(Some("weak"),Some(200),Some("AB123456A"),Some("/uri/to/userDetails"), - Some("/uri/to/enrolments"),Some("Individual"),Some("1304372065861347"))) - } - } -} - -class TestAuthConnector(wiremockBaseUrl: String) extends AuthConnector with MockitoSugar { - implicit val hc = HeaderCarrier() - - override val authBaseUrl: String = wiremockBaseUrl - override val http: HttpGet = WSHttp - - def authorityJson(confidenceLevel: ConfidenceLevel) = { - s""" - |{ - | "credentialStrength":"weak", - | "confidenceLevel": ${confidenceLevel.level}, - | "nino": "AB123456A", - | "userDetailsLink": "/uri/to/userDetails", - | "enrolments": "/uri/to/enrolments", - | "affinityGroup": "Individual", - | "credId": "1304372065861347" - |} - """.stripMargin - } - - def enrolmentsJson() = { - s""" - |[ - | { - | "key": "IR-SA", - | "identifiers": [ - | { - | "key": "UTR", - | "value": "174371121" - | } - | ], - | "state": "Activated" - | } - |] - """.stripMargin - } - - override def authConnector = ??? -} diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoControllerSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoControllerSpec.scala index 5f561ab..5c72a35 100644 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoControllerSpec.scala +++ b/test/unit/uk/gov/hmrc/openidconnect/userinfo/controllers/UserInfoControllerSpec.scala @@ -24,12 +24,13 @@ import org.scalatest.concurrent.ScalaFutures import org.scalatest.mock.MockitoSugar import play.api.libs.json.Json import play.api.test.FakeRequest +import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier} +import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier} import uk.gov.hmrc.openidconnect.userinfo.controllers.{ErrorBadRequest, LiveUserInfoController, SandboxUserInfoController} -import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, Enrolment, EnrolmentIdentifier, GovernmentGatewayDetails, UserInfo} +import uk.gov.hmrc.openidconnect.userinfo.domain.{Address, GovernmentGatewayDetails, UserInfo} import uk.gov.hmrc.openidconnect.userinfo.services.{LiveUserInfoService, SandboxUserInfoService} -import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication} -import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier} import uk.gov.hmrc.play.microservice.filters.MicroserviceFilterSupport +import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication} import scala.concurrent.Future @@ -43,7 +44,7 @@ class UserInfoControllerSpec extends UnitSpec with MockitoSugar with ScalaFuture Some("John.Smith@a.b.c.com"), Some(LocalDate.parse("1982-11-15")), Some("AR778351B"), - Some(Seq(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121"))))), + Some(Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated"))), Some(GovernmentGatewayDetails(Some("32131"),Some(Seq("User")), Some("John"), Some("affinityGroup"), Some("agent-code-12345"), Some("agent-id-12345"), Some("agent-friendly-name"), None, None)), None) diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilterSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilterSpec.scala index ce41e8e..a447c55 100644 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilterSpec.scala +++ b/test/unit/uk/gov/hmrc/openidconnect/userinfo/filters/MicroserviceAuthFilterSpec.scala @@ -16,6 +16,7 @@ package unit.uk.gov.hmrc.openidconnect.userinfo.filters +import org.mockito.Matchers import org.mockito.Matchers._ import org.mockito.Mockito._ import org.scalatest.concurrent.ScalaFutures @@ -25,15 +26,17 @@ import play.api.mvc.RequestHeader import play.api.mvc.Results._ import play.api.routing.Router import play.api.test.FakeRequest +import uk.gov.hmrc.auth.core.authorise.EmptyPredicate +import uk.gov.hmrc.auth.core.retrieve.EmptyRetrieval +import uk.gov.hmrc.auth.core.{AuthConnector, MissingBearerToken} +import uk.gov.hmrc.http.HeaderCarrier import uk.gov.hmrc.openidconnect.userinfo.filters.MicroserviceAuthFilter -import uk.gov.hmrc.openidconnect.userinfo.services.AuthService import uk.gov.hmrc.play.auth.controllers.{AuthConfig, AuthParamsControllerConfig} import uk.gov.hmrc.play.auth.microservice.connectors.ConfidenceLevel +import uk.gov.hmrc.play.microservice.filters.MicroserviceFilterSupport import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication} import scala.concurrent.Future -import uk.gov.hmrc.http.HeaderCarrier -import uk.gov.hmrc.play.microservice.filters.MicroserviceFilterSupport class MicroserviceAuthFilterSpec extends UnitSpec with ScalaFutures with MockitoSugar with WithFakeApplication { @@ -43,8 +46,8 @@ class MicroserviceAuthFilterSpec extends UnitSpec with ScalaFutures with Mockito trait Setup extends MicroserviceFilterSupport { val authFilter = new MicroserviceAuthFilter with MicroserviceFilterSupport { - override val authService = mock[AuthService] override val authParamsConfig = mock[AuthParamsControllerConfig] + override val authConnector = mock[AuthConnector] override def controllerNeedsAuth(controllerName: String): Boolean = { controllerName match { @@ -64,7 +67,7 @@ class MicroserviceAuthFilterSpec extends UnitSpec with ScalaFutures with Mockito "call the next filter if authentication is required and the user is authorised" in new Setup { - when(authFilter.authService.isAuthorised()(any())).thenReturn(Future.successful(true)) + when(authFilter.authConnector.authorise(Matchers.eq(EmptyPredicate), Matchers.eq(EmptyRetrieval))(any(), any())).thenReturn(Future.successful()) when(authFilter.authParamsConfig.authConfig(live)).thenReturn(AuthConfig(confidenceLevel = ConfidenceLevel.L50)) val request = FakeRequest("GET", "/").copy(tags = Map(Router.Tags.RouteController -> live)) @@ -76,7 +79,7 @@ class MicroserviceAuthFilterSpec extends UnitSpec with ScalaFutures with Mockito "return 401 (Unauthorized) if authentication is required and the user is not authorised" in new Setup { - when(authFilter.authService.isAuthorised()(any())).thenReturn(Future.successful(false)) + when(authFilter.authConnector.authorise(Matchers.eq(EmptyPredicate), Matchers.eq(EmptyRetrieval))(any(), any())).thenReturn(Future.failed(MissingBearerToken())) when(authFilter.authParamsConfig.authConfig(live)).thenReturn(AuthConfig(confidenceLevel = ConfidenceLevel.L50)) val request = FakeRequest("GET", "/").copy(tags = Map(Router.Tags.RouteController -> live)) @@ -95,7 +98,7 @@ class MicroserviceAuthFilterSpec extends UnitSpec with ScalaFutures with Mockito response.header.status shouldBe 200 bodyOf(response) shouldBe "Success" - verifyZeroInteractions(authFilter.authService, authFilter.authParamsConfig) + verifyZeroInteractions(authFilter.authConnector, authFilter.authParamsConfig) } } } diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoServiceSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoServiceSpec.scala index f17af10..a014a1e 100644 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoServiceSpec.scala +++ b/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoServiceSpec.scala @@ -21,8 +21,11 @@ import org.mockito.Matchers.any import org.mockito.Mockito.{never, verify} import org.scalatest.concurrent.ScalaFutures import org.scalatest.mock.MockitoSugar -import uk.gov.hmrc.auth.core.retrieve.{ItmpAddress, ItmpName, MdtpInformation} +import uk.gov.hmrc.auth.core.retrieve.{ItmpAddress, ItmpName} +import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier, Enrolments} import uk.gov.hmrc.domain.Nino +import uk.gov.hmrc.http.logging.Authorization +import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier, Token} import uk.gov.hmrc.openidconnect.userinfo.connectors.{AuthConnector, ThirdPartyDelegatedAuthorityConnector} import uk.gov.hmrc.openidconnect.userinfo.data.UserInfoGenerator import uk.gov.hmrc.openidconnect.userinfo.domain._ @@ -31,20 +34,17 @@ import uk.gov.hmrc.play.test.UnitSpec import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future -import uk.gov.hmrc.http.{BadRequestException, HeaderCarrier, Token} -import uk.gov.hmrc.http.logging.Authorization class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val nino = Nino("AB123456A") val authBearerToken = "AUTH_BEARER_TOKEN" val desUserInfo = DesUserInfo(ItmpName(Some("John"), None, Some("Smith")), None, ItmpAddress(Some("1 Station Road"), Some("Town Centre"), None, None, None, None, None, None)) - val enrolments = Seq(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")))) - val authority: Authority = Authority(Some("weak"),Some(200),Some("AB123456A"),Some("/uri/to/userDetails"), - Some("/uri/to/enrolments"),Some("Individual")) + val enrolments = Enrolments(Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated"))) + val authority: Authority = Authority("32131", Some("AB123456A")) - val userDetails: UserDetails = UserDetails(None, None, None, None, None, None, None, Some("affinityGroup"), None, None, - Some("User"), None, None, None, None, None, None) + val userDetails: UserDetails = UserDetails(None, None, None, None, None, None, None, None, Some("affinityGroup"), None, None, + Some("User"), None, None, None, None, None) val governmentGateway: GovernmentGatewayDetails = GovernmentGatewayDetails(Some("32131"),Some(Seq("User")), Some("John"), Some("affinityGroup"), Some("agent-code-12345"), Some("agent-id-12345"), Some("agent-friendly-name"), Some("gateway-token-val"), Some(11)) @@ -53,7 +53,7 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val ggToken = Token("ggToken") val userInfo = UserInfo(Some("John"), Some("Smith"), None, Some(Address("1 Station Road\nTown Centre", None, None, None)), - None, None, Some(nino).map(_.nino), Some(enrolments), Some(governmentGateway), Some(mdtp)) + None, None, Some(nino).map(_.nino), Some(enrolments.enrolments), Some(governmentGateway), Some(mdtp)) trait Setup { implicit val headers = HeaderCarrier().copy(authorization = Some(Authorization(s"Bearer $authBearerToken"))) @@ -76,15 +76,15 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val scopes = Set("openid", "address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "email", "openid:government-gateway") given(liveInfoService.thirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers)).willReturn(scopes) given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Some(authority)) - given(liveInfoService.authConnector.fetchEnrolments(authority)(headers)).willReturn(Some(enrolments)) + given(liveInfoService.authConnector.fetchEnrolments()(headers)).willReturn(Some(enrolments)) given(liveInfoService.authConnector.fetchUserDetails()(headers)).willReturn(Some(userDetails)) - given(liveInfoService.authConnector.fetchDesUserInfo(authority)(headers)).willReturn(Some(desUserInfo)) - given(liveInfoService.userInfoTransformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority),None)).willReturn(any[UserInfo], any[UserInfo]) + given(liveInfoService.authConnector.fetchDesUserInfo()(headers)).willReturn(Some(desUserInfo)) + given(liveInfoService.userInfoTransformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) await(liveInfoService.fetchUserInfo()) - verify(liveInfoService.authConnector).fetchDesUserInfo(authority) - verify(liveInfoService.authConnector).fetchEnrolments(authority) + verify(liveInfoService.authConnector).fetchDesUserInfo() + verify(liveInfoService.authConnector).fetchEnrolments() verify(liveInfoService.authConnector).fetchAuthority() verify(liveInfoService.authConnector).fetchUserDetails()(any[HeaderCarrier]) } @@ -92,8 +92,8 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { "should fail with BadRequestException when the NINO is not in the authority and a scope that requires a NINO is requested" in new Setup { val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments") given(liveInfoService.thirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers)).willReturn(scopes) - given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Future(Option(authority.copy(nino = None)))) - given(liveInfoService.authConnector.fetchEnrolments(any())(any())).willReturn(Future(None)) + given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Future(Some(authority.copy(nino = None)))) + given(liveInfoService.authConnector.fetchEnrolments()(any())).willReturn(Future(None)) a [BadRequestException] should be thrownBy await(liveInfoService.fetchUserInfo()) } @@ -102,14 +102,14 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val scopes = Set("openid:gov-uk-identifiers", "openid:hmrc-enrolments") given(liveInfoService.thirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers)).willReturn(scopes) - given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Future(Option(authority))) - given(liveInfoService.authConnector.fetchEnrolments(any())(any())).willReturn(Future(None)) - given(liveInfoService.userInfoTransformer.transform(scopes, None, Some(enrolments), Some(authority), Some(userDetails))).willReturn(any[UserInfo], any[UserInfo]) + given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Some(authority)) + given(liveInfoService.authConnector.fetchEnrolments()(any())).willReturn(Future(None)) + given(liveInfoService.userInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), Some(userDetails))).willReturn(any[UserInfo], any[UserInfo]) await(liveInfoService.fetchUserInfo()) - verify(liveInfoService.authConnector, never).fetchDesUserInfo(any[Authority])(any[HeaderCarrier]) - verify(liveInfoService.authConnector).fetchEnrolments(authority) + verify(liveInfoService.authConnector, never).fetchDesUserInfo()(any[HeaderCarrier]) + verify(liveInfoService.authConnector).fetchEnrolments() } "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 { @@ -117,29 +117,29 @@ class UserInfoServiceSpec extends UnitSpec with MockitoSugar with ScalaFutures { val scopes = Set("openid:hmrc-enrolments") given(liveInfoService.thirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers)).willReturn(scopes) - given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Option(authority)) - given(liveInfoService.authConnector.fetchEnrolments(authority)(headers)).willReturn(Some(enrolments)) - given(liveInfoService.userInfoTransformer.transform(scopes, None, Some(enrolments), Some(authority), None)).willReturn(any[UserInfo], any[UserInfo]) + given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Some(authority)) + given(liveInfoService.authConnector.fetchEnrolments()(headers)).willReturn(Some(enrolments)) + given(liveInfoService.userInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) await(liveInfoService.fetchUserInfo()) - verify(liveInfoService.authConnector, never).fetchDesUserInfo(any[Authority])(any[HeaderCarrier]) - verify(liveInfoService.authConnector).fetchEnrolments(authority) + verify(liveInfoService.authConnector, never).fetchDesUserInfo()(any[HeaderCarrier]) + verify(liveInfoService.authConnector).fetchEnrolments() } - "does not request AUTH::fetchEnrloments when the scopes does not contain 'openid:hmrc-enrolments'" in new Setup { + "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(liveInfoService.thirdPartyDelegatedAuthorityConnector.fetchScopes(authBearerToken)(headers)).willReturn(scopes) - given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Future(Option(authority))) - given(liveInfoService.authConnector.fetchDesUserInfo(authority)(headers)).willReturn(None) - given(liveInfoService.userInfoTransformer.transform(scopes, None, Some(enrolments), None, None)).willReturn(any[UserInfo], any[UserInfo]) + given(liveInfoService.authConnector.fetchAuthority()(headers)).willReturn(Some(authority)) + given(liveInfoService.authConnector.fetchDesUserInfo()(headers)).willReturn(None) + given(liveInfoService.userInfoTransformer.transform(scopes, Some(authority), None, Some(enrolments), None)).willReturn(any[UserInfo], any[UserInfo]) await(liveInfoService.fetchUserInfo()) - verify(liveInfoService.authConnector, never).fetchEnrolments(any[Authority])(any[HeaderCarrier]) - verify(liveInfoService.authConnector).fetchDesUserInfo(any[Authority])(any[HeaderCarrier]) + verify(liveInfoService.authConnector, never).fetchEnrolments()(any[HeaderCarrier]) + verify(liveInfoService.authConnector).fetchDesUserInfo()(any[HeaderCarrier]) } } diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformerSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformerSpec.scala index 67b4963..ee60860 100644 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformerSpec.scala +++ b/test/unit/uk/gov/hmrc/openidconnect/userinfo/services/UserInfoTransformerSpec.scala @@ -20,14 +20,15 @@ import org.joda.time.LocalDate import org.scalatest.BeforeAndAfterEach import org.scalatest.mock.MockitoSugar import uk.gov.hmrc.auth.core.retrieve.{GatewayInformation, ItmpAddress, ItmpName, MdtpInformation} +import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier, Enrolments} import uk.gov.hmrc.domain.Nino +import uk.gov.hmrc.http.{HeaderCarrier, Token} import uk.gov.hmrc.openidconnect.userinfo.config.{FeatureSwitch, UserInfoFeatureSwitches} import uk.gov.hmrc.openidconnect.userinfo.domain._ import uk.gov.hmrc.openidconnect.userinfo.services.UserInfoTransformer import uk.gov.hmrc.play.test.UnitSpec import scala.concurrent.ExecutionContext.Implicits.global -import uk.gov.hmrc.http.{ HeaderCarrier, Token } class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndAfterEach { @@ -36,15 +37,14 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val desAddress: ItmpAddress = ItmpAddress(Some("1 Station Road"), Some("Town Centre"), Some("London"), Some("England"), Some("UK"), Some("NW1 6XE"), Some("United Kingdom"), Some("GB")) val desUserInfo = DesUserInfo(ItmpName(Some("John"), Some("A"), Some("Smith")), Some(LocalDate.parse("1980-01-01")), desAddress) - val enrolments = Seq(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")))) + val enrolments = Enrolments(Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated"))) val gatewayInformation = GatewayInformation(Some("gateway-token-abc")) val mdtp = Mdtp("device-id1234", "session-id-123") val authMdtp = MdtpInformation("device-id1234", "session-id-123") val userAddress: Address = Address("1 Station Road\nTown Centre\nLondon\nEngland\nUK\nNW1 6XE\nUnited Kingdom", Some("NW1 6XE"), Some("United Kingdom"), Some("GB")) - val authority: Authority = Authority(Some("weak"), Some(200), Some("AB123456A"), Some("/uri/to/userDetails"), - Some("/uri/to/enrolments"), Some("Individual"), Some("1304372065861347")) + val authority: Authority = Authority("1304372065861347", Some("AB123456A")) val userDetails: UserDetails = UserDetails(email = Some("John.Smith@a.b.c.com"), affinityGroup = Some("affinityGroup"), name = Some("John"), credentialRole = Some("User"), agentCode = Some("agent-code-12345"), agentId = Some("agent-id-12345"), @@ -66,7 +66,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA Some("John.Smith@a.b.c.com"), Some(LocalDate.parse("1980-01-01")), Some("AB123456A"), - Some(enrolments), + Some(enrolments.enrolments), Some(government_gateway), Some(mdtp) ) @@ -95,7 +95,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway" , "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe userInfo } @@ -104,7 +104,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers") - val result = await(transformer.transform(scopes, None, None, Option(authority), None)) + val result = await(transformer.transform(scopes, Some(authority), None, None, None)) result shouldBe UserInfo(None, None, None, None, None, None, Some(nino.map(_.nino)), None, None, None) } @@ -113,7 +113,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe userInfo.copy(address = None) } @@ -123,7 +123,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:government-gateway", "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe userInfo.copy(hmrc_enrolments = None) } @@ -132,7 +132,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe userInfo.copy(given_name = None, family_name = None, middle_name = None, birthdate = None) } @@ -141,7 +141,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe userInfo.copy(uk_gov_nino = None) } @@ -150,7 +150,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("openid") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) result shouldBe UserInfo(None, None, None, None, None, None, None, None, None, None) } @@ -160,7 +160,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") val desUserMissingline1 = desUserInfo.copy(address = desAddress.copy(line1 = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingline1), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingline1), Some(enrolments), Some(userDetails))) val userInfoMissingLine1 = userInfo.copy(address = Some(userAddress.copy(formatted = "Town Centre\nLondon\nEngland\nUK\nNW1 6XE\nUnited Kingdom"))) result shouldBe userInfoMissingLine1 } @@ -170,7 +170,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") val desUserMissingLine2 = desUserInfo.copy(address = desAddress.copy(line2 = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingLine2), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingLine2), Some(enrolments), Some(userDetails))) val userInfoMissingLine2 = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nLondon\nEngland\nUK\nNW1 6XE\nUnited Kingdom"))) result shouldBe userInfoMissingLine2 } @@ -180,7 +180,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") val desUserMissingLine3 = desUserInfo.copy(address = desAddress.copy(line3 = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingLine3), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingLine3), Some(enrolments), Some(userDetails))) val userInfoMissingLine3 = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nTown Centre\nEngland\nUK\nNW1 6XE\nUnited Kingdom"))) result shouldBe userInfoMissingLine3 } @@ -190,7 +190,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:government-gateway", "email", "openid:mdtp") val desUserMissingLine4 = desUserInfo.copy(address = desAddress.copy(line4 = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingLine4), None, Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingLine4), None, Some(userDetails))) val userInfoMissingLine4 = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nTown Centre\nLondon\nUK\nNW1 6XE\nUnited Kingdom")), hmrc_enrolments = None) result shouldBe userInfoMissingLine4 } @@ -200,7 +200,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:government-gateway", "email", "openid:mdtp") val desUserMissingLine5 = desUserInfo.copy(address = desAddress.copy(line5 = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingLine5), None, Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingLine5), None, Some(userDetails))) val userInfoMissingLine5 = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nTown Centre\nLondon\nEngland\nNW1 6XE\nUnited Kingdom")), hmrc_enrolments = None) result shouldBe userInfoMissingLine5 } @@ -210,7 +210,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:government-gateway", "openid:mdtp") val desUserMissingPostCode = desUserInfo.copy(address = desAddress.copy(postCode = None)) - val result = await(transformer.transform(scopes, Some(desUserMissingPostCode), None, Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserMissingPostCode), None, Some(userDetails))) val userInfoMissingPostCode = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nTown Centre\nLondon\nEngland\nUK\nUnited Kingdom", postal_code = None)), hmrc_enrolments = None, email = None) result shouldBe userInfoMissingPostCode } @@ -219,7 +219,7 @@ class UserInfoTransformerSpec extends UnitSpec with MockitoSugar with BeforeAndA FeatureSwitch.disable(UserInfoFeatureSwitches.countryCode) val scopes = Set("address", "profile", "openid:gov-uk-identifiers", "openid:hmrc-enrolments", "openid:government-gateway", "email", "openid:mdtp") - val result = await(transformer.transform(scopes, Some(desUserInfo), Some(enrolments), Some(authority), Some(userDetails))) + val result = await(transformer.transform(scopes, Some(authority), Some(desUserInfo), Some(enrolments), Some(userDetails))) val userInfoMissingCountryCode = userInfo.copy(address = Some(userAddress.copy(formatted = "1 Station Road\nTown Centre\nLondon\nEngland\nUK\nNW1 6XE\nUnited Kingdom", country_code = None))) result shouldBe userInfoMissingCountryCode