-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...h/src/main/kotlin/com/ttasjwi/board/system/auth/domain/exception/AccessDeniedException.kt
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
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 | ||
) |
15 changes: 15 additions & 0 deletions
15
...rc/main/kotlin/com/ttasjwi/board/system/auth/domain/exception/UnauthenticatedException.kt
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
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 | ||
) |
40 changes: 40 additions & 0 deletions
40
...c/test/kotlin/com/ttasjwi/board/system/auth/domain/exception/AccessDeniedExceptionTest.kt
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
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("리소스에 접근할 수 없습니다. 해당 리소스에 접근할 권한이 없습니다.") | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...est/kotlin/com/ttasjwi/board/system/auth/domain/exception/UnauthenticatedExceptionTest.kt
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
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("리소스에 접근할 수 없습니다. 이 리소스에 접근하기 위해서는 인증이 필요합니다.") | ||
} | ||
} |