Example #1
0
        public void TestGetBucketPolicyStatus_PolicyNotSet()
        {
            try
            {
                //Get the policy status on the bucket
                GetBucketPolicyStatusRequest getRequest = new GetBucketPolicyStatusRequest
                {
                    BucketName = bucketName
                };

                UtilityMethods.WaitUntilException(() =>
                {
                    Client.GetBucketPolicyStatus(getRequest);
                });
            }
            catch (AmazonS3Exception ex)
            {
                Assert.AreEqual <string>("The bucket policy does not exist", ex.Message);
                throw;
            }
        }
        public void TestGetBucketPolicyStatus_IsNotPublic()
        {
            var bucketName = S3TestUtils.CreateBucket(s3Client);

            try
            {
                //Set the bucket policy to not public
                var putRequest = new PutBucketPolicyRequest
                {
                    BucketName = bucketName,
                    Policy     = string.Format(@"{{
                              ""Version"":""2012-10-17"",                                 
                              ""Statement"":[
                                {{
                                  ""Sid"":""AddPerm"",
                                  ""Effect"":""Deny"",
                                  ""Principal"": ""*"",
                                  ""Action"":[""s3:GetObject""],
                                  ""Resource"":[""arn:aws:s3:::{0}/*""]
                                }}
                              ]
                            }}", bucketName)
                };
                s3Client.PutBucketPolicy(putRequest);

                //Get the policy status on the bucket
                GetBucketPolicyStatusRequest getRequest = new GetBucketPolicyStatusRequest
                {
                    BucketName = bucketName
                };

                var getResponse = s3Client.GetBucketPolicyStatus(getRequest);
                Assert.AreEqual(false, getResponse.PolicyStatus.IsPublic);
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
            }
        }
Example #3
0
        public void TestGetBucketPolicyStatus_IsNotPublic()
        {
            //Set the bucket policy to not public
            var putRequest = new PutBucketPolicyRequest
            {
                BucketName = bucketName,
                Policy     = string.Format(@"{{
                              ""Version"":""2012-10-17"",                                 
                              ""Statement"":[
                                {{
                                  ""Sid"":""AddPerm"",
                                  ""Effect"":""Deny"",
                                  ""Principal"": ""*"",
                                  ""Action"":[""s3:GetObject""],
                                  ""Resource"":[""arn:aws:s3:::{0}/*""]
                                }}
                              ]
                            }}", bucketName)
            };

            Client.PutBucketPolicy(putRequest);

            //Get the policy status on the bucket
            GetBucketPolicyStatusRequest getRequest = new GetBucketPolicyStatusRequest
            {
                BucketName = bucketName
            };

            var getResponse = S3TestUtils.WaitForConsistency(() =>
            {
                var res = Client.GetBucketPolicyStatus(getRequest);
                return(res.PolicyStatus?.IsPublic == false ? res : null);
            });

            Assert.AreEqual(false, getResponse.PolicyStatus.IsPublic);
        }
        public void TestGetBucketPolicyStatus_PolicyNotSet()
        {
            var bucketName = S3TestUtils.CreateBucket(s3Client);

            try
            {
                //Get the policy status on the bucket
                GetBucketPolicyStatusRequest getRequest = new GetBucketPolicyStatusRequest
                {
                    BucketName = bucketName
                };

                var getResponse = s3Client.GetBucketPolicyStatus(getRequest);
            }
            catch (AmazonS3Exception ex)
            {
                Assert.AreEqual <string>("The bucket policy does not exist", ex.Message);
                throw;
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
            }
        }
 public Task <GetBucketPolicyStatusResponse> GetBucketPolicyStatusAsync(GetBucketPolicyStatusRequest request, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }