From a18b825aeddc0927706825381188d87ee6b5a1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Fri, 12 May 2023 20:38:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix=20:=20redis=20cache=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/aop/event/EventPublisherAspect.kt | 2 +- .../whatnow/config/redis/RedisCacheConfig.kt | 7 ++-- .../whatnow/api/KakaoOauthClientTest.kt | 39 ++++++++++--------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/aop/event/EventPublisherAspect.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/aop/event/EventPublisherAspect.kt index 385cba8a..226afdf3 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/aop/event/EventPublisherAspect.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/aop/event/EventPublisherAspect.kt @@ -17,7 +17,7 @@ class EventPublisherAspect : ApplicationEventPublisherAware { private val appliedLocal: ThreadLocal = ThreadLocal.withInitial { false } @Around("@annotation(org.springframework.transaction.annotation.Transactional)") - fun handleEvent(joinPoint: ProceedingJoinPoint): Any { + fun handleEvent(joinPoint: ProceedingJoinPoint): Any? { val appliedValue = appliedLocal.get() // nested를 쓰는이유 // 트랜잭션 안에 트랜잭션이 또있는 경우대비 diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt index cd64db46..c01afb70 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt @@ -25,9 +25,10 @@ class RedisCacheConfig { ), ) .serializeValuesWith( - RedisSerializationContext.SerializationPair.fromSerializer( - GenericJackson2JsonRedisSerializer(), - ), + RedisSerializationContext.SerializationPair + .fromSerializer( + GenericJackson2JsonRedisSerializer(), + ), ) .entryTtl(Duration.ofDays(7L)) return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(cf) diff --git a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt index 44c182a7..b6681b53 100644 --- a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt +++ b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest +import org.springframework.cache.annotation.EnableCaching import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock import org.springframework.http.HttpStatus import org.springframework.http.MediaType @@ -45,23 +46,23 @@ class KakaoOauthClientTest { assertEquals(response.refreshToken, "refreshToken") } - @Test - fun `카카오 OIDC 공개키 요청이 올바르게 파싱되어야한다`() { - val file = ResourceUtils.getFile("classpath:payload/oauth-oidc-public-key-response.json").toPath() - WireMock.stubFor( - WireMock.get(WireMock.urlPathEqualTo("/.well-known/jwks.json")) - .willReturn( - WireMock.aResponse() - .withStatus(HttpStatus.OK.value()) - .withHeader( - "Content-Type", - MediaType.APPLICATION_JSON_VALUE, - ) - .withBody(Files.readAllBytes(file)), - ), - ) - var response = kakaoOauthClient.kakaoOIDCOpenKeys() - assertEquals(response.keys[0].kid, "kid1") - assertEquals(response.keys[1].kid, "kid2") - } +// @Test +// fun `카카오 OIDC 공개키 요청이 올바르게 파싱되어야한다`() { +// val file = ResourceUtils.getFile("classpath:payload/oauth-oidc-public-key-response.json").toPath() +// WireMock.stubFor( +// WireMock.get(WireMock.urlPathEqualTo("/.well-known/jwks.json")) +// .willReturn( +// WireMock.aResponse() +// .withStatus(HttpStatus.OK.value()) +// .withHeader( +// "Content-Type", +// MediaType.APPLICATION_JSON_VALUE, +// ) +// .withBody(Files.readAllBytes(file)), +// ), +// ) +// var response = kakaoOauthClient.kakaoOIDCOpenKeys() +// assertEquals(response.keys[0].kid, "kid1") +// assertEquals(response.keys[1].kid, "kid2") +// } } From af61dbdea86ffadbbe244f9e6e501cb69289409a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Fri, 12 May 2023 21:02:52 +0900 Subject: [PATCH 2/3] style : spotless apply --- .../kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt index b6681b53..0f4b2a26 100644 --- a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt +++ b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest -import org.springframework.cache.annotation.EnableCaching import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock import org.springframework.http.HttpStatus import org.springframework.http.MediaType From 78e29eb35cfa961de17117c783e3357534dc2f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Fri, 12 May 2023 21:15:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix=20:=20redis=20cache=20object=20mapper?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whatnow/config/redis/RedisCacheConfig.kt | 13 ++++++- .../whatnow/api/KakaoOauthClientTest.kt | 38 +++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt index c01afb70..6b0268dd 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/redis/RedisCacheConfig.kt @@ -1,5 +1,8 @@ package com.depromeet.whatnow.config.redis +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.springframework.cache.CacheManager import org.springframework.cache.annotation.EnableCaching import org.springframework.context.annotation.Bean @@ -16,6 +19,14 @@ import java.time.Duration @Configuration class RedisCacheConfig { + val objectMapper: ObjectMapper = jacksonObjectMapper() + .activateDefaultTyping( + BasicPolymorphicTypeValidator.builder() + .allowIfBaseType(Any::class.java) + .build(), + ObjectMapper.DefaultTyping.EVERYTHING, + ) + @Bean fun oidcCacheManager(cf: RedisConnectionFactory): CacheManager { val redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() @@ -27,7 +38,7 @@ class RedisCacheConfig { .serializeValuesWith( RedisSerializationContext.SerializationPair .fromSerializer( - GenericJackson2JsonRedisSerializer(), + GenericJackson2JsonRedisSerializer(objectMapper), ), ) .entryTtl(Duration.ofDays(7L)) diff --git a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt index 0f4b2a26..44c182a7 100644 --- a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt +++ b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/api/KakaoOauthClientTest.kt @@ -45,23 +45,23 @@ class KakaoOauthClientTest { assertEquals(response.refreshToken, "refreshToken") } -// @Test -// fun `카카오 OIDC 공개키 요청이 올바르게 파싱되어야한다`() { -// val file = ResourceUtils.getFile("classpath:payload/oauth-oidc-public-key-response.json").toPath() -// WireMock.stubFor( -// WireMock.get(WireMock.urlPathEqualTo("/.well-known/jwks.json")) -// .willReturn( -// WireMock.aResponse() -// .withStatus(HttpStatus.OK.value()) -// .withHeader( -// "Content-Type", -// MediaType.APPLICATION_JSON_VALUE, -// ) -// .withBody(Files.readAllBytes(file)), -// ), -// ) -// var response = kakaoOauthClient.kakaoOIDCOpenKeys() -// assertEquals(response.keys[0].kid, "kid1") -// assertEquals(response.keys[1].kid, "kid2") -// } + @Test + fun `카카오 OIDC 공개키 요청이 올바르게 파싱되어야한다`() { + val file = ResourceUtils.getFile("classpath:payload/oauth-oidc-public-key-response.json").toPath() + WireMock.stubFor( + WireMock.get(WireMock.urlPathEqualTo("/.well-known/jwks.json")) + .willReturn( + WireMock.aResponse() + .withStatus(HttpStatus.OK.value()) + .withHeader( + "Content-Type", + MediaType.APPLICATION_JSON_VALUE, + ) + .withBody(Files.readAllBytes(file)), + ), + ) + var response = kakaoOauthClient.kakaoOIDCOpenKeys() + assertEquals(response.keys[0].kid, "kid1") + assertEquals(response.keys[1].kid, "kid2") + } }