Skip to content

Commit

Permalink
[TNT-84] feat: 소셜 로그인 요청 dto 검증 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
fakerdeft committed Jan 22, 2025
1 parent 9cb3725 commit 6a726a7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/main/java/com/tnt/dto/member/request/OAuthLoginRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ public record OAuthLoginRequest(
String idToken
) {

private static final String KAKAO = "KAKAO";
private static final String APPLE = "APPLE";

@AssertTrue(message = "카카오 로그인 시 소셜 액세스 토큰은 필수입니다.")
private boolean isValidKakaoLogin() {
if (KAKAO.equals(socialType)) {
public boolean validateKakaoLogin() {
if ("KAKAO".equals(socialType)) {
return socialAccessToken != null && !socialAccessToken.isBlank();
}

return true;
}

@AssertTrue(message = "애플 로그인 시 인가 코드 또는 ID 토큰 중 하나는 필수입니다.")
private boolean isValidAppleLogin() {
if (APPLE.equals(socialType)) {
public boolean validateAppleLogin() {
if ("APPLE".equals(socialType)) {
return (authorizationCode != null && !authorizationCode.isBlank()) || (idToken != null
&& !idToken.isBlank());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.tnt.presentation.member;

import static com.tnt.global.error.model.ErrorMessage.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.BDDMockito.*;
import static com.tnt.global.error.model.ErrorMessage.FAILED_TO_FETCH_USER_INFO;
import static com.tnt.global.error.model.ErrorMessage.MEMBER_NOT_FOUND;
import static com.tnt.global.error.model.ErrorMessage.UNSUPPORTED_SOCIAL_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.verify;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -117,4 +122,90 @@ void member_not_found_error() {
.isInstanceOf(NotFoundException.class)
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}

@Nested
@DisplayName("OAuthLoginRequest Validation 테스트")
class OAuthLoginRequestValidationTest {

@Test
@DisplayName("카카오 로그인 시 socialAccessToken이 없으면 실패")
void kakao_login_without_access_token_fail() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("KAKAO", "fcm-token", null, null, null);

// when & then
assertThat(request.validateKakaoLogin()).isFalse();
}

@Test
@DisplayName("카카오 로그인 시 socialAccessToken이 blank이면 실패")
void kakao_login_with_blank_access_token_fail() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("KAKAO", "fcm-token", " ", null, null);

// when & then
assertThat(request.validateKakaoLogin()).isFalse();
}

@Test
@DisplayName("카카오 로그인 시 socialAccessToken이 있으면 성공")
void kakao_login_with_access_token_success() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("KAKAO", "fcm-token", "valid-token", null, null);

// when & then
assertThat(request.validateKakaoLogin()).isTrue();
}

@Test
@DisplayName("애플 로그인 시 authorizationCode와 idToken이 모두 없으면 실패")
void apple_login_without_code_and_token_fail() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("APPLE", "fcm-token", null, null, null);

// when & then
assertThat(request.validateAppleLogin()).isFalse();
}

@Test
@DisplayName("애플 로그인 시 authorizationCode만 있어도 성공")
void apple_login_with_authorization_code_success() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("APPLE", "fcm-token", null, "valid-auth-code", null);

// when & then
assertThat(request.validateAppleLogin()).isTrue();
}

@Test
@DisplayName("애플 로그인 시 idToken만 있어도 성공")
void apple_login_with_id_token_success() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("APPLE", "fcm-token", null, null, "valid-id-token");

// when & then
assertThat(request.validateAppleLogin()).isTrue();
}

@Test
@DisplayName("애플 로그인 시 authorizationCode와 idToken이 모두 있어도 성공")
void apple_login_with_code_and_token_success() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("APPLE", "fcm-token", null, "valid-auth-code",
"valid-id-token");

// when & then
assertThat(request.validateAppleLogin()).isTrue();
}

@Test
@DisplayName("애플 로그인 시 blank 토큰은 실패")
void apple_login_with_blank_token_fail() {
// given
OAuthLoginRequest request = new OAuthLoginRequest("APPLE", "fcm-token", null, " ", " ");

// when & then
assertThat(request.validateAppleLogin()).isFalse();
}
}
}

0 comments on commit 6a726a7

Please sign in to comment.