Skip to content

Commit

Permalink
update keyvault tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-nash committed Dec 10, 2021
1 parent 5f77355 commit 1448e7c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ public ManagedHsmTests(bool isAsync)
}

[SetUp]
public void ClearChallengeCacheforRecord()
public async Task ClearChallengeCacheforRecord()
{
if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback)
{
Initialize().ConfigureAwait(false).GetAwaiter().GetResult();
await Initialize();
}
}

[PlaybackOnly("One location only support one MHSM")]
[RecordedTest]
public async Task ManagedHsmCreateUpdateDelete()
{
Location = "southcentralus";
var parameters = new ManagedHsmData(Location)
LocationToUse = "southcentralus";
var parameters = new ManagedHsmData(LocationToUse)
{
Sku = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
Properties = ManagedHsmProperties
Expand All @@ -46,7 +46,7 @@ public async Task ManagedHsmCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
ManagedHsmSkuFamily.B,
ManagedHsmSkuName.StandardB1,
CreateMode.Default,
Expand All @@ -61,7 +61,7 @@ public async Task ManagedHsmCreateUpdateDelete()

ManagedHsmProperties.PublicNetworkAccess = PublicNetworkAccess.Enabled;
ManagedHsmProperties.NetworkAcls.DefaultAction = "Allow";
parameters = new ManagedHsmData(Location)
parameters = new ManagedHsmData(LocationToUse)
{
Sku = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
Properties = ManagedHsmProperties
Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task ManagedHsmCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
ManagedHsmSkuFamily.B,
ManagedHsmSkuName.StandardB1,
CreateMode.Default,
Expand All @@ -125,7 +125,7 @@ public async Task ManagedHsmCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
ManagedHsmSkuFamily.B,
ManagedHsmSkuName.StandardB1,
CreateMode.Default,
Expand Down Expand Up @@ -155,10 +155,10 @@ public async Task ManagedHsmListKeys()
{
List<string> resourceIds = new List<string>();
List<ManagedHsm> vaultList = new List<ManagedHsm>();
Location = "westus";
LocationToUse = "westus";

string vaultName = Recording.GenerateAssetName("sdktestvault");
var parameters = new ManagedHsmData(Location)
var parameters = new ManagedHsmData(LocationToUse)
{
Sku = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
Properties = ManagedHsmProperties
Expand Down Expand Up @@ -195,8 +195,8 @@ public async Task ManagedHsmListKeys()
[RecordedTest]
public async Task ManagedHsmRecoverDeletedVault()
{
Location = "westus";
var parameters = new ManagedHsmData(Location)
LocationToUse = "westus";
var parameters = new ManagedHsmData(LocationToUse)
{
Sku = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
Properties = ManagedHsmProperties
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Azure.ResourceManager.KeyVault.Tests
public class VaultOperationsTests : VaultOperationsTestsBase
{
public VaultOperationsTests(bool isAsync)
: base(isAsync)
: base(isAsync)//, RecordedTestMode.Record)
{
}

Expand All @@ -33,7 +33,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
{
VaultProperties.EnableSoftDelete = null;

var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
var parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);

var rawVault = await VaultCollection.CreateOrUpdateAsync(VaultName, parameters).ConfigureAwait(false);
Expand All @@ -45,7 +45,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
"A",
SkuName.Standard,
true,
Expand All @@ -70,7 +70,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
createdVault.Properties.AccessPolicies.Add(AccessPolicy);
createdVault.Properties.Sku.Name = SkuName.Premium;

parameters = new VaultCreateOrUpdateParameters(Location, createdVault.Properties);
parameters = new VaultCreateOrUpdateParameters(LocationToUse, createdVault.Properties);
parameters.Tags.InitializeFrom(Tags);
var rawUpdateVault = await VaultCollection.CreateOrUpdateAsync(VaultName, parameters).ConfigureAwait(false);

Expand All @@ -81,7 +81,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
"A",
SkuName.Premium,
true,
Expand All @@ -100,7 +100,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
"A",
SkuName.Premium,
true,
Expand Down Expand Up @@ -143,7 +143,7 @@ public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy
AccessPolicy.ApplicationId = Guid.Parse(TestEnvironment.ClientId);
VaultProperties.EnableSoftDelete = null;

var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
var parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);

var createVault = await VaultCollection.CreateOrUpdateAsync(
Expand All @@ -157,7 +157,7 @@ public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
"A",
SkuName.Standard,
true,
Expand All @@ -175,7 +175,7 @@ public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy
ResGroupName,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
LocationToUse,
"A",
SkuName.Standard,
true,
Expand Down Expand Up @@ -206,7 +206,7 @@ public async Task KeyVaultManagementListVaults()
for (int i = 0; i < n; i++)
{
string vaultName = Recording.GenerateAssetName("sdktestvault");
var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
var parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);
var createdVault = await VaultCollection.CreateOrUpdateAsync(vaultName, parameters).ConfigureAwait(false);
var vaultValue = createdVault.Value;
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task KeyVaultManagementListVaults()
[Test]
public async Task KeyVaultManagementRecoverDeletedVault()
{
var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
var parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);
var createdVault = await VaultCollection.CreateOrUpdateAsync(VaultName, parameters).ConfigureAwait(false);
var vaultValue = createdVault.Value;
Expand All @@ -253,7 +253,7 @@ public async Task KeyVaultManagementRecoverDeletedVault()
await VaultCollection.GetAsync(VaultName);
});

parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);
// Recover in default mode
var recoveredRawVault = await VaultCollection.CreateOrUpdateAsync(VaultName,parameters).ConfigureAwait(false);
Expand All @@ -267,7 +267,7 @@ public async Task KeyVaultManagementRecoverDeletedVault()
await getResult.Value.DeleteAsync();

VaultProperties.CreateMode = CreateMode.Recover;
parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);

// Recover in recover mode
var recoveredRawVault2 = await VaultCollection.CreateOrUpdateAsync(VaultName, parameters).ConfigureAwait(false);
Expand All @@ -289,7 +289,7 @@ public async Task KeyVaultManagementListDeletedVaults()
int n = 3;
List<string> resourceIds = new List<string>();
List<Vault> vaultList = new List<Vault>();
var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
var parameters = new VaultCreateOrUpdateParameters(LocationToUse, VaultProperties);
parameters.Tags.InitializeFrom(Tags);
for (int i = 0; i < n; i++)
{
Expand All @@ -305,7 +305,7 @@ public async Task KeyVaultManagementListDeletedVaults()

await createdVault.DeleteAsync().ConfigureAwait(false);

var deletedVault = await DeletedVaultCollection.GetAsync(Location, vaultName).ConfigureAwait(false);
var deletedVault = await DeletedVaultCollection.GetAsync(LocationToUse, vaultName).ConfigureAwait(false);
Assert.IsTrue(deletedVault.Value.Data.Name.Equals(createdVault.Data.Name));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Azure.Graph.Rbac;
using Azure.ResourceManager.KeyVault.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
using Azure.ResourceManager.TestFramework;

namespace Azure.ResourceManager.KeyVault.Tests
Expand All @@ -23,7 +24,7 @@ public abstract class VaultOperationsTestsBase : ManagementRecordedTestBase<KeyV

public string ObjectId { get; set; }
//Could not use TestEnvironment.Location since Location is got dynamically
public string Location { get; set; }
public Location LocationToUse { get; set; }

public Subscription Subscription { get; private set; }
public AccessPolicyEntry AccessPolicy { get; internal set; }
Expand All @@ -44,6 +45,11 @@ protected VaultOperationsTestsBase(bool isAsync)
{
}

protected VaultOperationsTestsBase(bool isAsync, RecordedTestMode mode)
: base(isAsync, mode, useLegacyTransport: true)
{
}

protected async Task Initialize()
{
Client = GetArmClient();
Expand All @@ -65,10 +71,10 @@ protected async Task Initialize()
break;
}
}
Location = "North Central US";
LocationToUse = Location.NorthCentralUS;

ResGroupName = Recording.GenerateAssetName("sdktestrg");
var rgResponse = await Subscription.GetResourceGroups().CreateOrUpdateAsync(ResGroupName, new ResourceGroupData(Location)).ConfigureAwait(false);
var rgResponse = await Subscription.GetResourceGroups().CreateOrUpdateAsync(ResGroupName, new ResourceGroupData(LocationToUse)).ConfigureAwait(false);
ResourceGroup = rgResponse.Value;

VaultCollection = ResourceGroup.GetVaults();
Expand Down

0 comments on commit 1448e7c

Please sign in to comment.