Created
January 24, 2017 09:38
-
-
Save audax/ac07afbe225d0d6a04f57a9fa492bffb to your computer and use it in GitHub Desktop.
Test that proves that he InMemorySessionStorage crashes when given an invalid session
This file contains 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
package de.qabel.teqs.ktor.modules.auth | |
import org.jetbrains.ktor.application.* | |
import org.jetbrains.ktor.http.* | |
import org.jetbrains.ktor.response.* | |
import org.jetbrains.ktor.routing.* | |
import org.jetbrains.ktor.sessions.* | |
import org.jetbrains.ktor.testing.* | |
import org.jetbrains.ktor.tests.* | |
import org.junit.* | |
import kotlin.test.* | |
class ServerSessionTest { | |
@Test | |
fun testSessionById() { | |
val sessionStorage = inMemorySessionStorage() | |
withTestApplication { | |
application.withSessions<TestUserSession> { | |
withCookieBySessionId(sessionStorage) | |
} | |
application.routing { | |
get("/1") { | |
call.session(TestUserSession("id2", listOf("item1"))) | |
call.respondText("ok") | |
} | |
} | |
val call = handleRequest { | |
uri = "/1" | |
addHeader(HttpHeaders.Cookie, | |
"SESSION_ID=invalid") | |
} | |
val sessionId = call.response.cookies["SESSION_ID"]!!.value | |
val nextCall = handleRequest { | |
uri = "/1" | |
addHeader(HttpHeaders.Cookie, "SESSION_ID=$sessionId") | |
} | |
assertEquals(sessionId, nextCall.response.cookies["SESSION_ID"]!!.value) | |
} | |
} | |
data class TestUserSession(val userId: String, val cart: List<String>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment