Skip to content

Commit

Permalink
[ISSUE#11695] fix PreviousConfigHistory encryption (#11707)
Browse files Browse the repository at this point in the history
* fix PreviousConfigHistory encryption

* UT fix
  • Loading branch information
godhth authored Jan 31, 2024
1 parent bd5caa6 commit 817eb58
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public ConfigHistoryInfo getPreviousConfigHistoryInfo(String dataId, String grou
}
// 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ default MapperResult findConfigHistoryFetchRows(MapperContext context) {
*/
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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testDetailPreviousConfigHistory() {
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});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testDetailPreviousConfigHistory() {
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});
}

Expand Down

0 comments on commit 817eb58

Please sign in to comment.