-
Notifications
You must be signed in to change notification settings - Fork 390
feat: Enable full object checksum validation on JSON path #2687
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: main
Are you sure you want to change the base?
Conversation
Adds validation for client-provided (pre-calculated) and client-calculated CRC32C and MD5 hashes when the final upload request is made via the JSON API path (status 200). This ensures consistency checks are performed even when the `Upload` stream is finalized, preventing silent data corruption if the server-reported hash (in the response body) mismatches the client's expected hash.
Adds the 'Validation of Client Checksums Against Server Response' test suite. Fixes test failures in client-provided hash scenarios by updating mock responses to ensure server-reported checksums match the client's expected values.
Refactors four duplicate test cases (CRC32C/MD5 success and failure) into a single, parameterized test block within the 'Validation of Client Checksums Against Server Response' suite. This improves test clarity and reduces code duplication by dynamically generating test scenarios for post-upload hash validation.
This commit introduces several stability fixes for the ResumableUpload class: 1. **Fixes Timeouts in Unit Tests:** Updates `makeRequestStream` mocks to fully drain the request body stream, resolving stream consumption deadlocks and timeouts in `#startUploading` unit tests. 2. **Fixes Multi-Part Hang:** Correctly finalizes the `pipeline` for partial chunks (`isPartialUpload=true`) by calling `pipelineCallback()` immediately after successful chunk upload, preventing indefinite hangs in multi-session tests. 3. **Fixes Single-Chunk Checksum Missing Header:** Applies the `X-Goog-Hash` header unconditionally in single-chunk mode if a validator is present, ensuring checksum validation is active even when `contentLength` is unknown.
| ) || | ||
| this.#validateChecksum(clientMd5HashToValidate, serverMd5, 'MD5') | ||
| ) { | ||
| return; |
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.
Why would we exit early when there is a successful checksum check? Wouldn't we want to continue and do the cleanup below?
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 early exit (return;) is mandatory because if this.#validateChecksum detects a CRC32C or MD5 mismatch, it immediately calls this.destroy(error). This action places the stream in an error state.
Continuing execution without the early exit would lead to a "false success" by incorrectly running the subsequent cleanup code, which includes emitting 'metadata' and 'uploadFinished'. The return ensures that the upload process halts immediately upon data integrity failure, preventing the application from signaling a successful upload when a mismatch occurs. If both checksums pass or are skipped, the process continues normally to cleanup.
Simplify `HashStreamValidator._flush` by utilizing `md5Digest` getter.
|
@ddelgrosso1 Just a quick reminder to take a look at this PR when you get a chance! |
Description
Impact
Testing
Additional Information
Checklist
Fixes #