Skip to content

Commit

Permalink
Refactor | CAKK-81 | External 모듈, Client 모듈 통합
Browse files Browse the repository at this point in the history
* Refactor | CAKK-81 | external 모듈에 client 이관

* Refactor | CAKK-81 | client 모듈 제거 및 의존성 수정

* Refactor | CAKK-81 | Vo 관련 패키지 수정

* Test | CAKK-81 | 테스트 코드 non-null 이슈 해결
  • Loading branch information
lcomment authored Sep 13, 2024
1 parent f2aa133 commit 23d2974
Show file tree
Hide file tree
Showing 45 changed files with 147 additions and 161 deletions.
1 change: 0 additions & 1 deletion cakk-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencies {
implementation(project(":cakk-common"))
implementation(project(":cakk-domain:mysql"))
implementation(project(":cakk-domain:redis"))
implementation(project(":cakk-client"))
implementation(project(":cakk-external"))
implementation(project(":cakk-core"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.cakk.common.response.ApiResponse;
import com.cakk.external.service.S3Service;
import com.cakk.external.vo.PresignedUrl;
import com.cakk.external.vo.s3.PresignedUrl;

@RestController
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.cakk.external.extractor.MessageExtractor;
import com.cakk.external.sender.MessageSender;
import com.cakk.external.template.MessageTemplate;
import com.cakk.external.vo.CertificationMessage;
import com.cakk.external.vo.message.CertificationMessage;

@ApplicationEventListener
public class CertificationEventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.cakk.external.extractor.MessageExtractor;
import com.cakk.external.sender.MessageSender;
import com.cakk.external.template.MessageTemplate;
import com.cakk.external.vo.VerificationMessage;
import com.cakk.external.vo.message.VerificationMessage;

@ApplicationEventListener
public class EmailSendEventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.cakk.external.extractor.MessageExtractor;
import com.cakk.external.sender.MessageSender;
import com.cakk.external.template.MessageTemplate;
import com.cakk.external.vo.ErrorAlertMessage;
import com.cakk.external.vo.message.ErrorAlertMessage;

@ApplicationEventListener
public class ErrorAlertEventListener {
Expand Down
6 changes: 3 additions & 3 deletions cakk-api/src/main/java/com/cakk/api/mapper/EventMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import com.cakk.api.dto.event.ErrorAlertEvent;
import com.cakk.api.dto.event.IncreaseSearchCountEvent;
import com.cakk.domain.mysql.event.shop.CertificationEvent;
import com.cakk.external.vo.CertificationMessage;
import com.cakk.external.vo.ErrorAlertMessage;
import com.cakk.external.vo.VerificationMessage;
import com.cakk.external.vo.message.CertificationMessage;
import com.cakk.external.vo.message.ErrorAlertMessage;
import com.cakk.external.vo.message.VerificationMessage;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class EventMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import org.springframework.stereotype.Component;

import com.cakk.client.vo.OidcPublicKey;
import com.cakk.client.vo.OidcPublicKeyList;
import com.cakk.common.exception.CakkException;
import com.cakk.external.vo.key.OidcPublicKey;
import com.cakk.external.vo.key.OidcPublicKeyList;

@Component
public class PublicKeyProvider {
Expand All @@ -27,13 +27,13 @@ public PublicKey generatePublicKey(final Map<String, String> tokenHeaders, final
}

private PublicKey getPublicKey(final OidcPublicKey publicKey) {
final byte[] nBytes = decodeBase64(publicKey.n());
final byte[] eBytes = decodeBase64(publicKey.e());
final byte[] nBytes = decodeBase64(publicKey.getN());
final byte[] eBytes = decodeBase64(publicKey.getE());

final RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(1, nBytes), new BigInteger(1, eBytes));

try {
return KeyFactory.getInstance(publicKey.kty()).generatePublic(publicKeySpec);
return KeyFactory.getInstance(publicKey.getKty()).generatePublic(publicKeySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new CakkException(EXTERNAL_SERVER_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.cakk.api.provider.jwt.JwtProvider;
import com.cakk.api.provider.oauth.OidcProvider;
import com.cakk.api.provider.oauth.PublicKeyProvider;
import com.cakk.client.vo.OidcPublicKeyList;
import com.cakk.client.web.AppleAuthClient;
import com.cakk.external.client.AppleAuthClient;
import com.cakk.external.vo.key.OidcPublicKeyList;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.cakk.api.provider.jwt.JwtProvider;
import com.cakk.api.provider.oauth.OidcProvider;
import com.cakk.api.provider.oauth.PublicKeyProvider;
import com.cakk.client.vo.OidcPublicKeyList;
import com.cakk.client.web.KakaoAuthClient;
import com.cakk.external.client.KakaoAuthClient;
import com.cakk.external.vo.key.OidcPublicKeyList;

@Component
@RequiredArgsConstructor
Expand Down
14 changes: 14 additions & 0 deletions cakk-api/src/test/java/com/cakk/api/common/base/MockitoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;

import net.jqwik.api.Arbitraries;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.BuilderArbitraryIntrospector;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector;
import com.navercorp.fixturemonkey.jakarta.validation.plugin.JakartaValidationPlugin;

import com.cakk.domain.mysql.config.JpaConfig;
import com.cakk.external.vo.key.OidcPublicKey;

@Import(JpaConfig.class)
@ActiveProfiles("test")
Expand All @@ -38,4 +41,15 @@ protected final FixtureMonkey getBuilderMonkey() {
.objectIntrospector(BuilderArbitraryIntrospector.INSTANCE)
.build();
}

protected OidcPublicKey getOidcPublicKeyFixture() {
return getConstructorMonkey().giveMeBuilder(OidcPublicKey.class)
.set("kid", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.set("kty", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.set("alg", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.set("use", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.set("n", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.set("e", Arbitraries.strings().alpha().ofMinLength(10).ofMaxLength(10))
.sample();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.cakk.api.common.annotation.TestWithDisplayName;
import com.cakk.api.common.base.MockMvcTest;
import com.cakk.external.vo.PresignedUrl;
import com.cakk.external.vo.s3.PresignedUrl;

public class AwsS3ControllerTest extends MockMvcTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import com.cakk.api.provider.jwt.JwtProvider;
import com.cakk.api.provider.oauth.PublicKeyProvider;
import com.cakk.api.provider.oauth.impl.AppleAuthProvider;
import com.cakk.client.vo.OidcPublicKeyList;
import com.cakk.client.web.AppleAuthClient;
import com.cakk.common.enums.ReturnCode;
import com.cakk.common.exception.CakkException;
import com.cakk.external.client.AppleAuthClient;
import com.cakk.external.vo.key.OidcPublicKeyList;

public class AppleAuthProviderTest extends MockitoTest {

Expand All @@ -42,7 +42,9 @@ public class AppleAuthProviderTest extends MockitoTest {
@TestWithDisplayName("id token으로 제공자 id를 가져온다.")
void getProviderId() {
// given
OidcPublicKeyList oidcPublicKeyList = getConstructorMonkey().giveMeOne(OidcPublicKeyList.class);
OidcPublicKeyList oidcPublicKeyList = getConstructorMonkey().giveMeBuilder(OidcPublicKeyList.class)
.set("keys", Arbitraries.of(getOidcPublicKeyFixture()).list().ofMinSize(1).ofMaxSize(10))
.sample();
PublicKey publicKey = getConstructorMonkey().giveMeOne(PublicKey.class);
DefaultClaims claims = getConstructorMonkey().giveMeBuilder(DefaultClaims.class)
.set("sub", Arbitraries.strings().withCharRange('a', 'z').ofMinLength(5).ofMaxLength(10).sample())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import com.cakk.api.provider.jwt.JwtProvider;
import com.cakk.api.provider.oauth.PublicKeyProvider;
import com.cakk.api.provider.oauth.impl.KakaoAuthProvider;
import com.cakk.client.vo.OidcPublicKeyList;
import com.cakk.client.web.KakaoAuthClient;
import com.cakk.common.enums.ReturnCode;
import com.cakk.common.exception.CakkException;
import com.cakk.external.client.KakaoAuthClient;
import com.cakk.external.vo.key.OidcPublicKeyList;

class KakaoAuthProviderTest extends MockitoTest {

Expand All @@ -41,7 +41,9 @@ class KakaoAuthProviderTest extends MockitoTest {
@TestWithDisplayName("id token으로 제공자 id를 가져온다.")
void getProviderId() {
// given
OidcPublicKeyList oidcPublicKeyList = getConstructorMonkey().giveMeOne(OidcPublicKeyList.class);
OidcPublicKeyList oidcPublicKeyList = getConstructorMonkey().giveMeBuilder(OidcPublicKeyList.class)
.set("keys", Arbitraries.of(getOidcPublicKeyFixture()).list().ofMinSize(1).ofMaxSize(10))
.sample();
PublicKey publicKey = getConstructorMonkey().giveMeOne(PublicKey.class);
DefaultClaims claims = getConstructorMonkey().giveMeBuilder(DefaultClaims.class)
.set("sub", Arbitraries.strings().withCharRange('a', 'z').ofMinLength(5).ofMaxLength(10).sample())
Expand Down
14 changes: 0 additions & 14 deletions cakk-client/build.gradle

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions cakk-client/src/main/java/com/cakk/client/vo/OidcPublicKey.java

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions cakk-client/src/main/java/com/cakk/client/web/AppleAuthClient.java

This file was deleted.

30 changes: 0 additions & 30 deletions cakk-client/src/main/java/com/cakk/client/web/KakaoAuthClient.java

This file was deleted.

1 change: 0 additions & 1 deletion cakk-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencies {
implementation(project(":cakk-common"))
implementation(project(":cakk-domain:mysql"))
implementation(project(":cakk-domain:redis"))
implementation(project(":cakk-client"))
implementation(project(":cakk-external"))

// basic
Expand Down
1 change: 1 addition & 0 deletions cakk-external/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {

// Basic
implementation("org.springframework:spring-context")
implementation("org.springframework:spring-web")

// AWS
implementation("com.amazonaws:aws-java-sdk-s3:1.12.715")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cakk.external.client

import com.cakk.common.enums.ReturnCode
import com.cakk.common.exception.CakkException
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import org.springframework.web.client.RestClient

import com.cakk.external.vo.key.OidcPublicKeyList

@Component
class AppleAuthClient(
private val restClient: RestClient,
@Value("\${oauth.apple.public-key-url}")
private val publicKeyUrl: String
) {

fun getPublicKeys(): OidcPublicKeyList {
return restClient.get()
.uri(publicKeyUrl)
.retrieve()
.body(OidcPublicKeyList::class.java)
?: throw CakkException(ReturnCode.EXTERNAL_SERVER_ERROR)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cakk.external.client

import com.cakk.common.enums.ReturnCode
import com.cakk.common.exception.CakkException
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import org.springframework.web.client.RestClient

import com.cakk.external.vo.key.OidcPublicKeyList

@Component
class KakaoAuthClient(
private val restClient: RestClient,
@Value("\${oauth.kakao.public-key-info}")
private val publicKeyUrl: String
) {

fun getPublicKeys(): OidcPublicKeyList {
return restClient.get()
.uri(publicKeyUrl)
.retrieve()
.body(OidcPublicKeyList::class.java)
?: throw CakkException(ReturnCode.EXTERNAL_SERVER_ERROR)
}
}
Loading

0 comments on commit 23d2974

Please sign in to comment.