From 5962d7d0389cd9a5755511ecfaf90cf25cf03f71 Mon Sep 17 00:00:00 2001 From: chunqingchen Date: Mon, 9 Jan 2017 21:59:35 -0800 Subject: [PATCH] Get-Help does not work in JEA sessions --- .../help/ProviderContext.cs | 26 ++++++++++- .../Remoting/RemoteSession.Basic.Tests.ps1 | 44 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/help/ProviderContext.cs b/src/System.Management.Automation/help/ProviderContext.cs index 1cca401cbf4..c5ab2e911b2 100644 --- a/src/System.Management.Automation/help/ProviderContext.cs +++ b/src/System.Management.Automation/help/ProviderContext.cs @@ -110,14 +110,38 @@ internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) // Does the provider know how to generate MAML. CmdletProvider cmdletProvider = providerInfo.CreateInstance(); ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp; + + // Under JEA sessions the resolvedProviderPath will be null, we should allow get-help to continue. if (provider == null) { return null; } + bool isJEASession = false; + if (this._executionContext.InitialSessionState != null && this._executionContext.InitialSessionState.Providers != null && providerInfo != null) + { + foreach ( + Runspaces.SessionStateProviderEntry sessionStateProvider in + this._executionContext.InitialSessionState.Providers[providerInfo.Name]) + { + if (sessionStateProvider.Visibility == SessionStateEntryVisibility.Private) + { + isJEASession = true; + break; + } + } + } + if (resolvedProviderPath == null) { - throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); + if (isJEASession) + { + return null; + } + else + { + throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); + } } // ok we have path and valid provider that supplys content..initialize the provider diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index a0b0df0ac74..ad1ca3d7a58 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -8,4 +8,48 @@ Describe "New-PSSession basic test" -Tag @("CI") { $_.FullyQualifiedErrorId | Should Be "InvalidOperation,Microsoft.PowerShell.Commands.NewPSSessionCommand" } } +} + +Describe "JEA session Transcprit script test" -Tag @("Feature", 'RequireAdminOnWindows') { + It "Configuration name should be in the transcript header" -Pending { + [string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName + [string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc" + [string] $transScriptFile = "$RoleCapDirectory\*.txt" + try + { + New-PSSessionConfigurationFile -Path $PSSessionConfigFile -TranscriptDirectory $RoleCapDirectory -SessionType RestrictedRemoteServer + Register-PSSessionConfiguration -Name JEA -Path $PSSessionConfigFile -Force -ErrorAction SilentlyContinue + $scriptBlock = {Enter-PSSession -ComputerName Localhost -ConfigurationName JEA; Exit-PSSession} + & $scriptBlock + $headerFile = Get-ChildItem $transScriptFile | Sort-Object LastWriteTime | Select-Object -Last 1 + $header = Get-Content $headerFile | Out-String + $header | Should BeLike "Configuration Name: JEA" + } + finally + { + Unregister-PSSessionConfiguration -Name JEA -Force -ErrorAction SilentlyContinue + } + } +} + + +Describe "JEA session Get-Help test" -Tag @("CI", 'RequireAdminOnWindows') { + It "Get-Help should work in JEA sessions" -Pending { + [string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName + [string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc" + try + { + New-PSSessionConfigurationFile -Path $PSSessionConfigFile -TranscriptDirectory $RoleCapDirectory -SessionType RestrictedRemoteServer + Register-PSSessionConfiguration -Name JEA -Path $PSSessionConfigFile -Force -ErrorAction SilentlyContinue + $scriptBlock = {Enter-PSSession -ComputerName Localhost -ConfigurationName JEA; Get-Help Get-Command; Exit-PSSession} + $helpContent = & $scriptBlock + $helpContent | Should Not Be $null + } + finally + { + Unregister-PSSessionConfiguration -Name JEA -Force -ErrorAction SilentlyContinue + Remove-Item $RoleCapDirectory -Recurse -Force -ErrorAction SilentlyContinue + } + } + } \ No newline at end of file