Skip to content
Closed
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
@@ -1,31 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# The import and table creation work on non-windows, but are currently not needed
if($IsWindows)
{
Import-Module (Join-Path -Path $PSScriptRoot 'certificateCommon.psm1') -Force
}

$currentUserMyLocations = @(
@{path = 'Cert:\CurrentUser\my'}
@{path = 'cert:\currentuser\my'}
@{path = 'Microsoft.PowerShell.Security\Certificate::CurrentUser\My'}
@{path = 'Microsoft.PowerShell.Security\certificate::currentuser\my'}
)

$testLocations = @(
@{path = 'cert:\'}
@{path = 'CERT:\'}
@{path = 'Microsoft.PowerShell.Security\Certificate::'}
)

# Add CurrentUserMyLocations to TestLocations
foreach($location in $currentUserMyLocations)
{
$testLocations += $location
}

Describe "Certificate Provider tests" -Tags "CI" {
BeforeAll{
if(!$IsWindows)
Expand All @@ -34,6 +9,20 @@ Describe "Certificate Provider tests" -Tags "CI" {
$defaultParamValues = $global:PSDefaultParameterValues.Clone()
$global:PSDefaultParameterValues = @{ "it:skip" = $true }
}
else
{
$testLocations = @(
@{path = 'cert:\'}
@{path = 'CERT:\'}
@{path = 'Microsoft.PowerShell.Security\Certificate::'}
)
$currentUserMyLocations = @(
@{path = 'Cert:\CurrentUser\my'}
@{path = 'cert:\currentuser\my'}
@{path = 'Microsoft.PowerShell.Security\Certificate::CurrentUser\My'}
@{path = 'Microsoft.PowerShell.Security\certificate::currentuser\my'}
)
}
}

AfterAll {
Expand All @@ -44,17 +33,27 @@ Describe "Certificate Provider tests" -Tags "CI" {
}

Context "Get-Item tests" {
It "Should be able to get a certificate store, path: <path>" -TestCases $testLocations {
param([string] $path)
$expectedResolvedPath = Resolve-Path -LiteralPath $path
$result = Get-Item -LiteralPath $path
$result | Should -Not -Be null
$result | ForEach-Object {
$resolvedPath = Resolve-Path $_.PSPath
$resolvedPath.Provider | Should -Be $expectedResolvedPath.Provider
$resolvedPath.ProviderPath.TrimStart('\') | Should -Be $expectedResolvedPath.ProviderPath.TrimStart('\')
BeforeAll {
function GetItemTestHelper {
param([string] $path)
$expectedResolvedPath = Resolve-Path -LiteralPath $path
$result = Get-Item -LiteralPath $path
$result | Should -Not -Be $null
$result | ForEach-Object {
$resolvedPath = Resolve-Path $_.PSPath
$resolvedPath.Provider | Should -Be $expectedResolvedPath.Provider
$resolvedPath.ProviderPath.TrimStart('\') | Should -Be $expectedResolvedPath.ProviderPath.TrimStart('\')
}
}
}
It "Should be able to get a certificate store, path: <path>" -TestCases $currentUserMyLocations {
param([string] $path)
GetItemTestHelper $path
}
It "Should be able to get a certificate store, path: <path>" -TestCases $testLocations -Pending:$true {
param([string] $path)
GetItemTestHelper $path
}
It "Should return two items at the root of the provider" {
(Get-Item -Path cert:\*).Count | Should -Be 2
}
Expand Down Expand Up @@ -82,6 +81,8 @@ Describe "Certificate Provider tests" -Tags "Feature" {
BeforeAll{
if($IsWindows)
{
# The import and table creation work on non-windows, but are currently not needed
Import-Module (Join-Path -Path $PSScriptRoot 'certificateCommon.psm1') -Force
Install-TestCertificates
Push-Location Cert:\
}
Expand Down Expand Up @@ -111,7 +112,7 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$expectedThumbprint = (Get-GoodCertificateObject).Thumbprint
$leafPath = Join-Path -Path $path -ChildPath $expectedThumbprint
$cert = (Get-Item -LiteralPath $leafPath)
$cert | Should -Not -Be null
$cert | Should -Not -Be $null
$cert.Thumbprint | Should -Be $expectedThumbprint
}
It "Should be able to get DnsNameList of certifate by path: <path>" -TestCases $currentUserMyLocations {
Expand All @@ -121,8 +122,8 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$expectedEncodedName = (Get-GoodCertificateObject).DnsNameList[0].Punycode
$leafPath = Join-Path -Path $path -ChildPath $expectedThumbprint
$cert = (Get-Item -LiteralPath $leafPath)
$cert | Should -Not -Be null
$cert.DnsNameList | Should -Not -Be null
$cert | Should -Not -Be $null
$cert.DnsNameList | Should -Not -Be $null
$cert.DnsNameList.Count | Should -Be 1
$cert.DnsNameList[0].Unicode | Should -Be $expectedName
$cert.DnsNameList[0].Punycode | Should -Be $expectedEncodedName
Expand All @@ -133,36 +134,36 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$expectedOid = (Get-GoodCertificateObject).EnhancedKeyUsageList[0].ObjectId
$leafPath = Join-Path -Path $path -ChildPath $expectedThumbprint
$cert = (Get-Item -LiteralPath $leafPath)
$cert | Should -Not -Be null
$cert.EnhancedKeyUsageList | Should -Not -Be null
$cert | Should -Not -Be $null
$cert.EnhancedKeyUsageList | Should -Not -Be $null
$cert.EnhancedKeyUsageList.Count | Should -Be 1
$cert.EnhancedKeyUsageList[0].ObjectId.Length | Should -Not -Be 0
$cert.EnhancedKeyUsageList[0].ObjectId | Should -Be $expectedOid
}
It "Should filter to codesign certificates" {
It "Should filter to codesign certificates" -Pending:$true {
$allCerts = Get-Item cert:\CurrentUser\My\*
$codeSignCerts = Get-Item cert:\CurrentUser\My\* -CodeSigningCert
$codeSignCerts | Should -Not -Be null
$allCerts | Should -Not -Be null
$codeSignCerts | Should -Not -Be $null
$allCerts | Should -Not -Be $null
$nonCodeSignCertCount = $allCerts.Count - $codeSignCerts.Count
$nonCodeSignCertCount | Should -Not -Be 0
}
It "Should be able to exclude by thumbprint" {
$allCerts = Get-Item cert:\CurrentUser\My\*
$testThumbprint = (Get-GoodCertificateObject).Thumbprint
$allCertsExceptOne = (Get-Item "cert:\currentuser\my\*" -Exclude $testThumbprint)
$allCerts | Should -Not -Be null
$allCertsExceptOne | Should -Not -Be null
$allCerts | Should -Not -Be $null
$allCertsExceptOne | Should -Not -Be $null
$countDifference = $allCerts.Count - $allCertsExceptOne.Count
$countDifference | Should -Be 1
}
}
Context "Get-ChildItem tests"{
It "Should filter to codesign certificates" {
It "Should filter to codesign certificates" -Pending:$true {
$allCerts = Get-ChildItem cert:\CurrentUser\My
$codeSignCerts = Get-ChildItem cert:\CurrentUser\My -CodeSigningCert
$codeSignCerts | Should -Not -Be null
$allCerts | Should -Not -Be null
$codeSignCerts | Should -Not -Be $null
$allCerts | Should -Not -Be $null
$nonCodeSignCertCount = $allCerts.Count - $codeSignCerts.Count
$nonCodeSignCertCount | Should -Not -Be 0
}
Expand Down