Conversation
| @SpringBootTest | ||
| class JwtTokenProviderTest : BehaviorSpec() { |
There was a problem hiding this comment.
저는 kotest를 이용해서 테스트코드를 작성해봤습니다!
실제로 많이 쓰이는 라이브러리이고 Kotlin을 활용한 자연스러운 DSL을 제공해서 좋은 거 같아요. 혹시 제가 임의로 넣긴 했지만 수정님은 어떠신가요??
There was a problem hiding this comment.
저도 kotest를 사용해 본 경험이 있는데, 정말 유용한 라이브러리라고 생각합니다! 말씀해주신 코틀린의 DSL을 활용해서 가독성 높은 테스트 코드를 작성할 수 있다는 점에서 장점을 지닌다고 느꼈어요.
특히 kotest의 should나 expect 같은 직관적인 구문, 다양한 Matcher와 함께 제공되는 Assertion 기능 덕분에 테스트 의도를 간결하고 명확히 표현할 수 있어서 좋더라고요.
저도 테스트코드 작성에서 kotest를 활용하는 데 찬성합니다 😄
chock-cho
left a comment
There was a problem hiding this comment.
전반적으로 인증/인가 로직에 대한 기본적인 방향을 잘 작성해주신 것 같습니다!
몇 가지 자잘한 피드백 코멘트 드렸으니, 의견 함께 나누어보고 머지하면 좋을 것 같습니다
| @SpringBootTest | ||
| class JwtTokenProviderTest : BehaviorSpec() { |
There was a problem hiding this comment.
저도 kotest를 사용해 본 경험이 있는데, 정말 유용한 라이브러리라고 생각합니다! 말씀해주신 코틀린의 DSL을 활용해서 가독성 높은 테스트 코드를 작성할 수 있다는 점에서 장점을 지닌다고 느꼈어요.
특히 kotest의 should나 expect 같은 직관적인 구문, 다양한 Matcher와 함께 제공되는 Assertion 기능 덕분에 테스트 의도를 간결하고 명확히 표현할 수 있어서 좋더라고요.
저도 테스트코드 작성에서 kotest를 활용하는 데 찬성합니다 😄
There was a problem hiding this comment.
현재 generateAccessToken과 generateRefreshToken이 유사한 구조를 지니고 있어서, 공통 로직을 추출하는 방향으로 가면 코드의 가독성이 조금 더 개선될 수 있지 않을까 싶습니다!
fun generateAccessToken(authentication: Authentication): String {
return generateToken(
tokenType = ACCESS_TOKEN_TYPE_VALUE,
authentication = authentication,
expirationDate = generateAccessTokenExpiration()
)
}
fun generateRefreshToken(authentication: Authentication): String {
return generateToken(
tokenType = REFRESH_TOKEN_TYPE_VALUE,
authentication = authentication,
expirationDate = generateAccessTokenExpiration()
)
}
private fun generateToken(
tokenType: String,
authentication: Authentication,
expirationDate: Date
): String {
val authorities = authentication.authorities.joinToString(",") { it.authority }
return Jwts.builder()
.setHeader(mapOf(TOKEN_TYPE_HEADER_KEY to tokenType))
.setClaims(
mapOf(
USER_ID_CLAIM_KEY to authentication.name,
AUTHORITIES_CLAIM_KEY to authorities
)
)
.setExpiration(expirationDate)
.encryptWith(signKey, Jwts.ENC.A128CBC_HS256)
.compact()
}There was a problem hiding this comment.
확실히 공통 로직을 별도로 빼니까 가독성이 더 좋네요! 반영했습니다. 👍
There was a problem hiding this comment.
현재 단계에서 큰 틀에서 Test Code 너무 잘 작성해주신 것 같습니다!
핵심적인 기능(토큰 생성, 파싱, 예외처리)에 대한 검증이 잘 이루어졌고, 초기 단계에서 안정성을 충분하게 확보할 수 있을 것 같습니다.
MVP 목표 달성한 이후에, 발생할 수 있는 시나리오 생각하면서 Refresh Token 관련 로직, Expiration 처리, Signature 검증 같은 추가적인 Test Code 작성도 함께 고려해보면 좋을 것 같아요! 👍
* chore: add h2 dependency * chore: add yaml for test * chore: add security and jjwt dependency * feat: add Exception for Authentication * feat: add JwtTokenProvider * chore: add kotest dependency * chore: add access/refresh expriration variable * feat: add TokenGateway * feat: add Member model * refactor: add ApplicationConfig for application-wide settings * test: set up test environment configuration * test: add JwtTokenProvider's test code * refactor: change token property variable names in yaml * refact: refactor JWT token generation by extracting common logic
👋 개요
💻 작업사항