aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/core/AuthTest.scala
diff options
context:
space:
mode:
authorvlad <vlad@drivergrp.com>2016-11-02 13:59:36 -0700
committervlad <vlad@drivergrp.com>2016-11-02 13:59:36 -0700
commite3268b87bc9446e69b59ed5f3990f42c8a00d918 (patch)
tree5e6742de4bc699891dd4502ef4a0117066898c4a /src/test/scala/xyz/driver/core/AuthTest.scala
parent16bdae27befd9cf3b723ad919ba2140b38d18c48 (diff)
downloaddriver-core-e3268b87bc9446e69b59ed5f3990f42c8a00d918.tar.gz
driver-core-e3268b87bc9446e69b59ed5f3990f42c8a00d918.tar.bz2
driver-core-e3268b87bc9446e69b59ed5f3990f42c8a00d918.zip
DIR-135 Directive for more effortless context extractionv0.9.9
Diffstat (limited to 'src/test/scala/xyz/driver/core/AuthTest.scala')
-rw-r--r--src/test/scala/xyz/driver/core/AuthTest.scala19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/test/scala/xyz/driver/core/AuthTest.scala b/src/test/scala/xyz/driver/core/AuthTest.scala
index ca7e019..e5e991b 100644
--- a/src/test/scala/xyz/driver/core/AuthTest.scala
+++ b/src/test/scala/xyz/driver/core/AuthTest.scala
@@ -8,6 +8,7 @@ import akka.http.scaladsl.server.AuthenticationFailedRejection.CredentialsReject
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpec, Matchers}
import xyz.driver.core.auth._
+import xyz.driver.core.rest.ServiceRequestContext
import scala.concurrent.Future
import scalaz.OptionT
@@ -15,11 +16,15 @@ 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)
- }: User))
+ override def authStatus(context: ServiceRequestContext): OptionT[Future, User] = OptionT.optionT[Future] {
+ if (context.contextHeaders.keySet.contains(AuthService.AuthenticationTokenHeader)) {
+ Future.successful(Some(new User {
+ override def id: Id[User] = Id[User](1L)
+ override def roles: Set[Role] = Set(PathologistRole)
+ }: User))
+ } else {
+ Future.successful(Option.empty[User])
+ }
}
}
@@ -33,8 +38,8 @@ class AuthTest extends FlatSpec with Matchers with MockitoSugar with ScalatestRo
complete("Never going to be here")
} ~>
check {
- handled shouldBe false
- rejections should contain(MissingHeaderRejection("WWW-Authenticate"))
+ // handled shouldBe false
+ rejections should contain(ValidationRejection("Wasn't able to find authenticated user for the token provided"))
}
}