diff --git a/test/it/BaseFeatureISpec.scala b/it/unit/uk/gov/hmrc/openidconnect/BaseFeatureISpec.scala similarity index 68% rename from test/it/BaseFeatureISpec.scala rename to it/unit/uk/gov/hmrc/openidconnect/BaseFeatureISpec.scala index e9b3978..82f1bce 100644 --- a/test/it/BaseFeatureISpec.scala +++ b/it/unit/uk/gov/hmrc/openidconnect/BaseFeatureISpec.scala @@ -1,20 +1,4 @@ -/* - * Copyright 2020 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 it +package unit.uk.gov.hmrc.openidconnect import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.WireMock @@ -22,8 +6,9 @@ import com.github.tomakehurst.wiremock.client.WireMock.{aResponse, post, stubFor import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig import org.scalatest._ import uk.gov.hmrc.integration.ServiceSpec - import scala.concurrent.duration._ + +import scala.concurrent.duration.Duration import scala.concurrent.{Await, Future} trait BaseFeatureISpec diff --git a/it/unit/uk/gov/hmrc/openidconnect/FeatureSwitchControllerISpec.scala b/it/unit/uk/gov/hmrc/openidconnect/FeatureSwitchControllerISpec.scala new file mode 100644 index 0000000..726c306 --- /dev/null +++ b/it/unit/uk/gov/hmrc/openidconnect/FeatureSwitchControllerISpec.scala @@ -0,0 +1,51 @@ +package unit.uk.gov.hmrc.openidconnect + +import play.api.libs.json.Json +import scalaj.http.{Http, HttpOptions} + +class FeatureSwitchControllerISpec extends BaseFeatureISpec { + + val serviceUrl = "/feature-switches" + + feature("getting feature switches") { + scenario("calling GET /feature-switches") { + Given("we call GET /feature-switches") + + val result = Http(resource(s"$serviceUrl")).asString + + Then("the feature switches are returned as json with 200 OK") + + result.code shouldBe 200 + Json.parse(result.body) shouldBe Json.arr(Json.obj("name" -> "countryCode", "isEnabled" -> false), Json.obj("name" -> "addressLine5", "isEnabled" -> false)) + } + } + + feature("updating feature switches") { + scenario("calling POST /feature-switches") { + Given("we call GET /feature-switches") + + val result = Http(resource(s"$serviceUrl")).asString + + Then("the feature switches are returned as json with 200 OK") + + result.code shouldBe 200 + Json.parse(result.body) shouldBe Json.arr(Json.obj("name" -> "countryCode", "isEnabled" -> false), Json.obj("name" -> "addressLine5", "isEnabled" -> false)) + + When("we update the flags we should get 406 Accepted") + + val payload = Json.obj("featureSwitches" -> Json.arr(Json.obj("name" -> "countryCode", "isEnabled" -> true), Json.obj("name" -> "addressLine5", "isEnabled" -> true))) + + val updateResult = Http(resource(s"$serviceUrl")).method("POST").header("Content-Type", "application/json").postData(payload.toString()).asString + + updateResult.code shouldBe 202 + + When("we retrieve the flags back we see they should be negated") + + val updatedResult = Http(resource(s"$serviceUrl")).asString + + updatedResult.code shouldBe 200 + Json.parse(updatedResult.body) shouldBe Json.arr(Json.obj("name" -> "countryCode", "isEnabled" -> true), Json.obj("name" -> "addressLine5", "isEnabled" -> true)) + + } + } +} diff --git a/test/it/PlatformIntegrationISpec.scala b/it/unit/uk/gov/hmrc/openidconnect/PlatformIntegrationISpec.scala similarity index 99% rename from test/it/PlatformIntegrationISpec.scala rename to it/unit/uk/gov/hmrc/openidconnect/PlatformIntegrationISpec.scala index 44d47f1..1671f90 100644 --- a/test/it/PlatformIntegrationISpec.scala +++ b/it/unit/uk/gov/hmrc/openidconnect/PlatformIntegrationISpec.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package it +package unit.uk.gov.hmrc.openidconnect import org.scalatest.concurrent.ScalaFutures import play.api.libs.json._ diff --git a/test/it/SchemaISpec.scala b/it/unit/uk/gov/hmrc/openidconnect/SchemaISpec.scala similarity index 97% rename from test/it/SchemaISpec.scala rename to it/unit/uk/gov/hmrc/openidconnect/SchemaISpec.scala index 9816322..aa6e4d6 100644 --- a/test/it/SchemaISpec.scala +++ b/it/unit/uk/gov/hmrc/openidconnect/SchemaISpec.scala @@ -14,9 +14,10 @@ * limitations under the License. */ -package it +package unit.uk.gov.hmrc.openidconnect 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 diff --git a/test/it/UserInfoServiceISpec.scala b/it/unit/uk/gov/hmrc/openidconnect/UserInfoServiceISpec.scala similarity index 89% rename from test/it/UserInfoServiceISpec.scala rename to it/unit/uk/gov/hmrc/openidconnect/UserInfoServiceISpec.scala index 1a4e20a..69cec9b 100644 --- a/test/it/UserInfoServiceISpec.scala +++ b/it/unit/uk/gov/hmrc/openidconnect/UserInfoServiceISpec.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package it +package unit.uk.gov.hmrc.openidconnect import java.nio.file.Paths @@ -423,5 +423,66 @@ class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPart result.code shouldBe 502 Json.parse(result.body) shouldBe Json.parse(expectedErrorMessage) } + + scenario("fetching user info returns 5xx then we return 502") { + + 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 user details call will fail with 500") + willFindUserFailed(500) + + 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 + + + Then("The user information is returned") + result.code shouldBe 502 + + } + + scenario("fetching user info returns 4xx then we return 502") { + + 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 user details call will fail with 400") + willFindUserFailed(409) + + 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 + + + Then("The user information is returned") + result.code shouldBe 502 + + } + } + + } diff --git a/test/it/stubs/AuthStub.scala b/it/unit/uk/gov/hmrc/openidconnect/stubs/AuthStub.scala similarity index 95% rename from test/it/stubs/AuthStub.scala rename to it/unit/uk/gov/hmrc/openidconnect/stubs/AuthStub.scala index bcb67dd..204976c 100644 --- a/test/it/stubs/AuthStub.scala +++ b/it/unit/uk/gov/hmrc/openidconnect/stubs/AuthStub.scala @@ -60,6 +60,18 @@ import com.github.ghik.silencer.silent ) } + def willFindUserFailed(status: Int): Unit = { + stubFor(post(urlPathEqualTo(s"/auth/authorise")) + .withRequestBody(equalToJson(Json.obj( + "authorise" -> JsArray(), + "retrieve" -> JsArray(Retrievals.allItmpUserDetails.propertyNames.map(JsString)) + ).toString())) + .willReturn(aResponse() + .withBody("{}") + .withStatus(status)) + ) + } + 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, diff --git a/test/it/stubs/ThirdPartyDelegatedAuthorityStub.scala b/it/unit/uk/gov/hmrc/openidconnect/stubs/ThirdPartyDelegatedAuthorityStub.scala similarity index 100% rename from test/it/stubs/ThirdPartyDelegatedAuthorityStub.scala rename to it/unit/uk/gov/hmrc/openidconnect/stubs/ThirdPartyDelegatedAuthorityStub.scala diff --git a/project/ScoverageSettings.scala b/project/ScoverageSettings.scala index cc43d9f..dd5417e 100644 --- a/project/ScoverageSettings.scala +++ b/project/ScoverageSettings.scala @@ -9,8 +9,11 @@ object ScoverageSettings { "" + "", "Reverse.*", - ".*models.*", + ".*domain.*", + ".*views.*", ".*repositories.*", + ".*config.*", + ".*data.*", ".*BuildInfo.*", ".*javascript.*", ".*Routes.*",