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

adoroszlai 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 84df32662e4 HDDS-13932. Add test cases for PUT bucket ACL (#9371)
84df32662e4 is described below

commit 84df32662e4b7af23954cdb2fc80b11973e880c1
Author: Russole <[email protected]>
AuthorDate: Tue Jan 27 19:32:48 2026 +0800

    HDDS-13932. Add test cases for PUT bucket ACL (#9371)
---
 .../hadoop/ozone/s3/endpoint/TestBucketAcl.java    | 91 +++++++++++++++++++++-
 .../hadoop/ozone/s3/endpoint/TestBucketPut.java    | 40 ++--------
 2 files changed, 96 insertions(+), 35 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java
index 01bd95c8b53..ba16f7acac4 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java
@@ -17,22 +17,36 @@
 
 package org.apache.hadoop.ozone.s3.endpoint;
 
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
 import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
 import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
 import static java.net.HttpURLConnection.HTTP_OK;
+import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
+import static 
org.apache.hadoop.ozone.s3.endpoint.EndpointTestUtils.assertErrorResponse;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_REQUEST;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneAcl;
 import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.client.OzoneBucket;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneClientStub;
 import org.apache.hadoop.ozone.client.OzoneVolume;
@@ -55,6 +69,7 @@ public class TestBucketAcl {
   private HttpHeaders headers;
   private BucketEndpoint bucketEndpoint;
   private static final String ACL_MARKER = "acl";
+  private static final String WHITESPACE_ONLY = "  ";
 
   @BeforeEach
   public void setup() throws IOException {
@@ -255,7 +270,7 @@ public void testAclInBody() throws Exception {
   }
 
   @Test
-  public void testBucketNotExist() throws Exception {
+  public void testBucketNotExist() {
     when(parameterMap.containsKey(ACL_MARKER)).thenReturn(true);
     when(headers.getHeaderString(S3Acl.GRANT_READ))
         .thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
@@ -263,4 +278,78 @@ public void testBucketNotExist() throws Exception {
         bucketEndpoint.get("bucket-not-exist"));
     assertEquals(e.getHttpCode(), HTTP_NOT_FOUND);
   }
+
+  @Test
+  public void testPutAclWithInvalidXmlBody() {
+    InputStream body = new ByteArrayInputStream(
+        "not-xml".getBytes(StandardCharsets.UTF_8));
+
+    WebApplicationException wae = assertThrows(WebApplicationException.class,
+        () -> bucketEndpoint.put(BUCKET_NAME, body));
+
+    OS3Exception os3 = assertInstanceOf(OS3Exception.class, wae.getCause());
+
+    assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+    assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode());
+  }
+
+  @Test
+  public void testPutAclWithInvalidGrantHeaderValue() {
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn("id\"owner-id\"");
+    assertErrorResponse(INVALID_ARGUMENT, () -> 
bucketEndpoint.put(BUCKET_NAME, null));
+  }
+
+  @Test
+  public void testPutAclWithBothHeadersAndBody() throws Exception {
+    // Header: READ
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=owner-id");
+
+    // Body: FULL_CONTROL (from resource xml)
+    InputStream body = TestBucketAcl.class.getClassLoader()
+        .getResourceAsStream("userAccessControlList.xml");
+    assertNotNull(body, "userAccessControlList.xml not found in test 
resources");
+
+    Response resp = bucketEndpoint.put(BUCKET_NAME, body);
+    assertEquals(HTTP_OK, resp.getStatus());
+
+    OzoneBucket bucket = bucketEndpoint.getClient()
+        .getObjectStore()
+        .getS3Bucket(BUCKET_NAME);
+
+    List<OzoneAcl> acls = bucket.getAcls();
+    assertFalse(acls.isEmpty());
+
+    OzoneAcl ownerAcl = acls.stream()
+        .filter(acl -> "owner-id".equals(acl.getName())
+            && acl.getAclScope() == ACCESS)
+        .findFirst()
+        .orElseThrow(() -> new AssertionError("owner-id ACL not found"));
+
+    List<IAccessAuthorizer.ACLType> permissions = ownerAcl.getAclList();
+
+    assertThat(permissions)
+        .contains(IAccessAuthorizer.ACLType.READ);
+
+    assertFalse(permissions.contains(IAccessAuthorizer.ACLType.ALL),
+        "FULL_CONTROL/ALL from body should not be applied when header is 
present");
+  }
+  
+  @Test
+  public void testPutAclWithEmptyGrantHeaderValue() throws Exception {
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn(""); // empty
+
+    Response resp = bucketEndpoint.put(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, resp.getStatus());
+  }
+
+  @Test
+  public void testPutAclWithWhitespaceGrantHeaderValue() {
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn(WHITESPACE_ONLY); // whitespace only
+    assertErrorResponse(INVALID_ARGUMENT, () -> 
bucketEndpoint.put(BUCKET_NAME, null));
+  }
 }
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java
index 96eea22d9eb..32af79a6270 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java
@@ -17,19 +17,16 @@
 
 package org.apache.hadoop.ozone.s3.endpoint;
 
-import static java.net.HttpURLConnection.HTTP_CONFLICT;
-import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static 
org.apache.hadoop.ozone.s3.endpoint.EndpointTestUtils.assertErrorResponse;
 import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.BUCKET_ALREADY_EXISTS;
-import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.MALFORMED_HEADER;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import javax.ws.rs.core.Response;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneClientStub;
-import org.apache.hadoop.ozone.s3.exception.OS3Exception;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -43,46 +40,21 @@ public class TestBucketPut {
 
   @BeforeEach
   public void setup() throws Exception {
-
-    //Create client stub and object store stub.
     OzoneClient clientStub = new OzoneClientStub();
 
-    // Create HeadBucket and setClient to OzoneClientStub
     bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
         .setClient(clientStub)
         .build();
   }
 
   @Test
-  public void testBucketFailWithAuthHeaderMissing() throws Exception {
-    try {
-      bucketEndpoint.put(bucketName, null);
-    } catch (OS3Exception ex) {
-      assertEquals(HTTP_NOT_FOUND, ex.getHttpCode());
-      assertEquals(MALFORMED_HEADER.getCode(), ex.getCode());
-    }
-  }
-
-  @Test
-  public void testBucketPut() throws Exception {
+  public void testCreateBucketAndFailOnDuplicate() throws Exception {
     Response response = bucketEndpoint.put(bucketName, null);
-    assertEquals(200, response.getStatus());
+    assertEquals(HTTP_OK, response.getStatus());
     assertNotNull(response.getLocation());
 
     // Create-bucket on an existing bucket fails
-    OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
-        bucketName, null));
-    assertEquals(HTTP_CONFLICT, e.getHttpCode());
-    assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
-  }
-
-  @Test
-  public void testBucketFailWithInvalidHeader() throws Exception {
-    try {
-      bucketEndpoint.put(bucketName, null);
-    } catch (OS3Exception ex) {
-      assertEquals(HTTP_NOT_FOUND, ex.getHttpCode());
-      assertEquals(MALFORMED_HEADER.getCode(), ex.getCode());
-    }
+    assertErrorResponse(BUCKET_ALREADY_EXISTS,
+        () -> bucketEndpoint.put(bucketName, null));
   }
 }


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

Reply via email to