-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
액세스 토큰 유효성 검증 API 작성 완료
- Loading branch information
Showing
5 changed files
with
101 additions
and
10 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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/munecting/api/domain/user/dto/response/ValidateTokenResponseDto.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.munecting.api.domain.user.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ValidateTokenResponseDto( | ||
boolean isValid | ||
) { | ||
|
||
public static ValidateTokenResponseDto of(boolean isValid) { | ||
return ValidateTokenResponseDto.builder() | ||
.isValid(isValid) | ||
.build(); | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/test/java/com/munecting/api/domain/user/service/AuthServiceTest.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,46 @@ | ||
package com.munecting.api.domain.user.service; | ||
|
||
import com.munecting.api.domain.user.dto.response.ValidateTokenResponseDto; | ||
import com.munecting.api.global.auth.jwt.JwtProvider; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class AuthServiceTest { | ||
|
||
@Autowired | ||
private AuthService authService; | ||
|
||
@Autowired | ||
private JwtProvider jwtProvider; | ||
|
||
@DisplayName("주어진 액세스 토큰이 유효하면 true를 반환한다.") | ||
@Test | ||
public void validateAccessToken(){ | ||
//given | ||
String accessToken = "Bearer " + jwtProvider.getIssueToken(1L, true); | ||
|
||
//when | ||
ValidateTokenResponseDto response = authService.validateAccessToken(accessToken); | ||
|
||
//then | ||
Assertions.assertThat(response.isValid()).isTrue(); | ||
} | ||
|
||
@DisplayName("주어진 액세스 토큰이 유효하지 않으면 false를 반환한다.") | ||
@Test | ||
public void validateAccessToken_WithInValidToken(){ | ||
//given | ||
String accessToken = "Bearer notVaild.아무값이나 넣었어.sdfhsodjf"; | ||
|
||
//when | ||
ValidateTokenResponseDto response = authService.validateAccessToken(accessToken); | ||
|
||
//then | ||
Assertions.assertThat(response.isValid()).isFalse(); | ||
} | ||
|
||
} |