diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 index 9ac4ceb17a5..cffda8b11dd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 @@ -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) @@ -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 { @@ -44,17 +33,27 @@ Describe "Certificate Provider tests" -Tags "CI" { } Context "Get-Item tests" { - It "Should be able to get a certificate store, 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: " -TestCases $currentUserMyLocations { + param([string] $path) + GetItemTestHelper $path + } + It "Should be able to get a certificate store, 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 } @@ -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:\ } @@ -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: " -TestCases $currentUserMyLocations { @@ -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 @@ -133,17 +134,17 @@ 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 } @@ -151,18 +152,18 @@ Describe "Certificate Provider tests" -Tags "Feature" { $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 }