Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.RequiredArgsConstructor;
import org.runimo.runimo.auth.exceptions.SignUpException;
import org.runimo.runimo.auth.jwt.JwtTokenFactory;
import org.runimo.runimo.auth.service.TokenRefreshService;
import org.runimo.runimo.auth.service.dto.TokenPair;
import org.runimo.runimo.rewards.service.eggs.EggGrantService;
import org.runimo.runimo.user.domain.Gender;
import org.runimo.runimo.user.domain.User;
Expand All @@ -25,13 +27,16 @@ public class TestAuthService {
private final UserCreator userCreator;
private final UserItemCreator userItemCreator;
private final EggGrantService eggGrantService;
private final TokenRefreshService tokenRefreshService;


@Transactional
public TestAuthResponse login(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> SignUpException.of(UserHttpResponseCode.LOGIN_FAIL_NOT_SIGN_IN));
return new TestAuthResponse(jwtTokenFactory.generateTokenPair(user));
TokenPair pair = jwtTokenFactory.generateTokenPair(user);
tokenRefreshService.putRefreshToken(user.getPublicId(), pair.refreshToken());
return new TestAuthResponse(pair);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.runimo.runimo.auth.service;
package org.runimo.runimo.auth.controller;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;

import com.auth0.jwt.interfaces.DecodedJWT;
Expand All @@ -15,6 +16,7 @@
import org.runimo.runimo.auth.jwt.JwtTokenFactory;
import org.runimo.runimo.auth.service.apple.KakaoUserInfo;
import org.runimo.runimo.auth.service.kakao.KakaoTokenVerifier;
import org.runimo.runimo.auth.test.TestAuthRequest;
import org.runimo.runimo.user.UserFixtures;
import org.runimo.runimo.user.domain.OAuthInfo;
import org.runimo.runimo.user.domain.SocialProvider;
Expand Down Expand Up @@ -139,4 +141,28 @@ void setup() {

}

@Test
void 테스트_로그인_후_리프레쉬_성공() throws JsonProcessingException {
TestAuthRequest request = new TestAuthRequest(1L);
String refreshToken = given()
.contentType("application/json")
.body(objectMapper.writeValueAsString(request))
.when()
.post("/api/v1/auth/test/login")
.then()
.statusCode(HttpStatus.OK.value())
.extract()
.path("payload.tokens.refresh_token");

given()
.header("Authorization", "Bearer " + refreshToken)
.when()
.post("/api/v1/auth/refresh")
.then()
.log().all()
.statusCode(HttpStatus.OK.value())
.body("payload.access_token", notNullValue())
.body("payload.refresh_token", notNullValue());
}

}