[ISSUE#11695] fix PreviousConfigHistory encryption (#11707)

* fix PreviousConfigHistory encryption

* UT fix
This commit is contained in:
hth 2024-01-31 09:30:46 +08:00 committed by GitHub
parent bd5caa64a6
commit 817eb58597
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 3 deletions

View File

@ -87,6 +87,12 @@ public class HistoryService {
}
// check if history config match the input
checkHistoryInfoPermission(configHistoryInfo, dataId, group, namespaceId);
String encryptedDataKey = configHistoryInfo.getEncryptedDataKey();
Pair<String, String> pair = EncryptionHandler
.decryptHandler(dataId, encryptedDataKey, configHistoryInfo.getContent());
configHistoryInfo.setContent(pair.getSecond());
return configHistoryInfo;
}

View File

@ -105,7 +105,7 @@ public interface HistoryConfigInfoMapper extends Mapper {
*/
default MapperResult detailPreviousConfigHistory(MapperContext context) {
return new MapperResult(
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified "
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified,encrypted_data_key "
+ "FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)",
Collections.singletonList(context.getWhereParameter(FieldConstant.ID)));
}

View File

@ -107,7 +107,7 @@ public class HistoryConfigInfoMapperByDerbyTest {
MapperResult mapperResult = historyConfigInfoMapperByDerby.detailPreviousConfigHistory(context);
Assert.assertEquals(mapperResult.getSql(),
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
+ "gmt_modified FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
}

View File

@ -104,7 +104,7 @@ public class HistoryConfigInfoMapperByMySqlTest {
MapperResult mapperResult = historyConfigInfoMapperByMySql.detailPreviousConfigHistory(context);
Assert.assertEquals(mapperResult.getSql(),
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
+ "gmt_modified FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
}