Skip to content

Commit 2f8ff10

Browse files
authored
Merge pull request Azure#2855 from rohmano/feature/keyvault-certificates-autorest
Key Vault: Add support for certificates, move to auto-rest based net SDK
2 parents 6cee247 + 2febad4 commit 2f8ff10

File tree

117 files changed

+12133
-3240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+12133
-3240
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Commands.KeyVault.Test.csproj

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1818
<RestorePackages>true</RestorePackages>
1919
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
20-
<NuGetPackageImportStamp>653414c6</NuGetPackageImportStamp>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2324
<DebugSymbols>true</DebugSymbols>
@@ -64,18 +65,23 @@
6465
<Reference Include="Microsoft.Azure.Graph.RBAC">
6566
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.3.2.0-preview\lib\net45\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6667
</Reference>
67-
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
68-
<SpecificVersion>False</SpecificVersion>
69-
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.1.0.0\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
68+
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69+
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.2.0.1-preview\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
70+
<Private>True</Private>
71+
</Reference>
72+
<Reference Include="Microsoft.Azure.KeyVault.WebKey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
73+
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.WebKey.2.0.0-preview\lib\net45\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
74+
<Private>True</Private>
7075
</Reference>
7176
<Reference Include="Microsoft.Azure.Management.Authorization">
7277
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
78+
<Private>True</Private>
7379
</Reference>
7480
<Reference Include="Microsoft.Azure.Common.NetFramework">
7581
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
7682
</Reference>
77-
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.1.0.1\lib\net40\Microsoft.Azure.Management.KeyVault.dll</HintPath>
83+
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
84+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.2.0.0-preview\lib\net45\Microsoft.Azure.Management.KeyVault.dll</HintPath>
7985
<Private>True</Private>
8086
</Reference>
8187
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -148,6 +154,8 @@
148154
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
149155
</Reference>
150156
<Reference Include="System.Net.Http.WebRequest" />
157+
<Reference Include="System.Runtime.Serialization" />
158+
<Reference Include="System.Security" />
151159
<Reference Include="System.Xml" />
152160
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
153161
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
@@ -200,16 +208,15 @@
200208
<None Include="Scripts\Common.ps1" />
201209
<None Include="Scripts\ControlPlane\Common.ps1" />
202210
<None Include="Scripts\ControlPlane\KeyVaultManagementTests.ps1">
203-
<Link>ScenarioTests\KeyVaultManagementTests.ps1</Link>
204-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
211+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205212
</None>
206-
<None Include="Scripts\ControlPlane\KeyVaultManagementTests.ps1" />
207213
<None Include="Scripts\proddata\byoktest.byok" />
208214
<None Include="Scripts\proddata\byoktest1024.byok" />
209215
<None Include="Scripts\proddata\pfxtest.pfx" />
210216
<None Include="Scripts\proddata\pfxtest1024.pfx" />
211217
<None Include="Scripts\RunKeyVaultTests.ps1" />
212218
<None Include="Scripts\RunUITests.ps1" />
219+
<None Include="Scripts\VaultCertificateTests.ps1" />
213220
<None Include="Scripts\VaultKeyTests.ps1" />
214221
<None Include="Scripts\VaultManagementTests.ps1" />
215222
<None Include="Scripts\VaultSecretTests.ps1" />
@@ -335,11 +342,19 @@
335342
<EmbeddedResource Include="Resource.resx">
336343
<Generator>ResXFileCodeGenerator</Generator>
337344
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
345+
<SubType>Designer</SubType>
338346
</EmbeddedResource>
339347
</ItemGroup>
340348
<ItemGroup>
341349
<Content Include="Scripts\readme.txt" />
342350
</ItemGroup>
343351
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
344352
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
345-
</Project>
353+
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
354+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
355+
<PropertyGroup>
356+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
357+
</PropertyGroup>
358+
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
359+
</Target>
360+
</Project>

src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/Common.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ function Get-VaultName
3232

3333
<#
3434
.SYNOPSIS
35-
Gets the location for the Website. Default to West US if none found.
35+
Gets the location for the Vault. Default to West US if none found.
3636
#>
3737
function Get-Location
3838
{
39-
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
4040
{
4141
$namespace = "Microsoft.KeyVault"
4242
$type = "vaults"
@@ -60,7 +60,7 @@ Gets the default location for a provider
6060
#>
6161
function Get-ProviderLocation($provider)
6262
{
63-
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
63+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
6464
{
6565
$namespace = $provider.Split("/")[0]
6666
if($provider.Contains("/"))
@@ -89,7 +89,7 @@ Cleans the created resource groups
8989
#>
9090
function Clean-ResourceGroup($rgname)
9191
{
92-
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) {
92+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) {
9393
Remove-AzureRmResourceGroup -Name $rgname -Force
9494
}
9595
}

src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/KeyVaultEnvSetupHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void SetupEnvironment()
7171

7272
private string GetTenantId(TestEnvironment environment)
7373
{
74-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
74+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
7575
{
7676
HttpMockServer.Variables["TenantId"] = environment.AuthorizationContext.TenantId;
7777
return environment.AuthorizationContext.TenantId;
@@ -84,7 +84,7 @@ private string GetTenantId(TestEnvironment environment)
8484

8585
private string GetUser(TestEnvironment environment)
8686
{
87-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
87+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
8888
{
8989
HttpMockServer.Variables["User"] = environment.AuthorizationContext.UserId;
9090
return environment.AuthorizationContext.UserId;

src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/KeyVaultManagementController.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
using Microsoft.Azure.Management.Authorization;
1919
using Microsoft.Azure.Management.KeyVault;
2020
using Microsoft.Azure.Management.Resources;
21+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
2122
using Microsoft.Azure.Subscriptions;
22-
using Microsoft.Azure.Test;
2323
using Microsoft.Azure.Test.HttpRecorder;
24+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2425
using Microsoft.WindowsAzure.Commands.Common;
2526
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2627
using System;
2728
using System.Collections.Generic;
2829
using System.IO;
2930
using System.Linq;
31+
using LegacyTest = Microsoft.Azure.Test;
3032

3133
namespace Microsoft.Azure.Commands.KeyVault.Test
3234
{
@@ -38,10 +40,11 @@ namespace Microsoft.Azure.Commands.KeyVault.Test
3840
public class KeyVaultManagementController
3941
{
4042

41-
private CSMTestEnvironmentFactory csmTestFactory;
43+
private LegacyTest.CSMTestEnvironmentFactory csmTestFactory;
4244
private KeyVaultEnvSetupHelper helper;
4345
private const string TenantIdKey = "TenantId";
4446
private const string DomainKey = "Domain";
47+
private const string SubscriptionIdKey = "SubscriptionId";
4548

4649
public ResourceManagementClient ResourceManagementClient { get; private set; }
4750

@@ -70,11 +73,13 @@ public KeyVaultManagementController()
7073
helper = new KeyVaultEnvSetupHelper();
7174
}
7275

73-
public void RunPsTest(params string[] scripts)
76+
public void RunPsTest(XunitTracingInterceptor logger, params string[] scripts)
7477
{
7578
var callingClassType = TestUtilities.GetCallingClass(2);
7679
var mockName = TestUtilities.GetCurrentMethodName(2);
7780

81+
logger.Information(string.Format("Test method entered: {0}.{1}", callingClassType, mockName));
82+
helper.TracingInterceptor = logger;
7883
RunPsTestWorkflow(
7984
() => scripts,
8085
// no custom initializer
@@ -83,12 +88,13 @@ public void RunPsTest(params string[] scripts)
8388
null,
8489
callingClassType,
8590
mockName);
91+
logger.Information(string.Format("Test method finished: {0}.{1}", callingClassType, mockName));
8692
}
8793

8894

8995
public void RunPsTestWorkflow(
9096
Func<string[]> scriptBuilder,
91-
Action<CSMTestEnvironmentFactory> initialize,
97+
Action<LegacyTest.CSMTestEnvironmentFactory> initialize,
9298
Action cleanup,
9399
string callingClassType,
94100
string mockName)
@@ -104,7 +110,7 @@ public void RunPsTestWorkflow(
104110
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
105111
using (MockContext context = MockContext.Start(callingClassType, mockName))
106112
{
107-
this.csmTestFactory = new CSMTestEnvironmentFactory();
113+
this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory();
108114

109115
if (initialize != null)
110116
{
@@ -120,7 +126,7 @@ public void RunPsTestWorkflow(
120126
.Last();
121127
helper.SetupModules(AzureModule.AzureResourceManager,
122128
"ScenarioTests\\Common.ps1",
123-
"ScenarioTests\\" + callingClassName + ".ps1",
129+
"Scripts\\ControlPlane\\" + callingClassName + ".ps1",
124130
helper.RMProfileModule,
125131
helper.RMResourceModule,
126132
helper.GetRMModulePath("AzureRM.KeyVault.psd1"));
@@ -154,7 +160,7 @@ private void SetupManagementClients(MockContext context)
154160
GalleryClient = GetGalleryClient();
155161
AuthorizationManagementClient = GetAuthorizationManagementClient();
156162
GraphClient = GetGraphClient(context);
157-
KeyVaultManagementClient = GetKeyVaultManagementClient();
163+
KeyVaultManagementClient = GetKeyVaultManagementClient(context);
158164
helper.SetupManagementClients(ResourceManagementClient,
159165
SubscriptionClient,
160166
KeyVaultManagementClient,
@@ -167,26 +173,26 @@ private void SetupManagementClients(MockContext context)
167173

168174
private AuthorizationManagementClient GetAuthorizationManagementClient()
169175
{
170-
return TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
176+
return LegacyTest.TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
171177
}
172178

173179
private ResourceManagementClient GetResourceManagementClient()
174180
{
175-
return TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
181+
return LegacyTest.TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
176182
}
177183

178-
private KeyVaultManagementClient GetKeyVaultManagementClient()
184+
private KeyVaultManagementClient GetKeyVaultManagementClient(MockContext context)
179185
{
180-
return TestBase.GetServiceClient<KeyVaultManagementClient>(this.csmTestFactory);
186+
return context.GetServiceClient<KeyVaultManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
181187
}
182188
private SubscriptionClient GetSubscriptionClient()
183189
{
184-
return TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
190+
return LegacyTest.TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
185191
}
186192

187193
private GalleryClient GetGalleryClient()
188194
{
189-
return TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
195+
return LegacyTest.TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
190196
}
191197

192198
private GraphRbacManagementClient GetGraphClient(MockContext context)
@@ -207,19 +213,27 @@ private GraphRbacManagementClient GetGraphClient(MockContext context)
207213
if (HttpMockServer.Variables.ContainsKey(TenantIdKey))
208214
{
209215
tenantId = HttpMockServer.Variables[TenantIdKey];
210-
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = new Guid(tenantId);
211216
}
212217
if (HttpMockServer.Variables.ContainsKey(DomainKey))
213218
{
214219
UserDomain = HttpMockServer.Variables[DomainKey];
215-
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Domain = UserDomain;
216220
}
217-
221+
if (HttpMockServer.Variables.ContainsKey(SubscriptionIdKey))
222+
{
223+
AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = new Guid(HttpMockServer.Variables[SubscriptionIdKey]);
224+
}
218225
}
219226

220227
var client = context.GetGraphServiceClient<GraphRbacManagementClient>(environment);
221228
client.TenantID = tenantId;
222-
return client;
229+
if (AzureRmProfileProvider.Instance != null &&
230+
AzureRmProfileProvider.Instance.Profile != null &&
231+
AzureRmProfileProvider.Instance.Profile.Context != null &&
232+
AzureRmProfileProvider.Instance.Profile.Context.Tenant != null)
233+
{
234+
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = Guid.Parse(client.TenantID);
235+
}
236+
return client;
223237
}
224238

225239
}

src/ResourceManager/KeyVault/Commands.KeyVault.Test/ScenarioTests/KeyVaultManagementTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515

1616
using Microsoft.Azure.Graph.RBAC;
1717
using Microsoft.Azure.Graph.RBAC.Models;
18+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
1819
using Microsoft.Azure.Test;
1920
using Microsoft.Azure.Test.HttpRecorder;
2021
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2122
using System;
2223
using System.IO;
2324
using System.Linq;
2425
using Xunit;
26+
using Xunit.Abstractions;
2527

2628
namespace Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests
2729
{
@@ -38,7 +40,7 @@ public KeyVaultManagementTests(KeyVaultTestFixture fixture)
3840

3941
private void Initialize()
4042
{
41-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
43+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
4244
{
4345
HttpMockServer.Variables["ResourceGroupName"] = _data.resourceGroupName;
4446
HttpMockServer.Variables["Location"] = _data.location;
@@ -631,7 +633,7 @@ public void TestCreateDeleteVaultWithPiping()
631633
#region Helper Methods
632634
private string GetUser(TestEnvironment environment)
633635
{
634-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
636+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
635637
{
636638
HttpMockServer.Variables["User"] = environment.AuthorizationContext.UserId;
637639
return environment.AuthorizationContext.UserId;
@@ -644,7 +646,7 @@ private string GetUser(TestEnvironment environment)
644646

645647
private string GetUserObjectId(KeyVaultManagementController controllerAdmin, string upn)
646648
{
647-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
649+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
648650
{
649651
var user = controllerAdmin.GraphClient.Users.Get(upn);
650652
HttpMockServer.Variables["ObjectId"] = user.ObjectId;
@@ -661,7 +663,7 @@ private Guid GetApplicationId(TestEnvironment environment, int appNum)
661663
if (appNum < 0)
662664
throw new ArgumentException("Invalid appNum");
663665
string variableName = "AppId" + appNum;
664-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
666+
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
665667
{
666668
Guid appId = Guid.NewGuid();
667669
HttpMockServer.Variables[variableName] = appId.ToString();

0 commit comments

Comments
 (0)