diff options
Diffstat (limited to 'src/test/scala/com/drivergrp/core/AuthTest.scala')
-rw-r--r-- | src/test/scala/com/drivergrp/core/AuthTest.scala | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/test/scala/com/drivergrp/core/AuthTest.scala b/src/test/scala/com/drivergrp/core/AuthTest.scala index 7725a45..0e4841b 100644 --- a/src/test/scala/com/drivergrp/core/AuthTest.scala +++ b/src/test/scala/com/drivergrp/core/AuthTest.scala @@ -13,11 +13,13 @@ class AuthTest extends FlatSpec with Matchers with MockitoSugar with ScalatestRo "'authorize' directive" should "throw error is auth token is not in the request" in { Get("/naive/attempt") ~> - auth.directives.authorize(CanSignOutReport) { authToken => complete("Never going to be here") } ~> - check { - handled shouldBe false - rejections should contain (MissingHeaderRejection("WWW-Authenticate")) - } + auth.directives.authorize(CanSignOutReport) { authToken => + complete("Never going to be here") + } ~> + check { + handled shouldBe false + rejections should contain(MissingHeaderRejection("WWW-Authenticate")) + } } it should "throw error is authorized user is not having the requested permission" in { @@ -25,13 +27,15 @@ class AuthTest extends FlatSpec with Matchers with MockitoSugar with ScalatestRo val referenceAuthToken = AuthToken(Base64("I am a pathologist's token")) Post("/administration/attempt").addHeader( - RawHeader(auth.directives.AuthenticationTokenHeader, s"Macaroon ${referenceAuthToken.value.value}") + RawHeader(auth.directives.AuthenticationTokenHeader, s"Macaroon ${referenceAuthToken.value.value}") ) ~> - auth.directives.authorize(CanAssignRoles) { authToken => complete("Never going to get here") } ~> - check { - handled shouldBe false - rejections should contain (ValidationRejection("User does not have the required permission CanAssignRoles", None)) - } + auth.directives.authorize(CanAssignRoles) { authToken => + complete("Never going to get here") + } ~> + check { + handled shouldBe false + rejections should contain(ValidationRejection("User does not have the required permission CanAssignRoles", None)) + } } it should "pass and retrieve the token to client code, if token is in request and user has permission" in { @@ -39,14 +43,14 @@ class AuthTest extends FlatSpec with Matchers with MockitoSugar with ScalatestRo val referenceAuthToken = AuthToken(Base64("I am token")) Get("/valid/attempt/?a=2&b=5").addHeader( - RawHeader(auth.directives.AuthenticationTokenHeader, s"Macaroon ${referenceAuthToken.value.value}") + RawHeader(auth.directives.AuthenticationTokenHeader, s"Macaroon ${referenceAuthToken.value.value}") ) ~> - auth.directives.authorize(CanSignOutReport) { authToken => - complete("Alright, \"" + authToken.value.value + "\" is handled") - } ~> - check { - handled shouldBe true - responseAs[String] shouldBe "Alright, \"Macaroon I am token\" is handled" - } + auth.directives.authorize(CanSignOutReport) { authToken => + complete("Alright, \"" + authToken.value.value + "\" is handled") + } ~> + check { + handled shouldBe true + responseAs[String] shouldBe "Alright, \"Macaroon I am token\" is handled" + } } } |