This is an automated email from the ASF dual-hosted git repository.

sammichen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 5cf43fcfc6 HDDS-8011. IllegalArgumentException logged for invalid 
user-defined metadata (#5160)
5cf43fcfc6 is described below

commit 5cf43fcfc612204cd823d614b3ca5db23bbad412
Author: Tejaskriya <[email protected]>
AuthorDate: Mon Aug 21 11:33:50 2023 +0530

    HDDS-8011. IllegalArgumentException logged for invalid user-defined 
metadata (#5160)
---
 .../org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java  |  3 +--
 .../org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java |  6 ++++++
 .../apache/hadoop/ozone/s3/endpoint/TestEndpointBase.java  | 14 +++++++-------
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
index 6063d8bc5b..836d026975 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java
@@ -290,8 +290,7 @@ public abstract class EndpointBase implements Auditor {
 
         if (sizeInBytes >
                 OzoneConsts.S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB * KB) {
-          throw new IllegalArgumentException("Illegal user defined metadata." +
-              " Combined size cannot exceed 2KB.");
+          throw newError(S3ErrorTable.METADATA_TOO_LARGE, key);
         }
         customMetadata.put(mapKey, value);
       }
diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
index a584df6b0b..776f1c7654 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java
@@ -29,6 +29,7 @@ import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
 import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
 import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
 import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
+import static 
org.apache.hadoop.ozone.OzoneConsts.S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB;
 import static org.apache.hadoop.ozone.s3.util.S3Consts.RANGE_NOT_SATISFIABLE;
 
 /**
@@ -126,6 +127,11 @@ public final class S3ErrorTable {
   public static final OS3Exception NO_OVERWRITE = new OS3Exception(
       "Conflict", "Cannot overwrite file with directory", HTTP_CONFLICT);
 
+  public static final OS3Exception METADATA_TOO_LARGE = new OS3Exception(
+      "MetadataTooLarge", "Illegal user defined metadata. Combined size " +
+      "exceeds the maximum allowed metadata size of " +
+      S3_REQUEST_HEADER_METADATA_SIZE_LIMIT_KB + "KB", HTTP_BAD_REQUEST);
+
   public static OS3Exception newError(OS3Exception e, String resource) {
     return newError(e, resource, null);
   }
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestEndpointBase.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestEndpointBase.java
index 9c1f254b79..ebfe6f83db 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestEndpointBase.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestEndpointBase.java
@@ -26,7 +26,6 @@ import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.s3.exception.OS3Exception;
 import org.junit.Assert;
 import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
 
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
@@ -95,12 +94,13 @@ public class TestEndpointBase {
       public void init() { }
     };
 
-    Exception exception = Assertions.assertThrows(
-            IllegalArgumentException.class,
-            () -> endpointBase.getCustomMetadataFromHeaders(s3requestHeaders));
-    Assert.assertEquals(
-            "Illegal user defined metadata. Combined size cannot exceed 2KB.",
-            exception.getMessage());
+    try {
+      endpointBase.getCustomMetadataFromHeaders(s3requestHeaders);
+      Assert.fail("getCustomMetadataFromHeaders should fail. " +
+          "Expected OS3Exception not thrown");
+    } catch (OS3Exception ex) {
+      Assert.assertTrue(ex.getCode().contains("MetadataTooLarge"));
+    }
   }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to