Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Forked from joegaudet/gist:1635191
Created January 18, 2012 20:28
Show Gist options
  • Save rossabaker/1635340 to your computer and use it in GitHub Desktop.
Save rossabaker/1635340 to your computer and use it in GitHub Desktop.
import org.scalatra._
import org.scalatra.test.scalatest._
import org.scalatest._
import org.scalatest.matchers._
class MatygoAuthenticationTest extends WordSpec with ScalatraSuite with ShouldMatchers {
trait MatygoAuthentication extends ScalatraFilter with CookieSupport {
def setCookie(cookieString: String, expiry: Int) = {
println("Setting cookie");
try {
cookies.update("MatygoSession", cookieString)(CookieOptions(maxAge = expiry, path = "/"))
}
catch {
case e => e.printStackTrace()
}
cookieString
println("Cookie String: " + cookieString);
cookieString
}
}
class MockController extends ScalatraFilter with CookieSupport with MatygoAuthentication {
get("/login") {
println("Hello hello")
setCookie("Foo", 60)
println(cookies("MatygoSession"))
}
}
"The MatygoAuthentication trait" when {
addFilter(new MockController, "/*")
"setting the session string" should {
"have a cookieString value" in {
session {
get("/login", "userId" -> "Fred") {
val cookie = response.getHeader("Set-Cookie")
println(cookie)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment