Skip to content

Commit

Permalink
[BE] 액세스 토큰 존재 여부를 반환한다. (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
JINU-CHANG authored and tkdgur0906 committed Oct 15, 2024
1 parent 774d2ba commit 3f873fa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.bang_ggood.auth.dto.request.OauthLoginRequest;
import com.bang_ggood.auth.dto.request.RegisterRequestV1;
import com.bang_ggood.auth.dto.response.AuthTokenResponse;
import com.bang_ggood.auth.dto.response.RefreshTokenCheckResponse;
import com.bang_ggood.auth.dto.response.TokenExistResponse;
import com.bang_ggood.auth.service.AuthService;
import com.bang_ggood.user.domain.User;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -93,12 +93,13 @@ public ResponseEntity<Void> reissueAccessToken(HttpServletRequest httpServletReq
.build();
}

@GetMapping("/refreshToken-check")
public ResponseEntity<RefreshTokenCheckResponse> check(HttpServletRequest httpServletRequest) {
@GetMapping("/token-exist")
public ResponseEntity<TokenExistResponse> check(HttpServletRequest httpServletRequest) {
boolean isAccessTokenExist = !cookieResolver.isAccessTokenEmpty(httpServletRequest);
boolean isRefreshTokenExist = !cookieResolver.isRefreshTokenEmpty(httpServletRequest);

RefreshTokenCheckResponse refreshTokenCheckResponse = RefreshTokenCheckResponse.from(isRefreshTokenExist);
return ResponseEntity.ok(refreshTokenCheckResponse);
TokenExistResponse tokenExistResponse = TokenExistResponse.from(isAccessTokenExist, isRefreshTokenExist);
return ResponseEntity.ok(tokenExistResponse);
}

@DeleteMapping("/token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void checkLoginRequired(HttpServletRequest request) {
}
}

private boolean isAccessTokenEmpty(HttpServletRequest request) {
public boolean isAccessTokenEmpty(HttpServletRequest request) {
return isTokenEmpty(request, CookieProvider.ACCESS_TOKEN_COOKIE_NAME);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bang_ggood.auth.dto.response;

public record TokenExistResponse(boolean isAccessTokenExist, boolean isRefreshTokenExist) {

public static TokenExistResponse from(boolean isAccessTokenExist, boolean isRefreshTokenExist) {
return new TokenExistResponse(isAccessTokenExist, isRefreshTokenExist);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bang_ggood.auth.controller;

import com.bang_ggood.AcceptanceTest;
import com.bang_ggood.auth.dto.response.RefreshTokenCheckResponse;
import com.bang_ggood.auth.dto.response.TokenExistResponse;
import com.bang_ggood.auth.service.AuthService;
import com.bang_ggood.global.exception.ExceptionCode;
import io.restassured.RestAssured;
Expand Down Expand Up @@ -97,32 +97,33 @@ void authentication_invalid_cookie_exception() {
.body("message", containsString(ExceptionCode.AUTHENTICATION_TOKEN_EMPTY.getMessage()));
}

@DisplayName("리프레시 토큰 체크 성공 : 쿠키가 존재하지 않는 경우")
@DisplayName("토큰 존재여부 반환 성공 : 쿠키가 존재하지 않는 경우")
@Test
void checkRefreshToken_returnFalse() {
RefreshTokenCheckResponse refreshTokenCheckResponse = RestAssured.given().log().all()
void checkTokenExist_returnFalse() {
TokenExistResponse tokenExistResponse = RestAssured.given().log().all()
.contentType(ContentType.JSON)
.when().get("/refreshToken-check")
.when().get("/token-exist")
.then().log().all()
.statusCode(200)
.extract()
.as(RefreshTokenCheckResponse.class);
.as(TokenExistResponse.class);

Assertions.assertThat(refreshTokenCheckResponse.isRefreshTokenExist()).isFalse();
Assertions.assertThat(tokenExistResponse.isRefreshTokenExist()).isFalse();
}

@DisplayName("리프레시 토큰 체크 성공 : 리프레시 토큰이 존재하는 경우")
@DisplayName("토큰 존재여부 반환 성공 : 액세스 토큰이 존재하고 리프레시 토큰이 존재하는 경우")
@Test
void checkRefreshToken_returnTrue() {
RefreshTokenCheckResponse refreshTokenCheckResponse = RestAssured.given().log().all()
void checkTokenExist_AccessTokenExist_RefreshTokenExist() {
TokenExistResponse tokenExistResponse = RestAssured.given().log().all()
.contentType(ContentType.JSON)
.headers(this.headers)
.when().get("/refreshToken-check")
.when().get("/token-exist")
.then().log().all()
.statusCode(200)
.extract()
.as(RefreshTokenCheckResponse.class);
.as(TokenExistResponse.class);

Assertions.assertThat(refreshTokenCheckResponse.isRefreshTokenExist()).isTrue();
Assertions.assertThat(tokenExistResponse.isAccessTokenExist()).isTrue();
Assertions.assertThat(tokenExistResponse.isRefreshTokenExist()).isTrue();
}
}

0 comments on commit 3f873fa

Please sign in to comment.