Jimmyweng006 commented on code in PR #8506:
URL: https://github.com/apache/ozone/pull/8506#discussion_r2106115047
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestMultipartUploadComplete.java:
##########
@@ -266,4 +270,96 @@ public void testMultipartInvalidPartError() throws
Exception {
() -> completeMultipartUpload(key, completeMultipartUploadRequest,
uploadID));
assertEquals(ex.getCode(), S3ErrorTable.INVALID_PART.getCode());
}
+
+ @Test
+ public void testMultipartCompleteWithEtagMismatchShouldAbortAndThrow()
throws Exception {
+ // Arrange
+ String key = UUID.randomUUID().toString();
+ String uploadID = initiateMultipartUpload(key);
+ CompleteMultipartUploadRequest completeMultipartUploadRequest =
+ buildCompleteMultipartUploadRequest(key, uploadID);
+
+ // Mock headers to return a mismatched etag
+ HttpHeaders etagHeaders = mock(HttpHeaders.class);
+ String fakeMd5Hex = "deadbeefdeadbeefdeadbeefdeadbeef";
+ byte[] fakeMd5Bytes = Hex.decodeHex(fakeMd5Hex);
+ String encodedEtag = Base64.getEncoder().encodeToString(fakeMd5Bytes);
+ when(etagHeaders.getHeaderString(CHECKSUM_HEADER)).thenReturn(
+ encodedEtag);
+ rest.setHeaders(etagHeaders);
+
+ // Act & Assert
+ OS3Exception os3Exception = assertThrows(OS3Exception.class,
+ () -> rest.completeMultipartUpload(OzoneConsts.S3_BUCKET, key,
uploadID, completeMultipartUploadRequest));
+ assertEquals(S3ErrorTable.BAD_DIGEST.getCode(), os3Exception.getCode());
+ assertEquals(HTTP_BAD_REQUEST, os3Exception.getHttpCode());
+ }
+
+ @Test
+ public void testMultipartCompleteWithEtagMatchShouldSucceed() throws
Exception {
+ // Arrange
+ String key = UUID.randomUUID().toString();
+ String uploadID = initiateMultipartUpload(key);
+ CompleteMultipartUploadRequest completeMultipartUploadRequest =
+ buildCompleteMultipartUploadRequest(key, uploadID);
+
+ // calculate correct etag
+ Response tempResp =
+ rest.completeMultipartUpload(OzoneConsts.S3_BUCKET, key, uploadID,
completeMultipartUploadRequest);
Review Comment:
Yes I think you are right, using the same uploadID in second
**completeMultipartUpload** should cause NoSuchUpload error but somehow this
error did not show in unit test... let me use new **initializeMultipartUpload**
for second **completeMultipartUpload**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]