diff --git a/src/main/java/org/gaul/s3proxy/S3ErrorCode.java b/src/main/java/org/gaul/s3proxy/S3ErrorCode.java index 895dde6..a86d4d9 100644 --- a/src/main/java/org/gaul/s3proxy/S3ErrorCode.java +++ b/src/main/java/org/gaul/s3proxy/S3ErrorCode.java @@ -75,6 +75,8 @@ enum S3ErrorCode { "The specified bucket does not exist"), NO_SUCH_KEY(HttpServletResponse.SC_NOT_FOUND, "The specified key does not exist."), + NO_SUCH_POLICY(HttpServletResponse.SC_NOT_FOUND, + "The specified bucket does not have a bucket policy."), NO_SUCH_UPLOAD(HttpServletResponse.SC_NOT_FOUND, "Not Found"), NOT_IMPLEMENTED(HttpServletResponse.SC_NOT_IMPLEMENTED, "A header you provided implies functionality that is not" + diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index 0c4a25d..609dc75 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -146,7 +146,6 @@ public class S3ProxyHandler { "logging", "metrics", "notification", - "policy", "replication", "requestPayment", "restore", @@ -657,6 +656,9 @@ public class S3ProxyHandler { } else if ("".equals(request.getParameter("location"))) { handleContainerLocation(response); return; + } else if ("".equals(request.getParameter("policy"))) { + handleBucketPolicy(response, blobStore, path[1]); + return; } else if ("".equals(request.getParameter("uploads"))) { handleListMultipartUploads(request, response, blobStore, path[1]); @@ -1135,6 +1137,14 @@ public class S3ProxyHandler { } } + private static void handleBucketPolicy(HttpServletResponse response, + BlobStore blobStore, String containerName) throws S3Exception { + if (!blobStore.containerExists(containerName)) { + throw new S3Exception(S3ErrorCode.NO_SUCH_BUCKET); + } + throw new S3Exception(S3ErrorCode.NO_SUCH_POLICY); + } + private void handleListMultipartUploads(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String container) throws IOException, S3Exception { diff --git a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java index 5573059..0eb6df4 100644 --- a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java +++ b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java @@ -1443,6 +1443,16 @@ public final class AwsSdkTest { } } + @Test + public void testGetBucketPolicy() throws Exception { + try { + client.getBucketPolicy(containerName); + Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); + } catch (AmazonS3Exception e) { + assertThat(e.getErrorCode()).isEqualTo("NoSuchPolicy"); + } + } + @Test public void testUnknownParameter() throws Exception { try {