From 8ad65e10b2f75f660167d46592ddbfefe1c63ece Mon Sep 17 00:00:00 2001 From: devxb Date: Fri, 8 Mar 2024 18:42:44 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"refactor:=20login=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A1=B0=ED=9A=8C=20api=EA=B0=80=20email?= =?UTF-8?q?=EC=9D=84=20=ED=95=A8=EA=BB=98=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=ED=95=9C=EB=8B=A4"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0c46c828bd6e67649406715ae6dfd3e6f6f21c4d. --- .../user/UserAcceptanceTestSupporter.java | 2 +- .../test/user/UserAcceptanceValidator.java | 5 ++-- .../LoginedTargetFindAcceptanceTest.java | 7 ++--- .../common/dto/CreateAuthTokenRequest.java | 1 - .../auth/application/common/dto/Payload.java | 1 - .../service/AuthTokenCreateService.java | 3 -- .../service/JwtLoginedDecryptService.java | 3 +- .../service/SignInWithOAuthService.java | 2 +- .../service/AuthTokenCreateServiceTest.java | 29 +++---------------- support/e2e/v1_13_get_logined_target.hurl | 29 ------------------- .../application/common/dto/LoginedInfo.java | 2 +- .../LoginedUserGetByTokenServiceTest.java | 2 +- .../logined/LoginedUserGetController.java | 4 +-- .../logined/response/LoginedInfoResponse.java | 9 ------ 14 files changed, 15 insertions(+), 84 deletions(-) delete mode 100644 support/e2e/v1_13_get_logined_target.hurl diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java index 0731091e..cf415cb7 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java @@ -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) ); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java index 56504b3b..bf074b3f 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java @@ -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) ); } diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java index f7271847..176f5d65 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java @@ -45,12 +45,9 @@ 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()); @@ -58,7 +55,7 @@ void GET_LOGINED_USER_SUCCESS() throws Exception { ResultActions resultActions = getLoginedUser("bearer " + token); // then - assertIsLogined(resultActions, targetId, nickname, email); + assertIsLogined(resultActions, targetId, nickname); } } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java index 8c116802..6c98c9d4 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java @@ -7,5 +7,4 @@ public class CreateAuthTokenRequest { private final String userId; private final String nickname; private final String targetId; - private final String email; } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java index d4b79de8..f6fff8d9 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java @@ -15,6 +15,5 @@ public enum Key { USER_ID, TARGET_ID, NICKNAME, - EMAIL, } } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java index ac85d748..29c7e6fd 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java @@ -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 = 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); diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java index 884703fe..8f79ead5 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java @@ -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 diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java index 2e80a394..70866829 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java @@ -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); } diff --git a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java index a2151483..eff30c90 100644 --- a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java +++ b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java @@ -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)); @@ -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)); @@ -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)); @@ -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); diff --git a/support/e2e/v1_13_get_logined_target.hurl b/support/e2e/v1_13_get_logined_target.hurl deleted file mode 100644 index 8407dce4..00000000 --- a/support/e2e/v1_13_get_logined_target.hurl +++ /dev/null @@ -1,29 +0,0 @@ -POST http://nalab-server:8080/v1/oauth/default # Default provider를 통해서 로그인 진행 -{ - "nickname": "devxb", - "email": "get_logined_target@naver.com" -} - -HTTP 200 -[Asserts] -header "Content-type" == "application/json" - -jsonpath "$.access_token" exists -jsonpath "$.token_type" exists - -[Captures] -token_type: jsonpath "$.token_type" -auth_token: jsonpath "$.access_token" - -####### - -GET http://nalab-server:8080/v1/users/logins # Token에 해당하는 유저 조회 -Authorization: {{ token_type }} {{ auth_token }} - -HTTP 200 -[Asserts] -header "Content-type" == "application/json" - -jsonpath "$.target_id" exists -jsonpath "$.nickname" == "devxb" -jsonpath "$.email" == "get_logined_target@naver.com" diff --git a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java index c71afb65..c636eec5 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java +++ b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java @@ -8,5 +8,5 @@ public class LoginedInfo { private final String nickName; private final Long targetId; private final Long userId; - private final String email; + } diff --git a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java index 02796247..35423160 100644 --- a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java +++ b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java @@ -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); diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java index dba5afa6..31b9dbfe 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java @@ -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()); } } diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java index 096dcf0f..7197cc1b 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java @@ -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 { @@ -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()); - } }