Skip to content

Commit

Permalink
feat: 이미 블랙 리스트에 등록된 토큰에 대한 예외 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ503 committed Feb 4, 2024
1 parent 0b506e6 commit 388e94c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -170,4 +171,14 @@ public ResponseEntity<ExceptionResponse> handleDeleteFriendForbiddenException(
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new ExceptionResponse(exception.getMessage()));
}

@ExceptionHandler(AlreadyRegisterBlackListTokenException.class)
public ResponseEntity<ExceptionResponse> 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()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 388e94c

Please sign in to comment.