generated from pricelees/issue-pr-template
test: CookieUtils 테스트 추가
This commit is contained in:
parent
0180440a2f
commit
bf3111723b
63
src/test/java/roomescape/auth/web/support/CookieUtilsTest.kt
Normal file
63
src/test/java/roomescape/auth/web/support/CookieUtilsTest.kt
Normal file
@ -0,0 +1,63 @@
|
||||
package roomescape.auth.web.support
|
||||
|
||||
import io.kotest.assertions.assertSoftly
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import jakarta.servlet.http.Cookie
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import roomescape.auth.web.TokenResponse
|
||||
|
||||
class CookieUtilsTest : FunSpec({
|
||||
context("HttpServletRequest에서 accessToken 쿠키를 가져온다.") {
|
||||
val httpServletRequest: HttpServletRequest = mockk()
|
||||
|
||||
test("accessToken이 있으면 해당 쿠키를 반환한다.") {
|
||||
val token = "test-token"
|
||||
val cookie = Cookie(ACCESS_TOKEN_COOKIE_NAME, token)
|
||||
every { httpServletRequest.cookies } returns arrayOf(cookie)
|
||||
|
||||
assertSoftly(httpServletRequest.accessTokenCookie()) {
|
||||
this.name shouldBe ACCESS_TOKEN_COOKIE_NAME
|
||||
this.value shouldBe token
|
||||
}
|
||||
}
|
||||
|
||||
test("accessToken이 없으면 accessToken에 빈 값을 담은 쿠키를 반환한다.") {
|
||||
every { httpServletRequest.cookies } returns arrayOf()
|
||||
|
||||
assertSoftly(httpServletRequest.accessTokenCookie()) {
|
||||
this.name shouldBe ACCESS_TOKEN_COOKIE_NAME
|
||||
this.value shouldBe ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context("TokenResponse를 쿠키로 반환한다.") {
|
||||
val tokenResponse = TokenResponse("test-token")
|
||||
|
||||
val result: String = tokenResponse.toResponseCookie()
|
||||
|
||||
result.split("; ") shouldContainAll listOf(
|
||||
"accessToken=test-token",
|
||||
"HttpOnly",
|
||||
"Secure",
|
||||
"Path=/",
|
||||
"Max-Age=1800"
|
||||
)
|
||||
}
|
||||
|
||||
context("만료된 accessToken 쿠키를 반환한다.") {
|
||||
val result: String = expiredAccessTokenCookie()
|
||||
|
||||
result.split("; ") shouldContainAll listOf(
|
||||
"accessToken=",
|
||||
"HttpOnly",
|
||||
"Secure",
|
||||
"Path=/",
|
||||
"Max-Age=0"
|
||||
)
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user