public static CreateBucket ( IAmazonS3 s3Client ) : string | ||
s3Client | IAmazonS3 | |
return | string |
public void ServerSideEncryptionBYOKTransferUtility() { var bucketName = S3TestUtils.CreateBucket(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); } }
public static void Initialize(TestContext a) { StreamWriter writer = File.CreateText("PutObjectFile.txt"); writer.Write("This is some sample text.!!"); writer.Close(); bucketName = S3TestUtils.CreateBucket(Client); }
public void TestInitialize() { transferClient = new TransferUtility(Client); tempFilePath = System.IO.Path.GetTempFileName(); bucketName = S3TestUtils.CreateBucket(Client); UtilityMethods.GenerateFile(tempFilePath, 1024 * 1024 * 20); }
public static void CreateTestBase() { Client = new AmazonS3Client(); bucketName = S3TestUtils.CreateBucket(Client); Client.PutObject(new PutObjectRequest { BucketName = bucketName }); }
public static void Initialize(TestContext a) { bucketName = S3TestUtils.CreateBucket(Client); Client.PutObject(new PutObjectRequest { BucketName = bucketName, ContentBody = content, Key = "TestObject" }); }
public static void Initialize(TestContext tc) { bucketName = S3TestUtils.CreateBucket(Client); Client.PutBucketVersioning(new PutBucketVersioningRequest { BucketName = bucketName, VersioningConfig = new S3BucketVersioningConfig { Status = VersionStatus.Enabled } }); }
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.CreateBucket(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 = s3Client.GetBucketNotification(bucketName); 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); } } }
public void Initialize() { usEastClient = new AmazonS3Client(RegionEndpoint.USEast1); eastBucketName = S3TestUtils.CreateBucket(usEastClient); usEastClient.PutObject(new PutObjectRequest { BucketName = eastBucketName, Key = testKey, ContentBody = testContent }); var usWestClient = new AmazonS3Client(RegionEndpoint.USWest1); westBucketName = S3TestUtils.CreateBucket(usWestClient); }
public static void Initialize(TestContext a) { s3Client = new AmazonS3Client(TestRegionEndpoint); bucketName = S3TestUtils.CreateBucket(s3Client); BucketAccelerateStatus bucketStatus = null; s3Client.PutBucketAccelerateConfiguration(new PutBucketAccelerateConfigurationRequest { BucketName = bucketName, AccelerateConfiguration = new AccelerateConfiguration { Status = BucketAccelerateStatus.Enabled } }); bucketStatus = s3Client.GetBucketAccelerateConfiguration(bucketName).Status; Assert.AreEqual(BucketAccelerateStatus.Enabled, bucketStatus); }
public static void Initialize(TestContext a) { bucketName = S3TestUtils.CreateBucket(Client); foreach (var key in keys) { if (key.EndsWith("/")) { continue; } Client.PutObject(new PutObjectRequest { BucketName = bucketName, Key = key, ContentBody = content }); } }
public static void Initialize(TestContext a) { EncryptionMaterials encryptionMaterials = new EncryptionMaterials(generateAsymmetricProvider()); s3EncryptionClientMetadataMode = new AmazonS3EncryptionClient(encryptionMaterials); AmazonS3CryptoConfiguration config = new AmazonS3CryptoConfiguration() { StorageMode = CryptoStorageMode.InstructionFile }; s3EncryptionClientFileMode = new AmazonS3EncryptionClient(config, encryptionMaterials); using (StreamWriter writer = File.CreateText(fileName)) { writer.Write(sampleContent); } bucketName = S3TestUtils.CreateBucket(s3EncryptionClientFileMode); }
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); } }
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.CreateBucket(s3EncryptionClientFileMode); }
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.CreateBucket(eucentral1Client); try { var response = uswest2Client.PutObject(new PutObjectRequest { BucketName = bucketName, Key = "test.txt", ContentBody = "some stuff" }); } finally { AmazonS3Util.DeleteS3BucketWithObjects(eucentral1Client, bucketName); } }
public void TestPresignedUrls(string keyId) { var oldSigV4 = AWSConfigs.S3Config.UseSignatureVersion4; AWSConfigs.S3Config.UseSignatureVersion4 = true; using (var newClient = new AmazonS3Client()) { var bucketName = S3TestUtils.CreateBucket(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); AWSConfigs.S3Config.UseSignatureVersion4 = oldSigV4; } } }
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 void TestAWS2ToAWS4RedirectBeforeDNSPropagation() { var useast1Client = new AmazonS3Client(RegionEndpoint.USEast1); var eucentral1Client = new AmazonS3Client(RegionEndpoint.EUCentral1); var bucketName = S3TestUtils.CreateBucket(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); } }
public static void ClassInitialize(TestContext a) { bucketName = S3TestUtils.CreateBucket(Client); }
public static void ClassInitialize(TestContext a) { bucketName = S3TestUtils.CreateBucket(Client); fullPath = Path.GetFullPath(testFile); File.WriteAllText(fullPath, testContent); }
private void TestSseKms(string keyId) { var bucketName = S3TestUtils.CreateBucket(Client); try { var putObjectRequest = new PutObjectRequest { BucketName = bucketName, Key = key, ContentBody = testContents, ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS }; putObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId = keyId; var putObjectResponse = Client.PutObject(putObjectRequest); Assert.IsNotNull(putObjectResponse.ServerSideEncryptionKeyManagementServiceKeyId); var usedKeyId = putObjectResponse.ServerSideEncryptionKeyManagementServiceKeyId; VerifyKeyId(keyId, usedKeyId); VerifyObject(bucketName, key, usedKeyId); VerifyObjectWithTransferUtility(bucketName); TestCopyPart(bucketName, key, keyId); var key2 = key + "Copy"; var copyResponse = Client.CopyObject(new CopyObjectRequest { SourceBucket = bucketName, SourceKey = key, DestinationBucket = bucketName, DestinationKey = key2, ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS, ServerSideEncryptionKeyManagementServiceKeyId = keyId }); Assert.IsNotNull(copyResponse); usedKeyId = copyResponse.ServerSideEncryptionKeyManagementServiceKeyId; VerifyKeyId(keyId, usedKeyId); VerifyObject(bucketName, key2, usedKeyId); TransferUtility utility = new TransferUtility(Client); var smallUploadRequest = new TransferUtilityUploadRequest { BucketName = bucketName, Key = key, ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS, ServerSideEncryptionKeyManagementServiceKeyId = keyId, InputStream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(testContents)) }; utility.Upload(smallUploadRequest); VerifyObject(bucketName, key, keyId); var largeUploadRequest = new TransferUtilityUploadRequest { BucketName = bucketName, Key = key, ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS, ServerSideEncryptionKeyManagementServiceKeyId = keyId, InputStream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(largeTestContents)) }; utility.Upload(largeUploadRequest); VerifyObject(bucketName, key, keyId); TestUploadDirectory(bucketName, keyId); } finally { AmazonS3Util.DeleteS3BucketWithObjects(Client, bucketName); } }
public void ServerSideEncryptionBYOKPutAndGet() { var bucketName = S3TestUtils.CreateBucket(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); } }
public void SetQueueConfigurationTests() { var filterRule = new FilterRule("Prefix", "test/"); var s3Config = new AmazonS3Config(); using (var s3Client = new AmazonS3Client(s3Config)) using (var sqsClient = new AmazonSQSClient()) { var createResponse = sqsClient.CreateQueue("events-test-" + DateTime.Now.Ticks); var bucketName = S3TestUtils.CreateBucket(s3Client); try { var queueArn = sqsClient.AuthorizeS3ToSendMessage(createResponse.QueueUrl, bucketName); PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest { BucketName = bucketName, QueueConfigurations = new List <QueueConfiguration> { new QueueConfiguration { Id = "the-queue-test", Queue = queueArn, Events = { EventType.ObjectCreatedPut }, Filter = new Filter { S3KeyFilter = new S3KeyFilter { FilterRules = new List <FilterRule> { filterRule } } } } } }; s3Client.PutBucketNotification(putRequest); var getResponse = s3Client.GetBucketNotification(bucketName); Assert.AreEqual(1, getResponse.QueueConfigurations.Count); Assert.AreEqual(1, getResponse.QueueConfigurations[0].Events.Count); Assert.AreEqual(EventType.ObjectCreatedPut, getResponse.QueueConfigurations[0].Events[0]); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules); Assert.AreEqual(1, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules.Count); Assert.AreEqual(filterRule.Name, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Name); Assert.AreEqual(filterRule.Value, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Value); Assert.AreEqual("the-queue-test", getResponse.QueueConfigurations[0].Id); Assert.AreEqual(queueArn, getResponse.QueueConfigurations[0].Queue); // Purge queue to remove test message sent configuration was setup. sqsClient.PurgeQueue(createResponse.QueueUrl); Thread.Sleep(TimeSpan.FromSeconds(1)); var putObjectRequest = new PutObjectRequest { BucketName = bucketName, Key = "test/data.txt", ContentBody = "Important Data" }; s3Client.PutObject(putObjectRequest); string messageBody = null; for (int i = 0; i < 5 && messageBody == null; i++) { var receiveResponse = sqsClient.ReceiveMessage(new ReceiveMessageRequest { QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20 }); if (receiveResponse.Messages.Count != 0) { messageBody = receiveResponse.Messages[0].Body; } } var evnt = S3EventNotification.ParseJson(messageBody); Assert.AreEqual(1, evnt.Records.Count); Assert.AreEqual(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name); Assert.AreEqual(putObjectRequest.Key, evnt.Records[0].S3.Object.Key); Assert.AreEqual(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size); Assert.IsNotNull(evnt.Records[0].S3.Object.Sequencer); } finally { sqsClient.DeleteQueue(createResponse.QueueUrl); AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName); } } }
public static void CreateTestBase() { Client = new AmazonS3Client(); bucketName = S3TestUtils.CreateBucket(Client); }
public static void Initialize(TestContext a) { IAmazonS3 s3Client = new AmazonS3Client(); bucketName = S3TestUtils.CreateBucket(s3Client); }