Skip to content

Commit

Permalink
Feature: (BRD-74) 인증필요/인가 실패 예외 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
ttasjwi committed Nov 17, 2024
1 parent 230ad52 commit fb9ad3b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ttasjwi.board.system.auth.domain.exception

import com.ttasjwi.board.system.core.exception.CustomException
import com.ttasjwi.board.system.core.exception.ErrorStatus

class AccessDeniedException(
cause: Throwable? = null,
) : CustomException(
status = ErrorStatus.FORBIDDEN,
code = "Error.AccessDenied",
args = emptyList(),
source = "credentials",
debugMessage = "리소스에 접근할 수 없습니다. 해당 리소스에 접근할 권한이 없습니다.",
cause = cause
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ttasjwi.board.system.auth.domain.exception

import com.ttasjwi.board.system.core.exception.CustomException
import com.ttasjwi.board.system.core.exception.ErrorStatus

class UnauthenticatedException(
cause: Throwable? = null,
) : CustomException(
status = ErrorStatus.UNAUTHENTICATED,
code = "Error.Unauthenticated",
args = emptyList(),
source = "credentials",
debugMessage = "리소스에 접근할 수 없습니다. 이 리소스에 접근하기 위해서는 인증이 필요합니다.",
cause = cause
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ttasjwi.board.system.auth.domain.exception

import com.ttasjwi.board.system.core.exception.ErrorStatus
import com.ttasjwi.board.system.core.exception.fixture.customExceptionFixture
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("AccessDeniedException: 인가 실패, 권한부족 상황에서 발생하는 예외")
class AccessDeniedExceptionTest {

@Test
@DisplayName("예외 기본값 테스트")
fun test1() {
val exception = AccessDeniedException()

assertThat(exception.status).isEqualTo(ErrorStatus.FORBIDDEN)
assertThat(exception.code).isEqualTo("Error.AccessDenied")
assertThat(exception.source).isEqualTo("credentials")
assertThat(exception.args).isEmpty()
assertThat(exception.message).isEqualTo(exception.debugMessage)
assertThat(exception.cause).isNull()
assertThat(exception.debugMessage).isEqualTo("리소스에 접근할 수 없습니다. 해당 리소스에 접근할 권한이 없습니다.")
}

@Test
@DisplayName("근원 예외를 전달하여 생성할 수 있다.")
fun test2() {
val cause = customExceptionFixture()
val exception = AccessDeniedException(cause)

assertThat(exception.status).isEqualTo(ErrorStatus.FORBIDDEN)
assertThat(exception.code).isEqualTo("Error.AccessDenied")
assertThat(exception.source).isEqualTo("credentials")
assertThat(exception.args).isEmpty()
assertThat(exception.message).isEqualTo(exception.debugMessage)
assertThat(exception.cause).isEqualTo(cause)
assertThat(exception.debugMessage).isEqualTo("리소스에 접근할 수 없습니다. 해당 리소스에 접근할 권한이 없습니다.")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ttasjwi.board.system.auth.domain.exception

import com.ttasjwi.board.system.core.exception.ErrorStatus
import com.ttasjwi.board.system.core.exception.fixture.customExceptionFixture
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("UnauthenticatedException: 인증이 필요할 때 발생하는 예외")
class UnauthenticatedExceptionTest {

@Test
@DisplayName("예외 기본값 테스트")
fun test1() {
val exception = UnauthenticatedException()

assertThat(exception.status).isEqualTo(ErrorStatus.UNAUTHENTICATED)
assertThat(exception.code).isEqualTo("Error.Unauthenticated")
assertThat(exception.source).isEqualTo("credentials")
assertThat(exception.args).isEmpty()
assertThat(exception.message).isEqualTo(exception.debugMessage)
assertThat(exception.cause).isNull()
assertThat(exception.debugMessage).isEqualTo("리소스에 접근할 수 없습니다. 이 리소스에 접근하기 위해서는 인증이 필요합니다.")
}

@Test
@DisplayName("근원 예외를 전달하여 생성할 수 있다.")
fun test2() {
val cause = customExceptionFixture()
val exception = UnauthenticatedException(cause)

assertThat(exception.status).isEqualTo(ErrorStatus.UNAUTHENTICATED)
assertThat(exception.code).isEqualTo("Error.Unauthenticated")
assertThat(exception.source).isEqualTo("credentials")
assertThat(exception.args).isEmpty()
assertThat(exception.message).isEqualTo(exception.debugMessage)
assertThat(exception.cause).isEqualTo(cause)
assertThat(exception.debugMessage).isEqualTo("리소스에 접근할 수 없습니다. 이 리소스에 접근하기 위해서는 인증이 필요합니다.")
}
}

0 comments on commit fb9ad3b

Please sign in to comment.