-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 테스트 구동 시 인증 설정 관련 빈 주입 오류 해결 (#694)
- Loading branch information
Showing
10 changed files
with
77 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 2 additions & 27 deletions
29
backend/src/main/java/com/zzang/chongdae/auth/service/AuthClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,6 @@ | ||
package com.zzang.chongdae.auth.service; | ||
|
||
import com.zzang.chongdae.auth.exception.KakaoLoginExceptionHandler; | ||
import com.zzang.chongdae.auth.service.dto.KakaoLoginResponseDto; | ||
import com.zzang.chongdae.member.domain.AuthProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.client.RestClient; | ||
public interface AuthClient { | ||
|
||
@RequiredArgsConstructor | ||
public class AuthClient { | ||
|
||
private static final String BEARER_HEADER_FORMAT = "Bearer %s"; | ||
private static final String GET_KAKAO_USER_INFO_URI = "https://kapi.kakao.com/v2/user/me"; | ||
|
||
private final RestClient restClient; | ||
|
||
public String getKakaoUserInfo(String accessToken) { | ||
KakaoLoginResponseDto responseDto = restClient.get() | ||
.uri(GET_KAKAO_USER_INFO_URI) | ||
.header(HttpHeaders.AUTHORIZATION, createAuthorization(accessToken)) | ||
.retrieve() | ||
.onStatus(new KakaoLoginExceptionHandler()) | ||
.body(KakaoLoginResponseDto.class); | ||
return AuthProvider.KAKAO.buildLoginId(responseDto.id().toString()); // TODO: NPE 처리 고려하기 | ||
} | ||
|
||
private String createAuthorization(String accessToken) { | ||
return BEARER_HEADER_FORMAT.formatted(accessToken); | ||
} | ||
String getUserInfo(String accessToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../chongdae/auth/service/DevAuthClient.java → ...ae/auth/service/client/DevAuthClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/com/zzang/chongdae/auth/service/client/ProdAuthClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.zzang.chongdae.auth.service.client; | ||
|
||
import com.zzang.chongdae.auth.exception.KakaoLoginExceptionHandler; | ||
import com.zzang.chongdae.auth.service.AuthClient; | ||
import com.zzang.chongdae.auth.service.dto.KakaoLoginResponseDto; | ||
import com.zzang.chongdae.member.domain.AuthProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.client.RestClient; | ||
|
||
@RequiredArgsConstructor | ||
public class ProdAuthClient implements AuthClient { | ||
|
||
private static final String BEARER_HEADER_FORMAT = "Bearer %s"; | ||
private static final String GET_KAKAO_USER_INFO_URI = "https://kapi.kakao.com/v2/user/me"; | ||
|
||
private final RestClient restClient; | ||
|
||
@Override | ||
public String getUserInfo(String accessToken) { | ||
return getKakaoUserInfo(accessToken); | ||
} | ||
|
||
protected String getKakaoUserInfo(String accessToken) { | ||
KakaoLoginResponseDto responseDto = restClient.get() | ||
.uri(GET_KAKAO_USER_INFO_URI) | ||
.header(HttpHeaders.AUTHORIZATION, createAuthorization(accessToken)) | ||
.retrieve() | ||
.onStatus(new KakaoLoginExceptionHandler()) | ||
.body(KakaoLoginResponseDto.class); | ||
return AuthProvider.KAKAO.buildLoginId(responseDto.id().toString()); // TODO: NPE 처리 고려하기 | ||
} | ||
|
||
private String createAuthorization(String accessToken) { | ||
return BEARER_HEADER_FORMAT.formatted(accessToken); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/test/java/com/zzang/chongdae/auth/config/TestAuthClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.zzang.chongdae.auth.config; | ||
|
||
import com.zzang.chongdae.auth.service.AuthClient; | ||
import com.zzang.chongdae.auth.service.StubAuthClient; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@TestConfiguration | ||
public class TestAuthClientConfig { | ||
|
||
@Bean | ||
AuthClient testAuthConfig() { | ||
return new StubAuthClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
backend/src/test/java/com/zzang/chongdae/auth/service/StubAuthClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.zzang.chongdae.auth.service; | ||
|
||
public class StubAuthClient implements AuthClient { | ||
|
||
@Override | ||
public String getUserInfo(String accessToken) { | ||
return "stubUserInfo"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters