Skip to content

Commit

Permalink
TestUtils update
Browse files Browse the repository at this point in the history
Cleanup of unnecessary CA cert is done right in New-TestCertificate now, instead of later.  Makes this function less annoying to use for demos.
  • Loading branch information
dlwyatt committed Mar 29, 2015
1 parent f41e9d8 commit 9bfa49f
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions TestUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,34 +182,44 @@ OID = 1.3.6.1.4.1.311.80.1
{
Remove-Item -Path $requestfile -Force -ErrorAction SilentlyContinue
Remove-Item -Path $certFile -Force -ErrorAction SilentlyContinue

if (Test-Path Cert:\CurrentUser\CA\$newCert)
{
try
{
$store = Get-Item Cert:\CurrentUser\CA
$store.Open('ReadWrite')

$cert = Get-Item Cert:\CurrentUser\CA\$newCert

$store.Remove($cert)

$store.Close()
}
catch { }
}
}
}

function Remove-TestCertificate
{
$pathsToCheck = @(
'Cert:\CurrentUser\My'
'Cert:\CurrentUser\CA'
$path = 'Cert:\CurrentUser\My'

$oldCerts = @(
Get-ChildItem $path |
Where-Object { $_.Subject -eq $testCertificateSubject }
)

foreach ($path in $pathsToCheck)
if ($oldCerts.Count -gt 0)
{
$oldCerts = @(
Get-ChildItem $path |
Where-Object { $_.Subject -eq $testCertificateSubject }
)
$store = Get-Item $path
$store.Open('ReadWrite')

if ($oldCerts.Count -gt 0)
foreach ($oldCert in $oldCerts)
{
$store = Get-Item $path
$store.Open('ReadWrite')

foreach ($oldCert in $oldCerts)
{
$store.Remove($oldCert)
}

$store.Close()
$store.Remove($oldCert)
}

$store.Close()
}
}

0 comments on commit 9bfa49f

Please sign in to comment.