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


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,6 +89,36 @@ public void setup() throws Exception {
     bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
         .setClient(clientStub)
         .build();
+
+    mockHeaders = mock(HttpHeaders.class);
+    bucketEndpoint.setHeaders(mockHeaders);
+  }
+
+  @Test
+  public void testAclWithMissingHeaders() throws Exception {
+    bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+    InputStream body = new 
ByteArrayInputStream(VALID_ACL_XML.getBytes(StandardCharsets.UTF_8));
+
+    Response resp = bucketEndpoint.putAcl(bucketName, body);
+    assertEquals(HTTP_OK, resp.getStatus());

Review Comment:
   Now we have helper method to simplify this.
   
   ```java
   assertSucceeds(() -> bucketEndpoint.put(bucketName, body));
   ```



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -85,4 +245,30 @@ public void testBucketFailWithInvalidHeader() throws 
Exception {
       assertEquals(MALFORMED_HEADER.getCode(), ex.getCode());
     }
   }
+
+  @Test
+  public void testPutAclWithEmptyGrantHeaderValue() throws Exception {
+    bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+    when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn(""); // empty
+
+    Response resp = bucketEndpoint.putAcl(bucketName, null);
+
+    assertEquals(HTTP_OK, resp.getStatus());
+  }
+
+  @Test
+  public void testPutAclWithWhitespaceGrantHeaderValue() throws Exception {
+    bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+    when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+        .thenReturn(WHITESPACE_ONLY); // whitespace only
+
+    OS3Exception ex = assertThrows(OS3Exception.class,
+        () -> bucketEndpoint.putAcl(bucketName, null));
+
+    assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+    assertEquals(HTTP_BAD_REQUEST, ex.getHttpCode());

Review Comment:
   Now we have helper to simplify this:
   
   ```java
   assertErrorResponse(INVALID_ARGUMENT, () -> bucketEndpoint.put(bucketName, 
null));
   ```



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,16 +80,36 @@ public void setup() throws Exception {
     bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
         .setClient(clientStub)
         .build();
+
+    mockHeaders = mock(HttpHeaders.class);
+    bucketEndpoint.setHeaders(mockHeaders);
+  }
+
+  @Test
+  public void testAclWithMissingHeaders() throws Exception {
+    bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+    InputStream body = new 
ByteArrayInputStream(VALID_ACL_XML.getBytes(StandardCharsets.UTF_8));
+
+    Response resp = bucketEndpoint.put(bucketName, "acl", body);
+    Assertions.assertEquals(200, resp.getStatus());
   }
 
   @Test
-  public void testBucketFailWithAuthHeaderMissing() throws Exception {
-    try {
-      bucketEndpoint.put(bucketName, null, null);
-    } catch (OS3Exception ex) {
-      assertEquals(HTTP_NOT_FOUND, ex.getHttpCode());
-      assertEquals(MALFORMED_HEADER.getCode(), ex.getCode());
-    }
+  public void testAclWithMissingHeadersAndNoBody() throws Exception {

Review Comment:
   This test case `...MissingHeadersAndNoBody` is no longer necessary.



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