Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/kotlin/com/yapp2app/auth/api/dto/AuthRequest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yapp2app.auth.api.dto

import com.yapp2app.user.domain.enums.ProviderType
import jakarta.validation.constraints.NotBlank

/**
Expand All @@ -11,6 +10,4 @@ import jakarta.validation.constraints.NotBlank
*/
data class CreateAuthRequest(@field:NotBlank(message = "ID 토큰은 필수 입니다") val idToken: String)

data class LoginRequest(val oid: Long, val providerType: ProviderType)

data class RefreshTokenRequest(@field:NotBlank(message = "Refresh 토큰은 필수입니다") val refreshToken: String)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yapp2app.auth.application.command

import com.yapp2app.user.domain.enums.ProviderType

/**
* fileName : AuthCommand
* author : darren
Expand All @@ -10,6 +8,4 @@ import com.yapp2app.user.domain.enums.ProviderType
*/
data class RegisterKakaoUserCommand(val idToken: String)

data class LoginCommand(val oid: Long, val providerType: ProviderType)

data class RefreshTokenCommand(val refreshToken: String)
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class ExceptionHandler {
fun businessExceptionHandler(ex: BusinessException): ResponseEntity<ExceptionMsg> {
log.error("{} message = {}", ex.resultCode.code, ex.resultCode.message)

if (ex.resultCode == ResultCode.INVALID_TOKEN_ERROR) {
return ResponseEntity(
ExceptionMsg(
resultCode = ex.resultCode.code,
message = ex.resultCode.message,
success = false,
errors = emptyList(),
),
HttpStatus.FORBIDDEN,
)
}

val temp = ResponseEntity(
ExceptionMsg(
resultCode = ex.resultCode.code,
Expand Down
90 changes: 0 additions & 90 deletions src/test/kotlin/com/yapp2app/e2e/auth/AuthE2ETest.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.yapp2app.e2e.auth

import com.yapp2app.auth.api.dto.LoginRequest
import com.yapp2app.auth.api.dto.RefreshTokenRequest
import com.yapp2app.common.api.dto.ResultCode
import com.yapp2app.e2e.E2ETestBase
import com.yapp2app.user.domain.entity.User
import com.yapp2app.user.domain.enums.ProviderType
import io.restassured.RestAssured
import io.restassured.http.ContentType
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.notNullValue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -45,93 +42,6 @@ class AuthE2ETest : E2ETestBase() {
accessToken = token
}

@Test
@DisplayName("유효한 사용자 정보로 로그인 요청 시 성공 응답과 토큰을 반환한다")
fun givenValidCredentials_whenLogin_thenReturnsSuccessWithTokens() {
val request = LoginRequest(
oid = testUser.oid,
providerType = testUser.providerType,
)

val response = RestAssured.given()
.contentType(ContentType.JSON)
.body(request)
.`when`()
.post("/api/auth/login")
.then()
.statusCode(HttpStatus.OK.value())
.body("success", equalTo(true))
.body("resultCode", equalTo(ResultCode.SUCCESS.code))
.body("data.accessToken", notNullValue())
.body("data.refreshToken", notNullValue())
.extract()
.response()

val accessToken = response.jsonPath().getString("data.accessToken")
val refreshToken = response.jsonPath().getString("data.refreshToken")

println("========================================")
println("🔑 Access Token: $accessToken")
println("🔄 Refresh Token: $refreshToken")
println("========================================")
}

@Test
@DisplayName("존재하지 않는 사용자로 로그인 요청 시 400 에러를 반환한다")
fun givenNonExistentUser_whenLogin_thenReturnsNotFoundError() {
val request = LoginRequest(
oid = 99999L,
providerType = ProviderType.TEST,
)

RestAssured.given()
.contentType(ContentType.JSON)
.body(request)
.`when`()
.post("/api/auth/login")
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("success", equalTo(false))
.body("resultCode", equalTo(ResultCode.NOT_FOUND_USER.code))
}

@Test
@DisplayName("유효한 Refresh Token으로 토큰 갱신 요청 시 새로운 토큰을 반환한다")
fun givenValidRefreshToken_whenRefresh_thenReturnsNewTokens() {
// 먼저 로그인하여 토큰 획득
val loginRequest = LoginRequest(
oid = testUser.oid,
providerType = testUser.providerType,
)

val loginResponse = RestAssured.given()
.contentType(ContentType.JSON)
.body(loginRequest)
.`when`()
.post("/api/auth/login")
.then()
.statusCode(HttpStatus.OK.value())
.extract()
.jsonPath()

val refreshToken = loginResponse.getString("data.refreshToken")

// Refresh Token으로 토큰 갱신
val refreshRequest = RefreshTokenRequest(refreshToken = refreshToken)

RestAssured.given()
.contentType(ContentType.JSON)
.body(refreshRequest)
.`when`()
.post("/api/auth/refresh")
.then()
.statusCode(HttpStatus.OK.value())
.body("success", equalTo(true))
.body("resultCode", equalTo(ResultCode.SUCCESS.code))
.body("data.accessToken", notNullValue())
.body("data.refreshToken", notNullValue())
}

@Test
@DisplayName("유효하지 않은 Refresh Token으로 토큰 갱신 요청 시 400 에러를 반환한다")
fun givenInvalidRefreshToken_whenRefresh_thenReturnsInvalidTokenError() {
Expand Down