make transcripts include the configuration name in the transcript header (#2890)

* PowerShell transcripts should include the configuration name in the transcript header
* adding test case for PowerShell transcripts should include the configuration name in the transcript header #2890
This commit is contained in:
Chunqing Chen
2017-03-15 22:06:07 -07:00
committed by Travis Plunk
parent 76de340e79
commit 3f274aad9c
5 changed files with 42 additions and 6 deletions
@@ -453,7 +453,11 @@ namespace System.Management.Automation.Host
psVersionInfo.AppendLine(versionKey + ": " + valueString);
}
}
string psConfigurationName = string.Empty;
if (senderInfo != null && !string.IsNullOrEmpty(senderInfo.ConfigurationName))
{
psConfigurationName = senderInfo.ConfigurationName;
}
// Transcribe the transcript header
string format = InternalHostUserInterfaceStrings.TranscriptPrologue;
string line =
@@ -463,6 +467,7 @@ namespace System.Management.Automation.Host
DateTime.Now,
username,
runAsUser,
psConfigurationName,
Environment.MachineName,
Environment.OSVersion.VersionString,
String.Join(" ", Environment.GetCommandLineArgs()),
@@ -162,6 +162,11 @@ namespace System.Management.Automation.Remoting
internal set { _applicationArguments = value; }
}
/// <summary>
/// "ConfigurationName" from the sever remote session
/// </summary>
public string ConfigurationName { get; internal set; }
#endregion
}
@@ -206,7 +206,9 @@ namespace System.Management.Automation.Remoting
{
throw PSTraceSource.NewInvalidOperationException("RemotingErrorIdStrings.NonExistentInitialSessionStateProvider", configurationProviderId);
}
string shellPrefix = System.Management.Automation.Remoting.Client.WSManNativeApi.ResourceURIPrefix;
int index = configurationProviderId.IndexOf(shellPrefix, StringComparison.OrdinalIgnoreCase);
senderInfo.ConfigurationName = (index == 0) ? configurationProviderId.Substring(shellPrefix.Length) : string.Empty;
ServerRemoteSession result = new ServerRemoteSession(senderInfo,
configurationProviderId,
initializationParameters,
@@ -201,10 +201,11 @@ Windows PowerShell transcript start
Start time: {0:yyyyMMddHHmmss}
Username: {1}
RunAs User: {2}
Machine: {3} ({4})
Host Application: {5}
Process ID: {6}
{7}
Configuration Name: {3}
Machine: {4} ({5})
Host Application: {6}
Process ID: {7}
{8}
**********************</value>
</data>
<data name="TranscriptEpilogue" xml:space="preserve">
@@ -8,4 +8,27 @@ 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" {
[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
}
}
}