-
-
Save rossabaker/1635340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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