Skip to content

Commit 6ec2ab1

Browse files
authored
feat: 소셜 로그인 사용자는 비밀번호 변경을 할 수 없다. (#582)
* feat: 소셜 로그인 사용자는 비밀번호 변경을 할 수 없도록 * test: 소셜 로그인 사용자 비밀번호 변경 관련 테스트 코드 작성 * chore: 컨벤션에 맞게 메서드명 변경 - ~~ 예외가 발생한다 * chore: 충돌 해결
1 parent 48ebb9e commit 6ec2ab1

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/main/java/com/example/solidconnection/common/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public enum ErrorCode {
6767
PASSWORD_NOT_CHANGED(HttpStatus.BAD_REQUEST.value(), "현재 비밀번호와 새 비밀번호가 동일합니다."),
6868
PASSWORD_NOT_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "새 비밀번호가 일치하지 않습니다."),
6969
SIGN_IN_FAILED(HttpStatus.UNAUTHORIZED.value(), "로그인에 실패했습니다. 이메일과 비밀번호를 확인해주세요."),
70+
OAUTH_USER_CANNOT_CHANGE_PASSWORD(HttpStatus.BAD_REQUEST.value(), "소셜 로그인 사용자는 비밀번호를 변경할 수 없습니다."),
7071

7172
// s3
7273
S3_SERVICE_EXCEPTION(HttpStatus.BAD_REQUEST.value(), "S3 서비스 에러 발생"),

src/main/java/com/example/solidconnection/siteuser/service/MyPageService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.example.solidconnection.common.exception.ErrorCode.CAN_NOT_CHANGE_NICKNAME_YET;
44
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND;
55
import static com.example.solidconnection.common.exception.ErrorCode.NICKNAME_ALREADY_EXISTED;
6+
import static com.example.solidconnection.common.exception.ErrorCode.OAUTH_USER_CANNOT_CHANGE_PASSWORD;
67
import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_MISMATCH;
78
import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_NOT_FOUND;
89
import static com.example.solidconnection.common.exception.ErrorCode.USER_NOT_FOUND;
@@ -16,6 +17,7 @@
1617
import com.example.solidconnection.s3.domain.ImgType;
1718
import com.example.solidconnection.s3.dto.UploadedFileUrlResponse;
1819
import com.example.solidconnection.s3.service.S3Service;
20+
import com.example.solidconnection.siteuser.domain.AuthType;
1921
import com.example.solidconnection.siteuser.domain.Role;
2022
import com.example.solidconnection.siteuser.domain.SiteUser;
2123
import com.example.solidconnection.siteuser.dto.LocationUpdateRequest;
@@ -126,6 +128,10 @@ public void updatePassword(long siteUserId, PasswordUpdateRequest request) {
126128
SiteUser user = siteUserRepository.findById(siteUserId)
127129
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
128130

131+
if (!AuthType.isEmail(user.getAuthType())) {
132+
throw new CustomException(OAUTH_USER_CANNOT_CHANGE_PASSWORD);
133+
}
134+
129135
// 사용자의 비밀번호와 request의 currentPassword가 동일한지 검증
130136
validatePasswordMatch(request.currentPassword(), user.getPassword());
131137

src/main/resources/secret

src/test/java/com/example/solidconnection/siteuser/service/MyPageServiceTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.solidconnection.siteuser.service;
22

33
import static com.example.solidconnection.common.exception.ErrorCode.CAN_NOT_CHANGE_NICKNAME_YET;
4+
import static com.example.solidconnection.common.exception.ErrorCode.OAUTH_USER_CANNOT_CHANGE_PASSWORD;
45
import static com.example.solidconnection.common.exception.ErrorCode.PASSWORD_MISMATCH;
56
import static com.example.solidconnection.siteuser.service.MyPageService.MIN_DAYS_BETWEEN_NICKNAME_CHANGES;
67
import static com.example.solidconnection.siteuser.service.MyPageService.NICKNAME_LAST_CHANGE_DATE_FORMAT;
@@ -49,6 +50,8 @@
4950
import org.junit.jupiter.api.DisplayName;
5051
import org.junit.jupiter.api.Nested;
5152
import org.junit.jupiter.api.Test;
53+
import org.junit.jupiter.params.ParameterizedTest;
54+
import org.junit.jupiter.params.provider.EnumSource;
5255
import org.springframework.beans.factory.annotation.Autowired;
5356
import org.springframework.boot.test.mock.mockito.MockBean;
5457
import org.springframework.mock.web.MockMultipartFile;
@@ -328,6 +331,27 @@ void setUp() {
328331
.isInstanceOf(CustomException.class)
329332
.hasMessage(PASSWORD_MISMATCH.getMessage());
330333
}
334+
335+
@ParameterizedTest
336+
@EnumSource(value = AuthType.class, names = {"KAKAO", "APPLE"})
337+
void 소셜_로그인_사용자가_비밀번호를_변경하면_예외가_발생한다(AuthType authType) {
338+
// given
339+
SiteUser oauthUser = siteUserFixtureBuilder.siteUser()
340+
.email("oauth@example.com")
341+
.authType(authType)
342+
.nickname("소셜로그인사용자")
343+
.profileImageUrl("profileImageUrl")
344+
.role(Role.MENTEE)
345+
.password("randomPassword")
346+
.create();
347+
348+
PasswordUpdateRequest request = new PasswordUpdateRequest("anyPassword", "newPassword", "newPassword");
349+
350+
// when & then
351+
assertThatThrownBy(() -> myPageService.updatePassword(oauthUser.getId(), request))
352+
.isInstanceOf(CustomException.class)
353+
.hasMessage(OAUTH_USER_CANNOT_CHANGE_PASSWORD.getMessage());
354+
}
331355
}
332356

333357
@Nested

0 commit comments

Comments
 (0)