adoroszlai commented on code in PR #9516:
URL: https://github.com/apache/ozone/pull/9516#discussion_r2662123006


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");

Review Comment:
   This can be added in `setup()` to reduce duplication, then unset only in 
`testHandlePutRequestWithoutAclQueryParam`.



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNotNull(response, "Handler should handle request with ?acl param");
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithoutAclQueryParam() throws Exception {
+    // No "acl" query parameter - handler should not handle request
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNull(response, "Handler should return null without ?acl param");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithFullControlHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithMultipleHeaders() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser1\"");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser2\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL with multiple headers should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithUnsupportedGranteeType() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("uri=\"http://example.com\"";);
+
+    OS3Exception exception = assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for unsupported grantee type");
+
+    assertEquals(HTTP_NOT_IMPLEMENTED, exception.getHttpCode(),
+        "Should return NOT_IMPLEMENTED for unsupported grantee type");
+  }
+
+  @Test
+  public void testHandlePutRequestWithEmailAddressType() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("emailAddress=\"[email protected]\"");
+
+    OS3Exception exception = assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for email address grantee type");
+
+    assertEquals(HTTP_NOT_IMPLEMENTED, exception.getHttpCode(),
+        "Should return NOT_IMPLEMENTED for email address grantee type");
+  }
+
+  @Test
+  public void testHandlePutRequestBucketNotFound() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest("nonexistent-bucket", null);
+    }, "Should throw OS3Exception for non-existent bucket");
+  }
+
+  @Test
+  public void testHandlePutRequestWithBody() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    String aclXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+        "<AccessControlPolicy 
xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\";>\n" +
+        "  <Owner>\n" +
+        "    <ID>testowner</ID>\n" +
+        "    <DisplayName>Test Owner</DisplayName>\n" +
+        "  </Owner>\n" +
+        "  <AccessControlList>\n" +
+        "    <Grant>\n" +
+        "      <Grantee 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"; " +
+        "xsi:type=\"CanonicalUser\">\n" +
+        "        <ID>testuser</ID>\n" +
+        "      </Grantee>\n" +
+        "      <Permission>READ</Permission>\n" +
+        "    </Grant>\n" +
+        "  </AccessControlList>\n" +
+        "</AccessControlPolicy>";
+
+    InputStream body = new ByteArrayInputStream(
+        aclXml.getBytes(StandardCharsets.UTF_8));
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, body);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL with body should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithInvalidHeaderFormat() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("invalid-format");
+
+    assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for invalid header format");
+  }
+
+  @Test
+  public void testHandlePutRequestWithMultipleGrantees() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"user1\",id=\"user2\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL with multiple grantees should return 200 OK");
+  }
+
+  @Test
+  public void testPutAclReplacesExistingAcls() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+
+    // Set initial ACL
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"user1\"");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn(null);
+
+    aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    // Replace with new ACL
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn(null);
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"user2\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should replace existing ACLs");
+  }
+
+  @Test
+  public void testAuditLoggingOnBucketNotFound() throws Exception {
+    // Create a spy of AclHandler to verify audit logging
+    AclHandler spyHandler = spy(EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build());

Review Comment:
   We can `spy(aclHandler)`, no need to create new instance.



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNotNull(response, "Handler should handle request with ?acl param");
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithoutAclQueryParam() throws Exception {
+    // No "acl" query parameter - handler should not handle request
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNull(response, "Handler should return null without ?acl param");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser\"");

Review Comment:
   `testHandlePutRequestWithReadHeader`, `testHandlePutRequestWithWriteHeader`, 
`testHandlePutRequestWithReadAcpHeader`, 
`testHandlePutRequestWithWriteAcpHeader`, 
`testHandlePutRequestWithFullControlHeader` can be combined into a single 
`@ParameterizedTest`.



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNotNull(response, "Handler should handle request with ?acl param");
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithoutAclQueryParam() throws Exception {
+    // No "acl" query parameter - handler should not handle request
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNull(response, "Handler should return null without ?acl param");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");

Review Comment:
   Can simplify a bit:
   
   ```java
   assertSucceeds(() -> aclHandler.handlePutRequest(BUCKET_NAME, null));
   ```



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNotNull(response, "Handler should handle request with ?acl param");
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithoutAclQueryParam() throws Exception {
+    // No "acl" query parameter - handler should not handle request
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNull(response, "Handler should return null without ?acl param");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithFullControlHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithMultipleHeaders() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser1\"");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser2\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL with multiple headers should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithUnsupportedGranteeType() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("uri=\"http://example.com\"";);
+
+    OS3Exception exception = assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for unsupported grantee type");

Review Comment:
   nit: `{}` is unnecessary (in all `assertThrows` calls).



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestAclHandler.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.S3GAction;
+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.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for AclHandler.
+ */
+public class TestAclHandler {
+
+  private static final String BUCKET_NAME = OzoneConsts.S3_BUCKET;
+  private OzoneClient client;
+  private AclHandler aclHandler;
+  private HttpHeaders headers;
+
+  @BeforeEach
+  public void setup() throws IOException {
+    client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(BUCKET_NAME);
+
+    headers = mock(HttpHeaders.class);
+
+    // Build AclHandler using EndpointBuilder since it extends EndpointBase
+    aclHandler = EndpointBuilder.newAclHandlerBuilder()
+        .setClient(client)
+        .setHeaders(headers)
+        .build();
+  }
+
+  @AfterEach
+  public void clean() throws IOException {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Test
+  public void testHandlePutRequestWithAclQueryParam() throws Exception {
+    // Set up query parameter to indicate ACL operation
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNotNull(response, "Handler should handle request with ?acl param");
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithoutAclQueryParam() throws Exception {
+    // No "acl" query parameter - handler should not handle request
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertNull(response, "Handler should return null without ?acl param");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithReadAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithWriteAcpHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE_ACP))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithFullControlHeader() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn("id=\"testuser\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithMultipleHeaders() throws Exception {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("id=\"testuser1\"");
+    when(headers.getHeaderString(S3Acl.GRANT_WRITE))
+        .thenReturn("id=\"testuser2\"");
+
+    Response response = aclHandler.handlePutRequest(BUCKET_NAME, null);
+
+    assertEquals(HTTP_OK, response.getStatus(),
+        "PUT ACL with multiple headers should return 200 OK");
+  }
+
+  @Test
+  public void testHandlePutRequestWithUnsupportedGranteeType() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("uri=\"http://example.com\"";);
+
+    OS3Exception exception = assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for unsupported grantee type");
+
+    assertEquals(HTTP_NOT_IMPLEMENTED, exception.getHttpCode(),
+        "Should return NOT_IMPLEMENTED for unsupported grantee type");
+  }
+
+  @Test
+  public void testHandlePutRequestWithEmailAddressType() {
+    aclHandler.queryParamsForTest().set("acl", "");
+    when(headers.getHeaderString(S3Acl.GRANT_READ))
+        .thenReturn("emailAddress=\"[email protected]\"");
+
+    OS3Exception exception = assertThrows(OS3Exception.class, () -> {
+      aclHandler.handlePutRequest(BUCKET_NAME, null);
+    }, "Should throw OS3Exception for email address grantee type");
+
+    assertEquals(HTTP_NOT_IMPLEMENTED, exception.getHttpCode(),
+        "Should return NOT_IMPLEMENTED for email address grantee type");

Review Comment:
   These can be simplified to:
   
   ```java
   assertErrorResponse(S3ErrorTable.NOT_IMPLEMENTED,
       () -> aclHandler.handlePutRequest(BUCKET_NAME, null));
   ```



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