rich7420 commented on code in PR #11222:
URL: https://github.com/apache/ozone/pull/11222#discussion_r3996748541


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/signature/TestChunksValidator.java:
##########
@@ -91,6 +107,32 @@ void acceptsUppercaseChunkSignature() {
         SignatureTestUtils.sha256Hex(chunk, 0, 
chunk.length))).doesNotThrowAnyException();
   }
 
+  @Test
+  void acceptsMatchingTrailerSignature() {
+    ChunksValidator validator = newTrailerValidator();
+    byte[] chunk1 = repeat('a', 65536);
+    byte[] chunk2 = repeat('a', 1024);
+    String trailer = "x-amz-checksum-crc32c:sOO8/Q==";
+
+    assertDoesNotThrow(() -> validator.validateChunk(TRAILER_CHUNK1_SIGNATURE,
+        SignatureTestUtils.sha256Hex(chunk1, 0, chunk1.length)));
+    assertDoesNotThrow(() -> validator.validateChunk(TRAILER_CHUNK2_SIGNATURE,
+        SignatureTestUtils.sha256Hex(chunk2, 0, chunk2.length)));
+    assertDoesNotThrow(() -> 
validator.validateChunk(TRAILER_FINAL_CHUNK_SIGNATURE,
+        SignatureTestUtils.sha256Hex(new byte[0], 0, 0)));
+    assertDoesNotThrow(() -> validator.validateTrailer(TRAILER_SIGNATURE,
+        SignatureTestUtils.sha256Hex((trailer + 
"\n").getBytes(java.nio.charset.StandardCharsets.UTF_8),
+            0, trailer.length() + 1)));
+  }
+
+  @Test
+  void rejectsTamperedTrailerSignature() {
+    ChunksValidator validator = newTrailerValidator();
+    assertSignatureMismatch(() -> validator.validateTrailer(
+        TRAILER_SIGNATURE.substring(0, TRAILER_SIGNATURE.length() - 1) + "0",
+        "invalid-trailer-hash"));

Review Comment:
   oh, you're right



-- 
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]

Reply via email to