From 135c38f390da1a2faf983d9b2b2f0fea6a5e74b5 Mon Sep 17 00:00:00 2001 From: vlad Date: Fri, 9 Sep 2016 15:15:04 -0700 Subject: Scalacheck properties check inside of scalatest + code formatting --- src/test/scala/com/drivergrp/core/AuthTest.scala | 42 +++++++++++++----------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'src/test/scala/com/drivergrp/core/AuthTest.scala') 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" + } } } -- cgit v1.2.3