diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnector.scala b/app/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnector.scala index 8777cf7..bb78600 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnector.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnector.scala @@ -27,6 +27,8 @@ import scala.concurrent.ExecutionContext.Implicits.global trait DesConnector { + val NINO_LENGTH = 8 + val http: HttpGet val serviceUrl: String val desEnvironment: String @@ -37,10 +39,12 @@ trait DesConnector { "Authorization" -> ("Bearer " + desBearerToken), "Environment" -> desEnvironment) - http.GET[DesUserInfo](s"$serviceUrl/pay-as-you-earn/individuals/$nino")(implicitly[HttpReads[DesUserInfo]], newHc) map (Some(_)) recover { + http.GET[DesUserInfo](s"$serviceUrl/pay-as-you-earn/individuals/${withoutSuffix(nino)}")(implicitly[HttpReads[DesUserInfo]], newHc) map (Some(_)) recover { case _: NotFoundException | _: BadRequestException => None } } + + private def withoutSuffix(nino: String) = nino.take(NINO_LENGTH) } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/controllers/DocumentationController.scala b/app/uk/gov/hmrc/openidconnect/userinfo/controllers/DocumentationController.scala index 5f4df08..9186f36 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/controllers/DocumentationController.scala +++ b/app/uk/gov/hmrc/openidconnect/userinfo/controllers/DocumentationController.scala @@ -50,14 +50,12 @@ object DocumentationController extends DocumentationController object Documentation { val version1_0 = "1.0" val getUserInfo = "Get user info" - val getUserInfoPost = "Get user info POST" def findDocumentation(endpointName: String, version: String) = applyTemplate(endpointName, version)(userInfo) def applyTemplate(apiName: String, version: String)(info: UserInfo): Option[Xml] = { (apiName, version) match { case (`getUserInfo`, `version1_0`) => Some(xml.getUserInfo(info)) - case (`getUserInfoPost`, `version1_0`) => Some(xml.getUserInfoPost(info)) case _ => None } } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/views/definition.scala.txt b/app/uk/gov/hmrc/openidconnect/userinfo/views/definition.scala.txt index 7d2d674..8f254d2 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/views/definition.scala.txt +++ b/app/uk/gov/hmrc/openidconnect/userinfo/views/definition.scala.txt @@ -46,14 +46,6 @@ "authType":"USER", "throttlingTier":"UNLIMITED", "scope":"openid" - }, - { - "uriPattern":"", - "endpointName":"Get user info POST", - "method":"POST", - "authType":"USER", - "throttlingTier":"UNLIMITED", - "scope":"openid" } ] } diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfo.scala.xml b/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfo.scala.xml index 8364342..f09cd95 100644 --- a/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfo.scala.xml +++ b/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfo.scala.xml @@ -8,7 +8,7 @@ Retrieves OpenID Connect compliant information about the signed-in user
Resource - GET /userinfo + GET /userinfo/
Authorisation diff --git a/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfoPost.scala.xml b/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfoPost.scala.xml deleted file mode 100644 index fb56296..0000000 --- a/app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfoPost.scala.xml +++ /dev/null @@ -1,108 +0,0 @@ -@import uk.gov.hmrc.openidconnect.userinfo.domain.UserInfo -@import play.api.libs.json.Json - -@(userInfo: UserInfo) - - - Get User Info POST - Retrieves OpenID Connect compliant information about the signed-in user -
- Resource - POST /userinfo -
-
- Authorisation - - USER - openid - -
-
- Accepted Media Types - - - application/vnd.hmrc.1.0+json - - -
-
- Response - 200 (OK) - - - - Name - Type - Example - Description - - - - given_name - String - @userInfo.given_name - End-user's first name. - - - family_name - String - @userInfo.family_name - End-user's last name. - - - middle_name - String - @userInfo.middle_name.getOrElse("A.") - End user's middle name. - - - address.formatted - String - 221B Baker Street\nLondon\nNW1 9NT\nGreat Britain - End-user's mailing address, formatted for display or use on a mailing label. - - - address.postal_code - String - @userInfo.address.map(_.postal_code) - End-user's Zip code or postal code. - - - address.country - String - @userInfo.address.map(_.country) - End-user's country name. - - - birthdate - String - @userInfo.birthdate - End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format. - - - uk_gov_nino - String - @userInfo.uk_gov_nino - End-User's National Insurance Number. - - -
-
-
- Error Scenarios - - - Error Scenario - HTTP Status - Code - - - - Forbidden operation - 403 (Forbidden) - FORBIDDEN - - -
-
-
\ No newline at end of file diff --git a/test/it/stubs/DesStub.scala b/test/it/stubs/DesStub.scala index fdec80a..25a9e25 100644 --- a/test/it/stubs/DesStub.scala +++ b/test/it/stubs/DesStub.scala @@ -24,7 +24,8 @@ object DesStub extends Stub { override val stub: MockHost = new MockHost(22222) def willReturnUserInformation(desUserInfo: DesUserInfo, nino: String) = { - stub.mock.register(get(urlPathEqualTo(s"/pay-as-you-earn/individuals/$nino")) + val ninoWithoutSuffix = nino.take(8) + stub.mock.register(get(urlPathEqualTo(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")) .withHeader("Authorization", equalTo("Bearer local")) .withHeader("Environment", equalTo("local")) .willReturn(aResponse().withBody( diff --git a/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnectorSpec.scala b/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnectorSpec.scala index cdd74a8..6a91e14 100644 --- a/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnectorSpec.scala +++ b/test/unit/uk/gov/hmrc/openidconnect/userinfo/connectors/DesConnectorSpec.scala @@ -59,11 +59,12 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp } "fetch user info" should { - val nino = "AB123456" + val nino = "AA111111A" + val ninoWithoutSuffix = "AA111111" "return the user info" in new Setup { - stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")) + stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")) .withHeader("Authorization", equalTo(s"Bearer $desToken")) .withHeader("Environment", equalTo(desEnv)).willReturn( aResponse() @@ -72,7 +73,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp .withBody( s""" |{ - | "nino": "$nino", + | "nino": "$ninoWithoutSuffix", | "names": { | "1": { | "firstForenameOrInitial": "Andrew", @@ -106,7 +107,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp "return None when DES does not have an entry for the NINO" in new Setup { - stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn( + stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn( aResponse().withStatus(404))) val result = await(connector.fetchUserInfo(nino)) @@ -116,7 +117,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp "return None when DES does not have validated data" in new Setup { - stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn( + stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn( aResponse().withStatus(400))) val result = await(connector.fetchUserInfo(nino)) @@ -126,7 +127,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp "fail when DES returns a 500 response" in new Setup { - stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn( + stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn( aResponse().withStatus(500))) intercept[Upstream5xxResponse]{await(connector.fetchUserInfo(nino))}