From c0d18bf85da494f0830b893c82da9de3f442594e Mon Sep 17 00:00:00 2001 From: Adam Hodgson Date: Sat, 14 Mar 2020 05:59:54 +0000 Subject: [PATCH] Fix: MakeBucketAsync returns deserialization exception if BucketName is null (#382) --- Minio.Functional.Tests/FunctionalTest.cs | 22 ++++++++++++++++++++++ Minio.Functional.Tests/Program.cs | 2 ++ Minio/ApiEndpoints/BucketOperations.cs | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/Minio.Functional.Tests/FunctionalTest.cs b/Minio.Functional.Tests/FunctionalTest.cs index 8de26cc8..619395f7 100644 --- a/Minio.Functional.Tests/FunctionalTest.cs +++ b/Minio.Functional.Tests/FunctionalTest.cs @@ -300,6 +300,28 @@ namespace Minio.Functional.Tests } } + internal async static Task MakeBucket_Test5(MinioClient minio) + { + DateTime startTime = DateTime.Now; + string bucketName = null; + var args = new Dictionary + { + { "bucketName", bucketName }, + { "region", "us-east-1" }, + }; + + try + { + await Assert.ThrowsExceptionAsync(() => + minio.MakeBucketAsync(bucketName)); + new MintLogger(nameof(MakeBucket_Test5), makeBucketSignature, "Tests whether MakeBucket throws InvalidBucketNameException when bucketName is null", TestStatus.PASS, (DateTime.Now - startTime), args: args).Log(); + } + catch (MinioException ex) + { + new MintLogger(nameof(MakeBucket_Test5), makeBucketSignature, "Tests whether MakeBucket throws InvalidBucketNameException when bucketName is null", TestStatus.FAIL, (DateTime.Now - startTime), "", ex.Message, ex.ToString(), args).Log(); + } + } + #endregion internal async static Task RemoveBucket_Test1(MinioClient minio) diff --git a/Minio.Functional.Tests/Program.cs b/Minio.Functional.Tests/Program.cs index 1a73f020..2003159b 100644 --- a/Minio.Functional.Tests/Program.cs +++ b/Minio.Functional.Tests/Program.cs @@ -85,6 +85,8 @@ namespace Minio.Functional.Tests // Create a new bucket FunctionalTest.MakeBucket_Test1(minioClient).Wait(); FunctionalTest.MakeBucket_Test2(minioClient).Wait(); + FunctionalTest.MakeBucket_Test5(minioClient).Wait(); + if (useAWS) { FunctionalTest.MakeBucket_Test3(minioClient).Wait(); diff --git a/Minio/ApiEndpoints/BucketOperations.cs b/Minio/ApiEndpoints/BucketOperations.cs index 68260ffd..13863286 100644 --- a/Minio/ApiEndpoints/BucketOperations.cs +++ b/Minio/ApiEndpoints/BucketOperations.cs @@ -63,8 +63,14 @@ namespace Minio /// Region /// Optional cancellation token to cancel the operation /// Task + /// When bucketName is null public async Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken)) { + if (bucketName == null) + { + throw new InvalidBucketNameException(bucketName, "bucketName cannot be null"); + } + if (location == "us-east-1") { if (this.Region != string.Empty)