Skip to content
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

Update test project for KeyVault #12228

Merged
merged 2 commits into from
May 21, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\..\testcommon\Azure.Graph.Rbac\src\Azure.Graph.Rbac.csproj" />
<ProjectReference Include="..\..\..\testcommon\Azure.Management.Resource.2017_05\src\Azure.Management.Resource.csproj" />
<ProjectReference Include="..\..\..\testcommon\Azure.Management.Resources.2017_05\src\Azure.Management.Resources.csproj" />
<ProjectReference Include="..\src\Azure.Management.KeyVault.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@ namespace Azure.Management.KeyVault.Tests
{
public class KeyVaultManagementTestEnvironment : TestEnvironment
{
private const string TenantIdKey = "TenantId";
private const string SubIdKey = "SubId";
private const string ApplicationIdKey = "ApplicationId";

public KeyVaultManagementTestEnvironment() : base("keyvalutmgmt")
{
}

//Do not need to save to session record
public string UserName => GetVariable("AZURE_USER_NAME");

public string TenantIdTrack1 => GetRecordedVariable(TenantIdKey);

public string SubscriptionIdTrack1 => GetRecordedVariable(SubIdKey);

public string ApplicationIdTrack1 => GetRecordedVariable(ApplicationIdKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ValidateVault(createdVault,
VaultName,
ResGroupName,
SubscriptionId,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
"A",
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ValidateVault(updateVault,
VaultName,
ResGroupName,
SubscriptionId,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
"A",
Expand All @@ -107,7 +107,7 @@ public async Task KeyVaultManagementVaultCreateUpdateDelete()
ValidateVault(retrievedVault,
VaultName,
ResGroupName,
SubscriptionId,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
"A",
Expand Down Expand Up @@ -136,7 +136,7 @@ await VaultsClient.GetAsync(
[Test]
public async Task CreateKeyVaultDisableSoftDelete()
{
this.AccessPolicy.ApplicationId = Guid.Parse(this.ApplicationId);
this.AccessPolicy.ApplicationId = Guid.Parse(TestEnvironment.ClientId);
this.VaultProperties.EnableSoftDelete = false;

var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
Expand All @@ -156,7 +156,7 @@ public async Task CreateKeyVaultDisableSoftDelete()
[Test]
public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy()
{
AccessPolicy.ApplicationId = Guid.Parse(ApplicationId);
AccessPolicy.ApplicationId = Guid.Parse(TestEnvironment.ClientId);
VaultProperties.EnableSoftDelete = null;

var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties);
Expand All @@ -172,7 +172,7 @@ public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy
ValidateVault(vaultResponse.Value,
VaultName,
ResGroupName,
SubscriptionId,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
"A",
Expand All @@ -192,7 +192,7 @@ public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy
ValidateVault(retrievedVault.Value,
VaultName,
ResGroupName,
SubscriptionId,
TestEnvironment.SubscriptionId,
TenantIdGuid,
Location,
"A",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Azure.Management.KeyVault.Models;
using Azure.Management.Resources;

using NUnit.Framework;

namespace Azure.Management.KeyVault.Tests
{
[ClientTestFixture]
Expand All @@ -21,11 +19,9 @@ public abstract class VaultOperationsTestsBase : RecordedTestBase<KeyVaultManage
private const string ObjectIdKey = "ObjectId";
public static TimeSpan ZeroPollingInterval { get; } = TimeSpan.FromSeconds(0);

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

public AccessPolicyEntry AccessPolicy { get; internal set; }
public string ResGroupName { get; internal set; }
Expand All @@ -47,19 +43,6 @@ protected VaultOperationsTestsBase(bool isAsync)

protected async Task Initialize()
{
if (Mode == RecordedTestMode.Playback && Recording.IsTrack1SessionRecord())
{
this.TenantId = TestEnvironment.TenantIdTrack1;
this.SubscriptionId = TestEnvironment.SubscriptionIdTrack1;
this.ApplicationId = TestEnvironment.ApplicationIdTrack1;
}
else
{
this.TenantId = TestEnvironment.TenantId;
this.SubscriptionId = TestEnvironment.SubscriptionId;
this.ApplicationId = TestEnvironment.ClientId;
}

var resourceManagementClient = GetResourceManagementClient();
ResourcesClient = resourceManagementClient.GetResourcesClient();
ResourceGroupsClient = resourceManagementClient.GetResourceGroupsClient();
Expand All @@ -74,8 +57,8 @@ protected async Task Initialize()
}
else if (Mode == RecordedTestMode.Record)
{
var spClient = new RbacManagementClient(this.TenantId, TestEnvironment.Credential).GetServicePrincipalsClient();
var servicePrincipalList = spClient.ListAsync($"appId eq '{this.ApplicationId}'");
var spClient = new RbacManagementClient(TestEnvironment.TenantId, TestEnvironment.Credential).GetServicePrincipalsClient();
var servicePrincipalList = spClient.ListAsync($"appId eq '{TestEnvironment.ClientId}'");
await foreach (var servicePrincipal in servicePrincipalList)
{
this.ObjectId = servicePrincipal.ObjectId;
Expand All @@ -98,7 +81,7 @@ protected async Task Initialize()
await ResourceGroupsClient.CreateOrUpdateAsync(ResGroupName, new Resources.Models.ResourceGroup(Location));
VaultName = Recording.GenerateAssetName("sdktestvault");

TenantIdGuid = new Guid(TenantId);
TenantIdGuid = new Guid(TestEnvironment.TenantId);
Tags = new Dictionary<string, string> { { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" } };

var permissions = new Permissions
Expand Down Expand Up @@ -128,14 +111,14 @@ protected async Task Initialize()

internal KeyVaultManagementClient GetKeyVaultManagementClient()
{
return InstrumentClient(new KeyVaultManagementClient(this.SubscriptionId,
return InstrumentClient(new KeyVaultManagementClient(TestEnvironment.SubscriptionId,
TestEnvironment.Credential,
Recording.InstrumentClientOptions(new KeyVaultManagementClientOptions())));
}

internal ResourcesManagementClient GetResourceManagementClient()
{
return InstrumentClient(new ResourcesManagementClient(this.SubscriptionId,
return InstrumentClient(new ResourcesManagementClient(TestEnvironment.SubscriptionId,
TestEnvironment.Credential,
Recording.InstrumentClientOptions(new ResourcesManagementClientOptions())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\src\Azure.Management.Resource.csproj" />
<ProjectReference Include="..\src\Azure.Management.Resources.csproj" />
</ItemGroup>
</Project>