adoroszlai commented on code in PR #9371: URL: https://github.com/apache/ozone/pull/9371#discussion_r2727019861
########## hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java: ########## @@ -1,88 +0,0 @@ -/* - * 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_CONFLICT; -import static java.net.HttpURLConnection.HTTP_NOT_FOUND; -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; - -/** - * This class test Create Bucket functionality. - */ -public class TestBucketPut { Review Comment: Why is this test class deleted? ########## hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java: ########## @@ -263,4 +279,93 @@ public void testBucketNotExist() throws Exception { bucketEndpoint.get("bucket-not-exist")); assertEquals(e.getHttpCode(), HTTP_NOT_FOUND); } + + @Test + public void testPutAclWithInvalidXmlBody() throws Exception { + InputStream body = new ByteArrayInputStream( + "not-xml".getBytes(StandardCharsets.UTF_8)); + + WebApplicationException wae = assertThrows(WebApplicationException.class, + () -> bucketEndpoint.put(BUCKET_NAME, body)); + + Throwable cause = wae.getCause(); + assertNotNull(cause); + assertTrue(cause instanceof OS3Exception); + OS3Exception os3 = (OS3Exception) cause; + + assertEquals(INVALID_REQUEST.getCode(), os3.getCode()); + assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode()); + } + + @Test + public void testPutAclWithInvalidGrantHeaderValue() throws Exception { + 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(); + + assertTrue(permissions.contains(IAccessAuthorizer.ACLType.READ), + "Expected READ permission from header"); Review Comment: Please use `assertThat(permissions).contains(...)` ########## hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java: ########## @@ -263,4 +279,93 @@ public void testBucketNotExist() throws Exception { bucketEndpoint.get("bucket-not-exist")); assertEquals(e.getHttpCode(), HTTP_NOT_FOUND); } + + @Test + public void testPutAclWithInvalidXmlBody() throws Exception { + InputStream body = new ByteArrayInputStream( + "not-xml".getBytes(StandardCharsets.UTF_8)); + + WebApplicationException wae = assertThrows(WebApplicationException.class, + () -> bucketEndpoint.put(BUCKET_NAME, body)); + + Throwable cause = wae.getCause(); + assertNotNull(cause); + assertTrue(cause instanceof OS3Exception); + OS3Exception os3 = (OS3Exception) cause; Review Comment: Please use `assertInstanceOf`: ```suggestion OS3Exception os3 = assertInstanceOf(OS3Exception.class, wae.getCause()); ``` ########## hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketAcl.java: ########## @@ -263,4 +279,93 @@ public void testBucketNotExist() throws Exception { bucketEndpoint.get("bucket-not-exist")); assertEquals(e.getHttpCode(), HTTP_NOT_FOUND); } + + @Test + public void testPutAclWithInvalidXmlBody() throws Exception { Review Comment: nit: `throws Exception` is unnecessary (also in few other test cases) -- 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]
