CreateBucketWithWait() публичный статический Метод

public static CreateBucketWithWait ( IAmazonS3 s3Client ) : string
s3Client IAmazonS3
Результат string
Пример #1
0
        public void TestKmsOverHttp()
        {
            var config = new AmazonS3Config
            {
                RegionEndpoint = AWSConfigs.RegionEndpoint,
                UseHttp        = true
            };

            using (var client = new AmazonS3Client(config))
            {
                var bucketName = S3TestUtils.CreateBucketWithWait(client);
                try
                {
                    var putObjectRequest = new PutObjectRequest
                    {
                        BucketName  = bucketName,
                        Key         = key,
                        ContentBody = testContents,
                        ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS
                    };
                    Action action = () =>
                    {
                        client.PutObject(putObjectRequest);
                    };

                    AssertExtensions.ExpectException(action, typeof(AmazonClientException));
                }
                finally
                {
                    AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                }
            }
        }
 public static void Initialize(TestContext a)
 {
     bucketName = S3TestUtils.CreateBucketWithWait(Client, new PutBucketRequest
     {
         ObjectLockEnabledForBucket = true
     });
 }
Пример #3
0
        public void PutAndGetEventBridgeConfigurationTest()
        {
            using (var s3Client = new AmazonS3Client())
            {
                var bucketName = S3TestUtils.CreateBucketWithWait(s3Client);

                try
                {
                    var putRequest = new PutBucketNotificationRequest()
                    {
                        BucketName = bucketName,
                        EventBridgeConfiguration  = new EventBridgeConfiguration(),
                        SkipDestinationValidation = true
                    };

                    var putResponse = s3Client.PutBucketNotification(putRequest);

                    Assert.AreEqual(HttpStatusCode.OK, putResponse.HttpStatusCode);

                    var getRequest = new GetBucketNotificationRequest
                    {
                        BucketName = bucketName
                    };

                    var getResponse = s3Client.GetBucketNotification(getRequest);

                    Assert.IsNotNull(getResponse.EventBridgeConfiguration);
                }
                finally
                {
                    AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                }
            }
        }
Пример #4
0
        public void TestPostUpload()
        {
            var region = RegionEndpoint.USWest1;

            using (var client = new AmazonS3Client(region))
            {
                var bucketName = S3TestUtils.CreateBucketWithWait(client);
                client.PutACL(new PutACLRequest
                {
                    BucketName = bucketName,
                    CannedACL  = S3CannedACL.BucketOwnerFullControl
                });

                var credentials = GetCredentials(client);
                try
                {
                    var response = testPost("foo/bar/content.txt", bucketName, testContentStream("Line one\nLine two\nLine three\n"), "", credentials, region);
                    Assert.IsNotNull(response.RequestId);
                    Assert.IsNotNull(response.HostId);
                    Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
                }
                finally
                {
                    AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                }
            }
        }
Пример #5
0
        private static void CreateBucketWithObjectLockConfiguration()
        {
            bucketName = S3TestUtils.CreateBucketWithWait(Client, new PutBucketRequest
            {
                ObjectLockEnabledForBucket = true,
            });

            var objectLockConfiguration = new ObjectLockConfiguration();

            objectLockConfiguration.ObjectLockEnabled = ObjectLockEnabled.Enabled;
            objectLockConfiguration.Rule = new ObjectLockRule
            {
                DefaultRetention = new DefaultRetention
                {
                    Days = 1,
                    Mode = ObjectLockRetentionMode.Governance
                }
            };

            var putRequest = new PutObjectLockConfigurationRequest
            {
                BucketName              = bucketName,
                RequestPayer            = RequestPayer.Requester,
                ObjectLockConfiguration = objectLockConfiguration
            };

            var putResponse = Client.PutObjectLockConfiguration(putRequest);
        }
Пример #6
0
        public static void Initialize(TestContext a)
        {
            var config = new AmazonS3Config();

            s3Client   = new AmazonS3Client(config);
            bucketName = S3TestUtils.CreateBucketWithWait(s3Client);
        }
Пример #7
0
        public void GetObjectFromDefaultEndpointBeforeDNSResolution()
        {
            var client = new AmazonS3Client(RegionEndpoint.USWest2);
            var defaultEndpointClient = new AmazonS3Client(RegionEndpoint.USEast1);
            var bucketName            = S3TestUtils.CreateBucketWithWait(client);

            try
            {
                var putObjectRequest = new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = testContents,
                    ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS
                };
                client.PutObject(putObjectRequest);

                using (var response = defaultEndpointClient.GetObject(bucketName, key))
                    using (var reader = new StreamReader(response.ResponseStream))
                    {
                        var data = reader.ReadToEnd();
                        Assert.AreEqual(testContents, data);
                    }
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                client.Dispose();
                defaultEndpointClient.Dispose();
            }
        }
Пример #8
0
        public static void Setup(TestContext context)
        {
            _bucketName = S3TestUtils.CreateBucketWithWait(Client);
            _mrapName   = UtilityMethods.SDK_TEST_PREFIX + DateTime.Now.Ticks;

            // Look up the account ID for the credentials being used to run the tests
            _accountId = new AmazonSecurityTokenServiceClient().GetCallerIdentity(new GetCallerIdentityRequest()).Account;

            var request = new CreateMultiRegionAccessPointRequest
            {
                AccountId = _accountId,
                Details   = new CreateMultiRegionAccessPointInput
                {
                    Name    = _mrapName,
                    Regions = new List <Region>
                    {
                        new Region
                        {
                            Bucket = _bucketName
                        }
                    }
                }
            };

            // All MRAP control plane requests must go to us-west-2 per
            // https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManagingMultiRegionAccessPoints.html
            var mrapAlias = S3TestUtils.CreateMRAPWithWait(new AmazonS3ControlClient(RegionEndpoint.USWest2), request);

            _mrapArn = $"arn:aws:s3::{_accountId}:accesspoint/{mrapAlias}";
        }
Пример #9
0
        public void ServerSideEncryptionBYOKTransferUtility()
        {
            var bucketName = S3TestUtils.CreateBucketWithWait(Client);

            try
            {
                Aes aesEncryption = Aes.Create();
                aesEncryption.KeySize = 256;
                aesEncryption.GenerateKey();
                string base64Key = Convert.ToBase64String(aesEncryption.Key);

                TransferUtility utility = new TransferUtility(Client);

                var uploadRequest = new TransferUtilityUploadRequest
                {
                    BucketName = bucketName,
                    Key        = key,
                    ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey = base64Key
                };

                uploadRequest.InputStream = new MemoryStream(UTF8Encoding.UTF8.GetBytes("Encrypted Content"));

                utility.Upload(uploadRequest);

                GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest
                {
                    BucketName = bucketName,
                    Key        = key,

                    ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey = base64Key
                };

                GetObjectMetadataResponse getObjectMetadataResponse = Client.GetObjectMetadata(getObjectMetadataRequest);
                Assert.AreEqual(ServerSideEncryptionCustomerMethod.AES256, getObjectMetadataResponse.ServerSideEncryptionCustomerMethod);

                var openRequest = new TransferUtilityOpenStreamRequest
                {
                    BucketName = bucketName,
                    Key        = key,

                    ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey = base64Key
                };

                using (var stream = new StreamReader(utility.OpenStream(openRequest)))
                {
                    var content = stream.ReadToEnd();
                    Assert.AreEqual(content, "Encrypted Content");
                }
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(Client, bucketName);
            }
        }
Пример #10
0
        public void TestInitialize()
        {
            transferClient = new TransferUtility(Client);

            tempFilePath = System.IO.Path.GetTempFileName();
            bucketName   = S3TestUtils.CreateBucketWithWait(Client);

            UtilityMethods.GenerateFile(tempFilePath, 1024 * 1024 * 20);
        }
Пример #11
0
        public void SetTopicConfigurationTests()
        {
            var s3Config = new AmazonS3Config();

            using (var s3Client = new AmazonS3Client(s3Config))
                using (var snsClient = new AmazonSimpleNotificationServiceClient())
                {
                    var snsCreateResponse = snsClient.CreateTopic("events-test-" + DateTime.Now.Ticks);
                    var bucketName        = S3TestUtils.CreateBucketWithWait(s3Client);

                    try
                    {
                        snsClient.AuthorizeS3ToPublish(snsCreateResponse.TopicArn, bucketName);

                        PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest
                        {
                            BucketName          = bucketName,
                            TopicConfigurations = new List <TopicConfiguration>
                            {
                                new TopicConfiguration
                                {
                                    Id     = "the-topic-test",
                                    Topic  = snsCreateResponse.TopicArn,
                                    Events = new List <EventType> {
                                        EventType.ObjectCreatedPut
                                    }
                                }
                            }
                        };

                        s3Client.PutBucketNotification(putRequest);

                        var getResponse = S3TestUtils.WaitForConsistency(() =>
                        {
                            var res = s3Client.GetBucketNotification(bucketName);
                            return(res.TopicConfigurations?.Count > 0 && res.TopicConfigurations[0].Id == "the-topic-test" ? res : null);
                        });

                        Assert.AreEqual(1, getResponse.TopicConfigurations.Count);
                        Assert.AreEqual(1, getResponse.TopicConfigurations[0].Events.Count);
                        Assert.AreEqual(EventType.ObjectCreatedPut, getResponse.TopicConfigurations[0].Events[0]);

#pragma warning disable 618
                        Assert.AreEqual("s3:ObjectCreated:Put", getResponse.TopicConfigurations[0].Event);
#pragma warning restore 618
                        Assert.AreEqual("the-topic-test", getResponse.TopicConfigurations[0].Id);
                        Assert.AreEqual(snsCreateResponse.TopicArn, getResponse.TopicConfigurations[0].Topic);
                    }
                    finally
                    {
                        snsClient.DeleteTopic(snsCreateResponse.TopicArn);
                        AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                    }
                }
        }
Пример #12
0
        public static void Initialize(TestContext a)
        {
            bucketName = S3TestUtils.CreateBucketWithWait(Client);

            Client.PutObject(new PutObjectRequest
            {
                BucketName  = bucketName,
                ContentBody = content,
                Key         = "TestObject"
            });
        }
Пример #13
0
        public static void Initialize(TestContext testContext)
        {
            _bucketName = S3TestUtils.CreateBucketWithWait(Client);
            _keyName    = UtilityMethods.GenerateName(nameof(SelectObjectContentTests));

            Client.PutObject(new PutObjectRequest()
            {
                BucketName  = _bucketName,
                Key         = _keyName,
                ContentBody = TestContent
            });
        }
Пример #14
0
        public void DeleteBucketUsingS3RegionUSEast1Enum()
        {
            using (var runner = new BucketRegionTestRunner(true, true))
            {
                var bucketName = S3TestUtils.CreateBucketWithWait(runner.USEast1Client);

                runner.USWest1Client.DeleteBucket(new DeleteBucketRequest
                {
                    BucketName   = bucketName,
                    BucketRegion = S3Region.US
                });
            }
        }
        private string CreateBucketAndObject(AmazonS3Client client)
        {
            var bucketName = S3TestUtils.CreateBucketWithWait(client);

            client.PutObject(new PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = TestKey,
                ContentBody = TestContent
            });
            S3TestUtils.WaitForObject(client, bucketName, TestKey, 30);
            return(bucketName);
        }
Пример #16
0
        public void Initialize()
        {
            usEastClient   = new AmazonS3Client(RegionEndpoint.USEast1);
            eastBucketName = S3TestUtils.CreateBucketWithWait(usEastClient);
            usEastClient.PutObject(new PutObjectRequest
            {
                BucketName  = eastBucketName,
                Key         = testKey,
                ContentBody = testContent
            });
            var usWestClient = new AmazonS3Client(RegionEndpoint.USWest1);

            westBucketName = S3TestUtils.CreateBucketWithWait(usWestClient);
        }
Пример #17
0
        public static void Initialize(TestContext a)
        {
            bucketName = S3TestUtils.CreateBucketWithWait(Client);

            foreach (var key in keys)
            {
                if (key.EndsWith("/"))
                {
                    continue;
                }

                Client.PutObject(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = content
                });
            }
        }
Пример #18
0
        public static void Setup(TestContext context)
        {
            using (var stsClient = new AmazonSecurityTokenServiceClient())
                using (var s3ControlClient = new AmazonS3ControlClient())
                {
                    _accountId = stsClient.GetCallerIdentity(new GetCallerIdentityRequest()).Account;

                    _bucketName = S3TestUtils.CreateBucketWithWait(Client);

                    var response = s3ControlClient.CreateAccessPoint(new CreateAccessPointRequest
                    {
                        AccountId = _accountId,
                        Bucket    = _bucketName,
                        Name      = _accesspointName
                    });

                    _accesspointArn = new Arn {
                        AccountId = _accountId, Partition = "aws", Region = s3ControlClient.Config.RegionEndpoint.SystemName, Service = "s3", Resource = "accesspoint:" + _accesspointName
                    }.ToString();
                }
        }
Пример #19
0
        public static void Initialize(TestContext tc)
        {
            bucketName = S3TestUtils.CreateBucketWithWait(Client);
            Client.PutBucketVersioning(new PutBucketVersioningRequest
            {
                BucketName       = bucketName,
                VersioningConfig = new S3BucketVersioningConfig
                {
                    Status = VersionStatus.Enabled
                }
            });

            S3TestUtils.WaitForConsistency(() =>
            {
                var res = Client.GetBucketVersioning(new GetBucketVersioningRequest
                {
                    BucketName = bucketName
                });
                return(res.VersioningConfig?.Status == VersionStatus.Enabled ? res : null);
            });
        }
Пример #20
0
        public void TestLocation()
        {
            // Disable EUW2 for now until we figure out why we are hitting the bucket number limit.
            foreach (var location in new S3Region[] { S3Region.USW1, S3Region.EUC1, S3Region.EUW1 /*, S3Region.EUW2*/ })
            {
                string bucketName = null;
                var    region     = RegionEndpoint.GetBySystemName(location.Value);

                using (var client = new AmazonS3Client(region))
                {
                    try
                    {
                        bucketName = S3TestUtils.CreateBucketWithWait(client);
                        var returnedLocation = client.GetBucketLocation(new GetBucketLocationRequest
                        {
                            BucketName = bucketName
                        }).Location;

                        //Map S3Region.EUW1 to S3Region.EU
                        //S3 considers this as the same region.
                        if (location == S3Region.EUW1)
                        {
                            Assert.AreEqual(S3Region.EU, returnedLocation);
                        }
                        else
                        {
                            Assert.AreEqual(location, returnedLocation);
                        }
                    }
                    finally
                    {
                        if (bucketName != null)
                        {
                            AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                        }
                    }
                }
            }
        }
Пример #21
0
        public static void Initialize(TestContext a)
        {
            using (var kmsClient = new AmazonKeyManagementServiceClient())
            {
                var response = kmsClient.CreateKey(new CreateKeyRequest
                {
                    Description = "Key for .NET integration tests.",
                    Origin      = OriginType.AWS_KMS,
                    KeyUsage    = KeyUsageType.ENCRYPT_DECRYPT
                });
                kmsKeyID = response.KeyMetadata.KeyId;
            }

            var encryptionMaterials    = new EncryptionMaterials(RSA.Create());
            var kmsEncryptionMaterials = new EncryptionMaterials(kmsKeyID);

            AmazonS3CryptoConfiguration config = new AmazonS3CryptoConfiguration()
            {
                StorageMode = CryptoStorageMode.InstructionFile
            };

            s3EncryptionClientMetadataMode = new AmazonS3EncryptionClient(encryptionMaterials);
            RetryUtilities.ForceConfigureClient(s3EncryptionClientMetadataMode);

            s3EncryptionClientFileMode = new AmazonS3EncryptionClient(config, encryptionMaterials);
            RetryUtilities.ForceConfigureClient(s3EncryptionClientFileMode);

            s3EncryptionClientMetadataModeKMS = new AmazonS3EncryptionClient(kmsEncryptionMaterials);
            RetryUtilities.ForceConfigureClient(s3EncryptionClientMetadataModeKMS);

            s3EncryptionClientFileModeKMS = new AmazonS3EncryptionClient(config, kmsEncryptionMaterials);
            RetryUtilities.ForceConfigureClient(s3EncryptionClientFileModeKMS);

            using (StreamWriter writer = File.CreateText(filePath))
            {
                writer.Write(sampleContent);
            }
            bucketName = S3TestUtils.CreateBucketWithWait(s3EncryptionClientFileMode);
        }
Пример #22
0
        public void Test301RedirectTriggersException()
        {
            var uswest2Client    = new AmazonS3Client(RegionEndpoint.USWest2);
            var eucentral1Client = new AmazonS3Client(RegionEndpoint.EUCentral1);

            // there is no distinction given for buckets that have not had DNS
            // propagated yet so a new bucket will suffice
            var bucketName = S3TestUtils.CreateBucketWithWait(eucentral1Client);

            try
            {
                var response = uswest2Client.PutObject(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = "test.txt",
                    ContentBody = "some stuff"
                });
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(eucentral1Client, bucketName);
            }
        }
Пример #23
0
 public void ListMultipartUploadsTest(int maxUploads)
 {
     try
     {
         // hacky way to get the test to accept a random int as a parameter
         if (maxUploads != 1)
         {
             maxUploads = _num;
         }
         AmazonS3Util.DeleteS3BucketWithObjects(Client, _bucketName);
         _bucketName = S3TestUtils.CreateBucketWithWait(Client);
         var count = 0;
         for (var x = 0; x < 50; x++)
         {
             CreateMultipartUpload(x);
         }
         var request = new ListMultipartUploadsRequest
         {
             BucketName = _bucketName,
             MaxUploads = maxUploads
         };
         var paginator = Client.Paginators.ListMultipartUploads(request);
         foreach (var upload in paginator.Uploads)
         {
             // uploads are listed in alphabetical order
             // with 10 before 2 so not validating
             // exact name of file
             ValidateMultipartUpload(upload);
             count++;
         }
         Assert.AreEqual(50, count);
     }
     catch
     {
         Assert.Fail();
     }
 }
Пример #24
0
        public void TestPresignedUrls(string keyId)
        {
            var oldSigV4 = AWSConfigsS3.UseSignatureVersion4;

            AWSConfigsS3.UseSignatureVersion4 = true;

            using (var newClient = new AmazonS3Client())
            {
                var bucketName = S3TestUtils.CreateBucketWithWait(newClient);
                try
                {
                    VerifyPresignedPut(bucketName, key, keyId);
                    VerifyObjectWithTransferUtility(bucketName);
                    TestPresignedGet(bucketName, key, keyId);

                    var key2         = key + "Copy2";
                    var copyResponse = newClient.CopyObject(new CopyObjectRequest
                    {
                        SourceBucket      = bucketName,
                        SourceKey         = key,
                        DestinationBucket = bucketName,
                        DestinationKey    = key2,
                        // No KMS values set
                        //ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS,
                        //ServerSideEncryptionKeyManagementServiceKeyId = keyId
                    });
                    Assert.IsNotNull(copyResponse);
                    var usedKeyId = copyResponse.ServerSideEncryptionKeyManagementServiceKeyId;
                    Assert.IsNull(usedKeyId);
                }
                finally
                {
                    AmazonS3Util.DeleteS3BucketWithObjects(newClient, bucketName);
                    AWSConfigsS3.UseSignatureVersion4 = oldSigV4;
                }
            }
        }
Пример #25
0
        public static void Initialize(TestContext a)
        {
            s3Client   = new AmazonS3Client(TestRegionEndpoint);
            bucketName = S3TestUtils.CreateBucketWithWait(s3Client);
            BucketAccelerateStatus bucketStatus = null;

            s3Client.PutBucketAccelerateConfiguration(new PutBucketAccelerateConfigurationRequest
            {
                BucketName = bucketName,
                AccelerateConfiguration = new AccelerateConfiguration
                {
                    Status = BucketAccelerateStatus.Enabled
                }
            });

            var response = S3TestUtils.WaitForConsistency(() =>
            {
                var res = s3Client.GetBucketAccelerateConfiguration(bucketName);
                return(res.Status == BucketAccelerateStatus.Enabled ? res : null);
            });

            bucketStatus = response.Status;
            Assert.AreEqual(BucketAccelerateStatus.Enabled, bucketStatus);
        }
Пример #26
0
        public void TestAWS2ToAWS4RedirectBeforeDNSPropagation()
        {
            var useast1Client    = new AmazonS3Client(RegionEndpoint.USEast1);
            var eucentral1Client = new AmazonS3Client(RegionEndpoint.EUCentral1);

            var bucketName = S3TestUtils.CreateBucketWithWait(eucentral1Client);

            try
            {
                var response = useast1Client.PutObject(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = "test.txt",
                    ContentBody = "some stuff"
                });

                Assert.IsNotNull(response);
                Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(eucentral1Client, bucketName);
            }
        }
Пример #27
0
 public static void Initialize(TestContext a)
 {
     bucketName = S3TestUtils.CreateBucketWithWait(Client);
 }
Пример #28
0
 public static void ClassInitialize(TestContext a)
 {
     bucketName = S3TestUtils.CreateBucketWithWait(Client);
     fullPath   = Path.GetFullPath(testFile);
     File.WriteAllText(fullPath, testContent);
 }
 public void Init()
 {
     bucketName = S3TestUtils.CreateBucketWithWait(Client);
 }
Пример #30
0
        public void ServerSideEncryptionBYOKPutAndGet()
        {
            var bucketName = S3TestUtils.CreateBucketWithWait(Client);

            try
            {
                Aes aesEncryption = Aes.Create();
                aesEncryption.KeySize = 256;
                aesEncryption.GenerateKey();
                string base64Key    = Convert.ToBase64String(aesEncryption.Key);
                string base64KeyMd5 = ComputeEncodedMD5FromEncodedString(base64Key);

                PutObjectRequest putRequest = new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = "The Data To Encrypt in S3",

                    ServerSideEncryptionCustomerMethod         = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey    = base64Key,
                    ServerSideEncryptionCustomerProvidedKeyMD5 = base64KeyMd5
                };

                Client.PutObject(putRequest);

                GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest
                {
                    BucketName = bucketName,
                    Key        = key,

                    ServerSideEncryptionCustomerMethod         = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey    = base64Key,
                    ServerSideEncryptionCustomerProvidedKeyMD5 = base64KeyMd5
                };

                GetObjectMetadataResponse getObjectMetadataResponse = Client.GetObjectMetadata(getObjectMetadataRequest);
                Assert.AreEqual(ServerSideEncryptionCustomerMethod.AES256, getObjectMetadataResponse.ServerSideEncryptionCustomerMethod);

                GetObjectRequest getObjectRequest = new GetObjectRequest
                {
                    BucketName = bucketName,
                    Key        = key,

                    ServerSideEncryptionCustomerMethod         = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey    = base64Key,
                    ServerSideEncryptionCustomerProvidedKeyMD5 = base64KeyMd5
                };

                using (GetObjectResponse getResponse = Client.GetObject(getObjectRequest))
                    using (StreamReader reader = new StreamReader(getResponse.ResponseStream))
                    {
                        string content = reader.ReadToEnd();
                        Assert.AreEqual(putRequest.ContentBody, content);
                        Assert.AreEqual(ServerSideEncryptionCustomerMethod.AES256, getResponse.ServerSideEncryptionCustomerMethod);
                    }

                GetPreSignedUrlRequest getPresignedUrlRequest = new GetPreSignedUrlRequest
                {
                    BucketName = bucketName,
                    Key        = key,
                    ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256,
                    Expires = DateTime.Now.AddMinutes(5)
                };
                var url        = Client.GetPreSignedURL(getPresignedUrlRequest);
                var webRequest = HttpWebRequest.Create(url);
                webRequest.Headers.Add("x-amz-server-side-encryption-customer-algorithm", "AES256");
                webRequest.Headers.Add("x-amz-server-side-encryption-customer-key", base64Key);
                webRequest.Headers.Add("x-amz-server-side-encryption-customer-key-MD5", base64KeyMd5);

                using (var response = webRequest.GetResponse())
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        var contents = reader.ReadToEnd();
                        Assert.AreEqual(putRequest.ContentBody, contents);
                    }

                aesEncryption.GenerateKey();
                string copyBase64Key = Convert.ToBase64String(aesEncryption.Key);

                CopyObjectRequest copyRequest = new CopyObjectRequest
                {
                    SourceBucket      = bucketName,
                    SourceKey         = key,
                    DestinationBucket = bucketName,
                    DestinationKey    = "EncryptedObject_Copy",

                    CopySourceServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    CopySourceServerSideEncryptionCustomerProvidedKey = base64Key,
                    ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey = copyBase64Key
                };
                Client.CopyObject(copyRequest);

                getObjectMetadataRequest = new GetObjectMetadataRequest
                {
                    BucketName = bucketName,
                    Key        = "EncryptedObject_Copy",

                    ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.AES256,
                    ServerSideEncryptionCustomerProvidedKey = copyBase64Key
                };

                getObjectMetadataResponse = Client.GetObjectMetadata(getObjectMetadataRequest);
                Assert.AreEqual(ServerSideEncryptionCustomerMethod.AES256, getObjectMetadataResponse.ServerSideEncryptionCustomerMethod);

                // Test calls against HTTP client, some should fail on the client
                using (var httpClient = CreateHttpClient())
                {
                    getObjectMetadataRequest.ServerSideEncryptionCustomerMethod      = ServerSideEncryptionCustomerMethod.None;
                    getObjectMetadataRequest.ServerSideEncryptionCustomerProvidedKey = null;
                    AssertExtensions.ExpectException(() =>
                                                     httpClient.GetObjectMetadata(getObjectMetadataRequest), typeof(AmazonS3Exception));

                    getObjectMetadataRequest.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256;
                    AssertExtensions.ExpectException(() =>
                                                     httpClient.GetObjectMetadata(getObjectMetadataRequest), typeof(AmazonS3Exception));

                    getObjectMetadataRequest.ServerSideEncryptionCustomerProvidedKey = copyBase64Key;
                    AssertExtensions.ExpectException(() =>
                                                     httpClient.GetObjectMetadata(getObjectMetadataRequest), typeof(Amazon.Runtime.AmazonClientException));

                    url = httpClient.GetPreSignedURL(getPresignedUrlRequest);
                    Assert.IsFalse(string.IsNullOrEmpty(url));
                }
            }
            finally
            {
                AmazonS3Util.DeleteS3BucketWithObjects(Client, bucketName);
            }
        }