-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/feat(#45)-heachi-domain-redis'…
… into feat(#45)-heachi-domain-redis
- Loading branch information
Showing
10 changed files
with
339 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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
16 changes: 16 additions & 0 deletions
16
heachi-core/auth-api/src/main/java/com/heachi/auth/api/service/jwt/JwtTokenDTO.java
This file contains 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,16 @@ | ||
package com.heachi.auth.api.service.jwt; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class JwtTokenDTO { | ||
private String accessToken; | ||
private String refreshToken; | ||
|
||
@Builder | ||
public JwtTokenDTO(String accessToken, String refreshToken) { | ||
this.accessToken = accessToken; | ||
this.refreshToken = refreshToken; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -255,4 +255,50 @@ void userSimpleInfoTestWhenInvalidToken() throws Exception { | |
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.resCode").value(400)); | ||
} | ||
|
||
@Test | ||
@DisplayName("로그아웃 실패 테스트 - 잘못된 토큰으로 요청시 예외 발생") | ||
void logoutTestWhenInvalidToken() throws Exception { | ||
String accessToken = "strangeToken"; | ||
String refreshToken = "strangeToken"; | ||
|
||
// when | ||
mockMvc.perform( | ||
get("/auth/logout") | ||
.header("Authorization", "Bearer " + accessToken + " " + refreshToken)) | ||
|
||
// then | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.resCode").value(400)); | ||
} | ||
|
||
@Test | ||
@DisplayName("로그아웃 성공 테스트") | ||
void logoutSuccessTest() throws Exception { | ||
// given | ||
User user = User.builder() | ||
.name("김민수") | ||
.role(UserRole.USER) | ||
.email("[email protected]") | ||
.profileImageUrl("https://google.com") | ||
.build(); | ||
User savedUser = userRepository.save(user); | ||
|
||
HashMap<String, String> map = new HashMap<>(); | ||
map.put("role", savedUser.getRole().name()); | ||
map.put("name", savedUser.getName()); | ||
map.put("profileImageUrl", savedUser.getProfileImageUrl()); | ||
String accessToken = jwtService.generateAccessToken(map, savedUser); | ||
String refreshToken = jwtService.generateRefreshToken(map, savedUser); | ||
|
||
|
||
// when | ||
mockMvc.perform(get("/auth/logout") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", "Bearer " + accessToken + " " + refreshToken)) | ||
// then | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.resCode").value(200)) | ||
.andExpect(jsonPath("$.resObj").value("Logout successfully.")); | ||
} | ||
} |
Oops, something went wrong.