Skip to content

Commit

Permalink
fix: 추가된 디펜던시 삭제 및 주석처리
Browse files Browse the repository at this point in the history
  • Loading branch information
02ggang9 committed Feb 4, 2024
1 parent 57ae505 commit 81b435c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 79 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,4 @@ dependencies {
testImplementation("io.kotest:kotest-extensions-spring:${kotestVersion}")
testImplementation("io.mockk:mockk:1.13.4")
testImplementation("com.ninja-squad:springmockk:4.0.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,59 @@

class SignOutControllerTest extends IntegrationTest {

@Nested
@DisplayName("로그아웃 테스트")
class SignOut {
@Nested
@DisplayName("로그아웃 테스트")
class SignOut {

private Member member;
private Member member;

@BeforeEach
void setupMember() {
member = memberTestHelper.generate();
}

@Test
@DisplayName("유효한 요청이면 로그아웃이 성공해야 한다.")
void should_successfullySignOut_when_validRequest() throws Exception {
Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN.getTokenName(),
jwtTokenProvider.createAccessToken(ACCESS_TOKEN, member.getId(), ROLE_회원));
Cookie refreshTokenCookie = new Cookie(REFRESH_TOKEN.getTokenName(),
jwtTokenProvider.createAccessToken(REFRESH_TOKEN, member.getId(), ROLE_회원));
callSignOutApi(accessTokenCookie, refreshTokenCookie)
.andExpect(status().isNoContent())
.andExpect(cookie().maxAge(ACCESS_TOKEN.getTokenName(), 0))
.andExpect(cookie().maxAge(REFRESH_TOKEN.getTokenName(), 0))
.andDo(document("sign-out",
requestCookies(
cookieWithName(ACCESS_TOKEN.getTokenName()).description("ACCESS TOKEN"),
cookieWithName(REFRESH_TOKEN.getTokenName()).description("REFRESH TOKEN")
)));
@BeforeEach
void setupMember() {
member = memberTestHelper.generate();
}

assertThat(redisUtil.getData(String.valueOf(member.getId()), String.class)).isEmpty();
}
@Test
@DisplayName("유효한 요청이면 로그아웃이 성공해야 한다.")
void should_successfullySignOut_when_validRequest() throws Exception {
Cookie accessTokenCookie = new Cookie(ACCESS_TOKEN.getTokenName(),
jwtTokenProvider.createAccessToken(ACCESS_TOKEN, member.getId(), ROLE_회원));
Cookie refreshTokenCookie = new Cookie(REFRESH_TOKEN.getTokenName(),
jwtTokenProvider.createAccessToken(REFRESH_TOKEN, member.getId(), ROLE_회원));
callSignOutApi(accessTokenCookie, refreshTokenCookie)
.andExpect(status().isNoContent())
.andExpect(cookie().maxAge(ACCESS_TOKEN.getTokenName(), 0))
.andExpect(cookie().maxAge(REFRESH_TOKEN.getTokenName(), 0))
.andDo(document("sign-out",
requestCookies(
cookieWithName(ACCESS_TOKEN.getTokenName()).description("ACCESS TOKEN"),
cookieWithName(REFRESH_TOKEN.getTokenName()).description("REFRESH TOKEN")
)));

@Test
@Disabled
@DisplayName("RT도 AT도 만료되었으면 로그아웃시에 쿠키는 지워져야 한다")
void should_tokenDeleted_when_expiredTokens() throws Exception {
// PK: 0
// ROLE: 회원
// expired: 2023년 1월 25일
String expiredRefreshToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwIiwicm9sZXMiOiJST0xFX-2ajOybkCIsImlhdCI6MTY3NDYzMDk2MCwiZXhwIjoxNjc0NjMwOTYwfQ.qcAfEzhDulqsl6HCg8dziVlJoTPORpSUi5sjbCqTg_E";
Cookie expiredRefreshCookie = new Cookie(REFRESH_TOKEN.getTokenName(), expiredRefreshToken);
String expiredToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwicm9sZXMiOiJST0xFX-2ajOybkCIsImlhdCI6MTY3NDQ1MjM1NSwiZXhwIjoxNjc0NDUyMzU1fQ.FoRbgOGlzLwizp9jQNmM6pET4zA8TPXa56zZlsl6Al8";
Cookie expiredCookie = new Cookie(ACCESS_TOKEN.getTokenName(), expiredToken);
assertThat(redisUtil.getData(String.valueOf(member.getId()), String.class)).isEmpty();
}

callSignOutApi(expiredCookie, expiredRefreshCookie)
.andExpect(status().isUnauthorized())
.andExpect(cookie().maxAge(ACCESS_TOKEN.getTokenName(), 0))
.andExpect(cookie().maxAge(REFRESH_TOKEN.getTokenName(), 0));
}
// @Test
// @Disabled
// @DisplayName("RT도 AT도 만료되었으면 로그아웃시에 쿠키는 지워져야 한다")
// void should_tokenDeleted_when_expiredTokens() throws Exception {
// // PK: 0
// // ROLE: 회원
// // expired: 2023년 1월 25일
// String expiredRefreshToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwIiwicm9sZXMiOiJST0xFX-2ajOybkCIsImlhdCI6MTY3NDYzMDk2MCwiZXhwIjoxNjc0NjMwOTYwfQ.qcAfEzhDulqsl6HCg8dziVlJoTPORpSUi5sjbCqTg_E";
// Cookie expiredRefreshCookie = new Cookie(REFRESH_TOKEN.getTokenName(), expiredRefreshToken);
// String expiredToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwicm9sZXMiOiJST0xFX-2ajOybkCIsImlhdCI6MTY3NDQ1MjM1NSwiZXhwIjoxNjc0NDUyMzU1fQ.FoRbgOGlzLwizp9jQNmM6pET4zA8TPXa56zZlsl6Al8";
// Cookie expiredCookie = new Cookie(ACCESS_TOKEN.getTokenName(), expiredToken);
//
// callSignOutApi(expiredCookie, expiredRefreshCookie)
// .andExpect(status().isUnauthorized())
// .andExpect(cookie().maxAge(ACCESS_TOKEN.getTokenName(), 0))
// .andExpect(cookie().maxAge(REFRESH_TOKEN.getTokenName(), 0));
// }

@NotNull
private ResultActions callSignOutApi(Cookie accessTokenCookie, Cookie refreshTokenCookie) throws Exception {
return mockMvc.perform(post("/sign-out")
.cookie(accessTokenCookie, refreshTokenCookie));
@NotNull
private ResultActions callSignOutApi(Cookie accessTokenCookie, Cookie refreshTokenCookie) throws Exception {
return mockMvc.perform(post("/sign-out")
.cookie(accessTokenCookie, refreshTokenCookie));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,35 +183,34 @@ void setupRefreshToken() {
redisUtil.setDataExpire(JwtTokenProvider.getRefreshTokenKeyForRedis("0", null), refreshToken, REFRESH_TOKEN.getExpiredMillis());
}

@Test
@Disabled
@DisplayName("AT가 만료되었으면 200 OK를 응답한다.")
void should_200OK_when_accessTokenExpired() throws Exception {
JwtType MOCKED_ACCESS_TOKEN = Mockito.spy(ACCESS_TOKEN);
Mockito.doReturn(0L).when(MOCKED_ACCESS_TOKEN).getExpiredMillis();

String expiredAccessToken = jwtTokenProvider.createAccessToken(MOCKED_ACCESS_TOKEN, 0L, ROLE_회원);

Cookie expiredCookie = new Cookie(ACCESS_TOKEN.getTokenName(), expiredAccessToken);
expiredCookie.setHttpOnly(true);
assertThatThrownBy(() -> jwtTokenProvider.getAuthId(expiredAccessToken))
.isInstanceOf(ExpiredJwtException.class);

MvcResult result = callRefreshApi(refreshCookie, expiredCookie)
.andExpect(status().isOk())
.andReturn();

String newAccessToken = Objects.requireNonNull(
result.getResponse().getCookie(ACCESS_TOKEN.getTokenName()))
.getValue();
String newRefreshToken = Objects.requireNonNull(
result.getResponse().getCookie(REFRESH_TOKEN.getTokenName()))
.getValue();

jwtTokenProvider.getAuthId(newAccessToken);
assertThat(newRefreshToken).isNotEqualTo(refreshCookie.getValue());
assertThat(redisUtil.getData(JwtTokenProvider.getRefreshTokenKeyForRedis("0", null), String.class)).isNotEmpty();
}
// @Test
// @DisplayName("AT가 만료되었으면 200 OK를 응답한다.")
// void should_200OK_when_accessTokenExpired() throws Exception {
// JwtType MOCKED_ACCESS_TOKEN = Mockito.spy(ACCESS_TOKEN);
// Mockito.doReturn(0L).when(MOCKED_ACCESS_TOKEN).getExpiredMillis();
//
// String expiredAccessToken = jwtTokenProvider.createAccessToken(MOCKED_ACCESS_TOKEN, 0L, ROLE_회원);
//
// Cookie expiredCookie = new Cookie(ACCESS_TOKEN.getTokenName(), expiredAccessToken);
// expiredCookie.setHttpOnly(true);
// assertThatThrownBy(() -> jwtTokenProvider.getAuthId(expiredAccessToken))
// .isInstanceOf(ExpiredJwtException.class);
//
// MvcResult result = callRefreshApi(refreshCookie, expiredCookie)
// .andExpect(status().isOk())
// .andReturn();
//
// String newAccessToken = Objects.requireNonNull(
// result.getResponse().getCookie(ACCESS_TOKEN.getTokenName()))
// .getValue();
// String newRefreshToken = Objects.requireNonNull(
// result.getResponse().getCookie(REFRESH_TOKEN.getTokenName()))
// .getValue();
//
// jwtTokenProvider.getAuthId(newAccessToken);
// assertThat(newRefreshToken).isNotEqualTo(refreshCookie.getValue());
// assertThat(redisUtil.getData(JwtTokenProvider.getRefreshTokenKeyForRedis("0", null), String.class)).isNotEmpty();
// }

@Test
@DisplayName("AT도 있으면 200 OK를 응답한다.")
Expand Down

0 comments on commit 81b435c

Please sign in to comment.