Skip to content

HPF PR: dev <- Azure:dev #552

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 13 commits into from
Jun 17, 2016
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
Expand Up @@ -37,8 +37,7 @@ namespace Microsoft.Azure.Commands.Batch.Test
/// </summary>
public static class BatchTestHelpers
{
internal static readonly string TestCertificateFileName1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\BatchTestCert01.cer");
internal static readonly string TestCertificateFileName2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\BatchTestCert02.cer");
internal static readonly string TestCertificateFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\BatchTestCert01.cer");
internal const string TestCertificateAlgorithm = "sha1";
internal const string TestCertificatePassword = "Passw0rd";
internal static readonly int DefaultQuotaCount = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.BatchRequests;
using Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
Expand All @@ -22,6 +23,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

Expand All @@ -47,15 +49,15 @@ public NewBatchCertificateCommandTests(Xunit.Abstractions.ITestOutputHelper outp

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchCertificateParametersTest()
public void NewBatchCertificateRequiredParametersTest()
{
// Setup cmdlet without the required parameters
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());

cmdlet.FilePath = BatchTestHelpers.TestCertificateFileName1;
cmdlet.FilePath = BatchTestHelpers.TestCertificateFileName;

// Don't go to the service on an Add Certificate call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
Expand All @@ -70,11 +72,80 @@ public void NewBatchCertificateParametersTest()

// Use the RawData parameter set next
cmdlet.FilePath = null;
X509Certificate2 cert = new X509Certificate2(BatchTestHelpers.TestCertificateFileName1);
X509Certificate2 cert = new X509Certificate2(BatchTestHelpers.TestCertificateFileName);
cmdlet.RawData = cert.RawData;

// Verify no exceptions when required parameters are set
cmdlet.ExecuteCmdlet();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchCertificateRequestBodyTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

X509Certificate2 cert = new X509Certificate2(BatchTestHelpers.TestCertificateFileName);
string certDataBase64String = Convert.ToBase64String(cert.RawData);

CertificateAddParameter requestParameters = null;

// Don't go to the service on an Add Certificate call
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
{
CertificateAddBatchRequest request = (CertificateAddBatchRequest)baseRequest;

request.ServiceRequestFunc = (cancellationToken) =>
{
requestParameters = request.Parameters;

var response = new AzureOperationHeaderResponse<CertificateAddHeaders>();
Task<AzureOperationHeaderResponse<CertificateAddHeaders>> task = Task.FromResult(response);
return task;
};
});

cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify that when just the raw data is specified, the request body matches expectations
cmdlet.RawData = cert.RawData;
cmdlet.ExecuteCmdlet();
Assert.Equal(CertificateFormat.Cer, requestParameters.CertificateFormat);
Assert.Equal(BatchTestHelpers.TestCertificateAlgorithm, requestParameters.ThumbprintAlgorithm);
Assert.Equal(cert.Thumbprint.ToLowerInvariant(), requestParameters.Thumbprint.ToLowerInvariant());
Assert.True(string.IsNullOrEmpty(requestParameters.Password));
Assert.Equal(certDataBase64String, requestParameters.Data);

// Verify that when the raw data is specified with a password, the request body matches expectations
cmdlet.RawData = cert.RawData;
cmdlet.Password = BatchTestHelpers.TestCertificatePassword;
cmdlet.ExecuteCmdlet();
Assert.Equal(CertificateFormat.Pfx, requestParameters.CertificateFormat);
Assert.Equal(BatchTestHelpers.TestCertificateAlgorithm, requestParameters.ThumbprintAlgorithm);
Assert.Equal(cert.Thumbprint.ToLowerInvariant(), requestParameters.Thumbprint.ToLowerInvariant());
Assert.Equal(BatchTestHelpers.TestCertificatePassword, requestParameters.Password);
Assert.Equal(certDataBase64String, requestParameters.Data);

// Verify that when just a file path is specified, the request body matches expectations
cmdlet.RawData = null;
cmdlet.Password = null;
cmdlet.FilePath = BatchTestHelpers.TestCertificateFileName;
cmdlet.ExecuteCmdlet();
Assert.Equal(CertificateFormat.Cer, requestParameters.CertificateFormat);
Assert.Equal(BatchTestHelpers.TestCertificateAlgorithm, requestParameters.ThumbprintAlgorithm);
Assert.Equal(cert.Thumbprint.ToLowerInvariant(), requestParameters.Thumbprint.ToLowerInvariant());
Assert.True(string.IsNullOrEmpty(requestParameters.Password));
Assert.Equal(certDataBase64String, requestParameters.Data);

// Verify that when a file path is specified with a password, the request body matches expectations
cmdlet.Password = BatchTestHelpers.TestCertificatePassword;
cmdlet.ExecuteCmdlet();
Assert.Equal(CertificateFormat.Pfx, requestParameters.CertificateFormat);
Assert.Equal(BatchTestHelpers.TestCertificateAlgorithm, requestParameters.ThumbprintAlgorithm);
Assert.Equal(cert.Thumbprint.ToLowerInvariant(), requestParameters.Thumbprint.ToLowerInvariant());
Assert.Equal(BatchTestHelpers.TestCertificatePassword, requestParameters.Password);
Assert.Equal(certDataBase64String, requestParameters.Data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,6 @@
<None Include="Resources\BatchTestCert01.cer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\BatchTestCert02.cer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\BatchTestCert03.cer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\BatchTestCert04.pfx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\BatchTestCert05.pfx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Resources\TestApplicationPackage.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -371,29 +359,11 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchApplicationTests\TestUploadApplicationPackage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestAddCertificate.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestCancelCertificateDelete.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestDeleteCertificate.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestGetAndListCertificatesWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestGetCertificateByThumbprint.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestListAllCertificates.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestListCertificatesByFilter.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestListCertificatesWithMaxCount.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestCertificateCrudOperations.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestDisableAndEnableComputeNodeSchedulingById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -695,9 +665,6 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllTasks.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListSubtasksWithMaxCount.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListTaskPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using TestBase = Microsoft.Azure.Test.TestBase;
using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory;
using TestUtilities = Microsoft.Azure.Test.TestUtilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,152 +29,9 @@ public CertificateTests(Xunit.Abstractions.ITestOutputHelper output)

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAddCertificate()
public void TestCertificateCrudOperations()
{
BatchController.NewInstance.RunPsTest("Test-AddCertificate");
}

[Fact]
public void TestGetCertificateByThumbprint()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string thumbprint = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-GetCertificateByThumbprint '{0}' '{1}'", BatchTestHelpers.TestCertificateAlgorithm, thumbprint) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
},
() =>
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint);
},
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
public void TestListCertificatesByFilter()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string state = "active";
string thumbprint1 = null;
string toDeleteThumbprint = null;
int matchCount = 1;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-ListCertificatesByFilter '{0}' '{1}' '{2}'", state, toDeleteThumbprint, matchCount) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint1 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
toDeleteThumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName2);
},
() =>
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint1);
// Other cert is deleted as the first part of the PowerShell test script, but we ensure it's gone.
try
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, toDeleteThumbprint);
}
catch { }
},
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetAndListCertificatesWithSelect()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string thumbprint = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-GetAndListCertificatesWithSelect '{0}' '{1}'", BatchTestHelpers.TestCertificateAlgorithm, thumbprint) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
},
() =>
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint);
},
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
public void TestListCertificatesWithMaxCount()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
int maxCount = 1;
string thumbprint1 = null;
string thumbprint2 = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-ListCertificatesWithMaxCount '{0}'", maxCount) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint1 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
thumbprint2 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName2);
},
() =>
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint1);
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint2);
},
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
public void TestListAllCertificates()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
int count = 2;
string thumbprint1 = null;
string thumbprint2 = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-ListAllCertificates '{0}'", count) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint1 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
thumbprint2 = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName2);
},
() =>
{
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint1);
ScenarioTestHelpers.DeleteTestCertificate(controller, context, BatchTestHelpers.TestCertificateAlgorithm, thumbprint2);
},
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDeleteCertificate()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string thumbprint = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-DeleteCertificate '{0}' '{1}'", BatchTestHelpers.TestCertificateAlgorithm, thumbprint) }; },
() =>
{
context = new ScenarioTestContext();
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
},
null,
TestUtilities.GetCallingClass(),
TestUtilities.GetCurrentMethodName());
BatchController.NewInstance.RunPsTest("Test-CertificateCrudOperations");
}

[Fact]
Expand All @@ -189,7 +46,7 @@ public void TestCancelCertificateDelete()
() =>
{
context = new ScenarioTestContext();
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName1);
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName);
CertificateReference certRef = new CertificateReference();
certRef.StoreLocation = CertStoreLocation.CurrentUser;
certRef.StoreName = "My";
Expand Down
Loading