Skip to content

Record scenario test for Managed Hsm #12631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compute/Compute.Test/Compute.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="38.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.0.2-preview" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EventHub/EventHub.Test/EventHub.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="2.7.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/HDInsight/HDInsight.Test/HDInsight.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Management.HDInsight" Version="5.5.0" />
<PackageReference Include="Microsoft.Azure.Management.HDInsight.Job" Version="2.0.7" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.11.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.0.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
Expand Down
2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault.Test/KeyVault.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.0.2-preview" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ public void TestCreateNewVault()
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestManagedHsmCRUD()
{
KeyVaultManagementController.NewInstance.RunPsTestWorkflow(
_logger,
() => { return new[] { "Test-ManagedHsmCRUD" }; },
null,
MethodBase.GetCurrentMethod().ReflectedType?.ToString(),
MethodBase.GetCurrentMethod().Name
);
}

#endregion

#region Get-AzureRmKeyVault
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests
{
public class ManagedHsmManagementTests: KeyVaultTestRunner
{
public ManagedHsmManagementTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestManagedHsmCRUD()
{
TestRunner.RunTestScript("Test-ManagedHsmCRUD");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests CRUD for Managed Hsm.
#>
function Test-ManagedHsmCRUD {
$rgName = getAssetName
$rgLocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$hsmName = getAssetName
$hsmLocation = Get-Location "Microsoft.KeyVault" "managedHSMs" "East US 2"
$administrator = "c1be1392-39b8-4521-aafc-819a47008545"
New-AzResourceGroup -Name $rgName -Location $rgLocation

try {
# Test create a default Managed HSM
$hsm = New-AzKeyVault -Name $hsmName -ResourceGroupName $rgName -Location $hsmLocation -Administrator $administrator -Hsm
Assert-AreEqual $hsmName $hsm.VaultName
Assert-AreEqual $rgName $hsm.ResourceGroupName
Assert-AreEqual $hsmLocation $hsm.Location
Assert-AreEqual 1 $hsm.InitialAdminObjectIds.Count
Assert-True { $hsm.InitialAdminObjectIds.Contains($administrator) }
Assert-AreEqual "StandardB1" $hsm.Sku

# Default retention days
Assert-AreEqual 90 $hsm.SoftDeleteRetentionInDays "By default SoftDeleteRetentionInDays should be 90"

# Test get Managed HSM
$got = Get-AzKeyVault -Name $hsmName -ResourceType Hsm
Assert-NotNull $got
Assert-AreEqual $hsmName $got.VaultName
Assert-AreEqual $rgName $got.ResourceGroupName
Assert-AreEqual $hsmLocation $got.Location

# Test throws for existing vault
Assert-Throws { New-AzKeyVault -VaultName $hsmName -ResourceGroupName $rgname -Location $vaultLocation -Administrator $administrator -Hsm}

# Test remove Managed HSM
Remove-AzKeyVault -InputObject $got -Hsm -Force
$deletedMhsm = Get-AzKeyVault -VaultName $hsmName -ResourceGroupName $rgName
Assert-Null $deletedMhsm

# Test throws for resourcegroup nonexistent
Assert-Throws { New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName (getAssetName) -Location $vaultLocation -Administrator $administrator -Hsm}
}

finally {
Remove-AzResourceGroup -Name $rgName -Force
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,55 +156,6 @@ function Test-CreateNewVault {
}
}

<#
.SYNOPSIS
Tests CRUD for Managed Hsm.
#>
function Test-ManagedHsmCRUD {
$rgName = getAssetName
$rgLocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$hsmName = getAssetName
$hsmLocation = Get-Location "Microsoft.KeyVault" "managedHSMs" "East US 2"
$administrator = "c1be1392-39b8-4521-aafc-819a47008545"
New-AzResourceGroup -Name $rgName -Location $rgLocation

try {
# Test create a default Managed HSM
$actual = New-AzKeyVault -Name $hsmName -ResourceGroupName $rgName -Location $hsmLocation -Administrator $administrator -Hsm
Assert-AreEqual $hsmName $actual.VaultName
Assert-AreEqual $rgName $actual.ResourceGroupName
Assert-AreEqual $hsmLocation $actual.Location
Assert-AreEqual 1 $hsm.InitialAdminObjectIds.Count
Assert-True $hsm.InitialAdminObjectIds.Contains($administrator)
Assert-AreEqual "StandardB1" $actual.Sku

# Default retention days
Assert-AreEqual 90 $actual.SoftDeleteRetentionInDays "By default SoftDeleteRetentionInDays should be 90"

# Test get Managed HSM
$got = Get-AzKeyVault -Name $hsmName -ResourceType Hsm
Assert-NotNull $got
Assert-AreEqual $hsmName $got.VaultName
Assert-AreEqual $rgName $got.ResourceGroupName
Assert-AreEqual $hsmLocation $got.Location

# Test throws for existing vault
Assert-Throws { New-AzKeyVault -VaultName $hsmName -ResourceGroupName $rgname -Location $vaultLocation -Administrator $administrator -Hsm}

# Test remove Managed HSM
Remove-AzKeyVault -InputObject $got -Hsm -Force
$deletedMhsm = Get-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName
Assert-Null $deletedMhsm

# Test throws for resourcegroup nonexistent
Assert-Throws { New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName (getAssetName) -Location $vaultLocation -Administrator $administrator -Hsm}
}

finally {
Remove-AzResourceGroup -Name $rgName -Force
}
}

#-------------------------------------------------------------------------------------

#------------------------------Soft-delete--------------------------------------
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault/Commands/NewAzureKeyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Microsoft.Azure.Commands.KeyVault
/// <summary>
/// Create a new key vault.
/// </summary>
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "KeyVault", SupportsShouldProcess = true)]
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "KeyVault", DefaultParameterSetName = KeyVaultParameterSet, SupportsShouldProcess = true)]
[OutputType(typeof(PSKeyVault))]
public class NewAzureKeyVault : KeyVaultManagementCmdletBase
{
Expand Down
25 changes: 2 additions & 23 deletions src/KeyVault/KeyVault/Commands/UpdateAzureKeyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,16 @@ public class UpdateTopLevelResourceCommand : KeyVaultManagementCmdletBase
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByNameParameterSet,
HelpMessage = "Enable the soft-delete functionality for this key vault. Once enabled it cannot be disabled.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByInputObjectParameterSet,
HelpMessage = "Enable the soft-delete functionality for this key vault. Once enabled it cannot be disabled.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByResourceIdParameterSet,
[Parameter(Mandatory = false,
HelpMessage = "Enable the soft-delete functionality for this key vault. Once enabled it cannot be disabled.")]
public SwitchParameter EnableSoftDelete { get; set; }

[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByNameParameterSet,
HelpMessage = "Enable the purge protection functionality for this key vault. Once enabled it cannot be disabled. It requires soft-delete to be turned on.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByInputObjectParameterSet,
HelpMessage = "Enable the purge protection functionality for this key vault. Once enabled it cannot be disabled. It requires soft-delete to be turned on.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByResourceIdParameterSet,
HelpMessage = "Enable the purge protection functionality for this key vault. Once enabled it cannot be disabled. It requires soft-delete to be turned on.")]
public SwitchParameter EnablePurgeProtection { get; set; }

[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByNameParameterSet,
HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByInputObjectParameterSet,
HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
[Parameter(Mandatory = false,
ParameterSetName = UpdateKeyVault + ByResourceIdParameterSet,
HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
HelpMessage = "Specifies how long deleted resources are retained, and how long until a vault or an object in the deleted state can be purged. The default is " + Constants.DefaultSoftDeleteRetentionDaysString + " days.")]
[ValidateRange(Constants.MinSoftDeleteRetentionDays, Constants.MaxSoftDeleteRetentionDays)]
[ValidateNotNullOrEmpty]
public int SoftDeleteRetentionInDays { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault/KeyVault.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/KeyVault/KeyVault/Models/PSManagedHsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Azure.Management.KeyVault.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;

namespace Microsoft.Azure.Commands.KeyVault.Models
{
Expand All @@ -32,7 +33,7 @@ public PSManagedHsm(ManagedHsm managedHsm, ActiveDirectoryClient adClient)
TenantName = ModelExtensions.GetDisplayNameForTenant(TenantId, adClient);
SecurityDomainId = managedHsm.Properties.SecurityDomainId.Value;
SecurityDomainName = ModelExtensions.GetDisplayNameForTenant(SecurityDomainId, adClient);
InitialAdminObjectIds = managedHsm.Properties.InitialAdminObjectIds;
InitialAdminObjectIds = managedHsm.Properties.InitialAdminObjectIds.ToArray<string>();
HsmPoolUri = managedHsm.Properties.HsmPoolUri;
EnablePurgeProtection = managedHsm.Properties.EnablePurgeProtection;
EnableSoftDelete = managedHsm.Properties.EnableSoftDelete;
Expand All @@ -47,7 +48,7 @@ public PSManagedHsm(ManagedHsm managedHsm, ActiveDirectoryClient adClient)
public string TenantName { get; private set; }
public Guid SecurityDomainId { get; private set; }
public string SecurityDomainName { get; private set; }
public IList<string> InitialAdminObjectIds { get; private set; }
public string[] InitialAdminObjectIds { get; private set; }
public string HsmPoolUri { get; private set; }
public bool? EnableSoftDelete { get; private set; }
public int? SoftDeleteRetentionInDays { get; private set; }
Expand Down
6 changes: 3 additions & 3 deletions src/KeyVault/KeyVault/Models/VaultManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public PSKeyVault CreateNewVault(VaultCreationParameters parameters, ActiveDirec
throw new ArgumentException("parameters.TenantId");
if (!string.IsNullOrWhiteSpace(parameters.SkuName))
{
if (Enum.TryParse(parameters.SkuName, out SkuName skuName))
if (Enum.TryParse(parameters.SkuName, true, out SkuName skuName))
{
properties.Sku = new Sku(skuName);
}
Expand Down Expand Up @@ -380,7 +380,7 @@ public PSManagedHsm CreateNewManagedHsm(VaultCreationParameters parameters, Acti
throw new ArgumentException("parameters.TenantId");
if (!string.IsNullOrWhiteSpace(parameters.SkuName))
{
if (Enum.TryParse(parameters.SkuName, out ManagedHsmSkuName skuName))
if (Enum.TryParse(parameters.SkuName, true, out ManagedHsmSkuName skuName))
{
managedHsmSku.Name = skuName;
}
Expand Down Expand Up @@ -446,7 +446,7 @@ public PSManagedHsm GetManagedHsm(string managedHsmName, string resourceGroupNam

return new PSManagedHsm(response, adClient);
}
catch (CloudException ce)
catch (ManagedHsmErrorException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.NotFound)
{
Expand Down
2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault/help/New-AzKeyVault.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Accept wildcard characters: False
```

### -Hsm
Specifies the type of this vault as MHSM.
Specifies the type of this vault as managed hsm.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down
2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault/help/Remove-AzKeyVault.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Accept wildcard characters: False
```

### -Hsm
Specifies the type of vault as MHSM.
Specifies the type of vault as managed hsm.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down
2 changes: 1 addition & 1 deletion src/Sql/Sql.Test/Sql.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.2.0-preview" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.1" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.43.0-preview" />
</ItemGroup>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
"Microsoft.Azure.PowerShell.Cmdlets.KeyVault.dll","Microsoft.Azure.Commands.KeyVault.NewAzureKeyVault","New-AzKeyVault","0","2020","The cmdlet 'New-AzKeyVault' no longer supports the type 'Microsoft.Azure.Management.KeyVault.Models.SkuName' for parameter 'Sku'.","Change the type for parameter 'Sku' back to 'Microsoft.Azure.Management.KeyVault.Models.SkuName'."
"Microsoft.Azure.PowerShell.Cmdlets.KeyVault.dll","Microsoft.Azure.Commands.KeyVault.RemoveAzureKeyVault","Remove-AzKeyVault","0","2020","The cmdlet 'Remove-AzKeyVault' no longer supports the type 'Microsoft.Azure.Commands.KeyVault.Models.PSKeyVault' for parameter 'InputObject'.","Change the type for parameter 'InputObject' back to 'Microsoft.Azure.Commands.KeyVault.Models.PSKeyVault'."
"Microsoft.Azure.PowerShell.Cmdlets.KeyVault.dll","Microsoft.Azure.Commands.KeyVault.UpdateTopLevelResourceCommand","Update-AzKeyVault","0","2020","The cmdlet 'Update-AzKeyVault' no longer supports the type 'Microsoft.Azure.Commands.KeyVault.Models.PSKeyVault' for parameter 'InputObject'.","Change the type for parameter 'InputObject' back to 'Microsoft.Azure.Commands.KeyVault.Models.PSKeyVault'."