From 86aad8bdec883b8704c4a99cbfe6b1f0bec148f2 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 08:19:44 -0700 Subject: [PATCH 1/8] Add storage role assignment to extension tests --- sdk/extensions/test-resources.bicep | 9 +++++++++ sdk/extensions/test-resources.bicep.env | Bin 0 -> 994 bytes 2 files changed, 9 insertions(+) create mode 100644 sdk/extensions/test-resources.bicep.env diff --git a/sdk/extensions/test-resources.bicep b/sdk/extensions/test-resources.bicep index 71999a8efd11..ee66e3476b53 100644 --- a/sdk/extensions/test-resources.bicep +++ b/sdk/extensions/test-resources.bicep @@ -93,5 +93,14 @@ resource blobAcount 'Microsoft.Storage/storageAccounts@2019-04-01' = { } } +var contributorRole = 'b24988ac-6180-42a0-ab88-20f7382dd24c' +resource blobContributorAssignment 'Microsoft.Authorization/roleAssignments@2015-07-01' = { + name: guid(resourceGroup().id, testApplicationOid, contributorRole) + properties: { + principalId: testApplicationOid + roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', contributorRole) + } +} + output AZURE_KEYVAULT_URL string = keyVault.properties.vaultUri output BLOB_STORAGE_ENDPOINT string = blobAcount.properties.primaryEndpoints.blob diff --git a/sdk/extensions/test-resources.bicep.env b/sdk/extensions/test-resources.bicep.env new file mode 100644 index 0000000000000000000000000000000000000000..c9e9720348264b66bf4ed883872312e2802a4316 GIT binary patch literal 994 zcmV<810DPU0002cjGf;B710rldH}#r!k6m-0001Z=`I@^ti(>3>PC?~vI-Lb00002 z0000000U+K0KfnM01yBG0E)W$n&8z)8<{900e*l0H6Q>01yBG0C4HQ z%NNdp^lQ(~5|cM0iC6;w0Dz=0-3tRhA~w;=g#cShRDa*K>TGXcfgPnucf|*$!V6h0 zS;WXw(>fJ?(&ZD_!I@5?VRaDh2QH2%deE~5B$2;C9LZ9`iv>NY*4E|ba(h@woTYV* zY?`Hi9vmOM2i{1o1gjF@rkI?GiAZU79^YVc6{{$bt2(R+Sk#Bsw8&zMH3q_qvecno zPgm4cx#=|*As}FZDZC~}P3l5|??9C{@{VSl)N|DY^Co_EnH0};x(!xw z20cfO^*6W*bt|(l z_04qkBWz9wqI_pXrsXruQ_5yLGd&xE9Ks^mCZR@{a|hh-siiMHXQ0QLg;94g(*G+L4XoxF z0gqL|C*$Zh$)qrX0-mLbN4y_60^XT9tn`tJlVP}3Ill8EBVwh*865UJGY#+h#Gp1> zE0j*P>mk1x{}d^6x1zO;?>hnRO0a6E+;CHlwEsex3xGmcBNdVu0$90`yA9&N_At%= z&T`|VfkH&p0x#|)mY&zVQ3)>;ot`Rw@K5N)g5(^5E~>J**32y62bZL7gFo35wxnTU zpkI=wtwQadf2vPMG~;%)$K>mo4zexW7@6>POrSUPwPvx>;Z_F?cN72s0DNr8^bsGs Q8pZp&n%XMz_y_k5HLlsk3;+NC literal 0 HcmV?d00001 From 51c2ed4ada861c924302d1e0b3b30c8b0c360d7f Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 08:46:58 -0700 Subject: [PATCH 2/8] try different role --- sdk/extensions/test-resources.bicep | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/extensions/test-resources.bicep b/sdk/extensions/test-resources.bicep index ee66e3476b53..13f432079389 100644 --- a/sdk/extensions/test-resources.bicep +++ b/sdk/extensions/test-resources.bicep @@ -93,12 +93,13 @@ resource blobAcount 'Microsoft.Storage/storageAccounts@2019-04-01' = { } } -var contributorRole = 'b24988ac-6180-42a0-ab88-20f7382dd24c' -resource blobContributorAssignment 'Microsoft.Authorization/roleAssignments@2015-07-01' = { - name: guid(resourceGroup().id, testApplicationOid, contributorRole) +var blobDataContributorRole = 'ba92f5b4-2d11-453d-a403-e96b0029c9fe' +resource blobContributorAssignment 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = { + name: guid(resourceGroup().id, testApplicationOid, blobDataContributorRole) + scope: resourceGroup() properties: { principalId: testApplicationOid - roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', contributorRole) + roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', blobDataContributorRole) } } From 46d34718f38391da073432d28261f8b038bdec40 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 09:06:07 -0700 Subject: [PATCH 3/8] standard vault --- sdk/extensions/test-resources.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/extensions/test-resources.bicep b/sdk/extensions/test-resources.bicep index 13f432079389..e71a47a3e07f 100644 --- a/sdk/extensions/test-resources.bicep +++ b/sdk/extensions/test-resources.bicep @@ -16,7 +16,7 @@ resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' = { properties: { sku: { family: 'A' - name: 'premium' + name: 'standard' } tenantId: tenantId accessPolicies: [ From eb3f976a390a2935ffcc804c98f93206fe9bfb5e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 09:39:22 -0700 Subject: [PATCH 4/8] add env test func --- .../tests/DataProtectionTestEnvironment.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs index d76abd2bee76..d067fcf6e1ec 100644 --- a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs +++ b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs @@ -2,12 +2,35 @@ // Licensed under the MIT License. using System; +using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.Storage.Blobs; namespace Azure.Extensions.AspNetCore.DataProtection.Blobs.Tests { public class DataProtectionTestEnvironment: TestEnvironment { public Uri BlobStorageEndpoint => new(GetVariable("BLOB_STORAGE_ENDPOINT")); + + protected override async ValueTask IsEnvironmentReadyAsync() + { + try + { + var client = new BlobServiceClient(BlobStorageEndpoint, Credential); + var container = client.GetBlobContainerClient("test"); + await container.CreateIfNotExistsAsync(); + + var blob = container.GetBlobClient("test-blob"); + await blob.UploadAsync(new BinaryData("")); + + await container.DeleteAsync(); + + return await base.IsEnvironmentReadyAsync(); + } + catch (RequestFailedException e) when (e is { Status: 403}) + { + return false; + } + } } } \ No newline at end of file From 31243da6f9f0e50254495372759aa5e902728584 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 09:48:13 -0700 Subject: [PATCH 5/8] react to bicep fix --- .gitignore | 1 + .../src/TestEnvironment.cs | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b0eabb61a6ee..507e19286e63 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,7 @@ tools/*.dll *.pfx TestConfigurations.xml *.json.env +*.bicep.env # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) diff --git a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs index e263904613fa..10bcdb0d2e96 100644 --- a/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs +++ b/sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs @@ -60,16 +60,26 @@ protected TestEnvironment() _prefix = serviceName.ToUpperInvariant() + "_"; - var testEnvironmentFile = Path.Combine(serviceSdkDirectory, "test-resources.json.env"); - if (File.Exists(testEnvironmentFile)) + var testEnvironmentFiles = new[] { - var json = JsonDocument.Parse( - ProtectedData.Unprotect(File.ReadAllBytes(testEnvironmentFile), null, DataProtectionScope.CurrentUser) - ); + Path.Combine(serviceSdkDirectory, "test-resources.bicep.env"), + Path.Combine(serviceSdkDirectory, "test-resources.json.env") + }; - foreach (var property in json.RootElement.EnumerateObject()) + foreach (var testEnvironmentFile in testEnvironmentFiles) + { + if (File.Exists(testEnvironmentFile)) { - _environmentFile[property.Name] = property.Value.GetString(); + var json = JsonDocument.Parse( + ProtectedData.Unprotect(File.ReadAllBytes(testEnvironmentFile), null, DataProtectionScope.CurrentUser) + ); + + foreach (var property in json.RootElement.EnumerateObject()) + { + _environmentFile[property.Name] = property.Value.GetString(); + } + + break; } } } From 3e80ea7329b4835b730f787847e8b97d41aecd9b Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 09:48:56 -0700 Subject: [PATCH 6/8] rem --- sdk/extensions/test-resources.bicep.env | Bin 994 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 sdk/extensions/test-resources.bicep.env diff --git a/sdk/extensions/test-resources.bicep.env b/sdk/extensions/test-resources.bicep.env deleted file mode 100644 index c9e9720348264b66bf4ed883872312e2802a4316..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 994 zcmV<810DPU0002cjGf;B710rldH}#r!k6m-0001Z=`I@^ti(>3>PC?~vI-Lb00002 z0000000U+K0KfnM01yBG0E)W$n&8z)8<{900e*l0H6Q>01yBG0C4HQ z%NNdp^lQ(~5|cM0iC6;w0Dz=0-3tRhA~w;=g#cShRDa*K>TGXcfgPnucf|*$!V6h0 zS;WXw(>fJ?(&ZD_!I@5?VRaDh2QH2%deE~5B$2;C9LZ9`iv>NY*4E|ba(h@woTYV* zY?`Hi9vmOM2i{1o1gjF@rkI?GiAZU79^YVc6{{$bt2(R+Sk#Bsw8&zMH3q_qvecno zPgm4cx#=|*As}FZDZC~}P3l5|??9C{@{VSl)N|DY^Co_EnH0};x(!xw z20cfO^*6W*bt|(l z_04qkBWz9wqI_pXrsXruQ_5yLGd&xE9Ks^mCZR@{a|hh-siiMHXQ0QLg;94g(*G+L4XoxF z0gqL|C*$Zh$)qrX0-mLbN4y_60^XT9tn`tJlVP}3Ill8EBVwh*865UJGY#+h#Gp1> zE0j*P>mk1x{}d^6x1zO;?>hnRO0a6E+;CHlwEsex3xGmcBNdVu0$90`yA9&N_At%= z&T`|VfkH&p0x#|)mY&zVQ3)>;ot`Rw@K5N)g5(^5E~>J**32y62bZL7gFo35wxnTU zpkI=wtwQadf2vPMG~;%)$K>mo4zexW7@6>POrSUPwPvx>;Z_F?cN72s0DNr8^bsGs Q8pZp&n%XMz_y_k5HLlsk3;+NC From cf48c6b14f95a3f89a35b7c39168de4da9968333 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 10:17:04 -0700 Subject: [PATCH 7/8] build --- .../tests/DataProtectionTestEnvironment.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs index d067fcf6e1ec..9ca42220215d 100644 --- a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs +++ b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.IO; using System.Threading.Tasks; using Azure.Core.TestFramework; using Azure.Storage.Blobs; @@ -21,7 +22,7 @@ protected override async ValueTask IsEnvironmentReadyAsync() await container.CreateIfNotExistsAsync(); var blob = container.GetBlobClient("test-blob"); - await blob.UploadAsync(new BinaryData("")); + await blob.UploadAsync(new MemoryStream()); await container.DeleteAsync(); From 16d458ca2f2fb1ea9d41062694b3a175de3a738d Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 30 Aug 2021 11:01:39 -0700 Subject: [PATCH 8/8] check delete --- .../tests/DataProtectionTestEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs index 9ca42220215d..9122264aa0b8 100644 --- a/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs +++ b/sdk/extensions/Azure.Extensions.AspNetCore.DataProtection.Blobs/tests/DataProtectionTestEnvironment.cs @@ -23,7 +23,7 @@ protected override async ValueTask IsEnvironmentReadyAsync() var blob = container.GetBlobClient("test-blob"); await blob.UploadAsync(new MemoryStream()); - + await blob.DeleteAsync(); await container.DeleteAsync(); return await base.IsEnvironmentReadyAsync();