8000 Fix for implicit remote regression in restricted session (#4222) · PowerShell/PowerShell@7fa0dd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fa0dd0

Browse files
PaulHigindaxian-dbw
authored andcommitted
Fix for implicit remote regression in restricted session (#4222)
1 parent ea758a5 commit 7fa0dd0

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/System.Management.Automation/engine/CommandMetadata.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,10 @@ private static CommandMetadata GetRestrictedGetFormatData()
12201220
typeNameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
12211221
typeNameParameter.Attributes.Add(new ValidateCountAttribute(0, 1000));
12221222

1223-
return GetRestrictedCmdlet("Get-FormatData", null, "https://go.microsoft.com/fwlink/?LinkID=144303", typeNameParameter);
1223+
// This parameter is required for implicit remoting in PS V5.1.
1224+
ParameterMetadata powershellVersionParameter = new ParameterMetadata("PowerShellVersion", typeof(Version));
1225+
1226+
return GetRestrictedCmdlet("Get-FormatData", null, "https://go.microsoft.com/fwlink/?LinkID=144303", typeNameParameter, powershellVersionParameter);
12241227
}
12251228

12261229
private static CommandMetadata GetRestrictedGetHelp()

test/powershell/Modules/Microsoft.PowerShell.Utility/Implicit.Remoting.Tests.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,3 +2076,42 @@ Describe "GetCommand locally and remotely" -tags "Feature" {
20762076
$localCommandCount | Should Be $remoteCommandCount
20772077
}
20782078
}
2079+
2080+
Describe "Import-PSSession on Restricted Session" -tags "Feature","RequireAdminOnWindows","Slow" {
2081+
2082+
BeforeAll {
2083+
2084+
# Skip tests for non Windows
2085+
if (! $IsWindows)
2086+
{
2087+
$originalDefaultParameters = $PSDefaultParameterValues.Clone()
2088+
$global:PSDefaultParameterValues["it:skip"] = $true
2089+
}
2090+
else
2091+
{
2092+
New-PSSessionConfigurationFile -Path $TestDrive\restricted.pssc -SessionType RestrictedRemoteServer
2093+
Register-PSSessionConfiguration -Path $TestDrive\restricted.pssc -Name restricted -Force
2094+
$session = New-PSSession -ComputerName localhost -ConfigurationName restricted
2095+
}
2096+
}
2097+
2098+
AfterAll {
2099+
2100+
if ($originalDefaultParameters -ne $null)
2101+
{
2102+
$global:PSDefaultParameterValues = $originalDefaultParameters
2103+
}
2104+
else
2105+
{
2106+
if ($session -ne $null) { Remove-PSSession -Session $session -ErrorAction SilentlyContinue }
2107+
Unregister-PSSessionConfiguration -Name restricted -Force -ErrorAction SilentlyContinue
2108+
}
2109+
}
2110+
2111+
It "Verifies that Import-PSSession works on a restricted session" {
2112+
2113+
$errorVariable = $null
2114+
Import-PSSession -Session $session -AllowClobber -ErrorVariable $errorVariable
2115+
$errorVariable | Should BeNullOrEmpty
2116+
}
2117+
}

0 commit comments

Comments
 (0)
0