Skip to content

Commit

Permalink
fix md5 logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunrisea committed Dec 9, 2024
1 parent c26e740 commit fc6cf8e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit fc6cf8e

Please sign in to comment.