Skip to content

One SDK for Azure Backup Vault powershell cmdlet. #1216

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 121 commits into from
Jul 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
14032b5
Azure Backup Service Managment infra for
swatimadhukargit May 25, 2015
5d19671
Changing namespace from Microsoft.WindowsAzure to Microsoft.Azure
swatimadhukargit May 26, 2015
bb0c579
Infra for Hydra dll generation 2
swatimadhukargit May 27, 2015
09e7d1e
Merge pull request #1 from MabOneSdk/swatim
piyushka17 May 27, 2015
a70da55
Add BackupServices.Tests.csproj
swatimadhukargit May 28, 2015
fc0ecdf
adding missing BackupServicesTestBase file
swatimadhukargit May 28, 2015
54fb8f6
Merge branch 'master' of https://github.com/MabOneSdk/azure-sdk-for-net
swatimadhukargit May 28, 2015
54df845
DownloadVaultCredentials cmdlet (testing in progress) v2
Jun 3, 2015
8666fe2
committing generated code.
Jun 3, 2015
f3bcd97
commit post merge
Jun 3, 2015
0a0ce15
Azurebackup Container cmdlet
mkherani Jun 4, 2015
9aa47a0
Merge pull request #2 from MabOneSdk/anudeeb
Jun 4, 2015
21e3499
Merged with latest changes
mkherani Jun 4, 2015
1a93533
Merge branch 'mkherani'
mkherani Jun 4, 2015
37f7984
resolved conflicts due to changes elsewhere
mkherani Jun 4, 2015
71454d6
Get-AzureBackupContainer backend list containers API
Jun 5, 2015
5b2416a
fixes post merge
Jun 5, 2015
875fcfe
Merge pull request #4 from MabOneSdk/anudeeb
Jun 5, 2015
ec6db2c
Adding Sample Test case for Protection Policy
swatimadhukargit Jun 8, 2015
d9f0fa4
Merge branch 'master' into swatim
swatimadhukargit Jun 8, 2015
c5d5435
Merge pull request #5 from MabOneSdk/swatim
swatimadhukargit Jun 8, 2015
a2da26a
Adding resourcename and resourcegroup in app.config
swatimadhukargit Jun 8, 2015
a216af9
Merge pull request #6 from MabOneSdk/swatim
swatimadhukargit Jun 8, 2015
ecf390f
Regenerating hydra dll due to latest changes in api version.
Jun 8, 2015
2d21dc4
Download Vault Creds cmdlet fixes post component testing.
Jun 9, 2015
64f8f8f
Merge pull request #7 from MabOneSdk/anudeeb
Jun 9, 2015
5d6c78e
Fixes for build break
Jun 10, 2015
536e4ad
Fixes for build break part 2
Jun 10, 2015
4d75282
Merge pull request #8 from MabOneSdk/anudeeb
Jun 10, 2015
ed1c635
Get-AzureBackupContainer bug fixes
Jun 10, 2015
1ccebbc
Merge pull request #9 from MabOneSdk/anudeeb
Jun 10, 2015
e90d07d
ProtectionPolicy Changes in Azure-SDK-For-Net
pragrawa Jun 10, 2015
4462efe
Initial changes for jobs commandlets
AditTulasi Jun 11, 2015
6db2a81
Merge branch 'master' into adit-branch
AditTulasi Jun 11, 2015
40cfccc
Set-AzureBackupVaultStorageType cmdlet
Jun 11, 2015
7ce6a39
commit post merge
Jun 11, 2015
a004476
regenerating hydra post merge
Jun 11, 2015
ac6e572
Merge pull request #13 from MabOneSdk/anudeeb
Jun 11, 2015
7d32401
BackUpAndRecoveryScenario
panbha Jun 11, 2015
ac20df1
Merge pull request #14 from MabOneSdk/panbha5
panbha Jun 11, 2015
4d41be7
Saving temporary work
AditTulasi Jun 12, 2015
203ed1a
Upload Cert Test
Jun 12, 2015
12a4229
Merge pull request #15 from MabOneSdk/anudeeb
Jun 12, 2015
ceefa72
Including the session record for cert upload test
Jun 12, 2015
2e8ffe5
Adding a few more validations
Jun 12, 2015
0248967
Merge pull request #16 from MabOneSdk/anudeeb
Jun 12, 2015
8979849
Addint hydra testcases for azure backup item
pikumarmsft16 Jun 12, 2015
47ae706
Merge pull request #17 from MabOneSdk/pikumar-sdk-net
pikumarmsft16 Jun 12, 2015
7178961
Update storage type test
Jun 12, 2015
1978cfe
Merge pull request #18 from MabOneSdk/anudeeb
Jun 12, 2015
e711545
Container Tests
Jun 12, 2015
f23c1d1
Merge pull request #19 from MabOneSdk/anudeeb
Jun 12, 2015
93d0792
ProtectionPolicyHydraCases
pragrawa Jun 12, 2015
26d7b21
Resolving conflict for app.config
pragrawa Jun 12, 2015
8d6ade3
Merging the app.config conflict
pragrawa Jun 12, 2015
94350e6
Changing ScheduleRunTime
pragrawa Jun 12, 2015
5e63990
Merge pull request #12 from MabOneSdk/pragrawa
pragrawa Jun 12, 2015
3580eda
commit before merge
Jun 12, 2015
3e80e39
Merge branch 'master' into anudeeb
Jun 12, 2015
a6bb846
Protection policy tests -pragrawa
Jun 12, 2015
3a36f4e
Merge pull request #20 from MabOneSdk/anudeeb
Jun 12, 2015
1228324
Merge branch 'master' into adit-branch
AditTulasi Jun 15, 2015
bff4c8e
Adding jobs test cases
AditTulasi Jun 15, 2015
bd8f512
Merge branch 'master' into adit-branch
AditTulasi Jun 15, 2015
1602d2c
Adding session records for get jobs and job details
AditTulasi Jun 15, 2015
30c2258
Fixing a small mistake
AditTulasi Jun 15, 2015
123cd66
testcase
panbha Jun 15, 2015
8c88f3d
Merge pull request #21 from MabOneSdk/panbha11
panbha Jun 15, 2015
aaedaf8
testcase1
panbha Jun 15, 2015
aefe7c1
Merge pull request #22 from MabOneSdk/panbha11
panbha Jun 15, 2015
431393a
Modifying test case for storage type bug fixes. NOTE: Test will fail …
Jun 15, 2015
e057cbf
Merge pull request #23 from MabOneSdk/anudeeb
Jun 15, 2015
a8815e7
Updated cancel job test case to track cancel operation
AditTulasi Jun 16, 2015
469cfdd
Combining enable and disbale azure protection test case.
pikumarmsft16 Jun 16, 2015
062624d
Deleting json response
pikumarmsft16 Jun 16, 2015
469f0ac
Changes in protection policy json files according to new policy id.An…
pikumarmsft16 Jun 16, 2015
16dda1d
Adding json files
pikumarmsft16 Jun 16, 2015
809a0cc
small fix
pikumarmsft16 Jun 16, 2015
434601a
Adding ErrorInfo.cs file which was missed.
AditTulasi Jun 16, 2015
de1c573
Merge branch 'master' of https://github.com/MabOneSdk/azure-sdk-for-net
AditTulasi Jun 16, 2015
b27e6c7
Adding missing files in generated folder
pikumarmsft16 Jun 16, 2015
49cf0ec
Merge branch 'master' into pikumar5
pikumarmsft16 Jun 16, 2015
fda5d1f
ProtectionPolicyTest changes
pikumarmsft16 Jun 16, 2015
57aa9cc
Merge pull request #24 from MabOneSdk/pikumar5
pikumarmsft16 Jun 16, 2015
0eb2329
Adding a missing file in test cases
AditTulasi Jun 16, 2015
dbad961
change in json file due to change in policy id
pikumarmsft16 Jun 16, 2015
fec0f19
Changes for Reg and Unreg cmdlet
mkherani Jun 16, 2015
f77d10c
Merge pull request #25 from MabOneSdk/mkherani
mkherani Jun 16, 2015
4a908de
Added Hydra test case for Register and unregister cmdlet
mkherani Jun 16, 2015
d194e24
Merge pull request #26 from MabOneSdk/mkherani
mkherani Jun 16, 2015
95ff09a
Splitting enable and disable azure backup protection test case
pikumarmsft16 Jun 17, 2015
ea7968f
Merge branch 'master' of https://github.com/MabOneSdk/azure-sdk-for-net
pikumarmsft16 Jun 17, 2015
8dd31fe
Merge pull request #27 from MabOneSdk/pikumar5
pikumarmsft16 Jun 17, 2015
d02fe64
contracts for vault, and operation status
piyushka17 Jun 20, 2015
045e29c
Merge pull request #28 from MabOneSdk/piyushka
piyushka17 Jun 20, 2015
22b55b8
Changed some vault operations to take external input
piyushka17 Jun 22, 2015
6a2a1f6
Merge pull request #29 from MabOneSdk/piyushka
piyushka17 Jun 22, 2015
d3226e8
Adding a few helper methods for container tests (for future use)
Jun 22, 2015
46bd7cd
Merge branch 'master' into anudeeb
Jun 22, 2015
67b8da2
Merge pull request #30 from MabOneSdk/anudeeb
Jun 22, 2015
c778b90
Fix for JobLists to Jobs in OperationResponseResult
swatimadhukargit Jun 23, 2015
1b6ecb2
UpdatePolicy Asysc changes
pragrawa Jun 25, 2015
b5968aa
UpdatePolicy Asysc changes
pragrawa Jun 25, 2015
dec02f1
Merge branch 'master' into pragrawa
pragrawa Jun 25, 2015
76d6f53
UpdatePolicy Asysc changes
pragrawa Jun 25, 2015
cd5f83d
Merge pull request #31 from MabOneSdk/pragrawa
pragrawa Jun 25, 2015
5dd68e6
Fix for generating local nuget package
swatimadhukargit Jun 30, 2015
d7efac4
Merge pull request #32 from MabOneSdk/swatim2
swatimadhukargit Jun 30, 2015
e08f263
Renaming BackupServicesManagment to BackupServicesManagement
swatimadhukargit Jun 30, 2015
9a508c2
Merge pull request #33 from MabOneSdk/swatim2
swatimadhukargit Jun 30, 2015
fed128d
Merged from upstream/master
Jul 1, 2015
96438e6
Keeping only the sdk files for Vault cmdlets + their dependencies and…
Jul 1, 2015
28f5528
Hydra Tests
Jul 2, 2015
9b2826b
Using positive scenarios for Set-StorageType cmdlet instead of the ne…
Jul 2, 2015
df6f9b8
Removing some extra validation in UploadCert API test.
Jul 2, 2015
101e794
Added tests and the corresponding session records for vault APIs
Jul 3, 2015
7ba83f6
Undoing TestDependency project changes
swatimadhukargit Jul 3, 2015
92fd2a8
Using one ResourceApiVersion per client
swatimadhukargit Jul 8, 2015
03fc426
Removing nuget from BackupServicesManagement.csproj
swatimadhukargit Jul 8, 2015
ca558b9
Removing dependency of Security.Cryptography.dll and Microsoft.Azure.…
swatimadhukargit Jul 8, 2015
7ae6ef3
Ordering namespace
swatimadhukargit Jul 9, 2015
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
54 changes: 54 additions & 0 deletions src/ResourceManagement/AzureBackup/AzureBackup.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDependencies", "..\..\TestDependencies\TestDependencies.csproj", "{40F35645-00EE-4DF2-B66E-7624546B66DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupServices.Tests", "BackupServices.Tests\BackupServices.Tests.csproj", "{472DDC1D-318A-477C-949B-10811FDA6730}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackupServicesManagement", "BackupServicesManagement\BackupServicesManagement.csproj", "{38A6741C-77A3-42A8-A846-83373BE57C7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Net40-Debug|Any CPU = Net40-Debug|Any CPU
Net40-Release|Any CPU = Net40-Release|Any CPU
Net45-Debug|Any CPU = Net45-Debug|Any CPU
Net45-Release|Any CPU = Net45-Release|Any CPU
Portable-Debug|Any CPU = Portable-Debug|Any CPU
Portable-Release|Any CPU = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{40F35645-00EE-4DF2-B66E-7624546B66DF}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{472DDC1D-318A-477C-949B-10811FDA6730}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net40-Debug|Any CPU.ActiveCfg = Net40-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net40-Debug|Any CPU.Build.0 = Net40-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net40-Release|Any CPU.ActiveCfg = Net40-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net40-Release|Any CPU.Build.0 = Net40-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{38A6741C-77A3-42A8-A846-83373BE57C7F}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{472DDC1D-318A-477C-949B-10811FDA6730}</ProjectGuid>
<RootNamespace>BackupServices.Tests</RootNamespace>
<AssemblyName>BackupServices.Tests</AssemblyName>
</PropertyGroup>
<Import Project="..\..\..\..\tools\Library.Settings.targets" />
<Import Project="$(LibraryToolsFolder)\Test.Dependencies.target" />
<ItemGroup>
<Compile Include="Helpers\VaultTestHelper.cs" />
<Compile Include="ScenarioTests\BackupServicesTestBase.cs" />
<Compile Include="ScenarioTests\VaultTests.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web.Extensions" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\TestDependencies\TestDependencies.csproj">
<Project>{40f35645-00ee-4df2-b66e-7624546b66df}</Project>
<Name>TestDependencies</Name>
</ProjectReference>
<ProjectReference Include="..\BackupServicesManagement\BackupServicesManagement.csproj">
<Project>{38a6741c-77a3-42a8-a846-83373be57c7f}</Project>
<Name>BackupServicesManagement</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\CreateOrUpdateVaultReturnsValidCodeTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\DeleteVaultRemovesVaultTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\GetResourceStorageConfigReturnsStorageTypeTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\GetVaultReturnsSameVaultTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\ListVaultsByResourceGroupReturnsVaultsinResourceGroup.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\ListVaultsReturnsVaultsInSubscriptionTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\UpdateStorageTypeReturnsValidCodeTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\BackupServices.Tests.VaultTests\UploadCertReturnsValidResponseTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Microsoft.WindowsAzure.Management.Common.dll" />
<Content Include="Resources\Security.Cryptography.dll" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// 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.
//

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Microsoft.WindowsAzure.Management;

namespace BackupServices.Tests.Helpers
{
public static class VaultTestHelper
{
public const string MsEnhancedProv = "Microsoft Enhanced Cryptographic Provider v1.0";
public const string DefaultIssuer = "CN=Windows Azure Tools";

public const string DefaultPassword = "";
public const string OIDClientAuthValue = "1.3.6.1.5.5.7.3.2";
public const string OIDClientAuthFriendlyName = "Client Authentication";
public const int KeySize2048 = 2048;

///// <summary>
///// Windows Azure Service Management API requires 2048bit RSA keys.
///// The private key needs to be exportable so we can save it to .pfx for sharing with team members.
///// </summary>
///// <returns>A 2048 bit RSA key</returns>
////private static CngKey Create2048RsaKey()
//{
// var keyCreationParameters = new CngKeyCreationParameters
// {
// ExportPolicy = CngExportPolicies.AllowExport,
// KeyCreationOptions = CngKeyCreationOptions.None,
// KeyUsage = CngKeyUsages.AllUsages,
// Provider = new CngProvider(MsEnhancedProv)
// };

// keyCreationParameters.Parameters.Add(new CngProperty("Length", BitConverter.GetBytes(KeySize2048), CngPropertyOptions.None));

// return CngKey.Create(CngAlgorithm2.Rsa, null, keyCreationParameters);
//}

///// <summary>
///// Creates a new self-signed X509 certificate
///// </summary>
///// <param name="issuer">The certificate issuer</param>
///// <param name="friendlyName">Human readable name</param>
///// <param name="password">The certificate's password</param>
///// <param name="startTime">Certificate creation date & time</param>
///// <param name="endTime">Certificate expiry date & time</param>
///// <returns>An X509Certificate2</returns>
//public static X509Certificate2 CreateSelfSignedCert(string issuer, string friendlyName, string password, DateTime startTime, DateTime endTime)
//{
// string distinguishedNameString = issuer;
// var key = Create2048RsaKey();

// var creationParams = new X509CertificateCreationParameters(new X500DistinguishedName(distinguishedNameString))
// {
// TakeOwnershipOfKey = true,
// StartTime = startTime,
// EndTime = endTime
// };

// // adding client authentication, -eku = 1.3.6.1.5.5.7.3.2,
// // This is mandatory for the upload to be successful
// OidCollection oidCollection = new OidCollection();
// oidCollection.Add(new Oid(OIDClientAuthValue, OIDClientAuthFriendlyName));
// creationParams.Extensions.Add(new X509EnhancedKeyUsageExtension(oidCollection, false));

// // Documentation of CreateSelfSignedCertificate states:
// // If creationParameters have TakeOwnershipOfKey set to true, the certificate
// // generated will own the key and the input CngKey will be disposed to ensure
// // that the caller doesn't accidentally use it beyond its lifetime (which is
// // now controlled by the certificate object).
// // We don't dispose it ourselves in this case.
// var cert = key.CreateSelfSignedCertificate(creationParams);
// key = null;
// cert.FriendlyName = friendlyName;

// // X509 certificate needs PersistKeySet flag set.
// // Reload a new X509Certificate2 instance from exported bytes in order to set the PersistKeySet flag.
// var bytes = cert.Export(X509ContentType.Pfx, password);

// // NOTE: PfxValidation is not done here because these are newly created certs and assumed valid.

// ICommonEventSource evtSource = null;
// return X509Certificate2Helper.NewX509Certificate2(bytes, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable, evtSource, doPfxValidation: false);
//}

/// <summary>
/// Returns serialized certificate - Base64 encoded based on the content type
/// </summary>
/// <param name="cert">The certificate provided</param>
/// <param name="contentType">Cert content type</param>
/// <returns>The serialized cert value in string</returns>
public static string SerializeCert(X509Certificate2 cert, X509ContentType contentType)
{
return Convert.ToBase64String(cert.Export(contentType));
}

/// <summary>
/// Generates friendly name
/// </summary>
/// <param name="subscriptionId">Subscription id</param>
/// <param name="prefix">Prefix, likely resource name</param>
/// <returns>Friendly name</returns>
public static string GenerateCertFriendlyName(string subscriptionId, string prefix = "")
{
return string.Format("{0}{1}-{2}-vaultcredentials", prefix, subscriptionId, DateTime.Now.ToString("M-d-yyyy"));
}

/// <summary>
/// Method to return the Certificate Expiry time in hours
/// </summary>
/// <param name="resourceType"></param>
/// <returns></returns>
public static int GetCertificateExpiryInHours(string resourceType = null)
{
return Constants.VaultCertificateExpiryInHoursForBackup;
}
}

public static class Constants
{
public const int VaultCertificateExpiryInHoursForBackup = 48;
}

public enum AzureBackupVaultStorageType
{
GeoRedundant = 1,
LocallyRedundant,
}

public enum AzureBackupVaultStorageTypeState
{
Locked = 1,
Unlocked,
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// Copyright (c) Microsoft. All rights reserved.
//
// 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.
//

using System;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Reflection;
using Microsoft.Azure;
using Microsoft.Azure.Management.BackupServices;
using Microsoft.Azure.Management.BackupServices.Models;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;

namespace BackupServices.Tests
{
public class BackupServicesTestsBase : TestBase
{
public new static T GetServiceClient<T>() where T : class
{
var factory = (TestEnvironmentFactory)new CSMTestEnvironmentFactory();

var testEnvironment = factory.GetTestEnvironment();
ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

BackupVaultServicesManagementClient client;

string resourceName = ConfigurationManager.AppSettings["ResourceName"];
string resourceGroupName = ConfigurationManager.AppSettings["ResourceGroupName"];
if (testEnvironment.UsesCustomUri())
{
client = new BackupVaultServicesManagementClient(
resourceName,
resourceGroupName,
testEnvironment.Credentials as SubscriptionCloudCredentials,
testEnvironment.BaseUri);
}
else
{
client = new BackupVaultServicesManagementClient(
resourceName,
resourceGroupName,
testEnvironment.Credentials as SubscriptionCloudCredentials);
}

return GetServiceClient<T>(factory, client);
}


public static T GetServiceClient<T>(TestEnvironmentFactory factory, BackupVaultServicesManagementClient client) where T : class
{
TestEnvironment testEnvironment = factory.GetTestEnvironment();

HttpMockServer instance;
try
{
instance = HttpMockServer.CreateInstance();
}
catch (ApplicationException)
{
HttpMockServer.Initialize("TestEnvironment", "InitialCreation");
instance = HttpMockServer.CreateInstance();
}
T obj2 = typeof(T).GetMethod("WithHandler", new Type[1]
{
typeof (DelegatingHandler)
}).Invoke((object)client, new object[1]
{
(object) instance
}) as T;

if (HttpMockServer.Mode == HttpRecorderMode.Record)
{
HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId;
}

if (HttpMockServer.Mode == HttpRecorderMode.Playback)
{
PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int));
PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int));
if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null)
{
property1.SetValue((object)obj2, (object)0);
property2.SetValue((object)obj2, (object)0);
}
}
return obj2;
}

private static bool IgnoreCertificateErrorHandler
(object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}

public static CustomRequestHeaders GetCustomRequestHeaders()
{
return new CustomRequestHeaders()
{
ClientRequestId = Guid.NewGuid().ToString(),
};
}
}
}
Loading