diff --git a/build.psm1 b/build.psm1 index 68f6a5ea070..3d0be1a846b 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1118,17 +1118,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 @@ -1146,7 +1135,6 @@ function Publish-CustomConnectionTestModule # Clean up build artifacts ./build.ps1 -Clean - Remove-Item -Path $refPath -Recurse -Force -ErrorAction SilentlyContinue } finally { Pop-Location @@ -1219,6 +1207,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 { diff --git a/experimental-feature-linux.json b/experimental-feature-linux.json index 0e3bfc3d528..376ada0a790 100644 --- a/experimental-feature-linux.json +++ b/experimental-feature-linux.json @@ -5,5 +5,6 @@ "PSNativeCommandErrorActionPreference", "PSSubsystemPluginModel", "PSModuleAutoLoadSkipOfflineFiles", - "PSFeedbackProvider" + "PSFeedbackProvider", + "PSCommandWithArgs" ] diff --git a/experimental-feature-windows.json b/experimental-feature-windows.json index 0e3bfc3d528..376ada0a790 100644 --- a/experimental-feature-windows.json +++ b/experimental-feature-windows.json @@ -5,5 +5,6 @@ "PSNativeCommandErrorActionPreference", "PSSubsystemPluginModel", "PSModuleAutoLoadSkipOfflineFiles", - "PSFeedbackProvider" + "PSFeedbackProvider", + "PSCommandWithArgs" ] diff --git a/test/powershell/Host/HostUtilities.Tests.ps1 b/test/powershell/Host/HostUtilities.Tests.ps1 index b5c65af97e6..1f064408e3c 100644 --- a/test/powershell/Host/HostUtilities.Tests.ps1 +++ b/test/powershell/Host/HostUtilities.Tests.ps1 @@ -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) { diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index af35677834a..7a3722e93d2 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -541,11 +541,16 @@ using ` 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' { @@ -1229,12 +1234,8 @@ class InheritedClassTest : System.Attribute } It "Tab completion UNC path" -Skip:(!$IsWindows) { - if (!$env:HOMEDRIVE) { - Set-ItResult -Skipped -Because "Homerdrive is not set" - } - $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 @@ -2101,7 +2102,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) @@ -2110,33 +2111,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 { @@ -2351,7 +2408,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 diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 index d736d4b3945..41e3f3cebcf 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 @@ -312,6 +312,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 @@ -335,11 +343,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 } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 index 2ad47aa2414..95e522ab9aa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 @@ -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 index e783a6f69e7..ba7f35f0485 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 @@ -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 index 88bccb20a37..c6c468e5f0b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/CertificateProvider.Tests.ps1 @@ -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: " -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: " -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: " -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 index 67159e5c9e2..50cbdebab69 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage.Tests.ps1 @@ -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1 b/test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1 index 42e990b714e..5601767a120 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1 @@ -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) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index 6f93c3903e9..78cfb88b613 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -892,10 +892,16 @@ Describe 'Table color tests' -Tag 'CI' { } It 'Table header should use TableHeader' { - ([pscustomobject]@{foo = 1} | Format-Table | Out-String).Trim() | Should -BeExactly @" -$($PSStyle.Formatting.TableHeader)foo$($PSStyle.Reset) -$($PSStyle.Formatting.TableHeader)---$($PSStyle.Reset) - 1 -"@ + $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 } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 index 0b73e7be7aa..4b459fe67d9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -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 diff --git a/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 b/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 index d36fc3fddb8..0c6f0d31195 100644 --- a/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 +++ b/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 @@ -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()] diff --git a/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 index c98e3045e7e..a6a4f23e082 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 @@ -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 diff --git a/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 b/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 index 1266a6956e9..f4481c85eb0 100644 --- a/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 +++ b/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 @@ -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) diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index 8facd270576..f11f5432adf 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -30,10 +30,13 @@ FunctionsToExport = @( 'Start-NativeExecution' 'Test-CanWriteToPsHome' 'Test-IsElevated' + 'Test-IsPreview', + 'Test-IsReleaseCandidate' 'Test-IsRoot' 'Test-IsVstsLinux' 'Test-IsVstsWindows' 'Test-IsWindowsArm64' + 'Test-IsWinWow64' 'Test-TesthookIsSet' 'Wait-FileToBePresent' 'Wait-UntilTrue' diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index ef0683a6abe..013bd2cf700 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -400,3 +400,49 @@ function Get-WsManSupport { 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 +} diff --git a/test/tools/NamedPipeConnection/src/code/Microsoft.PowerShell.NamedPipeConnection.csproj b/test/tools/NamedPipeConnection/src/code/Microsoft.PowerShell.NamedPipeConnection.csproj index 0182a55f3e6..0a5ca72e317 100644 --- a/test/tools/NamedPipeConnection/src/code/Microsoft.PowerShell.NamedPipeConnection.csproj +++ b/test/tools/NamedPipeConnection/src/code/Microsoft.PowerShell.NamedPipeConnection.csproj @@ -15,8 +15,6 @@ - - .\Ref\System.Management.Automation.dll - +