chungen0126 commented on code in PR #9371:
URL: https://github.com/apache/ozone/pull/9371#discussion_r2597725416
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithInvalidXmlBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ InputStream body = new ByteArrayInputStream(
+ "not-xml".getBytes(StandardCharsets.UTF_8));
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", body));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
}
@Test
- public void testBucketFailWithInvalidHeader() 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 testPutAclWithMalformedGrantHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id\"owner-id\"");
+
+ OS3Exception ex = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+ assertEquals(400, ex.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithBothHeadersAndBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ // Header: READ
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_READ))
+ .thenReturn("id=owner-id");
+
+ // Body: FULL_CONTROL
+ InputStream body = new ByteArrayInputStream(
+ VALID_ACL_XML.getBytes(StandardCharsets.UTF_8));
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", body);
+ assertEquals(200, resp.getStatus());
Review Comment:
```suggestion
assertEquals(HTTP_OK, resp.getStatus());
```
Use `HTTP_OK` to replace `200`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithInvalidXmlBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ InputStream body = new ByteArrayInputStream(
+ "not-xml".getBytes(StandardCharsets.UTF_8));
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", body));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
}
@Test
- public void testBucketFailWithInvalidHeader() 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 testPutAclWithMalformedGrantHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id\"owner-id\"");
+
+ OS3Exception ex = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+ assertEquals(400, ex.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithBothHeadersAndBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ // Header: READ
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_READ))
+ .thenReturn("id=owner-id");
+
+ // Body: FULL_CONTROL
+ InputStream body = new ByteArrayInputStream(
+ VALID_ACL_XML.getBytes(StandardCharsets.UTF_8));
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", body);
+ assertEquals(200, resp.getStatus());
+
+ OzoneBucket bucket = bucketEndpoint.getClient()
+ .getObjectStore()
+ .getS3Bucket(bucketName);
+
+ 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"));
+
+ assertEquals("owner-id", ownerAcl.getName());
+
+ List<IAccessAuthorizer.ACLType> permissions = ownerAcl.getAclList();
+
+ assertTrue(permissions.contains(IAccessAuthorizer.ACLType.READ),
+ "Expected READ permission from header");
+
+ 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 {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn(""); // empty
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ Assertions.assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithWhitespaceGrantHeaderValue() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn(" "); // whitespace only
+
+ OS3Exception ex = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ Assertions.assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+ Assertions.assertEquals(400, ex.getHttpCode());
Review Comment:
```suggestion
assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode());
```
Use `HTTP_BAD_REQUEST` to replace `400`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithInvalidXmlBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ InputStream body = new ByteArrayInputStream(
+ "not-xml".getBytes(StandardCharsets.UTF_8));
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", body));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
}
@Test
- public void testBucketFailWithInvalidHeader() 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 testPutAclWithMalformedGrantHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id\"owner-id\"");
+
+ OS3Exception ex = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+ assertEquals(400, ex.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithBothHeadersAndBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ // Header: READ
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_READ))
+ .thenReturn("id=owner-id");
+
+ // Body: FULL_CONTROL
+ InputStream body = new ByteArrayInputStream(
+ VALID_ACL_XML.getBytes(StandardCharsets.UTF_8));
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", body);
+ assertEquals(200, resp.getStatus());
+
+ OzoneBucket bucket = bucketEndpoint.getClient()
+ .getObjectStore()
+ .getS3Bucket(bucketName);
+
+ 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"));
+
+ assertEquals("owner-id", ownerAcl.getName());
+
+ List<IAccessAuthorizer.ACLType> permissions = ownerAcl.getAclList();
+
+ assertTrue(permissions.contains(IAccessAuthorizer.ACLType.READ),
+ "Expected READ permission from header");
+
+ 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 {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn(""); // empty
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ Assertions.assertEquals(200, resp.getStatus());
Review Comment:
```suggestion
assertEquals(HTTP_OK, resp.getStatus());
```
Use `HTTP_OK` to replace `200`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
Review Comment:
```suggestion
assertEquals(HTTP_OK, resp.getStatus());
```
Use `HTTP_OK` to replace `200`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,16 +86,36 @@ public void setup() throws Exception {
bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
.setClient(clientStub)
.build();
+
+ mockHeaders = mock(HttpHeaders.class);
+ bucketEndpoint.setHeaders(mockHeaders);
}
@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 testAclWithMissingHeaders() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
Review Comment:
Why do we need to create an S3 bucket before bucket put?
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,16 +86,36 @@ public void setup() throws Exception {
bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
.setClient(clientStub)
.build();
+
+ mockHeaders = mock(HttpHeaders.class);
+ bucketEndpoint.setHeaders(mockHeaders);
}
@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 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);
Review Comment:
Introduce a static string constant to replace all hardcoded instances of
'acl'.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,16 +86,36 @@ public void setup() throws Exception {
bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
.setClient(clientStub)
.build();
+
+ mockHeaders = mock(HttpHeaders.class);
+ bucketEndpoint.setHeaders(mockHeaders);
}
@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 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);
+ assertEquals(200, resp.getStatus());
Review Comment:
```suggestion
assertEquals(HTTP_OK, resp.getStatus());
```
Use `HTTP_OK` to replace `200`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithInvalidXmlBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ InputStream body = new ByteArrayInputStream(
+ "not-xml".getBytes(StandardCharsets.UTF_8));
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", body));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
Review Comment:
```suggestion
assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode());
```
Use `HTTP_BAD_REQUEST` to replace `400`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -51,16 +86,36 @@ public void setup() throws Exception {
bucketEndpoint = EndpointBuilder.newBucketEndpointBuilder()
.setClient(clientStub)
.build();
+
+ mockHeaders = mock(HttpHeaders.class);
+ bucketEndpoint.setHeaders(mockHeaders);
}
@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 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);
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testAclWithMissingHeadersAndNoBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
Review Comment:
```suggestion
assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode());
```
Use `HTTP_BAD_REQUEST` to replace `400`.
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -72,17 +127,125 @@ public void testBucketPut() throws Exception {
// Create-bucket on an existing bucket fails
OS3Exception e = assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
bucketName, null, null));
- assertEquals(HTTP_CONFLICT, e.getHttpCode());
assertEquals(BUCKET_ALREADY_EXISTS.getCode(), e.getCode());
+ assertEquals(HTTP_CONFLICT, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclOnNonExistingBucket() throws Exception {
+ OS3Exception e = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+ assertEquals(NO_SUCH_BUCKET.getCode(), e.getCode());
+ assertEquals(HTTP_NOT_FOUND, e.getHttpCode());
+ }
+
+ @Test
+ public void testPutAclWithGrantFullControlHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id=\"owner-id\"");
+
+ Response resp = bucketEndpoint.put(bucketName, "acl", null);
+
+ assertEquals(200, resp.getStatus());
+ }
+
+ @Test
+ public void testPutAclWithInvalidXmlBody() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ InputStream body = new ByteArrayInputStream(
+ "not-xml".getBytes(StandardCharsets.UTF_8));
+
+ WebApplicationException wae = assertThrows(WebApplicationException.class,
+ () -> bucketEndpoint.put(bucketName, "acl", body));
+
+ Throwable cause = wae.getCause();
+ assertNotNull(cause);
+ assertTrue(cause instanceof OS3Exception);
+ OS3Exception os3 = (OS3Exception) cause;
+
+ assertEquals(INVALID_REQUEST.getCode(), os3.getCode());
+ assertEquals(400, os3.getHttpCode());
}
@Test
- public void testBucketFailWithInvalidHeader() 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 testPutAclWithMalformedGrantHeader() throws Exception {
+ bucketEndpoint.getClient().getObjectStore().createS3Bucket(bucketName);
+
+ when(mockHeaders.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
+ .thenReturn("id\"owner-id\"");
+
+ OS3Exception ex = assertThrows(OS3Exception.class,
+ () -> bucketEndpoint.put(bucketName, "acl", null));
+
+ assertEquals(INVALID_ARGUMENT.getCode(), ex.getCode());
+ assertEquals(400, ex.getHttpCode());
Review Comment:
```suggestion
assertEquals(HTTP_BAD_REQUEST, os3.getHttpCode());
```
Use `HTTP_BAD_REQUEST` to replace `400`.
--
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]