-
Notifications
You must be signed in to change notification settings - Fork 8
fix: 토큰 재발급 로직 수정 #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nayonsoso
merged 7 commits into
solid-connection:develop
from
nayonsoso:fix/258-reissue-logic
May 3, 2025
Merged
fix: 토큰 재발급 로직 수정 #289
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b23767c
refactor: 함수 분리
nayonsoso c9b545f
chore: 사용하지 않는 함수 삭제
nayonsoso abb3026
refactor: 가독성을 위해 함수 위치 변경
nayonsoso 71a7689
refactor: 재발급 로직 수정
nayonsoso 9beb32c
refactor: 리프레시 토큰 기간 연장
nayonsoso 699d9ab
refactor: 액세스 토큰 재발급 로직 수정
nayonsoso 0fb26cd
test: authServiceTest 작성
nayonsoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/solidconnection/auth/dto/ReissueRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.example.solidconnection.auth.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record ReissueRequest( | ||
| @NotBlank(message = "리프레시 토큰과 함께 요청해주세요.") | ||
| String refreshToken) { | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/test/java/com/example/solidconnection/auth/service/AuthServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package com.example.solidconnection.auth.service; | ||
|
|
||
| import com.example.solidconnection.auth.domain.TokenType; | ||
| import com.example.solidconnection.auth.dto.ReissueRequest; | ||
| import com.example.solidconnection.auth.dto.ReissueResponse; | ||
| import com.example.solidconnection.config.security.JwtProperties; | ||
| import com.example.solidconnection.custom.exception.CustomException; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.support.TestContainerSpringBootTest; | ||
| import com.example.solidconnection.type.PreparationStatus; | ||
| import com.example.solidconnection.type.Role; | ||
| import com.example.solidconnection.util.JwtUtils; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import static com.example.solidconnection.custom.exception.ErrorCode.REFRESH_TOKEN_EXPIRED; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
|
||
| @DisplayName("인증 서비스 테스트") | ||
| @TestContainerSpringBootTest | ||
| class AuthServiceTest { | ||
|
|
||
| @Autowired | ||
| private AuthService authService; | ||
|
|
||
| @Autowired | ||
| private AuthTokenProvider authTokenProvider; | ||
|
|
||
| @Autowired | ||
| private SiteUserRepository siteUserRepository; | ||
|
|
||
| @Autowired | ||
| private JwtProperties jwtProperties; | ||
|
|
||
| @Test | ||
| void 로그아웃한다() { | ||
| // given | ||
| String accessToken = "accessToken"; | ||
|
|
||
| // when | ||
| authService.signOut(accessToken); | ||
|
|
||
| // then | ||
| assertThat(authTokenProvider.findBlackListToken(accessToken)).isNotNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void 탈퇴한다() { | ||
| // given | ||
| SiteUser siteUser = createSiteUser(); | ||
|
|
||
| // when | ||
| authService.quit(siteUser); | ||
|
|
||
| // then | ||
| LocalDate tomorrow = LocalDate.now().plusDays(1); | ||
| assertThat(siteUser.getQuitedAt()).isEqualTo(tomorrow); | ||
| } | ||
|
|
||
| @Nested | ||
| class 토큰을_재발급한다 { | ||
|
|
||
| @Test | ||
| void 요청의_리프레시_토큰이_저장되어_있고_값이_일치면_액세스_토큰을_재발급한다() { | ||
| // given | ||
| SiteUser siteUser = createSiteUser(); | ||
| String refreshToken = authTokenProvider.generateAndSaveRefreshToken(siteUser); | ||
| ReissueRequest reissueRequest = new ReissueRequest(refreshToken); | ||
|
|
||
| // when | ||
| ReissueResponse reissuedAccessToken = authService.reissue(reissueRequest); | ||
|
|
||
| // then | ||
| String actualSubject = JwtUtils.parseSubject(reissuedAccessToken.accessToken(), jwtProperties.secret()); | ||
| String expectedSubject = JwtUtils.parseSubject(refreshToken, jwtProperties.secret()); | ||
| assertThat(actualSubject).isEqualTo(expectedSubject); | ||
| } | ||
|
|
||
| @Test | ||
| void 요청의_리프레시_토큰이_저장되어있지_않다면_예외_응답을_반환한다() { | ||
| // given | ||
| String refreshToken = authTokenProvider.generateToken("subject", TokenType.REFRESH); | ||
| ReissueRequest reissueRequest = new ReissueRequest(refreshToken); | ||
|
|
||
| // when, then | ||
| assertThatCode(() -> authService.reissue(reissueRequest)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(REFRESH_TOKEN_EXPIRED.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private SiteUser createSiteUser() { | ||
| SiteUser siteUser = new SiteUser( | ||
| "test@example.com", | ||
| "nickname", | ||
| "profileImageUrl", | ||
| PreparationStatus.CONSIDERING, | ||
| Role.MENTEE | ||
| ); | ||
| return siteUserRepository.save(siteUser); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사소하지만 ㅎㅎ.. 이 컨벤션이 늘 헷갈렸는데 제가 들어오기전 솔커 컨벤션에선 dto에서 어노테이션 쓸 때 한 칸 개행하고 썼더라구요! 나중에 개행한 거 다 없앨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 지금 어노테이션이 안붙어있는 값들은 개행이 안되어있고,
어노테이션이 붙어있는 것들만 시작 개행이 되어있는 상태군요 🫢
둘중에 어느것으로든 통일하면 좋겠는데.. 규혁님은 둘 다 개행 안한게 더 좋으신가요?
저는 둘 중 어느것으로 가도 큰 상관 없습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
읽는 측면에서 큰 차이는 없는 거 같아서 저도 큰 상관 없지만, 어노테이션 앞에 시작개행이 불필요한 빈 줄이라면 없애는 게 더 나은 거 같네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럼 시작 개행 안하도록 통일하는게 좋겠네요 ㅎㅎ