diff --git a/test/powershell/Host/HostUtilities.Tests.ps1 b/test/powershell/Host/HostUtilities.Tests.ps1 index 7f738cb01c3..da65dc81624 100644 --- a/test/powershell/Host/HostUtilities.Tests.ps1 +++ b/test/powershell/Host/HostUtilities.Tests.ps1 @@ -35,30 +35,23 @@ Describe "InvokeOnRunspace method as nested command" -tags "Feature" { Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAdminOnWindows" { BeforeAll { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() + $skipTest = (Test-IsWinWow64) -or !$IsWindows - $pendingTest = (Test-IsWinWow64) - - if ($pendingTest) { - $global:PSDefaultParameterValues["it:pending"] = $true + if ($skipTest) { return } - if ($IsWindows) { - $script:remoteRunspace = New-RemoteRunspace - } + $script:remoteRunspace = New-RemoteRunspace } AfterAll { - if ($script:remoteRunspace -and -not $pendingTest) + if ($script:remoteRunspace) { $script:remoteRunspace.Dispose(); } - - $global:PSDefaultParameterValues = $originalDefaultParameterValues } - It "Method should successfully invoke command on remote runspace" -Skip:(!$IsWindows) { + It "Method should successfully invoke command on remote runspace" -Skip:$skipTest { $command = [System.Management.Automation.PSCommand]::new() $command.AddScript('"Hello!"') diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 index 9542aafe368..d166ca265c7 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 @@ -361,6 +361,11 @@ Describe "Run native command from a mounted FAT-format VHD" -tags @("Feature", " } It "Should run 'whoami.exe' from FAT file system without error" -Skip:(!$IsWindows) { + if ((Test-IsWinServer2012R2) -or (Test-IsWindows2016)) { + Set-ItResult -Pending -Because "Marking as pending since whomai.exe is not found on T:\ on 2012R2 and 2016 after copying to VHD" + return + } + $expected = & "$env:WinDir\System32\whoami.exe" $result = T:\whoami.exe $result | Should -BeExactly $expected diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1 index 61f9f8e0f9f..a9c9b69b202 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1 @@ -451,9 +451,9 @@ Describe "Import-Module from CompatiblePSEditions-checked paths" -Tag "CI" { Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" { BeforeAll { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() if ( ! $IsWindows ) { - $PSDefaultParameterValues["it:skip"] = $true + Push-DefaultParameterValueStack @{ "it:skip" = $true } + return } $ModuleName = "DesktopModule" @@ -468,7 +468,10 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" { } AfterAll { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ( ! $IsWindows ) { + Pop-DefaultParameterValueStack + return + } } Context "Tests that ErrorAction/WarningAction have effect when Import-Module with WinCompat is used" { @@ -666,6 +669,11 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" { } It "NoClobber WinCompat list in powershell.config is a Desktop-edition module" { + if (Test-IsWinWow64) { + Set-ItResult -Skipped -Because "This test is not applicable to WoW64." + return + } + if (-not $desktopModuleToUse) { throw 'Neither the "PersistentMemory" module nor the "RemoteDesktop" module is available. Please check and use a desktop-edition module that is under the System32 module path.' } @@ -761,14 +769,16 @@ Remove-Module $desktopModuleToUse Describe "PSModulePath changes interacting with other PowerShell processes" -Tag "Feature" { BeforeAll { $pwsh = "$PSHOME/pwsh" - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() if ( ! $IsWindows ) { - $PSDefaultParameterValues["it:skip"] = $true + Push-DefaultParameterValueStack @{ "it:skip" = $true } + return } } AfterAll { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ( ! $IsWindows ) { + Pop-DefaultParameterValueStack + } } Context "System32 module path prepended to PSModulePath" { @@ -1403,8 +1413,7 @@ Describe "Import-Module nested module behaviour with Edition checking" -Tag "Fea Describe "WinCompat importing should check availablity of built-in modules" -Tag "CI" { BeforeAll { if (-not $IsWindows ) { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - $PSDefaultParameterValues["it:skip"] = $true + Push-DefaultParameterValueStack @{ "it:skip" = $true } return } @@ -1426,7 +1435,7 @@ Describe "WinCompat importing should check availablity of built-in modules" -Tag AfterAll { if (-not $IsWindows) { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + Pop-DefaultParameterValueStack return } @@ -1481,6 +1490,11 @@ Describe "WinCompat importing should check availablity of built-in modules" -Tag } It "Attempt to load a 'Desktop' edition module should fail because 'Export-PSSession' cannot be found" { + if (Test-IsWinWow64) { + Set-ItResult -Skipped -Because "This test is not applicable to WoW64." + return + } + if (-not $desktopModuleToUse) { throw 'Neither the "PersistentMemory" module nor the "RemoteDesktop" module is available. Please check and use a desktop-edition module that is under the System32 module path.' } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 index 48763dc00fa..67284151706 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 @@ -6,14 +6,20 @@ Import-Module HelpersCommon try { # Skip all tests on non-windows and non-PowerShellCore and non-elevated platforms. - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() $originalWarningPreference = $WarningPreference $WarningPreference = "SilentlyContinue" # Skip all tests if can't write to $PSHOME as Register-PSSessionConfiguration writes to $PSHOME # or if the processor architecture is Arm64 - $IsNotSkipped = ($IsWindows -and $IsCoreCLR -and (Test-IsElevated) -and (Test-CanWriteToPsHome) -and [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -ne [System.Runtime.InteropServices.Architecture]::Arm64) - $PSDefaultParameterValues["it:skip"] = !$IsNotSkipped - + $IsNotSkipped = ( + $IsWindows -and + $IsCoreCLR -and + (Test-IsElevated) -and + (Test-CanWriteToPsHome) -and + -not (Test-IsWindowsArm64) -and + -not (Test-IsWinWow64) + ) + + Push-DefaultParameterValueStack @{ "it:skip" = ! $IsNotSkipped } # # TODO: Enable-PSRemoting should be performed at a higher set up for all tests. # Tests whether PowerShell remoting is enabled for this instance of PowerShell. @@ -69,29 +75,20 @@ try # Register new session configuration function RegisterNewConfiguration { param ( - - [string] - $Name, - - [string] - $ConfigFilePath, - - [switch] - $Enabled + [string] $Name, + [string] $ConfigFilePath, + [switch] $Enabled ) $TestConfig = Get-PSSessionConfiguration -Name $Name -ErrorAction SilentlyContinue - if($TestConfig) - { + if($TestConfig) { $null = Unregister-PSSessionConfiguration -Name $Name } - if($Enabled) - { + if($Enabled) { $null = Register-PSSessionConfiguration -Name $Name -Path $ConfigFilePath } - else - { + else { $null = Register-PSSessionConfiguration -Name $Name -Path $ConfigFilePath -AccessMode Disabled } } @@ -99,9 +96,7 @@ try # Unregister session configuration function UnregisterPSSessionConfiguration{ param ( - - [string] - $Name + [string] $Name ) Unregister-PSSessionConfiguration -Name $Name -Force -NoServiceRestart -ErrorAction SilentlyContinue @@ -111,8 +106,7 @@ try function CreateTestConfigFile { $TestConfigFileLoc = Join-Path $TestDrive "Remoting" - if(-not (Test-path $TestConfigFileLoc)) - { + if(-not (Test-path $TestConfigFileLoc)) { $null = New-Item -Path $TestConfigFileLoc -ItemType Directory -Force -ErrorAction Stop } @@ -165,24 +159,12 @@ try function VerifyEnableAndDisablePSSessionConfig { param ( - [string] - $SessionConfigName, - - [string] - $ConfigFilePath, - - [Bool] - $InitialSessionStateEnabled, - - [Bool] - $FinalSessionStateEnabled, - - [string] - $TestDescription, - - [bool] - $EnablePSSessionConfig - ) + [string] $SessionConfigName, + [string] $ConfigFilePath, + [Bool] $InitialSessionStateEnabled, + [Bool] $FinalSessionStateEnabled, + [string] $TestDescription, + [bool] $EnablePSSessionConfig) It "$TestDescription" { @@ -190,15 +172,13 @@ try $TestConfigStateBeforeChange = (Get-PSSessionConfiguration -Name $SessionConfigName).Enabled - if($EnablePSSessionConfig) - { + if($EnablePSSessionConfig) { $isSkipNetworkCheck = $true # TODO: Get-NetConnectionProfile is not available during typical PS Core deployments. Once it is, this check should be used. #Get-NetConnectionProfile | Where-Object { $_.NetworkCategory -eq "Public" } | ForEach-Object { $isSkipNetworkCheck = $true } Enable-PSSessionConfiguration -Name $SessionConfigName -NoServiceRestart -SkipNetworkProfileCheck:$isSkipNetworkCheck } - else - { + else { Disable-PSSessionConfiguration -Name $SessionConfigName -NoServiceRestart } @@ -231,8 +211,7 @@ try } ) - foreach ($testcase in $testData) - { + foreach ($testcase in $testData) { VerifyEnableAndDisablePSSessionConfig @testcase } } @@ -240,12 +219,13 @@ try Context "Validate Unregister-PSSessionConfiguration cmdlet" { BeforeEach { - Register-PSSessionConfiguration -Name "TestUnregisterPSSessionConfig" + if ($IsNotSkipped) { + Register-PSSessionConfiguration -Name "TestUnregisterPSSessionConfig" + } } AfterAll { - if ($IsNotSkipped) - { + if ($IsNotSkipped) { Unregister-PSSessionConfiguration -name "TestUnregisterPSSessionConfig" -ErrorAction SilentlyContinue | Out-Null } } @@ -258,32 +238,26 @@ try $Result = [PSObject] @{Output = $true ; Error = $null} $error.Clear() - try - { + try { $null = Unregister-PSSessionConfiguration -name $SessionConfigName -ErrorAction stop } - catch - { + catch { $Result.Error = $_.Exception } - if(-not $Result.Error) - { + if(-not $Result.Error) { $ValidEndpoints = [PSObject]@(Get-PSSessionConfiguration) - foreach ($endpoint in $ValidEndpoints) - { + foreach ($endpoint in $ValidEndpoints) { # Setting it to false means the unregister was unsuccessful # and there is still an endpoint with name matching the one we wanted to remove. - if($endpoint.name -like $SessionConfigName) - { + if($endpoint.name -like $SessionConfigName) { $Result.Output = $false break } } } - else - { + else { $Result.Output = $false } @@ -833,7 +807,7 @@ namespace PowershellTestConfigNamespace BeforeAll { if (Test-IsWindowsArm64) { Write-Verbose "remoting is not setup on ARM64, skipping tests" -Verbose - $PSDefaultParameterValues["it:skip"] = $true + Push-DefaultParameterValueStack @{ "it:skip" = $true } return } @@ -842,6 +816,12 @@ namespace PowershellTestConfigNamespace } } + AfterAll { + if (Test-IsWindowsArm64) { + Pop-DefaultParameterValueStack + } + } + It "Enable-PSSession Cmdlet creates a PSSession configuration with a name tied to PowerShell version." { $endpointName = "PowerShell." + $PSVersionTable.GitCommitId.ToString() $matchedEndpoint = Get-PSSessionConfiguration $endpointName -ErrorAction SilentlyContinue @@ -863,7 +843,7 @@ namespace PowershellTestConfigNamespace } finally { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + Pop-DefaultParameterValueStack $WarningPreference = $originalWarningPreference } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 index 5ab0a043f01..42c8a3e8bf6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 @@ -38,11 +38,6 @@ Describe "Get-ChildItem" -Tags "CI" { @{Parameters = @{Path = (Join-Path $searchRoot 'F*.txt'); Recurse = $true; File = $true }; ExpectedCount = 1; Title = "file with wildcard filename"} ) - $SkipAppExeCLinks = $true - if ($IsWindows -and (Get-ChildItem -Path ~\AppData\Local\Microsoft\WindowsApps\*.exe -ErrorAction Ignore) -ne $null) - { - $SkipAppExeCLinks = $false - } } It "Should list the contents of the current folder" { @@ -187,7 +182,8 @@ Describe "Get-ChildItem" -Tags "CI" { (Get-ChildItem -File -LiteralPath TestDrive:/ -Filter noext*.*).Name | Should -BeExactly 'noextension' } - It "Understand APPEXECLINKs" -Skip:($SkipAppExeCLinks) { + # Because "dotnet API is not available, see PR 16044 + It "Understand APPEXECLINKs" -Skip { $app = Get-ChildItem -Path ~\appdata\local\microsoft\windowsapps\*.exe | Select-Object -First 1 $app.Target | Should -Not -Be $app.FullName $app.LinkType | Should -BeExactly 'AppExeCLink' @@ -232,6 +228,10 @@ Describe "Get-ChildItem" -Tags "CI" { It 'Works with Windows volume paths' -Skip:(!$IsWindows) { $volume = (Get-Volume -DriveLetter $env:SystemDrive[0]).Path $items = Get-ChildItem -LiteralPath "${volume}Windows" + Write-Verbose -Verbose "Trying files in '${volume}Windows'" + if (-not $items) { + Write-Verbose -Verbose "`$items is null!!" + } $items[0].Parent | Should -BeExactly "${volume}Windows" $items | Should -HaveCount (Get-ChildItem $env:SystemRoot).Count } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 index 2cd4e2a79bd..c7584293422 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -262,6 +262,15 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" { Context "MTUSizeDetect" { It "MTUSizeDetect works" { + + $platform = Get-PlatformInfo + $platform | Out-String -Stream | Write-Verbose -Verbose + + if ($platform.platform -match 'sles' -and $platform.version -match '15') { + Set-ItResult -Skipped -Because "MTUSizeDetect is not supported on OpenSUSE 15" + return + } + $result = Test-Connection $testAddress -MtuSize $result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index dee08f4e35d..c9de4236960 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -505,6 +505,12 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" { @{ httpVersion = '2'} ) { param($httpVersion) + + if(Test-IsWinServer2012R2 -and $httpVersion -eq '2') { + Set-ItResult -Skipped -Because "HTTP/2 is not supported on Windows Server 2012R2" + return + } + # Operation options $uri = Get-WebListenerUrl -Test 'Get' -Https $command = "Invoke-WebRequest -Uri $uri -HttpVersion $httpVersion -SkipCertificateCheck" @@ -2572,6 +2578,12 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { @{ httpVersion = '2'} ) { param($httpVersion) + + if(Test-IsWinServer2012R2 -and $httpVersion -eq '2') { + Set-ItResult -Skipped -Because "HTTP/2 is not supported on Windows Server 2012R2" + return + } + # Operation options $uri = Get-WebListenerUrl -Test 'Get' -Https $command = "Invoke-RestMethod -Uri $uri -HttpVersion $httpVersion -SkipCertificateCheck" @@ -4467,11 +4479,31 @@ Describe 'Invoke-WebRequest and Invoke-RestMethod support Cancellation through C Describe "Web cmdlets Unix Sockets tests" -Tags "CI", "RequireAdminOnWindows" { BeforeAll { - $unixSocket = Get-UnixSocketName - $WebListener = Start-UnixSocket $unixSocket + $isWin2016 = Test-IsWindows2016 + $isWin2012 = Test-IsWinServer2012R2 + $skipTests = $isWin2016 -or $isWin2012 + Write-Verbose -Verbose -Message "IsWin2016: $isWin2016 - IsWin2012: $isWin2012 - SkipTests: $skipTests" + if ($skipTests){ + return + } + + try { + $unixSocket = Get-UnixSocketName -ErrorAction Stop + $WebListener = Start-UnixSocket $unixSocket -ErrorAction Stop + } + catch { + Write-Verbose -Verbose -Message "Exception: $_" + $WebListener = $null + $skipTests = $true + } } It "Execute Invoke-WebRequest with -UnixSocket" { + if ($skipTests) { + Set-ItResult -Skipped -Because "Unix sockets are not supported on this platform." + return + } + $uri = Get-UnixSocketUri $result = Invoke-WebRequest $uri -UnixSocket $unixSocket $result.StatusCode | Should -Be "200" @@ -4479,6 +4511,11 @@ Describe "Web cmdlets Unix Sockets tests" -Tags "CI", "RequireAdminOnWindows" { } It "Execute Invoke-RestMethod with -UnixSocket" { + if ($skipTests) { + Set-ItResult -Skipped -Because "Unix sockets are not supported on this platform." + return + } + $uri = Get-UnixSocketUri $result = Invoke-RestMethod $uri -UnixSocket $unixSocket $result | Should -Be "Hello World Unix Socket." diff --git a/test/powershell/engine/Remoting/InvokeCommandRemoteDebug.Tests.ps1 b/test/powershell/engine/Remoting/InvokeCommandRemoteDebug.Tests.ps1 index 886bceb363d..ab0f5245cf8 100644 --- a/test/powershell/engine/Remoting/InvokeCommandRemoteDebug.Tests.ps1 +++ b/test/powershell/engine/Remoting/InvokeCommandRemoteDebug.Tests.ps1 @@ -4,8 +4,7 @@ ## PowerShell Invoke-Command -RemoteDebug Tests ## -if ($IsWindows) -{ +if ($IsWindows) { $typeDef = @' using System; using System.Globalization; @@ -120,19 +119,16 @@ Describe "Invoke-Command remote debugging tests" -Tags 'Feature','RequireAdminOn BeforeAll { - if (!$IsWindows) - { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - $PSDefaultParameterValues["it:skip"] = $true - return - } - elseif (Test-IsWindowsArm64) { - Write-Verbose "remoting is not setup on ARM64, skipping tests" -Verbose - $PSDefaultParameterValues["it:skip"] = $true + $isArm64orWow64 = (Test-IsWindowsArm64) -or (Test-IsWinWow64) + $skipTest = ! $IsWindows -or $isArm64orWow64 + if ($skipTest) { + if ($isArm64orWow64) { + Write-Verbose "remoting is not setup on ARM64 or x86, skipping tests" -Verbose + } + Push-DefaultParameterValueStack @{ "it:skip" = $true } return } - $sb = [scriptblock]::Create('"Hello!"') Add-Type -TypeDefinition $typeDef @@ -156,9 +152,8 @@ Describe "Invoke-Command remote debugging tests" -Tags 'Feature','RequireAdminOn AfterAll { - if (!$IsWindows) - { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ($skipTest) { + Pop-DefaultParameterValueStack return } @@ -171,11 +166,15 @@ Describe "Invoke-Command remote debugging tests" -Tags 'Feature','RequireAdminOn } BeforeEach { - - $remoteSession = New-RemoteSession + if (!$skipTest) { + $remoteSession = New-RemoteSession + } } AfterEach { + if ($skipTest) { + return + } $ps.Commands.Clear() $ps2.Commands.Clear() diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index 7c0a0f81727..8efe61de357 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -59,20 +59,30 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { Describe "JEA session Transcript script test" -Tag @("Feature", 'RequireAdminOnWindows') { BeforeAll { - $originalDefaultParameterValues = $global:PSDefaultParameterValues.Clone() - if ( ! $IsWindows -or !(Test-CanWriteToPsHome)) - { - $global:PSDefaultParameterValues["it:skip"] = $true + $skipTest = ! $IsWindows -or !(Test-CanWriteToPsHome) + if ($skipTest) { + Push-DefaultParameterValueStack @{ "it:skip" = $true } + return } - else - { - Enable-PSRemoting -SkipNetworkProfileCheck + + try { + Enable-PSRemoting -SkipNetworkProfileCheck -ErrorAction Stop + } + catch { + Write-Verbose -Verbose "exception: $_" + Push-DefaultParameterValueStack @{ "it:skip" = $true } + $skipTest = $true + return } } AfterAll { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ($skipTest) { + Pop-DefaultParameterValueStack + return + } + Pop-DefaultParameterValueStack } It "Configuration name should be in the transcript header" { @@ -101,20 +111,29 @@ Describe "JEA session Transcript script test" -Tag @("Feature", 'RequireAdminOnW Describe "JEA session Get-Help test" -Tag @("CI", 'RequireAdminOnWindows') { BeforeAll { - $originalDefaultParameterValues = $global:PSDefaultParameterValues.Clone() - if ( ! $IsWindows -or !(Test-CanWriteToPsHome)) - { - $global:PSDefaultParameterValues["it:skip"] = $true + $skipTest = ! $IsWindows -or !(Test-CanWriteToPsHome) + if ($skipTest) { + Push-DefaultParameterValueStack @{ "it:skip" = $true } + return } - else - { - Enable-PSRemoting -SkipNetworkProfileCheck + + try { + Enable-PSRemoting -SkipNetworkProfileCheck -ErrorAction Stop + } + catch { + Write-Verbose -Verbose "Enable-PSRemoting failed: $($_.Message)" + Push-DefaultParameterValueStack @{ "it:skip" = $true } + $skipTest = $true + return } } AfterAll { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ($skipTest) { + Pop-DefaultParameterValueStack + return + } } It "Get-Help should work in JEA sessions" { @@ -141,78 +160,89 @@ Describe "JEA session Get-Help test" -Tag @("CI", 'RequireAdminOnWindows') { Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') { BeforeAll { - $originalDefaultParameterValues = $global:PSDefaultParameterValues.Clone() + $skipTest = ! $IsWindows + if ($skipTest) { + Push-DefaultParameterValueStack @{ "it:skip" = $true } + return + } - if ( ! $IsWindows ) - { - $global:PSDefaultParameterValues["it:skip"] = $true + try { + Enable-PSRemoting -SkipNetworkProfileCheck -ErrorAction Stop } - else - { - Enable-PSRemoting -SkipNetworkProfileCheck - $configName = "PowerShell." + $PSVersionTable.GitCommitId - $configuration = Get-PSSessionConfiguration -Name $configName -ErrorAction Ignore - if ($null -eq $configuration) { - $global:PSDefaultParameterValues["it:skip"] = $true - return - } - $endPoint = $configuration.Name - $disconnectedSession = New-RemoteSession -ConfigurationName $endPoint -ComputerName localhost | Disconnect-PSSession - $closedSession = New-RemoteSession -ConfigurationName $endPoint -ComputerName localhost - $closedSession.Runspace.Close() - $openSession = New-RemoteSession -ConfigurationName $endPoint - - $ParameterError = @( - @{ - parameters = @{ - 'InDisconnectedSession' = $true - 'AsJob' = $true - 'ScriptBlock' = {1} - 'ComputerName' = 'localhost' - 'ConfigurationName' = $endpoint - } - expectedError = 'System.InvalidOperationException,Microsoft.PowerShell.Commands.InvokeCommandCommand' - title = 'Cannot use InDisconnectedState and AsJob together' - }, - @{ - parameters = @{ - 'ScriptBlock' = {1} - 'SessionName' = 'SomeSessionName' - } - expectedError = 'System.InvalidOperationException,Microsoft.PowerShell.Commands.InvokeCommandCommand' - title = 'Cannot use SessionName without InDisconnectedSession' - }, - @{ - parameters = @{ - 'ScriptBlock' = { 1 } - 'Session' = $disconnectedSession - 'ErrorAction' = 'Stop' - } - expectedError = 'InvokeCommandCommandInvalidSessionState,Microsoft.PowerShell.Commands.InvokeCommandCommand' - title = 'Cannot use Invoke-Command on a disconnected session' + catch { + Write-Verbose -Verbose "Enable-PSRemoting failed: $($_.Message)" + Push-DefaultParameterValueStack @{ "it:skip" = $true } + $skipTest = $true + return + } + + $configName = "PowerShell." + $PSVersionTable.GitCommitId + $configuration = Get-PSSessionConfiguration -Name $configName -ErrorAction Ignore + if ($null -eq $configuration) { + Push-DefaultParameterValueStack @{ "it:skip" = $true } + $skipTest = $true + return + } + + $endPoint = $configuration.Name + $disconnectedSession = New-RemoteSession -ConfigurationName $endPoint -ComputerName localhost | Disconnect-PSSession + $closedSession = New-RemoteSession -ConfigurationName $endPoint -ComputerName localhost + $closedSession.Runspace.Close() + $openSession = New-RemoteSession -ConfigurationName $endPoint + + $ParameterError = @( + @{ + parameters = @{ + 'InDisconnectedSession' = $true + 'AsJob' = $true + 'ScriptBlock' = {1} + 'ComputerName' = 'localhost' + 'ConfigurationName' = $endpoint } - @{ - parameters = @{ - 'ScriptBlock' = { 1 } - 'Session' = $closedSession - 'ErrorAction' = 'Stop' - } - expectedError = 'InvokeCommandCommandInvalidSessionState,Microsoft.PowerShell.Commands.InvokeCommandCommand' - title = 'Cannot use Invoke-Command on a closed session' + expectedError = 'System.InvalidOperationException,Microsoft.PowerShell.Commands.InvokeCommandCommand' + title = 'Cannot use InDisconnectedState and AsJob together' + }, + @{ + parameters = @{ + 'ScriptBlock' = {1} + 'SessionName' = 'SomeSessionName' } - ) - - function script:ValidateSessionInfo($session, $state) - { - $session.ComputerName | Should -BeExactly 'localhost' - $session.ConfigurationName | Should -BeExactly $endPoint - $session.State | Should -Be $state + expectedError = 'System.InvalidOperationException,Microsoft.PowerShell.Commands.InvokeCommandCommand' + title = 'Cannot use SessionName without InDisconnectedSession' + }, + @{ + parameters = @{ + 'ScriptBlock' = { 1 } + 'Session' = $disconnectedSession + 'ErrorAction' = 'Stop' + } + expectedError = 'InvokeCommandCommandInvalidSessionState,Microsoft.PowerShell.Commands.InvokeCommandCommand' + title = 'Cannot use Invoke-Command on a disconnected session' } + @{ + parameters = @{ + 'ScriptBlock' = { 1 } + 'Session' = $closedSession + 'ErrorAction' = 'Stop' + } + expectedError = 'InvokeCommandCommandInvalidSessionState,Microsoft.PowerShell.Commands.InvokeCommandCommand' + title = 'Cannot use Invoke-Command on a closed session' + } + ) + + function script:ValidateSessionInfo($session, $state) + { + $session.ComputerName | Should -BeExactly 'localhost' + $session.ConfigurationName | Should -BeExactly $endPoint + $session.State | Should -Be $state } } AfterAll { - $global:PSDefaultParameterValues = $originalDefaultParameterValues + If ($skipTest) { + Pop-DefaultParameterValueStack + return + } if($IsWindows) { @@ -223,36 +253,31 @@ Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') { It 'Can connect to default endpoint' { $session = New-RemoteSession -ConfigurationName $endPoint - try - { + try { ValidateSessionInfo -session $session -state 'Opened' } - finally - { + finally { $session | Remove-PSSession -ErrorAction SilentlyContinue } } It 'Can execute command in a disconnected session' { $session = Invoke-RemoteCommand -InDisconnectedSession -ComputerName 'localhost' -ScriptBlock { 1 + 1 } -ConfigurationName $endPoint - try - { + try { ValidateSessionInfo -session $session -state 'Disconnected' $result = Receive-PSSession -Session $session $result | Should -Be 2 $result.PSComputerName | Should -BeExactly 'localhost' } - finally - { + finally { $session | Remove-PSSession -ErrorAction SilentlyContinue } } It 'Can disconnect and connect to PSSession' { $session = New-RemoteSession -ConfigurationName $endPoint - try - { + try { ValidateSessionInfo -session $session -state 'Opened' Disconnect-PSSession -Session $session @@ -263,8 +288,7 @@ Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') { $result | Should -Be 2 $result.PSComputerName | Should -BeExactly 'localhost' } - finally - { + finally { $session | Remove-PSSession -ErrorAction SilentlyContinue } } @@ -276,12 +300,10 @@ Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') { } It 'Can execute command if one of the sessions is available' { - try - { + try { $result = Invoke-Command -Session $openSession,$disconnectedSession,$closedSession -ScriptBlock { 1+1 } -ErrorAction SilentlyContinue } - catch - { + catch { if($_.FullyQualifiedErrorId -ne 'InvokeCommandCommandInvalidSessionState,Microsoft.PowerShell.Commands.InvokeCommandCommand') { # We expect the error from $disconnectedSession and $closedSession. Hence, throw otherwise. @@ -316,14 +338,12 @@ Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') { Connect-RemoteSession -ComputerName localhost -Name $connectionNames -ConfigurationName $endpoint $sessions = Get-PSSession -Name $connectionNames - try - { + try { $sessions | ForEach-Object { ValidateSessionInfo -session $_ -state 'Opened' } } - finally - { + finally { $sessions | Remove-PSSession -ErrorAction SilentlyContinue } } diff --git a/test/powershell/engine/Security/FileSignature.Tests.ps1 b/test/powershell/engine/Security/FileSignature.Tests.ps1 index 0a9b283273a..51194903a94 100644 --- a/test/powershell/engine/Security/FileSignature.Tests.ps1 +++ b/test/powershell/engine/Security/FileSignature.Tests.ps1 @@ -22,12 +22,11 @@ Describe "Windows platform file signatures" -Tags 'Feature' { } Describe "Windows file content signatures" -Tags @('Feature', 'RequireAdminOnWindows') { - $shouldSkip = (-not $IsWindows) -or (Test-IsWinServer2012R2) - - $PSDefaultParameterValues = @{ "It:Skip" = $shouldSkip } - BeforeAll { + $shouldSkip = (-not $IsWindows) -or (Test-IsWinServer2012R2) + if ($shouldSkip) { + Push-DefaultParameterValueStack @{ "it:skip" = $shouldSkip } return } @@ -100,9 +99,9 @@ Describe "Windows file content signatures" -Tags @('Feature', 'RequireAdminOnWin ) foreach($path in $paths) { - if (Test-Path $path) { + if (Test-Path $path -PathType Leaf) { # failing to remove is not fatal - Remove-Item -Force -Path $path -ErrorAction Continue + Remove-Item -Force -Path $path -ErrorAction Ignore } } } diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index ca9fb8a8131..897d41c251b 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -38,9 +38,16 @@ FunctionsToExport = @( 'Test-IsWindowsArm64' 'Test-IsWinServer2012R2' 'Test-IsWinWow64' + 'Test-IsWindows2016' 'Test-TesthookIsSet' 'Wait-FileToBePresent' 'Wait-UntilTrue' + 'Initialize-PSDefaultParameterValue' + 'Reset-DefaultParameterValueStack' + 'Get-DefaultParameterValueStack' + 'Test-PSDefaultParameterValue' + 'Push-DefaultParameterValueStack' + 'Pop-DefaultParameterValueStack' ) CmdletsToExport= @() diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 6056bbce68b..aefd2893a21 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -456,3 +456,80 @@ function Test-IsWinServer2012R2 $osInfo = [System.Environment]::OSVersion.Version return ($osInfo.Major -eq 6 -and $osInfo.Minor -eq 3) } + +function Test-IsWindows2016 { + if (-not $IsWindows) { + return $false + } + + $osInfo = [System.Environment]::OSVersion.Version + return ($osInfo.Major -eq 10 -and $osInfo.Minor -eq 0 -and $osInfo.Build -eq 14393) +} + + +# helpers for managing psdefaultparametervalues +[system.collections.generic.Stack[hashtable]]$script:DefaultParameterValueStack = [system.collections.generic.Stack[hashtable]]::new() + +# Ensure that the global:PSDefaultParameterValues variable is a hashtable +function Initialize-PSDefaultParameterValue { + if ( $global:PSDefaultParameterValues -isnot [hashtable] ) { + $global:PSDefaultParameterValues = @{} + } +} + +# reset the stack +function Reset-DefaultParameterValueStack { + $script:DefaultParameterValueStack = [system.collections.generic.Stack[hashtable]]::new() + Initialize-PSDefaultParameterValue +} + +# return the current stack +function Get-DefaultParameterValueStack { + $script:DefaultParameterValueStack +} + +# PSDefaultParameterValue may not have both skip and pending keys +function Test-PSDefaultParameterValue { + if ( $global:PSDefaultParameterValues -is [hashtable] ) { + if ( $global:PSDefaultParameterValues.ContainsKey('skip') -and $global:PSDefaultParameterValues.ContainsKey('pending') ) { + return $false + } + return $true + } + Initialize-PSDefaultParameterValue +} + +# push a new value onto the stack +# if $ht is null, then the current value of $global:PSDefaultParameterValues is pushed +# if $NewValue is used, then $ht is used as the new value of $global:PSDefaultParameterValues +function Push-DefaultParameterValueStack { + param ([hashtable]$ht, [switch]$NewValue) + Initialize-PSDefaultParameterValue + + $script:DefaultParameterValueStack.Push($global:PSDefaultParameterValues.Clone()) + if ( $ht ) { + if ( $NewValue ) { + $global:PSDefaultParameterValues = $ht + } + else { + foreach ($k in $ht.Keys) { + $global:PSDefaultParameterValues[$k] = $ht[$k] + } + } + if ( ! (Test-PSDefaultParameterValue)) { + Write-Warning -Message "PSDefaultParameterValues may not have both skip and pending keys, resetting." + Pop-DefaultParameterValueStack + } + } +} + +function Pop-DefaultParameterValueStack { + try { + $global:PSDefaultParameterValues = $script:DefaultParameterValueStack.Pop() + return $true + } + catch { + Initialize-PSDefaultParameterValue + return $false + } +} diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index f9227854c84..e860390a38f 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -125,7 +125,6 @@ function Start-PSPackage { # Runtime will be one of win7-x64, win7-x86, "win-arm" and "win-arm64" on Windows. # Build the name suffix for universal win-plat packages. switch ($Runtime) { - "win-arm" { $NameSuffix = "win-arm32" } "win-arm64" { $NameSuffix = "win-arm64" } default { $NameSuffix = $_ -replace 'win\d+', 'win' } } diff --git a/tools/releaseBuild/azureDevOps/templates/global-tool-pkg-sbom.yml b/tools/releaseBuild/azureDevOps/templates/global-tool-pkg-sbom.yml index b437816d2fd..d7200809cca 100644 --- a/tools/releaseBuild/azureDevOps/templates/global-tool-pkg-sbom.yml +++ b/tools/releaseBuild/azureDevOps/templates/global-tool-pkg-sbom.yml @@ -14,7 +14,6 @@ parameters: - PowerShell.Linux.arm32 - PowerShell.Linux.arm64 - PowerShell.Windows.x64 - - PowerShell.Windows.arm32 steps: diff --git a/tools/releaseBuild/azureDevOps/templates/release-ValidatePackageNames.yml b/tools/releaseBuild/azureDevOps/templates/release-ValidatePackageNames.yml index 4d9ab047389..50d75753f1f 100644 --- a/tools/releaseBuild/azureDevOps/templates/release-ValidatePackageNames.yml +++ b/tools/releaseBuild/azureDevOps/templates/release-ValidatePackageNames.yml @@ -70,7 +70,7 @@ steps: - pwsh: | $message = @() Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -include *.zip, *.msi | ForEach-Object { - if($_.Name -notmatch 'PowerShell-\d+\.\d+\.\d+\-([a-z]*.\d+\-)?win\-(fxdependent|x64|arm32|arm64|x86|fxdependentWinDesktop)\.(msi|zip){1}') + if($_.Name -notmatch 'PowerShell-\d+\.\d+\.\d+\-([a-z]*.\d+\-)?win\-(fxdependent|x64|arm64|x86|fxdependentWinDesktop)\.(msi|zip){1}') { $messageInstance = "$($_.Name) is not a valid package name" $message += $messageInstance diff --git a/tools/releaseBuild/azureDevOps/templates/vpackReleaseJob.yml b/tools/releaseBuild/azureDevOps/templates/vpackReleaseJob.yml index 429daa983cd..b6d18b8eaaf 100644 --- a/tools/releaseBuild/azureDevOps/templates/vpackReleaseJob.yml +++ b/tools/releaseBuild/azureDevOps/templates/vpackReleaseJob.yml @@ -55,7 +55,7 @@ jobs: - pwsh: | $message = @() Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -include *.zip, *.msi | ForEach-Object { - if($_.Name -notmatch 'PowerShell-\d+\.\d+\.\d+\-([a-z]*.\d+\-)?win\-(fxdependent|x64|arm32|arm64|x86|fxdependentWinDesktop)\.(msi|zip){1}') + if($_.Name -notmatch 'PowerShell-\d+\.\d+\.\d+\-([a-z]*.\d+\-)?win\-(fxdependent|x64|arm64|x86|fxdependentWinDesktop)\.(msi|zip){1}') { $messageInstance = "$($_.Name) is not a valid package name" $message += $messageInstance diff --git a/tools/releaseBuild/azureDevOps/templates/windows-hosted-build.yml b/tools/releaseBuild/azureDevOps/templates/windows-hosted-build.yml index d0952568bf9..539992c63ce 100644 --- a/tools/releaseBuild/azureDevOps/templates/windows-hosted-build.yml +++ b/tools/releaseBuild/azureDevOps/templates/windows-hosted-build.yml @@ -53,7 +53,6 @@ jobs: { "x64" { "win7-x64" } "x86" { "win7-x86" } - "arm" { "win-arm"} "arm64" { "win-arm64" } "fxdependent" { "fxdependent" } "fxdependentWinDesktop" { "fxdependent-win-desktop" } diff --git a/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml b/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml index 44b76127ddc..fdff7af73b1 100644 --- a/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml +++ b/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml @@ -95,12 +95,6 @@ jobs: version: $(version) pdb: yes - - template: upload.yml - parameters: - architecture: arm32 - version: $(version) - msi: no - - template: upload.yml parameters: architecture: arm64 diff --git a/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml b/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml index 1ebb0be033a..ffc3225e387 100644 --- a/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml +++ b/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml @@ -43,7 +43,7 @@ jobs: - template: shouldSign.yml - pwsh: | - $pkgFilter = if ( '$(Architecture)' -eq 'arm' ) { "arm32" } else { '$(Architecture)' } + $pkgFilter = '$(Architecture)' if ($env:BuildConfiguration -eq 'minSize') { $pkgFilter += '-gc' } $vstsCommandString = "vso[task.setvariable variable=PkgFilter]$pkgFilter" @@ -243,7 +243,6 @@ jobs: { "x64" { "win7-x64" } "x86" { "win7-x86" } - "arm" { "win-arm"} "arm64" { "win-arm64" } "fxdependent" { "fxdependent" } "fxdependentWinDesktop" { "fxdependent-win-desktop" }