fix(s3): return BadDigest for Content-MD5 mismatch (#6842)

This commit is contained in:
Zhengchao An
2026-08-29 17:00:18 +08:00
committed by GitHub
parent 11c6ee42ea
commit e1ea99ff06
2 changed files with 30 additions and 2 deletions
+15
View File
@@ -621,6 +621,21 @@ mod tests {
assert_eq!(api_error.message, ApiError::error_code_to_message(&S3ErrorCode::BadDigest));
}
#[test]
fn content_md5_mismatch_io_errors_map_to_bad_digest() {
let bad_digest = || rustfs_rio::BadDigest {
expected_md5: "expected".to_string(),
calculated_md5: "calculated".to_string(),
};
let api_error = ApiError::from(IoError::new(ErrorKind::InvalidData, bad_digest()));
assert_eq!(api_error.code, S3ErrorCode::BadDigest);
assert_eq!(api_error.message, ApiError::error_code_to_message(&S3ErrorCode::BadDigest));
let api_error = ApiError::from(StorageError::Io(IoError::new(ErrorKind::InvalidData, bad_digest())));
assert_eq!(api_error.code, S3ErrorCode::BadDigest);
assert_eq!(api_error.message, ApiError::error_code_to_message(&S3ErrorCode::BadDigest));
}
#[test]
fn upload_stream_sha256_mismatch_maps_to_bad_digest() {
let api_error = ApiError::from(IoError::other(MockUploadStreamError::Sha256Mismatch));