From fc6cf8edb9e49a9af9e884a287874aacf6f57bda Mon Sep 17 00:00:00 2001 From: Sunrisea <1336317033@qq.com> Date: Sun, 8 Dec 2024 21:53:51 +0800 Subject: [PATCH] fix md5 logic --- .../server/service/query/handler/FormalHandler.java | 4 +--- .../service/query/handler/GrayRuleMatchHandler.java | 4 +--- .../query/handler/SpecialTagNotFoundHandler.java | 4 +--- .../server/controller/ConfigServletInnerTest.java | 11 ++++------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/FormalHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/FormalHandler.java index 660c956f3c..dccbe620ca 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/FormalHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/FormalHandler.java @@ -23,8 +23,6 @@ import java.io.IOException; -import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_UTF8; - /** * Formal Handler. * This class represents a formal handler in the configuration query processing chain. @@ -49,7 +47,7 @@ public ConfigQueryChainResponse handle(ConfigQueryChainRequest request) throws I String tenant = request.getTenant(); CacheItem cacheItem = ConfigChainEntryHandler.getThreadLocalCacheItem(); - String md5 = cacheItem.getConfigCache().getMd5(ENCODE_UTF8); + String md5 = cacheItem.getConfigCache().getMd5(); long lastModified = cacheItem.getConfigCache().getLastModifiedTs(); String encryptedDataKey = cacheItem.getConfigCache().getEncryptedDataKey(); String contentType = cacheItem.getType(); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/GrayRuleMatchHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/GrayRuleMatchHandler.java index e95640539d..412fd8d78e 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/GrayRuleMatchHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/GrayRuleMatchHandler.java @@ -24,8 +24,6 @@ import java.io.IOException; -import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_UTF8; - /** * GrayRuleMatchHandler. * This class represents a gray rule handler in the configuration query processing chain. @@ -60,7 +58,7 @@ public ConfigQueryChainResponse handle(ConfigQueryChainRequest request) throws I ConfigQueryChainResponse response = new ConfigQueryChainResponse(); long lastModified = matchedGray.getLastModifiedTs(); - String md5 = matchedGray.getMd5(ENCODE_UTF8); + String md5 = matchedGray.getMd5(); String encryptedDataKey = matchedGray.getEncryptedDataKey(); String content = ConfigDiskServiceFactory.getInstance() .getGrayContent(request.getDataId(), request.getGroup(), request.getTenant(), diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/SpecialTagNotFoundHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/SpecialTagNotFoundHandler.java index 08dee4c44c..900e755ecf 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/SpecialTagNotFoundHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/query/handler/SpecialTagNotFoundHandler.java @@ -24,8 +24,6 @@ import java.io.IOException; -import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_UTF8; - /** * SpecialTagNotFound Handler. * This class represents special tag not found handler in the configuration query processing chain. @@ -51,7 +49,7 @@ public ConfigQueryChainResponse handle(ConfigQueryChainRequest request) throws I String tenant = request.getTenant(); CacheItem cacheItem = ConfigChainEntryHandler.getThreadLocalCacheItem(); - String md5 = cacheItem.getConfigCache().getMd5(ENCODE_UTF8); + String md5 = cacheItem.getConfigCache().getMd5(); long lastModified = cacheItem.getConfigCache().getLastModifiedTs(); String encryptedDataKey = cacheItem.getConfigCache().getEncryptedDataKey(); String contentType = cacheItem.getType(); diff --git a/config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java b/config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java index a08073fd79..80460c67d4 100644 --- a/config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java +++ b/config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java @@ -62,7 +62,6 @@ import static com.alibaba.nacos.api.common.Constants.VIPSERVER_TAG; import static com.alibaba.nacos.config.server.constant.Constants.CONTENT_MD5; -import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_GBK; import static com.alibaba.nacos.config.server.constant.Constants.ENCODE_UTF8; import static com.alibaba.nacos.config.server.utils.RequestUtil.CLIENT_APPNAME_HEADER; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -184,8 +183,7 @@ void testDoGetConfigV1Beta() throws Exception { private void mockGray4Beta(CacheItem cacheItem, String content, String betaIps, String dataKey) { cacheItem.initConfigGrayIfEmpty(BetaGrayRule.TYPE_BETA); ConfigCacheGray configCacheGray = cacheItem.getConfigCacheGray().get(BetaGrayRule.TYPE_BETA); - configCacheGray.setMd5Utf8(MD5Utils.md5Hex(content, ENCODE_UTF8)); - configCacheGray.setMd5Gbk(MD5Utils.md5Hex(content, ENCODE_GBK)); + configCacheGray.setMd5(MD5Utils.md5Hex(content, ENCODE_UTF8)); configCacheGray.setEncryptedDataKey(dataKey); ConfigGrayPersistInfo configGrayPersistInfo = new ConfigGrayPersistInfo(BetaGrayRule.TYPE_BETA, BetaGrayRule.VERSION, betaIps, -1000); @@ -196,8 +194,7 @@ private void mockGray4Beta(CacheItem cacheItem, String content, String betaIps, private void mockGray4Tag(CacheItem cacheItem, String content, String tagValue, String dataKey, long ts) { cacheItem.initConfigGrayIfEmpty(TagGrayRule.TYPE_TAG + "_" + tagValue); ConfigCacheGray configCacheGray = cacheItem.getConfigCacheGray().get(TagGrayRule.TYPE_TAG + "_" + tagValue); - configCacheGray.setMd5Utf8(MD5Utils.md5Hex(content, ENCODE_UTF8)); - configCacheGray.setMd5Gbk(MD5Utils.md5Hex(content, ENCODE_GBK)); + configCacheGray.setMd5(MD5Utils.md5Hex(content, ENCODE_UTF8)); configCacheGray.setLastModifiedTs(ts); configCacheGray.setEncryptedDataKey(dataKey); ConfigGrayPersistInfo configGrayPersistInfo = new ConfigGrayPersistInfo(TagGrayRule.TYPE_TAG, @@ -295,7 +292,7 @@ void testDoGetConfigFormal() throws Exception { CacheItem cacheItem = new CacheItem("test"); String md5 = "md5wertyui"; final String content = "content345678"; - cacheItem.getConfigCache().setMd5Utf8(md5); + cacheItem.getConfigCache().setMd5(md5); long ts = System.currentTimeMillis(); cacheItem.getConfigCache().setLastModifiedTs(ts); cacheItem.getConfigCache().setEncryptedDataKey("key2345678"); @@ -330,7 +327,7 @@ void testDoGetConfigFormalV2() throws Exception { CacheItem cacheItem = new CacheItem("test"); String md5 = "md5wertyui"; final String content = "content345678"; - cacheItem.getConfigCache().setMd5Utf8(md5); + cacheItem.getConfigCache().setMd5(md5); long ts = System.currentTimeMillis(); cacheItem.getConfigCache().setLastModifiedTs(ts); cacheItem.getConfigCache().setEncryptedDataKey("key2345678");