Skip to content

Commit 8d632ea

Browse files
Updating Namespace CMDLETS to accomodate MSI encryption. (#16994)
* Added MSI cmdlets * Made fixes * Revert to old ways for sku object construction * Fixed error due to wrong merge * Updating test * Fixed tests by adding new SB Runner class * Removed shouldprocess from new-azeventhubencryptionconfig * Update SignatureIssues.csv Adding error message to SignatureIssues.csv to suppress it. * Tests added * Fixing tests * Added session records * Fixed bug * Fixing doc bugs * Update ChangeLog.md * Adding tests and fixed models * Adding session records Co-authored-by: Yabo Hu <[email protected]>
1 parent 4ad0d1e commit 8d632ea

24 files changed

+6446
-77
lines changed

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public void RunPsTestWorkflow(
9292
"ScenarioTests\\" + callingClassName + ".ps1",
9393
_helper.RMProfileModule,
9494
_helper.GetRMModulePath(@"AzureRM.ServiceBus.psd1"),
95+
_helper.GetRMModulePath(@"AzureRM.KeyVault.psd1"),
96+
_helper.GetRMModulePath(@"AzureRM.ManagedServiceIdentity.psd1"),
9597
"AzureRM.Resources.ps1");
9698
try
9799
{

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,45 @@
1414

1515
namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests
1616
{
17+
using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests;
1718
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1819
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1920
using ServiceManagement.Common.Models;
2021
using Xunit;
2122
using Xunit.Abstractions;
22-
public class ServiceBusServiceTests : RMTestBase
23+
public class ServiceBusServiceTests : ServiceBusTestRunner
2324
{
24-
public XunitTracingInterceptor _logger;
25-
26-
public ServiceBusServiceTests(ITestOutputHelper output)
25+
public ServiceBusServiceTests(ITestOutputHelper output) : base(output)
2726
{
28-
_logger = new XunitTracingInterceptor(output);
29-
XunitTracingInterceptor.AddToContext(_logger);
27+
3028
}
3129

3230
[Fact]
3331
[Trait(Category.AcceptanceType, Category.CheckIn)]
3432
public void ServiceBusNameSpace_CURD_Tests()
3533
{
36-
ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusTests");
34+
TestRunner.RunTestScript("ServiceBusTests");
3735
}
3836

3937
[Fact]
4038
[Trait(Category.AcceptanceType, Category.CheckIn)]
4139
public void ServiceBusNameSpaceAuth_CURD_Tests()
4240
{
43-
ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusNameSpaceAuthTests");
41+
TestRunner.RunTestScript("ServiceBusNameSpaceAuthTests");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void ServiceBusNameSpaceEncryption_CRUD()
47+
{
48+
TestRunner.RunTestScript("EncryptionTest");
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void ServiceBusNameSpaceMSI()
54+
{
55+
TestRunner.RunTestScript("MSITest");
4456
}
4557
}
4658
}

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.ps1

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
.SYNOPSIS
1818
Tests EventHub Namespace Create List Remove operations.
1919
#>
20+
2021
function ServiceBusTests {
2122
# Setup
2223
$location = "East US 2"
@@ -237,4 +238,117 @@ function ServiceBusNameSpaceAuthTests {
237238
Write-Debug " Delete namespaces"
238239
Remove-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespaceName
239240

241+
}
242+
243+
function MSITest{
244+
$resourceGroupName = "PS-Testing"
245+
$msi1 = "PS-Testing-MSI1"
246+
$msi2 = "PS-Testing-MSI2"
247+
$msi3 = "PS-Testing-MSI3"
248+
$namespace1 = getAssetName "Namespace1-"
249+
$namespace2 = getAssetName "Namespace2-"
250+
try{
251+
252+
$uad1 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi1
253+
$uad2 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi2
254+
$uad3 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi3
255+
256+
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -SkuName Standard -Location northeurope
257+
Assert-AreEqual $namespace.Name $namespace1
258+
Assert-AreEqual $namespace.Sku.Name "Standard"
259+
260+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "SystemAssigned"
261+
Assert-AreEqual $namespace.Name $namespace1
262+
Assert-AreEqual $namespace.Sku.Name "Standard"
263+
Assert-AreEqual $namespace.IdentityType "SystemAssigned"
264+
265+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "UserAssigned" -IdentityId $uad1.Id,$uad2.Id
266+
Assert-AreEqual $namespace.Name $namespace1
267+
Assert-AreEqual $namespace.Sku.Name "Standard"
268+
Assert-AreEqual $namespace.IdentityType "UserAssigned"
269+
Assert-True { $namespace.IdentityId.Count -eq 2 }
270+
271+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "SystemAssigned, UserAssigned" -IdentityId $uad1.Id,$uad2.Id
272+
Assert-AreEqual $namespace.Name $namespace1
273+
Assert-AreEqual $namespace.Sku.Name "Standard"
274+
Assert-AreEqual $namespace.IdentityType "SystemAssignedUserAssigned"
275+
Assert-True { $namespace.IdentityId.Count -eq 2 }
276+
277+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "None"
278+
Assert-AreEqual $namespace.Name $namespace1
279+
Assert-AreEqual $namespace.Sku.Name "Standard"
280+
Assert-Null $namespace.Identity
281+
}
282+
finally{
283+
Remove-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1
284+
}
285+
}
286+
287+
function EncryptionTest{
288+
try{
289+
$resourceGroupName = "PS-Testing"
290+
$msi1 = "PS-Testing-MSI1"
291+
$msi2 = "PS-Testing-MSI2"
292+
$msi3 = "PS-Testing-MSI3"
293+
$kv1 = "PS-Testing-kv1"
294+
$kv2 = "PS-Testing-kv2"
295+
$kv1uri = "https://ps-testing-kv1.vault.azure.net/"
296+
$kv2uri = "https://ps-testing-kv2.vault.azure.net"
297+
$namespace1 = getAssetName "Namespace1-"
298+
$namespace2 = getAssetName "Namespace2-"
299+
300+
$uad1 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi1
301+
$uad2 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi2
302+
$uad3 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi3
303+
304+
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace2 -SkuName Premium -Location northeurope -IdentityType SystemAssigned
305+
Assert-AreEqual $namespace.Name $namespace2
306+
Assert-AreEqual $namespace.Sku.Name "Premium"
307+
Assert-AreEqual $namespace.IdentityType "SystemAssigned"
308+
309+
Set-AzKeyVaultAccessPolicy -VaultName $kv1 -ObjectId $namespace.Identity.PrincipalId -PermissionsToKeys wrapkey,unwrapkey,get -BypassObjectIdValidation
310+
311+
$ec1 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv1uri
312+
$ec2 = New-AzServiceBusEncryptionConfig -KeyName key2 -KeyVaultUri $kv1uri
313+
314+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace2 -EncryptionConfig $ec1,$ec2
315+
Assert-AreEqual $namespace.Name $namespace2
316+
Assert-AreEqual $namespace.Sku.Name "Premium"
317+
Assert-AreEqual $namespace.IdentityType "SystemAssigned"
318+
Assert-True { $namespace.EncryptionConfig.Count -eq 2 }
319+
320+
321+
$ec1 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1.Id
322+
$ec2 = New-AzServiceBusEncryptionConfig -KeyName key2 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1.Id
323+
324+
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -SkuName Premium -Location northeurope -IdentityType UserAssigned -IdentityId $uad1.Id,$uad2.Id -EncryptionConfig $ec1,$ec2
325+
Assert-AreEqual $namespace.Name $namespace1
326+
Assert-AreEqual $namespace.Sku.Name "Premium"
327+
Assert-AreEqual $namespace.IdentityType "UserAssigned"
328+
Assert-True { $namespace.IdentityId.Count -eq 2 }
329+
Assert-True { $namespace.EncryptionConfig.Count -eq 2 }
330+
331+
$ec3 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv2uri -UserAssignedIdentity $uad1.id
332+
$namespace.EncryptionConfig += $ec3
333+
334+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -EncryptionConfig $namespace.EncryptionConfig -Location northeurope
335+
Assert-AreEqual $namespace.Name $namespace1
336+
Assert-AreEqual $namespace.Sku.Name "Premium"
337+
Assert-AreEqual $namespace.IdentityType "UserAssigned"
338+
Assert-True { $namespace.IdentityId.Count -eq 2 }
339+
Assert-True { $namespace.EncryptionConfig.Count -eq 3 }
340+
341+
$namespace = Get-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1
342+
Assert-AreEqual $namespace.Name $namespace1
343+
Assert-AreEqual $namespace.Sku.Name "Premium"
344+
Assert-AreEqual $namespace.IdentityType "UserAssigned"
345+
Assert-True { $namespace.IdentityId.Count -eq 2 }
346+
Assert-True { $namespace.EncryptionConfig.Count -eq 3 }
347+
348+
}
349+
350+
finally{
351+
Remove-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1
352+
Remove-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace2
353+
}
240354
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.TestFx;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit.Abstractions;
19+
20+
namespace Microsoft.Azure.Commands.EventHub.Test.ScenarioTests
21+
{
22+
public class ServiceBusTestRunner
23+
{
24+
protected readonly ITestRunner TestRunner;
25+
26+
protected ServiceBusTestRunner(ITestOutputHelper output)
27+
{
28+
TestRunner = TestFx.TestManager.CreateInstance(output)
29+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
30+
.WithProjectSubfolderForTests("ScenarioTests")
31+
.WithCommonPsScripts(new[]
32+
{
33+
@"../AzureRM.Resources.ps1",
34+
@"../AzureRM.Storage.ps1"
35+
})
36+
.WithNewRmModules(helper => new[]
37+
{
38+
helper.RMProfileModule,
39+
helper.GetRMModulePath("AzureRM.ServiceBus.psd1"),
40+
helper.GetRMModulePath("AzureRM.KeyVault.psd1"),
41+
helper.GetRMModulePath("AzureRM.ManagedServiceIdentity.psd1"),
42+
43+
})
44+
.WithRecordMatcher(
45+
(ignoreResourcesClient, resourceProviders, userAgentsToIgnore) =>
46+
new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient, resourceProviders, userAgentsToIgnore)
47+
)
48+
.WithNewRecordMatcherArguments(
49+
userAgentsToIgnore: new Dictionary<string, string>
50+
{
51+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
52+
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"},
53+
{"Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-09-01"},
54+
},
55+
resourceProviders: new Dictionary<string, string>
56+
{
57+
{"Microsoft.Resources", null},
58+
{"Microsoft.Features", null},
59+
{"Microsoft.Authorization", null},
60+
{"Microsoft.ServiceBus", null},
61+
{"Microsoft.KeyVault", null},
62+
{"Microsoft.ManagedServiceIdentity", null},
63+
}
64+
)
65+
.Build();
66+
}
67+
}
68+
}

src/ServiceBus/ServiceBus.Test/ServiceBus.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
15+
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0" />
16+
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.11.0" />
1417
<PackageReference Include="Microsoft.Azure.Management.ServiceBus" Version="3.0.0" />
1518
</ItemGroup>
1619

0 commit comments

Comments
 (0)