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

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


The following commit(s) were added to refs/heads/HDDS-8342 by this push:
     new 724803f21a0 HDDS-14184. Reject lifecycle configuration if 'Status' is 
missing (#9513)
724803f21a0 is described below

commit 724803f21a08b1e0404ea6623f3e9f9f00c85115
Author: KUAN-HAO HUANG <[email protected]>
AuthorDate: Fri Dec 19 12:55:16 2025 +0800

    HDDS-14184. Reject lifecycle configuration if 'Status' is missing (#9513)
---
 .../s3/endpoint/S3LifecycleConfiguration.java      |  7 ++++++-
 .../endpoint/TestS3LifecycleConfigurationPut.java  | 24 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java
index 8e459281965..193538ced75 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java
@@ -279,7 +279,12 @@ public OmLifecycleConfiguration 
toOmLifecycleConfiguration(OzoneBucket ozoneBuck
    * @param rule the S3 lifecycle rule
    * @return OmLCRule internal rule representation
    */
-  private OmLCRule convertToOmRule(Rule rule) throws OMException {
+  private OmLCRule convertToOmRule(Rule rule) throws OMException, OS3Exception 
{
+    if (rule.getStatus() == null || rule.getStatus().isEmpty()) {
+      throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_XML,
+          "The Status element is required in LifecycleConfiguration");
+    }
+
     OmLCRule.Builder builder = new OmLCRule.Builder()
         .setEnabled("Enabled".equals(rule.getStatus()))
         .setId(rule.getId())
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3LifecycleConfigurationPut.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3LifecycleConfigurationPut.java
index ac0c533bd57..1f5825b8674 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3LifecycleConfigurationPut.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestS3LifecycleConfigurationPut.java
@@ -108,6 +108,17 @@ public void testPutInvalidLifecycleConfiguration() throws 
Exception {
         HTTP_BAD_REQUEST, INVALID_REQUEST.getCode());
   }
 
+  @Test
+  public void testPutLifecycleConfigurationWithoutStatus() throws Exception {
+    try {
+      bucketEndpoint.put("bucket1", null, "", null, withoutStatus());
+      fail("Expected an OS3Exception to be thrown");
+    } catch (OS3Exception ex) {
+      assertEquals(HTTP_BAD_REQUEST, ex.getHttpCode());
+      assertEquals(MALFORMED_XML.getCode(), ex.getCode());
+    }
+  }
+
   private void testInvalidLifecycleConfiguration(Supplier<InputStream> 
inputStream,
       int expectedHttpCode, String expectedErrorCode) throws Exception {
     try {
@@ -200,6 +211,19 @@ private static InputStream withoutAction() {
     return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
   }
 
+  private static InputStream withoutStatus() {
+    String xml = (
+        "<LifecycleConfiguration xmlns=\"http://s3.amazonaws"; +
+        ".com/doc/2006-03-01/\">" +
+        "<Rule>" +
+        "<ID>remove logs after 30 days</ID>" +
+        "<Prefix>prefix/</Prefix>" +
+        "<Expiration><Days>30</Days></Expiration>" +
+        "</Rule>" +
+        "</LifecycleConfiguration>");
+    return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
+  }
+
 
   private static InputStream withoutFilter() {
     String xml =


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

Reply via email to