-
Notifications
You must be signed in to change notification settings - Fork 1.3k
engine/schema: prepend algorithm to checksum during systemvm template registration #12165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from all commits
97424f2
4f08312
2b8a847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,4 +142,19 @@ public static String calculateChecksum(File file) { | |||||||||||||||||||||||||||||||||||||||
| throw new CloudRuntimeException(errMsg, e); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public static String prependAlgorithm(String checksum) { | ||||||||||||||||||||||||||||||||||||||||
| if (StringUtils.isEmpty(checksum)) { | ||||||||||||||||||||||||||||||||||||||||
| return checksum; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| int checksumLength = checksum.length(); | ||||||||||||||||||||||||||||||||||||||||
| Map<String, Integer> paddingLengths = getChecksumLengthsMap(); | ||||||||||||||||||||||||||||||||||||||||
| for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) { | ||||||||||||||||||||||||||||||||||||||||
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
| if (entry.getValue().equals(checksumLength)) { | ||||||||||||||||||||||||||||||||||||||||
| String algorithm = entry.getKey(); | ||||||||||||||||||||||||||||||||||||||||
| return String.format("{%s}%s", algorithm, checksum); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+152
to
+157
|
||||||||||||||||||||||||||||||||||||||||
| for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) { | |
| if (entry.getValue().equals(checksumLength)) { | |
| String algorithm = entry.getKey(); | |
| return String.format("{%s}%s", algorithm, checksum); | |
| } | |
| } | |
| String selectedAlgorithm = null; | |
| // In case multiple algorithms share the same digest length, choose deterministically | |
| for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) { | |
| if (entry.getValue().equals(checksumLength)) { | |
| String algorithm = entry.getKey(); | |
| if (selectedAlgorithm == null || algorithm.compareTo(selectedAlgorithm) < 0) { | |
| selectedAlgorithm = algorithm; | |
| } | |
| } | |
| } | |
| if (selectedAlgorithm != null) { | |
| return String.format("{%s}%s", selectedAlgorithm, checksum); | |
| } |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prependAlgorithm method doesn't check if the algorithm prefix is already present before prepending, which could result in double-prefixing (e.g., {SHA-512}{SHA-512}checksum). Add a check using the existing isAlgorithmPresent() method at the start of the function to return the checksum unchanged if it already has the prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
prependAlgorithmmethod lacks test coverage. Add test cases covering: (1) checksum without prefix for each supported algorithm, (2) checksum that already has a prefix, (3) null/empty checksum, (4) checksum with invalid length that doesn't match any algorithm.