CLDSRV-848: add missing checksum algorithms#6081
Conversation
Hello leif-scality,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Incorrect fix versionThe
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
Please check the |
5c6e2cd to
7498887
Compare
❌ 2 Tests Failed:
View the full list of 2 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
e519604 to
12f1006
Compare
Incorrect fix versionThe
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
Please check the |
52c366f to
8493f53
Compare
Incorrect fix versionThe
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
Please check the |
bdf8518 to
6833dde
Compare
59a4a0e to
5ed0d44
Compare
Incorrect fix versionThe
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
Please check the |
Incorrect fix versionThe
Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:
Please check the |
5ed0d44 to
ec2d446
Compare
| }); | ||
|
|
||
| const algorithms = { | ||
| 'crc64nvme': { |
There was a problem hiding this comment.
Normally you can remove all the quotes from property names
| const result = await crc.digest(); | ||
| return Buffer.from(result).toString('base64'); | ||
| }, | ||
| 'checkExpected': expected => { |
There was a problem hiding this comment.
What about naming this callback isValidDigest (I understand you mean to check the "expected" digest, as if the digest is expected to match the contents' digest, but doesn't come obvious when reading the code, I think isValidDigest is more appropriate as it implies it returns true/false if the digest is a valid digest or not based on the expected type, without actually checking it against any content.
I don't know if it matters, but optionally we could also check that characters are valid within the expected encoding.
There was a problem hiding this comment.
renamed to isValidDigest and added base64 regex test
|
|
||
| async function validateXAmzChecksums(headers, body) { | ||
| const checksumHeaders = Object.keys(headers).filter(header => header.startsWith('x-amz-checksum-')); | ||
| const xAmzCheckumCnt = checksumHeaders.length; |
There was a problem hiding this comment.
| const xAmzCheckumCnt = checksumHeaders.length; | |
| const xAmzChecksumCnt = checksumHeaders.length; |
| return { error: ChecksumError.AlgoNotSupported, details: { algorithm: algo } }; | ||
| } | ||
|
|
||
| if (algo in algorithms === false) { |
There was a problem hiding this comment.
nitpick: it's more typical to avoid explicit boolean value checks
| if (algo in algorithms === false) { | |
| if (!(algo in algorithms)) { |
| const { config } = require('../../../Config'); | ||
|
|
||
| const ChecksumError = Object.freeze({ | ||
| MD5Mismatch: 'MD5Mismatch', |
There was a problem hiding this comment.
Instead of creating internal error types that are not used for any logic nor returned to the client, we could instead directly construct the error when we see it and return it as is with an appropriate descriptive error message (i.e. construct directly an error with InvalidRequest.customizeDescription(...)). We can keep the special errors that we need special handling for (MissingChecksum etc.)
In the unit tests, you can simply check that the error is InvalidRequest, and if you want to be fancy, also check a part of the error message.
There was a problem hiding this comment.
The internal errors are have more details than the AWS errors(used for logging), they are also easier to test.
I prefer having the building of the AMZ error outside the validation function.
| return null; | ||
| log.debug('failed checksum validation', { method: request.apiMethod }, err); | ||
|
|
||
| switch (err.error) { |
There was a problem hiding this comment.
See my suggestion about returning directly errors to avoid having to do this conversion.
There was a problem hiding this comment.
The internal errors are have more details than the AWS errors(used for logging), they are also easier to test.
I prefer having the building of the AMZ error outside the validation function.
| const validationFunc = methodValidationFunc[request.apiMethod]; | ||
| if (!validationFunc) { | ||
| return null; | ||
| return null; //await defaultValidationFunc2(request, body, log); |
There was a problem hiding this comment.
Why adding this comment?
| ); | ||
| }); | ||
|
|
||
| itSkipIfAWS('should respond InvalidRequest with if invalid x-amz-checksum- algorithm', done => { |
There was a problem hiding this comment.
| itSkipIfAWS('should respond InvalidRequest with if invalid x-amz-checksum- algorithm', done => { | |
| itSkipIfAWS('should respond InvalidRequest with invalid x-amz-checksum- algorithm', done => { |
| data += chunk; | ||
| }); | ||
| res.on('end', () => { | ||
| assert(!data.includes('BadDigest')); |
There was a problem hiding this comment.
Could we more simply check that res.statusCode == 200?
There was a problem hiding this comment.
The request is going to fail, because it is not a complete request, so we only check that it is not a BadDigest meaning that we passed the checksum checks.
I added missing asserts to cover the other errors (InvalidDigest, ...)
1b5e6e0 to
26d6e14
Compare
26d6e14 to
5f93d3e
Compare
jonathan-gramain
left a comment
There was a problem hiding this comment.
Comments on error names, otherwise LGTM
| AlgoNotSupportedSDK: 'AlgoNotSupportedSDK', | ||
| MultipleChecksumTypes: 'MultipleChecksumTypes', | ||
| MissingCorresponding: 'MissingCorresponding', | ||
| InvalidAlgoValue: 'InvalidAlgoValue', |
There was a problem hiding this comment.
This error seems to be used not when the algorithm is invalid, but when the checksum is malformed. So I suggest to rename the error to MalformedChecksum.
| AlgoNotSupported: 'AlgoNotSupported', | ||
| AlgoNotSupportedSDK: 'AlgoNotSupportedSDK', | ||
| MultipleChecksumTypes: 'MultipleChecksumTypes', | ||
| MissingCorresponding: 'MissingCorresponding', |
There was a problem hiding this comment.
nitpick: rename to MissingExpectedChecksum?
There was a problem hiding this comment.
I prefer MissingCorresponding because it points to this specific error x-amz-sdk-checksum-algorithm specified, but no corresponding x-amz-checksum-* or x-amz-trailer headers were found..
MissingExpectedChecksum is not as precise
5f93d3e to
732bc8d
Compare
732bc8d to
bf5fa48
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
|
/approve |
Build failedThe build for commit did not succeed in branch improvement/CLDSRV-848-add-missing-checksum-algorithms The following options are set: approve |
Build failedThe build for commit did not succeed in branch improvement/CLDSRV-848-add-missing-checksum-algorithms The following options are set: approve |
|
I have successfully merged the changeset of this pull request
The following branches have NOT changed:
Please check the status of the associated issue CLDSRV-848. Goodbye leif-scality. The following options are set: approve |
Add CRC32, CRC32C, CRC64NVME, SHA1, SHA256 checksum support for non streaming methods (all methods except PutObject and PutPart).