diff --git a/src/main/java/com/backend/blooming/exception/GlobalExceptionHandler.java b/src/main/java/com/backend/blooming/exception/GlobalExceptionHandler.java index 3ff0b32e..032ae857 100644 --- a/src/main/java/com/backend/blooming/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/backend/blooming/exception/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package com.backend.blooming.exception; +import com.backend.blooming.authentication.application.exception.AlreadyRegisterBlackListTokenException; import com.backend.blooming.authentication.infrastructure.exception.InvalidTokenException; import com.backend.blooming.authentication.infrastructure.exception.OAuthException; import com.backend.blooming.authentication.infrastructure.exception.UnsupportedOAuthTypeException; @@ -170,4 +171,14 @@ public ResponseEntity handleDeleteFriendForbiddenException( return ResponseEntity.status(HttpStatus.FORBIDDEN) .body(new ExceptionResponse(exception.getMessage())); } + + @ExceptionHandler(AlreadyRegisterBlackListTokenException.class) + public ResponseEntity handleAlreadyRegisterBlackListTokenException( + final AlreadyRegisterBlackListTokenException exception + ) { + logger.warn(String.format(LOG_MESSAGE_FORMAT, exception.getClass().getSimpleName(), exception.getMessage())); + + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(new ExceptionResponse(exception.getMessage())); + } } diff --git a/src/test/java/com/backend/blooming/authentication/presentation/AuthenticationControllerTest.java b/src/test/java/com/backend/blooming/authentication/presentation/AuthenticationControllerTest.java index 3c1b4c52..a59f9fd6 100644 --- a/src/test/java/com/backend/blooming/authentication/presentation/AuthenticationControllerTest.java +++ b/src/test/java/com/backend/blooming/authentication/presentation/AuthenticationControllerTest.java @@ -1,6 +1,7 @@ package com.backend.blooming.authentication.presentation; import com.backend.blooming.authentication.application.AuthenticationService; +import com.backend.blooming.authentication.application.exception.AlreadyRegisterBlackListTokenException; import com.backend.blooming.authentication.infrastructure.exception.InvalidTokenException; import com.backend.blooming.authentication.infrastructure.exception.OAuthException; import com.backend.blooming.authentication.infrastructure.jwt.TokenProvider; @@ -26,6 +27,7 @@ import static org.hamcrest.Matchers.is; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willDoNothing; +import static org.mockito.BDDMockito.willThrow; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; @@ -235,6 +237,26 @@ class AuthenticationControllerTest extends AuthenticationControllerTestFixture { ); } + @Test + void 로그아웃을_수행시_이미_로그인했다면_400_예외를_반환한다() throws Exception { + // given + given(tokenProvider.parseToken(TokenType.ACCESS, 소셜_액세스_토큰)).willReturn(사용자_토큰_정보); + given(userRepository.existsByIdAndDeletedIsFalse(사용자_아이디)).willReturn(true); + willThrow(new AlreadyRegisterBlackListTokenException()).given(authenticationService) + .logout(사용자_아이디, 로그아웃_정보_dto); + + // when & then + mockMvc.perform(post("/auth/logout") + .header("X-API-VERSION", 1) + .header(HttpHeaders.AUTHORIZATION, 소셜_액세스_토큰) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(로그아웃_정보_요청)) + ).andExpectAll( + status().isBadRequest(), + jsonPath("$.message").exists() + ).andDo(print()); + } + @Test void 탈퇴를_수행한다() throws Exception { // given