diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-19 12:32:18 -0500 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2016-12-19 12:32:18 -0500 |
commit | 8515d672a9fdbb0eb9038a96cee661828cafa61a (patch) | |
tree | 3f04b773de6cea3def3566d2ca4bdff9b78ace8b /src/test/scala/com/drivergrp/core/AuthTest.scala | |
parent | 1702e1c44c45e36e2d6d289ef1b7d703f65ec422 (diff) | |
parent | 861ceb03e8faeb564dd027b13250b5604af8645f (diff) | |
download | driver-core-8515d672a9fdbb0eb9038a96cee661828cafa61a.tar.gz driver-core-8515d672a9fdbb0eb9038a96cee661828cafa61a.tar.bz2 driver-core-8515d672a9fdbb0eb9038a96cee661828cafa61a.zip |
Merge branch 'master' into implicit-companions
Diffstat (limited to 'src/test/scala/com/drivergrp/core/AuthTest.scala')
-rw-r--r-- | src/test/scala/com/drivergrp/core/AuthTest.scala | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/test/scala/com/drivergrp/core/AuthTest.scala b/src/test/scala/com/drivergrp/core/AuthTest.scala deleted file mode 100644 index 42f9155..0000000 --- a/src/test/scala/com/drivergrp/core/AuthTest.scala +++ /dev/null @@ -1,77 +0,0 @@ -package com.drivergrp.core - -import com.drivergrp.core.auth._ -import akka.http.scaladsl.testkit.ScalatestRouteTest -import akka.http.scaladsl.server._ -import Directives._ -import akka.http.scaladsl.model.headers.{HttpChallenges, RawHeader} -import akka.http.scaladsl.server.AuthenticationFailedRejection.CredentialsRejected -import org.scalatest.mock.MockitoSugar -import org.scalatest.{FlatSpec, Matchers} - -import scala.concurrent.Future -import scalaz.OptionT - -class AuthTest extends FlatSpec with Matchers with MockitoSugar with ScalatestRouteTest { - - val authStatusService: AuthService[User] = new AuthService[User] { - override def authStatus(authToken: AuthToken): OptionT[Future, User] = OptionT.optionT[Future] { - Future.successful(Some(new User() { - override def id: Id[User] = Id[User](1L) - override def roles: Set[Role] = Set(PathologistRole) - })) - } - } - - import authStatusService._ - - "'authorize' directive" should "throw error is auth token is not in the request" in { - - Get("/naive/attempt") ~> - authorize(CanSignOutReport) { - case (authToken, user) => - 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 { - - val referenceAuthToken = AuthToken(Base64("I am a pathologist's token")) - - Post("/administration/attempt").addHeader( - RawHeader(AuthService.AuthenticationTokenHeader, referenceAuthToken.value.value) - ) ~> - authorize(CanAssignRoles) { - case (authToken, user) => - complete("Never going to get here") - } ~> - check { - handled shouldBe false - rejections should contain( - AuthenticationFailedRejection( - CredentialsRejected, - HttpChallenges.basic("User does not have the required permission CanAssignRoles"))) - } - } - - it should "pass and retrieve the token to client code, if token is in request and user has permission" in { - - val referenceAuthToken = AuthToken(Base64("I am token")) - - Get("/valid/attempt/?a=2&b=5").addHeader( - RawHeader(AuthService.AuthenticationTokenHeader, referenceAuthToken.value.value) - ) ~> - authorize(CanSignOutReport) { - case (authToken, user) => - complete("Alright, \"" + authToken.value.value + "\" is handled") - } ~> - check { - handled shouldBe true - responseAs[String] shouldBe "Alright, \"I am token\" is handled" - } - } -} |