From 388e94cc05f05463b9abff982026cd0b80bfa087 Mon Sep 17 00:00:00 2001 From: JJ503 <63184334+JJ503@users.noreply.github.com> Date: Sun, 4 Feb 2024 19:48:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=97=90=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=EB=90=9C=20=ED=86=A0=ED=81=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 11 ++++++++++ .../AuthenticationControllerTest.java | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) 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