Test fixes for stabilizing tests (#19068)

This commit is contained in:
Aditya Patwardhan
2023-04-07 11:59:37 -07:00
committed by Dongbo Wang
parent 6af9948e45
commit 9386b76796
17 changed files with 307 additions and 58 deletions
+3 -12
View File
@@ -1061,17 +1061,6 @@ function Publish-CustomConnectionTestModule
$sourcePath = "${PSScriptRoot}/test/tools/NamedPipeConnection"
$outPath = "${PSScriptRoot}/test/tools/NamedPipeConnection/out/Microsoft.PowerShell.NamedPipeConnection"
$publishPath = "${PSScriptRoot}/test/tools/Modules"
$refPath = "${sourcePath}/src/code/Ref"
# Copy the current SMA build to the refPath.
$smaPath = Join-Path -Path (Split-Path -Path (Get-PSOutput)) -ChildPath 'System.Management.Automation.dll'
if (! (Test-Path -Path $smaPath)) {
throw "Publish-CustomConnectionTestModule: Cannot find reference SMA at: ${smaPath}"
}
if (! (Test-Path -Path $refPath)) {
$null = New-Item -Path $refPath -ItemType Directory -Force
}
Copy-Item -Path $smapath -Destination $refPath -Force
Find-DotNet
@@ -1089,7 +1078,6 @@ function Publish-CustomConnectionTestModule
# Clean up build artifacts
./build.ps1 -Clean
Remove-Item -Path $refPath -Recurse -Force -ErrorAction SilentlyContinue
}
finally {
Pop-Location
@@ -1162,6 +1150,9 @@ function Publish-PSTestTools {
# `dotnet restore` on test project is not called if product projects have been restored unless -Force is specified.
Copy-PSGalleryModules -Destination "${PSScriptRoot}/test/tools/Modules" -CsProjPath "$PSScriptRoot/test/tools/Modules/PSGalleryTestModules.csproj" -Force
# Publish the Microsoft.PowerShell.NamedPipeConnection module
Publish-CustomConnectionTestModule
}
function Get-ExperimentalFeatureTests {
@@ -35,6 +35,12 @@ Describe "InvokeOnRunspace method as nested command" -tags "Feature" {
Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAdminOnWindows" {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if (Test-IsWinWow64) {
$global:PSDefaultParameterValues["it:skip"] = $true
return
}
if ($IsWindows) {
$script:remoteRunspace = New-RemoteRunspace
@@ -46,6 +52,8 @@ Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAd
{
$script:remoteRunspace.Dispose();
}
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
It "Method should successfully invoke command on remote runspace" -Skip:(!$IsWindows) {
@@ -522,11 +522,16 @@ switch ($x)
It 'Should show multiple constructors in the tooltip' {
$res = TabExpansion2 -inputScript 'class ConstructorTestClass{ConstructorTestClass ([string] $s){}ConstructorTestClass ([int] $i){}ConstructorTestClass ([int] $i, [bool]$b){}};[ConstructorTestClass]::new'
$res.CompletionMatches | Should -HaveCount 1
$completionText = $res.CompletionMatches.ToolTip | Should -BeExactly @'
$completionText = $res.CompletionMatches.ToolTip
$completionText.replace("`r`n", [System.Environment]::NewLine).trim()
$expected = @'
ConstructorTestClass(string s)
ConstructorTestClass(int i)
ConstructorTestClass(int i, bool b)
'@
$expected.replace("`r`n", [System.Environment]::NewLine).trim()
$completionText.replace("`r`n", [System.Environment]::NewLine).trim() | Should -BeExactly $expected
}
It 'Should complete parameter in param block' {
@@ -1134,9 +1139,8 @@ ConstructorTestClass(int i, bool b)
}
It "Tab completion UNC path" -Skip:(!$IsWindows) {
$homeDrive = $env:HOMEDRIVE.Replace(":", "$")
$beforeTab = "\\localhost\$homeDrive\wind"
$afterTab = "& '\\localhost\$homeDrive\Windows'"
$beforeTab = "\\localhost\ADMIN$\boo"
$afterTab = "& '\\localhost\ADMIN$\Boot'"
$res = TabExpansion2 -inputScript $beforeTab -cursorColumn $beforeTab.Length
$res.CompletionMatches.Count | Should -BeGreaterThan 0
$res.CompletionMatches[0].CompletionText | Should -BeExactly $afterTab
@@ -1989,7 +1993,7 @@ dir -Recurse `
Context "Tab completion help test" {
BeforeAll {
if ([System.Management.Automation.Platform]::IsWindows) {
if ($IsWindows) {
$userHelpRoot = Join-Path $HOME "Documents/PowerShell/Help/"
} else {
$userModulesRoot = [System.Management.Automation.Platform]::SelectProductNameForDirectory([System.Management.Automation.Platform+XDG_Type]::USER_MODULES)
@@ -1998,33 +2002,89 @@ dir -Recurse `
}
It 'Should complete about help topic' {
$aboutHelpPathUserScope = Join-Path $userHelpRoot (Get-Culture).Name
$aboutHelpPathAllUsersScope = Join-Path $PSHOME (Get-Culture).Name
$helpName = "about_Splatting"
$helpFileName = "${helpName}.help.txt"
$inputScript = "get-help about_spla"
$culture = "en-US"
$aboutHelpPathUserScope = Join-Path $userHelpRoot $culture
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $culture
$expectedCompletionCount = 0
## If help content does not exist, tab completion will not work. So update it first.
$userScopeHelp = Test-Path (Join-Path $aboutHelpPathUserScope "about_Splatting.help.txt")
$allUserScopeHelp = Test-Path (Join-Path $aboutHelpPathAllUsersScope "about_Splatting.help.txt")
if ((-not $userScopeHelp) -and (-not $aboutHelpPathAllUsersScope)) {
$userHelpPath = Join-Path $aboutHelpPathUserScope $helpFileName
$userScopeHelp = Test-Path $userHelpPath
if ($userScopeHelp) {
$expectedCompletionCount++
} else {
Update-Help -Force -ErrorAction SilentlyContinue -Scope 'CurrentUser'
if (Test-Path $userHelpPath) {
$expectedCompletionCount++
}
}
# If help content is present on both scopes, expect 2 or else expect 1 completion.
$expectedCompletions = if ($userScopeHelp -and $allUserScopeHelp) { 2 } else { 1 }
$allUserScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersScope $helpFileName)
if ($allUserScopeHelpPath) {
$expectedCompletionCount++
}
$res = TabExpansion2 -inputScript 'get-help about_spla' -cursorColumn 'get-help about_spla'.Length
$res.CompletionMatches | Should -HaveCount $expectedCompletions
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'about_Splatting'
$res = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length
$res.CompletionMatches | Should -HaveCount $expectedCompletionCount
$res.CompletionMatches[0].CompletionText | Should -BeExactly $helpName
}
It 'Should complete about help topic regardless of culture' {
try
{
## Save original culture and temporarily set it to da-DK because there's no localized help for da-DK.
$OriginalCulture = [cultureinfo]::CurrentCulture
[cultureinfo]::CurrentCulture="da-DK"
$defaultCulture = "en-US"
$culture = "da-DK"
[cultureinfo]::CurrentCulture = $culture
$helpName = "about_Splatting"
$helpFileName = "${helpName}.help.txt"
$aboutHelpPathUserScope = Join-Path $userHelpRoot $culture
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $culture
$expectedCompletionCount = 0
## If help content does not exist, tab completion will not work. So update it first.
$userHelpPath = Join-Path $aboutHelpPathUserScope $helpFileName
$userScopeHelp = Test-Path $userHelpPath
if ($userScopeHelp) {
$expectedCompletionCount++
}
else { Update-Help -Force -ErrorAction SilentlyContinue -Scope 'CurrentUser'
if (Test-Path $userHelpPath) {
$expectedCompletionCount++
}
else {
$aboutHelpPathUserScope = Join-Path $userHelpRoot $defaultCulture
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $defaultCulture
$userHelpDefaultPath = Join-Path $aboutHelpPathUserScope $helpFileName
$userDefaultScopeHelp = Test-Path $userHelpDefaultPath
if ($userDefaultScopeHelp) {
$expectedCompletionCount++
}
}
}
$allUserScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersScope $helpFileName)
if ($allUserScopeHelpPath) {
$expectedCompletionCount++
}
else {
$aboutHelpPathAllUsersDefaultScope = Join-Path $PSHOME $defaultCulture
$allUsersDefaultScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersDefaultScope $helpFileName)
if ($allUsersDefaultScopeHelpPath) {
$expectedCompletionCount++
}
}
$res = TabExpansion2 -inputScript 'get-help about_spla' -cursorColumn 'get-help about_spla'.Length
$res.CompletionMatches | Should -HaveCount 1
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'about_Splatting'
$res.CompletionMatches | Should -HaveCount $expectedCompletionCount
$res.CompletionMatches[0].CompletionText | Should -BeExactly $helpName
}
finally
{
@@ -2239,7 +2299,7 @@ function MyFunction ($param1, $param2)
Describe "Tab completion tests with remote Runspace" -Tags Feature,RequireAdminOnWindows {
BeforeAll {
if ($IsWindows) {
if ($IsWindows -and -not (Test-IsWinWow64)) {
$session = New-RemoteSession
$powershell = [powershell]::Create()
$powershell.Runspace = $session.Runspace
@@ -308,6 +308,14 @@ Describe "Run native command from a mounted FAT-format VHD" -tags @("Feature", "
if (-not $IsWindows) {
return;
}
else {
$storageModule = Get-Module -Name 'Storage' -ListAvailable -ErrorAction SilentlyContinue
if (-not $storageModule) {
Write-Verbose -Verbose "Storage module is not available."
return;
}
}
$vhdx = Join-Path -Path $TestDrive -ChildPath ncp.vhdx
@@ -331,11 +339,18 @@ Describe "Run native command from a mounted FAT-format VHD" -tags @("Feature", "
diskpart.exe /s $create_vhdx
Mount-DiskImage -ImagePath $vhdx > $null
Copy-Item "$env:WinDir\System32\whoami.exe" T:\whoami.exe
Copy-Item "$env:WinDir\System32\whoami.exe" "T:\whoami.exe"
}
AfterAll {
if ($IsWindows) {
$storageModule = Get-Module -Name 'Storage' -ListAvailable -ErrorAction SilentlyContinue
if (-not $storageModule) {
Write-Verbose -Verbose "Storage module is not available."
return;
}
Dismount-DiskImage -ImagePath $vhdx
Remove-Item $vhdx, $create_vhdx -Force
}
@@ -4,7 +4,7 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {
BeforeAll {
if (!$IsWindows)
if (!$IsWindows -or (Test-IsWinWow64))
{
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:skip"] = $true
@@ -5,7 +5,7 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$modulePath = "$testdrive\Modules\TestImport"
if (!$IsWindows) {
if (!$IsWindows -or (Test-IsWinWow64)) {
$PSDefaultParameterValues["it:skip"] = $true
} else {
$pssession = New-RemoteSession
@@ -82,8 +82,13 @@ Describe "Certificate Provider tests" -Tags "Feature" {
BeforeAll{
if($IsWindows)
{
Install-TestCertificates
Push-Location Cert:\
if (-not (Install-TestCertificates) ) {
$SetupFailure = $true
}
else {
Push-Location Cert:\
$SetupFailure = $false
}
}
else
{
@@ -94,28 +99,45 @@ Describe "Certificate Provider tests" -Tags "Feature" {
}
AfterAll {
if($IsWindows)
if($IsWindows -and -not $SetupFailure)
{
Remove-TestCertificates
Pop-Location
}
else
{
$global:PSDefaultParameterValues = $defaultParamValues
if ($defaultParamValues -ne $null) {
$global:PSDefaultParameterValues = $defaultParamValues
}
}
}
Context "Get-Item tests" {
It "Should be able to get certifate by path: <path>" -TestCases $currentUserMyLocations {
param([string] $path)
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$expectedThumbprint = (Get-GoodCertificateObject).Thumbprint
$leafPath = Join-Path -Path $path -ChildPath $expectedThumbprint
$cert = (Get-Item -LiteralPath $leafPath)
$cert | Should -Not -Be null
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$cert.Thumbprint | Should -Be $expectedThumbprint
}
It "Should be able to get DnsNameList of certifate by path: <path>" -TestCases $currentUserMyLocations {
param([string] $path)
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$expectedThumbprint = (Get-GoodCertificateObject).Thumbprint
$expectedName = (Get-GoodCertificateObject).DnsNameList
$expectedEncodedName = (Get-GoodCertificateObject).DnsNameList
@@ -133,6 +155,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
}
it "Should be able to get EnhancedKeyUsageList of certifate by path: <path>" -TestCases $currentUserMyLocations {
param([string] $path)
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$expectedThumbprint = (Get-GoodCertificateObject).Thumbprint
$expectedOid = (Get-GoodCertificateObject).EnhancedKeyUsageList[0].ObjectId
$leafPath = Join-Path -Path $path -ChildPath $expectedThumbprint
@@ -144,6 +171,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$cert.EnhancedKeyUsageList[0].ObjectId | Should -Be $expectedOid
}
It "Should filter to codesign certificates" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$allCerts = Get-Item cert:\CurrentUser\My\*
$codeSignCerts = Get-Item cert:\CurrentUser\My\* -CodeSigningCert
$codeSignCerts | Should -Not -Be null
@@ -152,6 +184,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$nonCodeSignCertCount | Should -Not -Be 0
}
It "Should be able to exclude by thumbprint" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$allCerts = Get-Item cert:\CurrentUser\My\*
$testThumbprint = (Get-GoodCertificateObject).Thumbprint
$allCertsExceptOne = (Get-Item "cert:\currentuser\my\*" -Exclude $testThumbprint)
@@ -166,6 +203,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$cert = Get-GoodServerCertificateObject
}
it "Should filter to codesign certificates" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$allCerts = get-ChildItem cert:\CurrentUser\My
$codeSignCerts = get-ChildItem cert:\CurrentUser\My -CodeSigningCert
$codeSignCerts | Should -Not -Be null
@@ -174,6 +216,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$nonCodeSignCertCount | Should -Not -Be 0
}
it "Should filter to ExpiringInDays certificates" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$thumbprint = $cert.Thumbprint
$NotAfter = $cert.NotAfter
$before = ($NotAfter.AddDays(-1) - (Get-Date)).Days
@@ -186,6 +233,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
$afterCerts.Thumbprint | Should -BeExactly $thumbprint
}
it "Should filter to DocumentEncryptionCert certificates" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$thumbprint = $cert.Thumbprint
$certs = Get-ChildItem cert:\CurrentUser\My\$thumbprint -DocumentEncryptionCert
@@ -199,6 +251,10 @@ Describe "Certificate Provider tests" -Tags "Feature" {
) {
param($name, $searchName, $count, $thumbprint)
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$certs = Get-ChildItem cert:\CurrentUser\My\$thumbprint -DNSName $searchName
$certs.Count | Should -Be $count
@@ -206,6 +262,11 @@ Describe "Certificate Provider tests" -Tags "Feature" {
}
it "Should filter to SSLServerAuthentication certificates" {
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$thumbprint = $cert.Thumbprint
$certs = Get-ChildItem cert:\CurrentUser\My\$thumbprint -SSLServerAuthentication
@@ -221,6 +282,10 @@ Describe "Certificate Provider tests" -Tags "Feature" {
) {
param($name, $ekuSearch, $count, $thumbprint)
if ($SetupFailure) {
Set-ItResult -Inconclusive -Because "Test certificates are not installed"
}
$certs = Get-ChildItem cert:\CurrentUser\My\$thumbprint -EKU $ekuSearch
$certs.Count | Should -Be $count
@@ -81,7 +81,12 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
BeforeAll{
if($IsWindows)
{
Install-TestCertificates
if (-not (Install-TestCertificates) ) {
$SetupFailure = $true
} else {
Push-Location Cert:\
$SetupFailure = $false
}
}
else
{
@@ -92,13 +97,16 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
AfterAll {
if($IsWindows)
if($IsWindows -and -not $SetupFailure)
{
Remove-TestCertificates
}
else
{
$global:PSdefaultParameterValues = $defaultParamValues
if ($defaultParamValues -ne $null) {
$global:PSDefaultParameterValues = $defaultParamValues
}
}
}
@@ -136,6 +144,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify wildcarded recipient resolution by path [Decryption]" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] ((Get-GoodCertificateLocation) + "*")
$recipient.Resolve($ExecutionContext.SessionState, "Decryption", [ref] $errors)
@@ -145,6 +154,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify wildcarded recipient resolution by path [Encryption]" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] ((Get-GoodCertificateLocation) + "*")
$recipient.Resolve($ExecutionContext.SessionState, "Encryption", [ref] $errors)
@@ -153,6 +163,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify resolution by directory" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$protectedEventLoggingCertPath = Join-Path $TestDrive ProtectedEventLoggingDir
$null = New-Item -ItemType Directory $protectedEventLoggingCertPath -Force
Copy-Item (Get-GoodCertificateLocation) $protectedEventLoggingCertPath
@@ -167,6 +178,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify resolution by thumbprint" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] (Get-GoodCertificateObject).Thumbprint
$recipient.Resolve($ExecutionContext.SessionState, "Decryption", [ref] $errors)
@@ -177,6 +189,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify resolution by subject name" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] (Get-GoodCertificateObject).Subject
$recipient.Resolve($ExecutionContext.SessionState, "Decryption", [ref] $errors)
@@ -186,6 +199,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify error when no cert found in encryption for encryption" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] "SomeCertificateThatDoesNotExist*"
$recipient.Resolve($ExecutionContext.SessionState, "Encryption", [ref] $errors)
@@ -195,6 +209,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify error when encrypting to non-wildcarded identifier for decryption" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] "SomeCertificateThatDoesNotExist"
$recipient.Resolve($ExecutionContext.SessionState, "Decryption", [ref] $errors)
@@ -204,6 +219,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify error when encrypting to wrong cert" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] (Get-BadCertificateObject).Thumbprint
$recipient.Resolve($ExecutionContext.SessionState, "Encryption", [ref] $errors)
@@ -213,6 +229,7 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify no error when encrypting to wildcarded identifier for decryption" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$errors = $null
$recipient = [System.Management.Automation.CmsMessageRecipient] "SomeCertificateThatDoesNotExist*"
$recipient.Resolve($ExecutionContext.SessionState, "Decryption", [ref] $errors)
@@ -222,11 +239,14 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify Protect-CmsMessage emits recipient errors" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
{ "Hello World" | Protect-CmsMessage -To "SomeThumbprintThatDoesNotExist" -ErrorAction Stop } |
Should -Throw -ErrorId "NoCertificateFound,Microsoft.PowerShell.Commands.ProtectCmsMessageCommand"
}
It "Verify CmsMessage cmdlets works with paths" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
try {
$randomNum = Get-Random -Minimum 1000 -Maximum 9999
$tempPath = Join-Path $TestDrive "$randomNum-Path-Test-File"
@@ -251,6 +271,8 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify Unprotect-CmsMessage works with local store" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
try {
$randomNum = Get-Random -Minimum 1000 -Maximum 9999
$tempPath = Join-Path $TestDrive "$randomNum-Path-Test-File"
@@ -265,27 +287,37 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify Unprotect-CmsMessage emits recipient errors" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
{ "" | Unprotect-CmsMessage -To "SomeThumbprintThatDoesNotExist" -IncludeContext -ErrorAction Stop } |
Should -Throw -ErrorId "NoCertificateFound,Microsoft.PowerShell.Commands.UnprotectCmsMessageCommand"
}
It "Verify failure to extract Ascii armor generates an error [Unprotect-CmsMessage]" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
{ "Hello World" | Unprotect-CmsMessage -ErrorAction Stop } |
Should -Throw -ErrorId "InputContainedNoEncryptedContentIncludeContext,Microsoft.PowerShell.Commands.UnprotectCmsMessageCommand"
}
It "Verify failure to extract Ascii armor generates an error [Get-CmsMessage]" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
{ "Hello World" | Get-CmsMessage -ErrorAction Stop } |
Should -Throw -ErrorId "InputContainedNoEncryptedContent,Microsoft.PowerShell.Commands.GetCmsMessageCommand"
}
It "Verify 'Unprotect-CmsMessage -IncludeContext' with no encrypted input" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
# Should have round-tripped content
$result = "Hello World" | Unprotect-CmsMessage -IncludeContext
$result | Should -Be "Hello World"
}
It "Verify Unprotect-CmsMessage lets you include context" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$protected = "Hello World" | Protect-CmsMessage -To (Get-GoodCertificateLocation)
$adjustedProtected = "Pre content" + [System.Environment]::NewLine + $protected + [System.Environment]::NewLine + "Post content"
@@ -299,6 +331,8 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify Unprotect-CmsMessage treats event logs as a first class citizen" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$protected = "Encrypted Message1","Encrypted Message2" | Protect-CmsMessage -To (Get-GoodCertificateLocation)
$virtualEventLog = Get-WinEvent Microsoft-Windows-PowerShell/Operational -MaxEvents 1
$savedId = $virtualEventLog.Id
@@ -327,6 +361,8 @@ Describe "CmsMessage cmdlets thorough tests" -Tags "Feature" {
}
It "Verify protect message using OutString" {
if ($SetupFailure) { Set-ItResult -Inconclusive -Because "Test certificates are not installed"}
$protected = Get-Process -Id $PID | Protect-CmsMessage -To (Get-GoodCertificateLocation)
$decrypted = $protected | Unprotect-CmsMessage -To (Get-GoodCertificateLocation)
# Should have had PID in output
@@ -240,13 +240,19 @@ nMbw+XY4C8xdDnHfS6mF+Hol98dURB/MC/x3sZ3gSjKo
function Install-TestCertificates
{
$script:certLocation = New-GoodCertificate
$script:certLocation | Should -Not -BeNullOrEmpty | Out-Null
if (-not $script:certLocation) {
return $false
}
$script:certServerLocation = New-GoodServerCertificate
$script:certServerLocation | Should -Not -BeNullOrEmpty | Out-Null
if (-not $script:certServerLocation) {
return $false
}
$script:badCertLocation = New-BadCertificate
$script:badCertLocation | Should -Not -BeNullOrEmpty | Out-Null
if (-not $script:badCertLocation) {
return $false
}
if ($IsCoreCLR -and $IsWindows)
{
@@ -876,11 +876,17 @@ Describe 'Table color tests' -Tag 'CI' {
$PSStyle.OutputRendering = $originalRendering
}
It 'Table header should use FormatAccent' {
([pscustomobject]@{foo = 1} | Format-Table | Out-String).Trim() | Should -BeExactly @"
$($PSStyle.Formatting.FormatAccent)foo$($PSStyle.Reset)
$($PSStyle.Formatting.FormatAccent)---$($PSStyle.Reset)
1
"@
It 'Table header should use TableHeader' {
$expected = @(
""
"$($PSStyle.Formatting.TableHeader)foo$($PSStyle.Reset)"
"$($PSStyle.Formatting.TableHeader)---$($PSStyle.Reset)"
" 1"
""
)
$actual = [pscustomobject]@{foo = 1} | Format-Table | Out-String -Stream
$actual | Should -BeExactly $expected
}
}
@@ -5,7 +5,7 @@
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$originalWarningPreference = $WarningPreference
$WarningPreference = "SilentlyContinue"
$skipTest = ! ($IsWindows -and $IsCoreCLR -and (Test-IsElevated))
$skipTest = ! ($IsWindows -and $IsCoreCLR -and (Test-IsElevated)) -or (Test-IsWinWow64)
$PSDefaultParameterValues["it:skip"] = $skipTest
try
@@ -133,7 +133,7 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
Describe "Default enablement of Experimental Features" -Tags CI {
BeforeAll {
$isPreview = $PSVersionTable.GitCommitId -match "preview|daily"
$isPreview = (Test-IsPreview -Version $PSVersionTable.PSVersion) -and (-not (Test-IsReleaseCandidate -Version $PSVersionTable.PSVersion))
Function BeEnabled {
[CmdletBinding()]
@@ -7,7 +7,7 @@ Describe "WinRM based remoting session abrupt disconnect" -Tags 'Feature','Requi
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if (! $IsWindows)
if (! $IsWindows -or (Test-IsWinWow64))
{
$PSDefaultParameterValues["it:skip"] = $true
return
@@ -8,7 +8,7 @@ Describe "Remote runspace pool should expose commands in endpoint configuration"
BeforeAll {
if ($IsWindows -and (Test-CanWriteToPsHome))
if ($IsWindows -and (Test-CanWriteToPsHome) -and -not (Test-IsWinWow64))
{
$configName = "restrictedV"
$configPath = Join-Path $TestDrive ($configName + ".pssc")
@@ -19,10 +19,20 @@ Describe "Remote runspace pool should expose commands in endpoint configuration"
$remoteRunspacePool = New-RemoteRunspacePool -ConfigurationName $configName
}
elseif (Test-IsWinWow64)
{
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:skip"] = $true
}
}
AfterAll {
if (Test-IsWinWow64) {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
return
}
if ($IsWindows -and (Test-CanWriteToPsHome))
{
if ($remoteRunspacePool -ne $null)
@@ -28,9 +28,13 @@ FunctionsToExport = @(
'Set-TesthookResult'
'Start-NativeExecution'
'Test-IsElevated'
'Test-IsPreview',
'Test-IsReleaseCandidate'
'Test-IsRoot'
'Test-IsVstsLinux'
'Test-IsVstsWindows'
'Test-IsWindowsArm64'
'Test-IsWinWow64'
'Test-TesthookIsSet'
'Wait-FileToBePresent'
'Wait-UntilTrue'
@@ -396,3 +396,53 @@ function Get-WsManSupport {
}
return $false
}
function Test-IsWindowsArm64 {
return $IsWindows -and [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64
}
function Test-IsWinWow64 {
return $IsWindows -and [System.Environment]::Is64BitOperatingSystem -and -not [System.Environment]::Is64BitProcess
}
function Test-IsPreview
{
param(
[parameter(Mandatory)]
[string]
$Version,
[switch]$IsLTS
)
if ($IsLTS.IsPresent) {
## If we are building a LTS package, then never consider it preview.
return $false
}
return $Version -like '*-*'
}
<#
.Synopsis
Tests if a version is a Release Candidate
.EXAMPLE
Test-IsReleaseCandidate -version '6.1.0-sometthing' # returns false
Test-IsReleaseCandidate -version '6.1.0-rc.1' # returns true
Test-IsReleaseCandidate -version '6.1.0' # returns false
#>
function Test-IsReleaseCandidate
{
param(
[parameter(Mandatory)]
[string]
$Version
)
if ($Version -like '*-rc.*')
{
return $true
}
return $false
}
@@ -15,8 +15,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<Reference Include="System.Management.Automation">
<HintPath>.\Ref\System.Management.Automation.dll</HintPath>
</Reference>
<PackageReference Include="System.Management.Automation" Version="7.4.0-preview.1" />
</ItemGroup>
</Project>