Skip to content

Commit

Permalink
Revert "refactor: login된 유저 조회 api가 email을 함께 반환하도록 수정한다"
Browse files Browse the repository at this point in the history
This reverts commit 0c46c82.
  • Loading branch information
devxb committed Mar 8, 2024
1 parent 0c46c82 commit 8ad65e1
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UserAcceptanceTestSupporter {

protected ResultActions getLoginedUser(String token) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders
.get(API_VERSION + "/users/logins")
.get(API_VERSION + "/users/logined")
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, token)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

public class UserAcceptanceValidator {

public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname, String email) throws Exception {
public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname) throws Exception {
resultActions.andExpectAll(
status().isOk(),
jsonPath("$.target_id").value(targetId),
jsonPath("$.nickname").value(nickname),
jsonPath("$.email").value(email)
jsonPath("$.nickname").value(nickname)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,17 @@ class LoginedTargetFindAcceptanceTest extends UserAcceptanceTestSupporter {
void GET_LOGINED_USER_SUCCESS() throws Exception {
// given
String nickname = "devxb";
String email = "email";
Long targetId = targetInitializer.saveTargetAndGetId(nickname, Instant.now());
String token = jwtUtils.createAccessToken(Set.of(new Payload(Payload.Key.NICKNAME, nickname),
new Payload(Payload.Key.USER_ID, 12345 + ""),
new Payload(Payload.Key.TARGET_ID, targetId + ""),
new Payload(Payload.Key.EMAIL, email)));
new Payload(Payload.Key.USER_ID, 12345 + ""), new Payload(Payload.Key.TARGET_ID, targetId + "")));
applicationEventPublisher.publishEvent(
MockUserRegisterEvent.builder().expectedToken("bearer " + token).expectedId(targetId).build());

// when
ResultActions resultActions = getLoginedUser("bearer " + token);

// then
assertIsLogined(resultActions, targetId, nickname, email);
assertIsLogined(resultActions, targetId, nickname);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public class CreateAuthTokenRequest {
private final String userId;
private final String nickname;
private final String targetId;
private final String email;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public enum Key {
USER_ID,
TARGET_ID,
NICKNAME,
EMAIL,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ public AuthToken create(CreateAuthTokenRequest request) {
var userId = request.getUserId();
var nickname = request.getNickname();
var targetId = request.getTargetId();
var email = request.getEmail();
Assert.isTrue(userId != null && !userId.isBlank(), "Authentication token 생성 시 유저 식별자는 필수입니다.");
Assert.isTrue(nickname != null && !nickname.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다.");
Assert.isTrue(targetId != null && !targetId.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다.");
Assert.isTrue(email != null && !email.isBlank(), "Authentication token 생성 시 유저의 이메일은 필수입니다.");

Set<Payload> payload = new HashSet<>();
payload.add(new Payload(Payload.Key.USER_ID, userId));
payload.add(new Payload(Payload.Key.NICKNAME, nickname));
payload.add(new Payload(Payload.Key.TARGET_ID, targetId));
payload.add(new Payload(Payload.Key.EMAIL, email));

String token = createToken(payload);
return new AuthToken(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public LoginedInfo decryptToken(String encryptedToken) {
String nickName = decodedJWT.getClaim(Payload.Key.NICKNAME.name()).asString();
Long userId = Long.valueOf(decodedJWT.getClaim(Payload.Key.USER_ID.name()).asString());
Long targetId = Long.valueOf(decodedJWT.getClaim(Payload.Key.TARGET_ID.name()).asString());
String email = decodedJWT.getClaim(Payload.Key.EMAIL.name()).asString();
return new LoginedInfo(nickName, targetId, userId, email);
return new LoginedInfo(nickName, targetId, userId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AuthToken signInWithOAuth(SignInWithOAuthRequest request) {
var userId = foundUser.orElseThrow(IllegalAccessError::new);
var targetId = targetFindByUsernameUseCase.findTargetByUsername(request.getUsername()).orElseThrow().getId();

var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), request.getUsername(), String.valueOf(targetId), email);
var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), request.getUsername(), String.valueOf(targetId));

return authTokenCreateUseCase.create(authTokenCreateRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void THROW_EXCEPTION_WHEN_USER_ID_IS_BLANK(String userId) {
// given
var nickname = "nickname";
var targetId = "targetId";
var email = "email";
var request = new CreateAuthTokenRequest(userId, nickname, targetId, email);
var request = new CreateAuthTokenRequest(userId, nickname, targetId);

// when
var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request));
Expand All @@ -50,8 +49,7 @@ void THROW_EXCEPTION_WHEN_NICKNAME_IS_BLANK(String nickname) {
// given
var userId = "userId";
var targetId = "targetId";
var email = "email";
var request = new CreateAuthTokenRequest(userId, nickname, targetId, email);
var request = new CreateAuthTokenRequest(userId, nickname, targetId);

// when
var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request));
Expand All @@ -67,25 +65,7 @@ void THROW_EXCEPTION_WHEN_TARGET_ID_IS_BLANK(String targetId) {
// given
var userId = "userId";
var nickname = "nickname";
var email = "email";
var request = new CreateAuthTokenRequest(userId, nickname, targetId, email);

// when
var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request));

// then
Assertions.assertThat(throwable).isInstanceOf(IllegalArgumentException.class);
}

@ParameterizedTest
@NullAndEmptySource
@DisplayName("이메일이 비어있거나 null이면 예외를 발생시킨다.")
void THROW_EXCEPTION_WHEN_EMAIL_IS_BLANK(String email) {
// given
var userId = "userId";
var targetId = "targetId";
var nickname = "nickname";
var request = new CreateAuthTokenRequest(userId, nickname, targetId, email);
var request = new CreateAuthTokenRequest(userId, nickname, targetId);

// when
var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request));
Expand All @@ -101,8 +81,7 @@ void RETURN_TOKEN_WHEN_VALID_REQUEST() {
var userId = "userId";
var nickname = "nickname";
var targetId = "targetId";
var email = "email";
var request = new CreateAuthTokenRequest(userId, nickname, targetId, email);
var request = new CreateAuthTokenRequest(userId, nickname, targetId);
var expectedToken = "token";

when(jwtUtils.createAccessToken(any())).thenReturn(expectedToken);
Expand Down
29 changes: 0 additions & 29 deletions support/e2e/v1_13_get_logined_target.hurl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class LoginedInfo {
private final String nickName;
private final Long targetId;
private final Long userId;
private final String email;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LoginedUserGetByTokenServiceTest {
@DisplayName("토큰을 이용해 로그인된 유저의 정보를 조회 성공 테스트")
void GET_LOGINED_INFO_BY_TOKEN_SUCCESS() {
// given
LoginedInfo expected = new LoginedInfo("hello", 12345L, 54321L, "email");
LoginedInfo expected = new LoginedInfo("hello", 12345L, 54321L);
String token = "hello token";

Mockito.when(loginedUserGetByTokenPort.decryptToken(token.split(" ")[1])).thenReturn(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class LoginedUserGetController {

private final LoginedUserGetByTokenUseCase loginedUserGetByTokenUseCase;

@GetMapping("/users/logins")
@GetMapping("/users/logined")
public LoginedInfoResponse getLoginedUserByToken(@RequestHeader(HttpHeaders.AUTHORIZATION) String token) {
LoginedInfo loginedInfo = loginedUserGetByTokenUseCase.decryptToken(token);

return LoginedInfoResponse.of(loginedInfo);
return new LoginedInfoResponse(String.valueOf(loginedInfo.getTargetId()), loginedInfo.getNickName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;
import me.nalab.user.application.common.dto.LoginedInfo;

@Data
public class LoginedInfoResponse {
Expand All @@ -12,13 +11,5 @@ public class LoginedInfoResponse {
private final String targetId;
@JsonProperty("nickname")
private final String nickName;
@JsonProperty("email")
private final String email;

public static LoginedInfoResponse of(LoginedInfo loginedInfo) {
return new LoginedInfoResponse(String.valueOf(loginedInfo.getTargetId()),
loginedInfo.getNickName(),
loginedInfo.getEmail());
}

}

0 comments on commit 8ad65e1

Please sign in to comment.