From 7fa0dd054992082787bd1ef7e99bc0f2c9e2a05c Mon Sep 17 00:00:00 2001 From: Paul Higinbotham Date: Fri, 14 Jul 2017 12:28:22 -0700 Subject: [PATCH] Fix for implicit remote regression in restricted session (#4222) --- .../engine/CommandMetadata.cs | 5 ++- .../Implicit.Remoting.Tests.ps1 | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandMetadata.cs b/src/System.Management.Automation/engine/CommandMetadata.cs index d6b5ffc24..d1165546f 100644 --- a/src/System.Management.Automation/engine/CommandMetadata.cs +++ b/src/System.Management.Automation/engine/CommandMetadata.cs @@ -1220,7 +1220,10 @@ end typeNameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000)); typeNameParameter.Attributes.Add(new ValidateCountAttribute(0, 1000)); - return GetRestrictedCmdlet("Get-FormatData", null, "https://go.microsoft.com/fwlink/?LinkID=144303", typeNameParameter); + // This parameter is required for implicit remoting in PS V5.1. + ParameterMetadata powershellVersionParameter = new ParameterMetadata("PowerShellVersion", typeof(Version)); + + return GetRestrictedCmdlet("Get-FormatData", null, "https://go.microsoft.com/fwlink/?LinkID=144303", typeNameParameter, powershellVersionParameter); } private static CommandMetadata GetRestrictedGetHelp() 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 63ac3f1f4..72247041c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1 @@ -2076,3 +2076,42 @@ Describe "GetCommand locally and remotely" -tags "Feature" { $localCommandCount | Should Be $remoteCommandCount } } + +Describe "Import-PSSession on Restricted Session" -tags "Feature","RequireAdminOnWindows","Slow" { + + BeforeAll { + + # Skip tests for non Windows + if (! $IsWindows) + { + $originalDefaultParameters = $PSDefaultParameterValues.Clone() + $global:PSDefaultParameterValues["it:skip"] = $true + } + else + { + New-PSSessionConfigurationFile -Path $TestDrive\restricted.pssc -SessionType RestrictedRemoteServer + Register-PSSessionConfiguration -Path $TestDrive\restricted.pssc -Name restricted -Force + $session = New-PSSession -ComputerName localhost -ConfigurationName restricted + } + } + + AfterAll { + + if ($originalDefaultParameters -ne $null) + { + $global:PSDefaultParameterValues = $originalDefaultParameters + } + else + { + if ($session -ne $null) { Remove-PSSession -Session $session -ErrorAction SilentlyContinue } + Unregister-PSSessionConfiguration -Name restricted -Force -ErrorAction SilentlyContinue + } + } + + It "Verifies that Import-PSSession works on a restricted session" { + + $errorVariable = $null + Import-PSSession -Session $session -AllowClobber -ErrorVariable $errorVariable + $errorVariable | Should BeNullOrEmpty + } +}