aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/com/drivergrp/core/AuthTest.scala
diff options
context:
space:
mode:
authorvlad <vlad@drivergrp.com>2016-10-03 14:25:24 -0700
committervlad <vlad@drivergrp.com>2016-10-03 14:25:24 -0700
commit94c324e249ab3e5848191602c3549cef350e83b1 (patch)
tree01ef6a4da7d3638e160fd2d25b4c621c3b793fe0 /src/test/scala/com/drivergrp/core/AuthTest.scala
parentd53f8227eea53871b08829909760b9e37e22a817 (diff)
downloaddriver-core-94c324e249ab3e5848191602c3549cef350e83b1.tar.gz
driver-core-94c324e249ab3e5848191602c3549cef350e83b1.tar.bz2
driver-core-94c324e249ab3e5848191602c3549cef350e83b1.zip
Auth service providing directive and using external source of token-to-user resolutionv0.9.0
Diffstat (limited to 'src/test/scala/com/drivergrp/core/AuthTest.scala')
-rw-r--r--src/test/scala/com/drivergrp/core/AuthTest.scala35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/test/scala/com/drivergrp/core/AuthTest.scala b/src/test/scala/com/drivergrp/core/AuthTest.scala
index 992ae83..42f9155 100644
--- a/src/test/scala/com/drivergrp/core/AuthTest.scala
+++ b/src/test/scala/com/drivergrp/core/AuthTest.scala
@@ -9,13 +9,28 @@ import akka.http.scaladsl.server.AuthenticationFailedRejection.CredentialsReject
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") ~>
- auth.directives.authorize(CanSignOutReport) { authToken =>
- complete("Never going to be here")
+ authorize(CanSignOutReport) {
+ case (authToken, user) =>
+ complete("Never going to be here")
} ~>
check {
handled shouldBe false
@@ -28,10 +43,11 @@ 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(AuthService.AuthenticationTokenHeader, referenceAuthToken.value.value)
) ~>
- auth.directives.authorize(CanAssignRoles) { authToken =>
- complete("Never going to get here")
+ authorize(CanAssignRoles) {
+ case (authToken, user) =>
+ complete("Never going to get here")
} ~>
check {
handled shouldBe false
@@ -47,14 +63,15 @@ 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(AuthService.AuthenticationTokenHeader, referenceAuthToken.value.value)
) ~>
- auth.directives.authorize(CanSignOutReport) { authToken =>
- complete("Alright, \"" + authToken.value.value + "\" is handled")
+ authorize(CanSignOutReport) {
+ case (authToken, user) =>
+ complete("Alright, \"" + authToken.value.value + "\" is handled")
} ~>
check {
handled shouldBe true
- responseAs[String] shouldBe "Alright, \"Macaroon I am token\" is handled"
+ responseAs[String] shouldBe "Alright, \"I am token\" is handled"
}
}
}