From 68a3514b9c88f1f22a561d404b06a42ab1f1bfa2 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Thu, 3 Sep 2020 15:33:45 -0500 Subject: [PATCH 1/3] Fixed bug where BlobAccessPolicy.StartsOn and .ExpiresOn would cause the process to crash --- .../src/Models/BlobAccessPolicy.cs | 8 ++++---- .../tests/ContainerClientTests.cs | 12 ++++++++++++ .../BlobAccessPolicyNullStartsOnExpiresOnTest.json | 4 ++++ ...obAccessPolicyNullStartsOnExpiresOnTestAsync.json | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTest.json create mode 100644 sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTestAsync.json diff --git a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobAccessPolicy.cs b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobAccessPolicy.cs index 2ee4173ee790e..2818c44868243 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobAccessPolicy.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobAccessPolicy.cs @@ -23,8 +23,8 @@ public System.DateTimeOffset StartsOn get { return PolicyStartsOn == default ? - StartsOn : - (DateTimeOffset)PolicyStartsOn; + new DateTimeOffset() : + PolicyStartsOn.Value; } set { @@ -42,8 +42,8 @@ public System.DateTimeOffset ExpiresOn get { return PolicyExpiresOn == default ? - ExpiresOn : - (DateTimeOffset)PolicyExpiresOn; + new DateTimeOffset() : + PolicyExpiresOn.Value; } set { diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs index 83a2e80f37ab1..f986650ef8684 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs @@ -1004,6 +1004,18 @@ await test.Container.SetAccessPolicyAsync( Assert.AreEqual(signedIdentifiers[0].AccessPolicy.Permissions, acl.AccessPolicy.Permissions); } + [Test] + public void BlobAccessPolicyNullStartsOnExpiresOnTest() + { + BlobAccessPolicy accessPolicy = new BlobAccessPolicy() + { + Permissions = "rw" + }; + + Assert.AreEqual(new DateTimeOffset(), accessPolicy.StartsOn); + Assert.AreEqual(new DateTimeOffset(), accessPolicy.ExpiresOn); + } + [Test] public async Task SetAccessPolicyAsync_OldProperties() { diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTest.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTest.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTest.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTestAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTestAsync.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/BlobAccessPolicyNullStartsOnExpiresOnTestAsync.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file From 5dcbc1558ae0bfc346c5b20147f60b3fdb15ba30 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Thu, 3 Sep 2020 15:35:04 -0500 Subject: [PATCH 2/3] updated change log --- sdk/storage/Azure.Storage.Blobs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md b/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md index c726c4f2f3e1c..f1761230304ff 100644 --- a/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.7.0-preview.1 (Unreleased) - Fixed bug where Stream returned from AppendBlobClient.OpenWrite(), BlockBlobClient.OpenWrite() and PageBlobClient.OpenWrite() did not flush while disposing preventing compatibility with using keyword. - Fixed bug where Listing Blobs with BlobTraits.Metadata would return BlobItems with null metadata instead of an empty dictionary if no metadata was present. +- Fixed bug where BlobAccessPolicy.StartsOn and .ExpiresOn would cause the process to crash. ## 12.6.0 (2020-08-31) - Fixed bug where BlobClient.Upload(), BlockBlobClient.Upload(), AppendBlobClient.AppendBlock(), and PageBlobClient.UploadPages() would deadlock if the content stream's position was not 0. From 0dfc974f8c87ceec209215d2ec39a54dd536bc28 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Thu, 3 Sep 2020 16:23:26 -0500 Subject: [PATCH 3/3] PR feedback --- .../Azure.Storage.Files.DataLake/CHANGELOG.md | 1 + .../src/Models/DataLakeAccessPolicy.cs | 8 ++++---- .../tests/FileSystemClientTests.cs | 12 ++++++++++++ ...ataLakeAccessPolicyNullStartsOnExpiresOnTest.json | 4 ++++ ...keAccessPolicyNullStartsOnExpiresOnTestAsync.json | 4 ++++ sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md | 1 + .../src/Models/ShareAccessPolicy.cs | 8 ++++---- .../ShareAccessPolicyNullStartsOnExpiresOnTest.json | 4 ++++ ...reAccessPolicyNullStartsOnExpiresOnTestAsync.json | 4 ++++ .../tests/ShareClientTests.cs | 12 ++++++++++++ 10 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTest.json create mode 100644 sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTestAsync.json create mode 100644 sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTest.json create mode 100644 sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTestAsync.json diff --git a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md index 89cfdc8ada966..7a31ba44b4358 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.5.0-preview.1 (Unreleased) - Fixed bug where Stream returned from DataLakeFileClient.OpenWrite() did not flush while disposing preventing compatibility with using keyword. - Fixed bug where DataLakeFileClient.Upload() could not upload read-only files. +- Fixed bug where DataLakeBlobAccessPolicy.StartsOn and .ExpiresOn would cause the process to crash. ## 12.4.0 (2020-08-31) - Fixed bug where DataLakeFileClient.Upload() would deadlock if the content stream's position was not 0. diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeAccessPolicy.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeAccessPolicy.cs index f5a7675764354..e6b9326948e73 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeAccessPolicy.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeAccessPolicy.cs @@ -32,8 +32,8 @@ public System.DateTimeOffset StartsOn get { return PolicyStartsOn == default ? - StartsOn : - (DateTimeOffset)PolicyStartsOn; + new DateTimeOffset() : + PolicyStartsOn.Value; } set { @@ -51,8 +51,8 @@ public System.DateTimeOffset ExpiresOn get { return PolicyExpiresOn == default ? - ExpiresOn : - (DateTimeOffset)PolicyExpiresOn; + new DateTimeOffset() : + PolicyExpiresOn.Value; } set { diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs index 926092be3a568..685a2c9fadc1b 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs @@ -1807,6 +1807,18 @@ await TestHelper.AssertExpectedExceptionAsync( } } + [Test] + public void DataLakeAccessPolicyNullStartsOnExpiresOnTest() + { + DataLakeAccessPolicy accessPolicy = new DataLakeAccessPolicy() + { + Permissions = "rw" + }; + + Assert.AreEqual(new DateTimeOffset(), accessPolicy.StartsOn); + Assert.AreEqual(new DateTimeOffset(), accessPolicy.ExpiresOn); + } + [Test] [TestCase("!'();[]@&%=+$,#äÄöÖüÜß;")] [TestCase("%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B")] diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTest.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTest.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTest.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTestAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTestAsync.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/DataLakeAccessPolicyNullStartsOnExpiresOnTestAsync.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md index f7eae6cac5fa4..b2dac7c683fed 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md @@ -2,6 +2,7 @@ ## 12.5.0-preview.1 (Unreleased) - Fixed bug where Stream returned from ShareFileClient.OpenWrite() did not flush while disposing preventing compatibility with using keyword. +- Fixed bug where ShareAccessPolicy.StartsOn and .ExpiresOn would cause the process to crash. ## 12.4.0 (2020-08-31) - Fixed bug where ShareFileClient.Upload() and .UploadRange() would deadlock if the content stream's position was not zero. diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareAccessPolicy.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareAccessPolicy.cs index b35dfb30e23fa..6aa188d47f79c 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareAccessPolicy.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareAccessPolicy.cs @@ -23,8 +23,8 @@ public System.DateTimeOffset StartsOn get { return PolicyStartsOn == default ? - StartsOn : - (DateTimeOffset)PolicyStartsOn; + new DateTimeOffset() : + PolicyStartsOn.Value; } set { @@ -42,8 +42,8 @@ public System.DateTimeOffset ExpiresOn get { return PolicyExpiresOn == default ? - ExpiresOn : - (DateTimeOffset)PolicyExpiresOn; + new DateTimeOffset() : + PolicyExpiresOn.Value; } set { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTest.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTest.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTest.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTestAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTestAsync.json new file mode 100644 index 0000000000000..20e5015d169f8 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/ShareAccessPolicyNullStartsOnExpiresOnTestAsync.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs index 55628f6d6972a..f4768894887b1 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs @@ -752,6 +752,18 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("ShareNotFound", e.ErrorCode)); } + [Test] + public void ShareAccessPolicyNullStartsOnExpiresOnTest() + { + ShareAccessPolicy accessPolicy = new ShareAccessPolicy() + { + Permissions = "rw" + }; + + Assert.AreEqual(new DateTimeOffset(), accessPolicy.StartsOn); + Assert.AreEqual(new DateTimeOffset(), accessPolicy.ExpiresOn); + } + [Test] public async Task GetStatisticsAsync() {