Skip to content

Commit

Permalink
Merge pull request #46 from hmrc/PE-3304
Browse files Browse the repository at this point in the history
PE-3304 - test if userinfo returns upstream error messages
  • Loading branch information
gitplaneta authored Dec 15, 2017
2 parents eaf29db + 24d6bb2 commit d69eed9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/it/UserInfoServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,15 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll {
feature("fetching user information handles upstream errors") {

scenario("return 502 when Auth returns error") {
val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"GET of 'http://localhost:22221/auth/authority' returned 503. Response body: ''"}"""
val errorMsg = "auth error msg"
val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"GET of 'http://localhost:22221/auth/authority' 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)
authStub.willReturnEnrolmentsWith(503)
authStub.willReturnAuthorityWith(503, errorMsg)
authStub.willReturnEnrolmentsWith(503, errorMsg)

When("We request the user information")
val result = Http(s"$serviceUrl")
Expand All @@ -336,7 +337,8 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll {
}

scenario("return 502 when Auth returns not found") {
val expectedErrorMessage = s"""{"code":"BAD_GATEWAY","message":"GET of 'http://localhost:22221/auth/authority' returned 404 (Not Found). Response body: ''"}"""
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'"}"""
Given("A Auth token with openid:government-gateway, openid:hmrc-enrolments, address scopes")
thirdPartyDelegatedAuthorityStub.willReturnScopesForAuthBearerToken(authBearerToken,
Set("openid:government-gateway", "openid:hmrc-enrolments", "address"))
Expand All @@ -345,8 +347,8 @@ class UserInfoServiceSpec extends BaseFeatureSpec with BeforeAndAfterAll {
authStub.willAuthorise(Some(desUserInfo))

And("Auth returns not found")
authStub.willReturnAuthorityWith(404)
authStub.willReturnEnrolmentsWith(404)
authStub.willReturnAuthorityWith(404, errorMsg)
authStub.willReturnEnrolmentsWith(404, errorMsg)

When("We request the user information")
val result = Http(s"$serviceUrl")
Expand Down

0 comments on commit d69eed9

Please sign in to comment.