Skip to content

Update Batch REST client internals #1275

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 2 commits into from
Nov 13, 2015
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 @@ -215,6 +215,7 @@
<Compile Include="ScenarioTests\FileTests.cs" />
<Compile Include="ScenarioTests\JobTests.cs" />
<Compile Include="ScenarioTests\PoolTests.cs" />
<Compile Include="ScenarioTests\ScenarioTestContext.cs" />
<Compile Include="ScenarioTests\ScenarioTestHelpers.cs" />
<Compile Include="ScenarioTests\SubscriptionTests.cs" />
<Compile Include="ScenarioTests\TaskTests.cs" />
Expand Down Expand Up @@ -274,7 +275,7 @@
</None>
<None Include="ScenarioTests\SubscriptionTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
<None Include="ScenarioTests\TaskTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -568,7 +569,7 @@
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.SubscriptionTests\TestGetSubscriptionQuotas.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestCreateTask.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void TestGetCertificateByThumbprint()
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string thumbprintAlgorithm = null;
string thumbprint = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-GetCertificateByThumbprint '{0}' '{1}' '{2}'", accountName, BatchTestHelpers.TestCertificateAlgorithm, thumbprint) }; },
Expand Down Expand Up @@ -218,45 +217,4 @@ public void TestCancelCertificateDelete()
TestUtilities.GetCurrentMethodName());
}
}

// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
[Cmdlet(VerbsCommon.Get, "AzureBatchCertificate_ST", DefaultParameterSetName = Constants.ODataFilterParameterSet)]
public class GetBatchCertificateScenarioTestCommand : GetBatchCertificateCommand
{
protected override void ProcessRecord()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ProcessRecord();
}
}

[Cmdlet(VerbsCommon.New, "AzureBatchCertificate_ST", DefaultParameterSetName = FileParameterSet)]
public class NewBatchCertificateScenarioTestCommand : NewBatchCertificateCommand
{
protected override void ProcessRecord()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ProcessRecord();
}
}

[Cmdlet(VerbsCommon.Remove, "AzureBatchCertificate_ST")]
public class RemoveBatchCertificateScenarioTestCommand : RemoveBatchCertificateCommand
{
protected override void ProcessRecord()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ProcessRecord();
}
}

[Cmdlet(VerbsLifecycle.Stop, "AzureBatchCertificateDeletion_ST")]
public class StopBatchCertificateDeletionScenarioTestCommand : StopBatchCertificateDeletionCommand
{
protected override void ProcessRecord()
{
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
base.ProcessRecord();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,52 @@ Tests adding certificates to a Batch account
#>
function Test-AddCertificate
{
param([string]$accountName)

$context = Get-AzureRmBatchAccountKeys -Name $accountName

# Load certificates so thumbprints can be compared later
$localDir = ($pwd).Path # Use $pwd to get the local directory. If $pwd is not used, paths are relative to [Environment]::CurrentDirectory, which can be different
$cer2Path = $localDir + "\Resources\BatchTestCert02.cer"
$cer3Path = $localDir + "\Resources\BatchTestCert03.cer"
$pfx4Path = $localDir + "\Resources\BatchTestCert04.pfx"
$pfx5Path = $localDir + "\Resources\BatchTestCert05.pfx"

$password = "Passw0rd"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

$cer2 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $cer2Path
$cer3 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $cer3Path
$pfx4 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($pfx4Path,$securePassword)
$pfx5 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($pfx5Path,$securePassword)
$pfx5Bytes = [System.IO.File]::ReadAllBytes($pfx5Path)
try
{
# .cer by file path
New-AzureBatchCertificate_ST $cer2Path -BatchContext $context
$cert = Get-AzureBatchCertificate_ST "sha1" $cer2.Thumbprint -BatchContext $context
Assert-AreEqual $cer2.Thumbprint $cert.Thumbprint

# .cer by raw data
$cer3 | New-AzureBatchCertificate_ST -BatchContext $context
$cert = Get-AzureBatchCertificate_ST "sha1" $cer3.Thumbprint -BatchContext $context
Assert-AreEqual $cer3.Thumbprint $cert.Thumbprint
# .pfx by file path
New-AzureBatchCertificate_ST $pfx4Path -Password $password -BatchContext $context
$cert = Get-AzureBatchCertificate_ST "sha1" $pfx4.Thumbprint -BatchContext $context
Assert-AreEqual $pfx4.Thumbprint $cert.Thumbprint

# .pfx by raw data
New-AzureBatchCertificate_ST $pfx5Bytes -Password $password -BatchContext $context
$cert = Get-AzureBatchCertificate_ST "sha1" $pfx4.Thumbprint -BatchContext $context
Assert-AreEqual $pfx4.Thumbprint $cert.Thumbprint
}
finally
{
Get-AzureBatchCertificate_ST -BatchContext $context | Remove-AzureBatchCertificate_ST -Force -BatchContext $context
}
param([string]$accountName)

$context = Get-ScenarioTestContext $accountName

# Load certificates so thumbprints can be compared later
$localDir = ($pwd).Path # Use $pwd to get the local directory. If $pwd is not used, paths are relative to [Environment]::CurrentDirectory, which can be different
$cer2Path = $localDir + "\Resources\BatchTestCert02.cer"
$cer3Path = $localDir + "\Resources\BatchTestCert03.cer"
$pfx4Path = $localDir + "\Resources\BatchTestCert04.pfx"
$pfx5Path = $localDir + "\Resources\BatchTestCert05.pfx"

$password = "Passw0rd"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

$cer2 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $cer2Path
$cer3 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $cer3Path
$pfx4 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($pfx4Path,$securePassword)
$pfx5 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($pfx5Path,$securePassword)
$pfx5Bytes = [System.IO.File]::ReadAllBytes($pfx5Path)
try
{
# .cer by file path
New-AzureBatchCertificate $cer2Path -BatchContext $context
$cert = Get-AzureBatchCertificate "sha1" $cer2.Thumbprint -BatchContext $context
Assert-AreEqual $cer2.Thumbprint $cert.Thumbprint

# .cer by raw data
$cer3 | New-AzureBatchCertificate -BatchContext $context
$cert = Get-AzureBatchCertificate "sha1" $cer3.Thumbprint -BatchContext $context
Assert-AreEqual $cer3.Thumbprint $cert.Thumbprint
# .pfx by file path
New-AzureBatchCertificate $pfx4Path -Password $password -BatchContext $context
$cert = Get-AzureBatchCertificate "sha1" $pfx4.Thumbprint -BatchContext $context
Assert-AreEqual $pfx4.Thumbprint $cert.Thumbprint

# .pfx by raw data
New-AzureBatchCertificate $pfx5Bytes -Password $password -BatchContext $context
$cert = Get-AzureBatchCertificate "sha1" $pfx4.Thumbprint -BatchContext $context
Assert-AreEqual $pfx4.Thumbprint $cert.Thumbprint
}
finally
{
Get-AzureBatchCertificate -BatchContext $context | Remove-AzureBatchCertificate -Force -BatchContext $context
}
}

<#
Expand All @@ -72,13 +72,13 @@ Tests querying for a certificate by its thumbprint
#>
function Test-GetCertificateByThumbprint
{
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$cert = Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context
$context = Get-ScenarioTestContext $accountName
$cert = Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context

Assert-AreEqual $thumbprint $cert.Thumbprint
Assert-AreEqual $thumbprintAlgorithm $cert.ThumbprintAlgorithm
Assert-AreEqual $thumbprint $cert.Thumbprint
Assert-AreEqual $thumbprintAlgorithm $cert.ThumbprintAlgorithm
}

<#
Expand All @@ -87,21 +87,21 @@ Tests querying for Batch certs using a filter
#>
function Test-ListCertificatesByFilter
{
param([string]$accountName, [string]$state, [string]$toDeleteThumbprint, [string]$matches)
param([string]$accountName, [string]$state, [string]$toDeleteThumbprint, [string]$matches)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$filter = "state eq '$state'"
$context = Get-ScenarioTestContext $accountName
$filter = "state eq '$state'"

# Put a cert in the 'deleting' state
Remove-AzureBatchCertificate_ST "sha1" $toDeleteThumbprint -Force -BatchContext $context
# Put a cert in the 'deleting' state
Remove-AzureBatchCertificate "sha1" $toDeleteThumbprint -Force -BatchContext $context

$certs = Get-AzureBatchCertificate_ST -Filter $filter -BatchContext $context
$certs = Get-AzureBatchCertificate -Filter $filter -BatchContext $context

Assert-AreEqual $matches $certs.Length
foreach($cert in $certs)
{
Assert-AreEqual $state $cert.State
}
Assert-AreEqual $matches $certs.Length
foreach($cert in $certs)
{
Assert-AreEqual $state $cert.State
}
}

<#
Expand All @@ -110,29 +110,29 @@ Tests querying for Batch certs using a select clause
#>
function Test-GetAndListCertificatesWithSelect
{
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$filter = "state eq 'active'"
$selectClause = "thumbprint,state"
$context = Get-ScenarioTestContext $accountName
$filter = "state eq 'active'"
$selectClause = "thumbprint,state"

# Test with Get cert API
$cert = Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreNotEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint
# Test with Get cert API
$cert = Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreNotEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint

$cert = Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -Select $selectClause -BatchContext $context
Assert-AreEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint
$cert = Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -Select $selectClause -BatchContext $context
Assert-AreEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint

# Test with List certs API
$cert = Get-AzureBatchCertificate_ST -Filter $filter -BatchContext $context
Assert-AreNotEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint
# Test with List certs API
$cert = Get-AzureBatchCertificate -Filter $filter -BatchContext $context
Assert-AreNotEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint

$cert = Get-AzureBatchCertificate_ST -Filter $filter -Select $selectClause -BatchContext $context
Assert-AreEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint
$cert = Get-AzureBatchCertificate -Filter $filter -Select $selectClause -BatchContext $context
Assert-AreEqual $null $cert.Url
Assert-AreEqual $thumbprint $cert.Thumbprint
}

<#
Expand All @@ -141,12 +141,12 @@ Tests querying for Batch certs and supplying a max count
#>
function Test-ListCertificatesWithMaxCount
{
param([string]$accountName, [string]$maxCount)
param([string]$accountName, [string]$maxCount)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$certs = Get-AzureBatchCertificate_ST -MaxCount $maxCount -BatchContext $context
$context = Get-ScenarioTestContext $accountName
$certs = Get-AzureBatchCertificate -MaxCount $maxCount -BatchContext $context

Assert-AreEqual $maxCount $certs.Length
Assert-AreEqual $maxCount $certs.Length
}

<#
Expand All @@ -155,12 +155,12 @@ Tests querying for all certs under an account
#>
function Test-ListAllCertificates
{
param([string]$accountName, [string]$count)
param([string]$accountName, [string]$count)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$certs = Get-AzureBatchCertificate_ST -BatchContext $context
$context = Get-ScenarioTestContext $accountName
$certs = Get-AzureBatchCertificate -BatchContext $context

Assert-AreEqual $count $certs.Length
Assert-AreEqual $count $certs.Length
}

<#
Expand All @@ -169,21 +169,21 @@ Tests deleting a cert
#>
function Test-DeleteCertificate
{
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$context = Get-ScenarioTestContext $accountName

# Verify the cert exists
$cert = Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreEqual $thumbprint $cert.Thumbprint
# Verify the cert exists
$cert = Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreEqual $thumbprint $cert.Thumbprint

Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context | Remove-AzureBatchCertificate_ST -Force -BatchContext $context
Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context | Remove-AzureBatchCertificate -Force -BatchContext $context

# Verify the cert was deleted. Use the List API since the Get Certificate API will return a 404 if the cert isn't found.
$filter = "state eq 'deleting'"
$cert = Get-AzureBatchCertificate_ST -Filter $filter -BatchContext $context
Assert-True { $cert -eq $null -or $cert.Thumbprint -eq $thumbprint }
# Verify the cert was deleted. Use the List API since the Get Certificate API will return a 404 if the cert isn't found.
$filter = "state eq 'deleting'"
$cert = Get-AzureBatchCertificate -Filter $filter -BatchContext $context
Assert-True { $cert -eq $null -or $cert.Thumbprint -eq $thumbprint }
}

<#
Expand All @@ -192,19 +192,19 @@ Tests canceling a cert deletion
#>
function Test-TestCancelCertificateDelete
{
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)
param([string]$accountName, [string]$thumbprintAlgorithm, [string]$thumbprint)

$context = Get-AzureRmBatchAccountKeys -Name $accountName
$context = Get-ScenarioTestContext $accountName

# Verify the cert is in the deletefailed state
$cert = Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreEqual 'deletefailed' $cert.State.ToString().ToLower()
# Verify the cert is in the deletefailed state
$cert = Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context
Assert-AreEqual 'deletefailed' $cert.State.ToString().ToLower()

Get-AzureBatchCertificate_ST $thumbprintAlgorithm $thumbprint -BatchContext $context | Stop-AzureBatchCertificateDeletion_ST -BatchContext $context
Get-AzureBatchCertificate $thumbprintAlgorithm $thumbprint -BatchContext $context | Stop-AzureBatchCertificateDeletion -BatchContext $context

# Verify the cert went back to the active state
$filter = "state eq 'active'"
$cert = Get-AzureBatchCertificate_ST -Filter $filter -BatchContext $context
Assert-AreEqual $thumbprint $cert.Thumbprint
# Verify the cert went back to the active state
$filter = "state eq 'active'"
$cert = Get-AzureBatchCertificate -Filter $filter -BatchContext $context
Assert-AreEqual $thumbprint $cert.Thumbprint
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Gets a ScenarioTestContext for the specified account
#>
function Get-ScenarioTestContext($accountName)
{
$context = Get-AzureRmBatchAccountKeys $accountName
$testContext = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext -ArgumentList $context
return $testContext
}


<#
.SYNOPSIS
Gets a Batch account name for testing.
Expand Down
Loading