From fe5f625db2ccec3de4fd9e529f51c91923ef5089 Mon Sep 17 00:00:00 2001 From: jjongwa Date: Tue, 14 Nov 2023 09:40:37 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20RedisRepository=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=9C=20=EB=A1=9C=EC=A7=81=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/hanglog/login/LoginArgumentResolver.java | 3 +-- .../domain/repository/RefreshTokenRepository.java | 5 ----- .../main/java/hanglog/login/service/LoginService.java | 2 +- .../presentation/CommunityControllerTest.java | 2 +- .../community/presentation/LikeControllerTest.java | 2 +- .../integration/controller/DayLogIntegrationTest.java | 4 +++- .../login/presentation/LoginControllerTest.java | 4 ++-- .../member/controller/MemberControllerTest.java | 2 +- .../trip/presentation/DayLogControllerTest.java | 2 +- .../hanglog/trip/presentation/ItemControllerTest.java | 2 +- .../hanglog/trip/presentation/TripControllerTest.java | 10 +++++----- 11 files changed, 17 insertions(+), 21 deletions(-) diff --git a/backend/src/main/java/hanglog/login/LoginArgumentResolver.java b/backend/src/main/java/hanglog/login/LoginArgumentResolver.java index f9cd84c1a..0fdec17fa 100644 --- a/backend/src/main/java/hanglog/login/LoginArgumentResolver.java +++ b/backend/src/main/java/hanglog/login/LoginArgumentResolver.java @@ -77,8 +77,7 @@ private String extractRefreshToken(final Cookie... cookies) { } private boolean isValidRefreshToken(final Cookie cookie) { - // TODO: refreshToken 만료 기한 검사 필요 return REFRESH_TOKEN.equals(cookie.getName()) && - refreshTokenRepository.existsByToken(cookie.getValue()); + refreshTokenRepository.existsById(cookie.getValue()); } } diff --git a/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java b/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java index 4c278cc1d..d444e1375 100644 --- a/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java +++ b/backend/src/main/java/hanglog/login/domain/repository/RefreshTokenRepository.java @@ -1,12 +1,7 @@ package hanglog.login.domain.repository; import hanglog.login.domain.RefreshToken; -import java.util.Optional; import org.springframework.data.repository.CrudRepository; public interface RefreshTokenRepository extends CrudRepository { - - Optional findByToken(final String token); - - boolean existsByToken(final String token); } diff --git a/backend/src/main/java/hanglog/login/service/LoginService.java b/backend/src/main/java/hanglog/login/service/LoginService.java index c9352dfb2..388108183 100644 --- a/backend/src/main/java/hanglog/login/service/LoginService.java +++ b/backend/src/main/java/hanglog/login/service/LoginService.java @@ -82,7 +82,7 @@ private String generateRandomFourDigitCode() { public String renewalAccessToken(final String refreshTokenRequest, final String authorizationHeader) { final String accessToken = bearerExtractor.extractAccessToken(authorizationHeader); if (jwtProvider.isValidRefreshAndInvalidAccess(refreshTokenRequest, accessToken)) { - final RefreshToken refreshToken = refreshTokenRepository.findByToken(refreshTokenRequest) + final RefreshToken refreshToken = refreshTokenRepository.findById(refreshTokenRequest) .orElseThrow(() -> new AuthException(INVALID_REFRESH_TOKEN)); return jwtProvider.regenerateAccessToken(refreshToken.getMemberId().toString()); } diff --git a/backend/src/test/java/hanglog/community/presentation/CommunityControllerTest.java b/backend/src/test/java/hanglog/community/presentation/CommunityControllerTest.java index 3984ef23c..0cfcdd22f 100644 --- a/backend/src/test/java/hanglog/community/presentation/CommunityControllerTest.java +++ b/backend/src/test/java/hanglog/community/presentation/CommunityControllerTest.java @@ -73,7 +73,7 @@ class CommunityControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); } diff --git a/backend/src/test/java/hanglog/community/presentation/LikeControllerTest.java b/backend/src/test/java/hanglog/community/presentation/LikeControllerTest.java index ffff8a020..ebec47aca 100644 --- a/backend/src/test/java/hanglog/community/presentation/LikeControllerTest.java +++ b/backend/src/test/java/hanglog/community/presentation/LikeControllerTest.java @@ -47,7 +47,7 @@ class LikeControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); } diff --git a/backend/src/test/java/hanglog/integration/controller/DayLogIntegrationTest.java b/backend/src/test/java/hanglog/integration/controller/DayLogIntegrationTest.java index d632f2e63..4de3f9d57 100644 --- a/backend/src/test/java/hanglog/integration/controller/DayLogIntegrationTest.java +++ b/backend/src/test/java/hanglog/integration/controller/DayLogIntegrationTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; -public class DayLogIntegrationTest extends IntegrationTest { +class DayLogIntegrationTest extends IntegrationTest { private Long tripId; private Long dayLogId; @@ -32,6 +32,8 @@ public class DayLogIntegrationTest extends IntegrationTest { void setUp() { final ExtractableResponse tripCreateResponse = TripIntegrationTest.requestCreateTrip(memberTokens, TRIP_CREATE_REQUEST); + System.out.println("tripCreateResponse = " + tripCreateResponse); + System.out.println("tripCreateResponse.header(\"Location\") = " + tripCreateResponse.header("Location")); tripId = Long.parseLong(parseUri(tripCreateResponse.header("Location"))); final ExtractableResponse tripGetResponse = TripIntegrationTest.requestGetTrip(memberTokens, tripId); diff --git a/backend/src/test/java/hanglog/login/presentation/LoginControllerTest.java b/backend/src/test/java/hanglog/login/presentation/LoginControllerTest.java index 16ccbb8c4..65ed9756b 100644 --- a/backend/src/test/java/hanglog/login/presentation/LoginControllerTest.java +++ b/backend/src/test/java/hanglog/login/presentation/LoginControllerTest.java @@ -158,7 +158,7 @@ void extendLogin() throws Exception { @Test void logout() throws Exception { // given - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(loginService).removeRefreshToken(anyString()); @@ -194,7 +194,7 @@ void logout() throws Exception { @Test void deleteAccount() throws Exception { // given - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(loginService).deleteAccount(anyLong()); diff --git a/backend/src/test/java/hanglog/member/controller/MemberControllerTest.java b/backend/src/test/java/hanglog/member/controller/MemberControllerTest.java index 53ea41a02..d1f14ce7c 100644 --- a/backend/src/test/java/hanglog/member/controller/MemberControllerTest.java +++ b/backend/src/test/java/hanglog/member/controller/MemberControllerTest.java @@ -55,7 +55,7 @@ class MemberControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); } diff --git a/backend/src/test/java/hanglog/trip/presentation/DayLogControllerTest.java b/backend/src/test/java/hanglog/trip/presentation/DayLogControllerTest.java index baec33add..e103e7bab 100644 --- a/backend/src/test/java/hanglog/trip/presentation/DayLogControllerTest.java +++ b/backend/src/test/java/hanglog/trip/presentation/DayLogControllerTest.java @@ -58,7 +58,7 @@ class DayLogControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong()); diff --git a/backend/src/test/java/hanglog/trip/presentation/ItemControllerTest.java b/backend/src/test/java/hanglog/trip/presentation/ItemControllerTest.java index 22b60e060..95b2dd51a 100644 --- a/backend/src/test/java/hanglog/trip/presentation/ItemControllerTest.java +++ b/backend/src/test/java/hanglog/trip/presentation/ItemControllerTest.java @@ -61,7 +61,7 @@ class ItemControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong()); diff --git a/backend/src/test/java/hanglog/trip/presentation/TripControllerTest.java b/backend/src/test/java/hanglog/trip/presentation/TripControllerTest.java index 2e119ab6e..ea3459772 100644 --- a/backend/src/test/java/hanglog/trip/presentation/TripControllerTest.java +++ b/backend/src/test/java/hanglog/trip/presentation/TripControllerTest.java @@ -89,7 +89,7 @@ class TripControllerTest extends ControllerTest { @BeforeEach void setUp() { - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); } @@ -740,7 +740,7 @@ void updateSharedStatus() throws Exception { final SharedCodeResponse sharedCodeResponse = new SharedCodeResponse("sharedCode"); when(tripService.updateSharedTripStatus(anyLong(), any(SharedStatusRequest.class))) .thenReturn(sharedCodeResponse); - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong()); @@ -783,7 +783,7 @@ void getSharedTrip_NullSharedStatus() throws Exception { final SharedCodeResponse sharedCodeResponse = new SharedCodeResponse("xxxxxx"); when(tripService.updateSharedTripStatus(anyLong(), any(SharedStatusRequest.class))) .thenReturn(sharedCodeResponse); - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong()); @@ -803,7 +803,7 @@ void getSharedTrip_NullSharedStatus() throws Exception { void updatePublishedStatus() throws Exception { // given final PublishedStatusRequest publishedStatusRequest = new PublishedStatusRequest(true); - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong()); @@ -834,7 +834,7 @@ void updatePublishedStatus() throws Exception { @Test void getLedger() throws Exception { // given - given(refreshTokenRepository.existsByToken(any())).willReturn(true); + given(refreshTokenRepository.existsById(any())).willReturn(true); doNothing().when(jwtProvider).validateTokens(any()); given(jwtProvider.getSubject(any())).willReturn("1"); doNothing().when(tripService).validateTripByMember(anyLong(), anyLong());