Skip to content

Commit

Permalink
Merge pull request #96 from hmrc/GG-7233-yaml
Browse files Browse the repository at this point in the history
Gg 7233 yaml
  • Loading branch information
AadilAkhtar authored Aug 16, 2023
2 parents 7e27676 + 3cb24ab commit 4bef234
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 618 deletions.
4 changes: 1 addition & 3 deletions app/config/GuiceModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +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]).annotatedWith(Names.named("v2Connector")).to(classOf[AuthConnectorV2])
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])
Expand Down
5 changes: 0 additions & 5 deletions app/connectors/AuthConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
68 changes: 0 additions & 68 deletions app/connectors/AuthV2UserDetailsFetcher.scala

This file was deleted.

2 changes: 0 additions & 2 deletions app/controllers/UserInfoController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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")
}
}
Expand Down
13 changes: 3 additions & 10 deletions app/services/UserInfoService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -32,8 +32,7 @@ trait UserInfoService {
}

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

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

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

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

val scopesForDes = Set("profile", "address")
def maybeDesUserInfo = {
Expand Down Expand Up @@ -94,7 +88,6 @@ class SandboxUserInfoService @Inject() (userInfoGenerator: UserInfoGenerator) ex
override def fetchUserInfo(version: Version)(implicit hc: HeaderCarrier): Future[UserInfo] = {
val generator: UserInfo = version match {
case Version_1_0 => userInfoGenerator.userInfoV1_0()
case Version_1_1 => userInfoGenerator.userInfoV1_1()
case _ => UserInfo()
}
Future.successful(generator)
Expand Down
8 changes: 0 additions & 8 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}


Expand Down
68 changes: 0 additions & 68 deletions it/UserInfoServiceISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
27 changes: 1 addition & 26 deletions it/stubs/AuthStub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 4bef234

Please sign in to comment.