Skip to content

Commit

Permalink
refactor: RedisRepository를 통한 로직으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jjongwa committed Nov 14, 2023
1 parent 83c107c commit fe5f625
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<RefreshToken, String> {

Optional<RefreshToken> findByToken(final String token);

boolean existsByToken(final String token);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +32,8 @@ public class DayLogIntegrationTest extends IntegrationTest {
void setUp() {
final ExtractableResponse<Response> 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<Response> tripGetResponse = TripIntegrationTest.requestGetTrip(memberTokens, tripId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit fe5f625

Please sign in to comment.