Skip to content

Commit

Permalink
GG-6516
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-armstrong committed Aug 9, 2022
1 parent 343af7f commit b42ecbb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/connectors/ThirdPartyDelegatedAuthorityConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class ThirdPartyDelegatedAuthorityConnector @Inject() (appContext: AppContext, h
val serviceUrl: String = appContext.thirdPartyDelegatedAuthorityUrl

def fetchScopes(authBearerToken: String)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Set[String]] = {
http.GET(s"$serviceUrl/delegated-authority", Seq("auth_bearer_token" -> authBearerToken))(readRaw, hc, ec) map { response =>
http.GET(s"$serviceUrl/delegated-authority", Nil, Seq("auth-bearer-token" -> authBearerToken))(readRaw, hc, ec) map { response =>
if (response.status == Status.NOT_FOUND) {
Set.empty
Set[String]()
} else {
(response.json \ "token" \ "scopes").as[Set[String]]
}
Expand Down
3 changes: 1 addition & 2 deletions it/UserInfoServiceISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/

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 config.{FeatureSwitch, UserInfoFeatureSwitches}
import controllers.Version_1_1
import domain._
import it.stubs.{AuthStub, ThirdPartyDelegatedAuthorityStub}
import org.joda.time.LocalDate
import play.api.libs.json.Json
import scalaj.http.{Http, HttpOptions}
import stubs.{AuthStub, ThirdPartyDelegatedAuthorityStub}
import uk.gov.hmrc.auth.core._
import uk.gov.hmrc.auth.core.retrieve._
import uk.gov.hmrc.domain.Nino
Expand Down
2 changes: 1 addition & 1 deletion it/stubs/AuthStub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package it.stubs
package stubs

import com.github.tomakehurst.wiremock.client.WireMock._
import play.api.libs.json._
Expand Down
7 changes: 4 additions & 3 deletions it/stubs/ThirdPartyDelegatedAuthorityStub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/

package it.stubs
package stubs

import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.stubbing.StubMapping
import play.api.libs.json.Json

trait ThirdPartyDelegatedAuthorityStub {
def willReturnScopesForAuthBearerToken(authBearerToken: String, scopes: Set[String]) = {
def willReturnScopesForAuthBearerToken(authBearerToken: String, scopes: Set[String]):StubMapping = {
stubFor(get(urlPathEqualTo(s"/delegated-authority"))
.withQueryParam("auth_bearer_token", equalTo(authBearerToken))
.withHeader("auth-bearer-token", equalTo(authBearerToken))
.willReturn(aResponse().withBody(
s"""
|{"token":
Expand Down
4 changes: 2 additions & 2 deletions project/ScoverageSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ object ScoverageSettings {
".*DateTimeQueryStringBinder.*", // better covered via wiremock/E2E integration tests
".*Test.*"
).mkString(";"),
ScoverageKeys.coverageMinimum := 78,
ScoverageKeys.coverageMinimumStmtTotal := 78,
ScoverageKeys.coverageFailOnMinimum := true,
ScoverageKeys.coverageHighlighting := true,
parallelExecution in Test := false
Test / parallelExecution := false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ThirdPartyDelegatedAuthorityConnectorSpec extends UnitSpec with MockitoSug
"return the scopes of the delegated authority" in new Setup {
val authBearerToken = "AUTH_TOKEN"

stubFor(get(urlPathMatching(s"/delegated-authority")).withQueryParam("auth_bearer_token", equalTo(authBearerToken)).
stubFor(get(urlPathMatching(s"/delegated-authority")).withHeader("auth-bearer-token", equalTo(authBearerToken)).
willReturn(
aResponse()
.withStatus(200)
Expand All @@ -83,7 +83,7 @@ class ThirdPartyDelegatedAuthorityConnectorSpec extends UnitSpec with MockitoSug
"return an empty set when delegated authority is not found" in new Setup {
val authBearerToken = "AUTH_TOKEN"

stubFor(get(urlPathMatching(s"/delegated-authority")).withQueryParam("auth_bearer_token", equalTo(authBearerToken)).
stubFor(get(urlPathMatching(s"/delegated-authority")).withHeader("auth-bearer-token", equalTo(authBearerToken)).
willReturn(aResponse().withStatus(404)))

val scopes: Set[String] = await(connector.fetchScopes(authBearerToken))
Expand Down

0 comments on commit b42ecbb

Please sign in to comment.