Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ dotnet_code_quality_unused_parameters = non_public:suggestion
# https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca1859
dotnet_diagnostic.CA1859.severity = suggestion

# Disable SA1600 (ElementsMustBeDocumented) for test directory only
[test/**/*.cs]
dotnet_diagnostic.SA1600.severity = none

# CSharp code style settings:
[*.cs]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
- master
- release/**
- github-mirror
- "*-feature"
# Path filters for PRs need to go into the changes job

concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- master
- release/**
- github-mirror
- "*-feature"
# Path filters for PRs need to go into the changes job

concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- master
- release/**
- github-mirror
- "*-feature"

# Path filters for PRs need to go into the changes job

Expand Down
27 changes: 24 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,9 @@ function Test-PSPesterResults

function Start-PSxUnit {
[CmdletBinding()]param(
[string] $xUnitTestResultsFile = "xUnitResults.xml"
[string] $xUnitTestResultsFile = "xUnitResults.xml",
[switch] $DebugLogging,
[string] $Filter
)

# Add .NET CLI tools to PATH
Expand Down Expand Up @@ -2042,9 +2044,28 @@ function Start-PSxUnit {

# We run the xUnit tests sequentially to avoid race conditions caused by manipulating the config.json file.
# xUnit tests run in parallel by default. To make them run sequentially, we need to define the 'xunit.runner.json' file.
dotnet test --configuration $Options.configuration --test-adapter-path:. "--logger:xunit;LogFilePath=$xUnitTestResultsFile"
$extraParams = @()
if($Filter) {
$extraParams += @(
'--filter'
$Filter
)
}

if($DebugLogging) {
$extraParams += @(
"--logger:console;verbosity=detailed"
)
} else {
$extraParams += @(
"--logger:xunit;LogFilePath=$xUnitTestResultsFile"
)
}
dotnet test @extraParams --configuration $Options.configuration --test-adapter-path:.

Publish-TestResults -Path $xUnitTestResultsFile -Type 'XUnit' -Title 'Xunit Sequential'
if(!$DebugLogging){
Publish-TestResults -Path $xUnitTestResultsFile -Type 'XUnit' -Title 'Xunit Sequential'
}
}
finally {
$env:DOTNET_ROOT = $originalDOTNET_ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,42 +196,44 @@ internal static int MaxNameLength()
"workingdirectory"
};

#pragma warning disable SA1025 // CodeMustNotContainMultipleWhitespaceInARow
/// <summary>
/// These represent the parameters that are used when starting pwsh.
/// We can query in our telemetry to determine how pwsh was invoked.
/// </summary>
[Flags]
internal enum ParameterBitmap : long
{
Command = 0x00000001, // -Command | -c
ConfigurationName = 0x00000002, // -ConfigurationName | -config
CustomPipeName = 0x00000004, // -CustomPipeName
EncodedCommand = 0x00000008, // -EncodedCommand | -e | -ec
EncodedArgument = 0x00000010, // -EncodedArgument
ExecutionPolicy = 0x00000020, // -ExecutionPolicy | -ex | -ep
File = 0x00000040, // -File | -f
Help = 0x00000080, // -Help, -?, /?
InputFormat = 0x00000100, // -InputFormat | -inp | -if
Interactive = 0x00000200, // -Interactive | -i
Login = 0x00000400, // -Login | -l
MTA = 0x00000800, // -MTA
NoExit = 0x00001000, // -NoExit | -noe
NoLogo = 0x00002000, // -NoLogo | -nol
NonInteractive = 0x00004000, // -NonInteractive | -noni
NoProfile = 0x00008000, // -NoProfile | -nop
OutputFormat = 0x00010000, // -OutputFormat | -o | -of
SettingsFile = 0x00020000, // -SettingsFile | -settings
SSHServerMode = 0x00040000, // -SSHServerMode | -sshs
SocketServerMode = 0x00080000, // -SocketServerMode | -sockets
ServerMode = 0x00100000, // -ServerMode | -server
NamedPipeServerMode = 0x00200000, // -NamedPipeServerMode | -namedpipes
STA = 0x00400000, // -STA
Version = 0x00800000, // -Version | -v
WindowStyle = 0x01000000, // -WindowStyle | -w
WorkingDirectory = 0x02000000, // -WorkingDirectory | -wd
ConfigurationFile = 0x04000000, // -ConfigurationFile
NoProfileLoadTime = 0x08000000, // -NoProfileLoadTime
CommandWithArgs = 0x10000000, // -CommandWithArgs | -cwa
Command = 0x0000000000000001, // -Command | -c
ConfigurationName = 0x0000000000000002, // -ConfigurationName | -config
CustomPipeName = 0x0000000000000004, // -CustomPipeName
EncodedCommand = 0x0000000000000008, // -EncodedCommand | -e | -ec
EncodedArgument = 0x0000000000000010, // -EncodedArgument
ExecutionPolicy = 0x0000000000000020, // -ExecutionPolicy | -ex | -ep
File = 0x0000000000000040, // -File | -f
Help = 0x0000000000000080, // -Help, -?, /?
InputFormat = 0x0000000000000100, // -InputFormat | -inp | -if
Interactive = 0x0000000000000200, // -Interactive | -i
Login = 0x0000000000000400, // -Login | -l
MTA = 0x0000000000000800, // -MTA
NoExit = 0x0000000000001000, // -NoExit | -noe
NoLogo = 0x0000000000002000, // -NoLogo | -nol
NonInteractive = 0x0000000000004000, // -NonInteractive | -noni
NoProfile = 0x0000000000008000, // -NoProfile | -nop
OutputFormat = 0x0000000000010000, // -OutputFormat | -o | -of
SettingsFile = 0x0000000000020000, // -SettingsFile | -settings
SSHServerMode = 0x0000000000040000, // -SSHServerMode | -sshs
SocketServerMode = 0x0000000000080000, // -SocketServerMode | -sockets
ServerMode = 0x0000000000100000, // -ServerMode | -server
NamedPipeServerMode = 0x0000000000200000, // -NamedPipeServerMode | -namedpipes
STA = 0x0000000000400000, // -STA
Version = 0x0000000000800000, // -Version | -v
WindowStyle = 0x0000000001000000, // -WindowStyle | -w
WorkingDirectory = 0x0000000002000000, // -WorkingDirectory | -wd
ConfigurationFile = 0x0000000004000000, // -ConfigurationFile
NoProfileLoadTime = 0x0000000008000000, // -NoProfileLoadTime
CommandWithArgs = 0x0000000010000000, // -CommandWithArgs | -cwa

// Enum values for specified ExecutionPolicy
EPUnrestricted = 0x0000000100000000, // ExecutionPolicy unrestricted
EPRemoteSigned = 0x0000000200000000, // ExecutionPolicy remote signed
Expand All @@ -241,7 +243,11 @@ internal enum ParameterBitmap : long
EPBypass = 0x0000002000000000, // ExecutionPolicy bypass
EPUndefined = 0x0000004000000000, // ExecutionPolicy undefined
EPIncorrect = 0x0000008000000000, // ExecutionPolicy incorrect

// V2 Socket Server Mode
V2SocketServerMode = 0x0000100000000000, // -V2SocketServerMode | -v2so
}
#pragma warning restore SA1025 // CodeMustNotContainMultipleWhitespaceInARow

internal ParameterBitmap ParametersUsed = 0;

Expand Down Expand Up @@ -597,6 +603,33 @@ internal bool RemoveWorkingDirectoryTrailingCharacter
return _removeWorkingDirectoryTrailingCharacter;
}
}

internal DateTimeOffset? UTCTimestamp
{
get
{
AssertArgumentsParsed();
return _utcTimestamp;
}
}

internal string? Token
{
get
{
AssertArgumentsParsed();
return _token;
}
}

internal bool V2SocketServerMode
{
get
{
AssertArgumentsParsed();
return _v2SocketServerMode;
}
}
#endif

#endregion Internal properties
Expand Down Expand Up @@ -916,6 +949,14 @@ private void ParseHelper(string[] args)
_showBanner = false;
ParametersUsed |= ParameterBitmap.SocketServerMode;
}
#if !UNIX
else if (MatchSwitch(switchKey, "v2socketservermode", "v2so"))
{
_v2SocketServerMode = true;
_showBanner = false;
ParametersUsed |= ParameterBitmap.V2SocketServerMode;
}
#endif
else if (MatchSwitch(switchKey, "servermode", "s"))
{
_serverMode = true;
Expand Down Expand Up @@ -1176,6 +1217,37 @@ private void ParseHelper(string[] args)
{
_removeWorkingDirectoryTrailingCharacter = true;
}
else if (MatchSwitch(switchKey, "token", "to"))
{
++i;
if (i >= args.Length)
{
SetCommandLineError(
string.Format(CultureInfo.CurrentCulture, CommandLineParameterParserStrings.MissingMandatoryArgument, "-Token"));
break;
}

_token = args[i];

// Not adding anything to ParametersUsed, because it is required with V2 socket server mode
// So, we can assume it based on that bit
}
else if (MatchSwitch(switchKey, "utctimestamp", "utc"))
{
++i;
if (i >= args.Length)
{
SetCommandLineError(
string.Format(CultureInfo.CurrentCulture, CommandLineParameterParserStrings.MissingMandatoryArgument, "-UTCTimestamp"));
break;
}

// Parse as iso8601UtcString
_utcTimestamp = DateTimeOffset.ParseExact(args[i], "yyyy-MM-dd'T'HH:mm:ssK", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);

// Not adding anything to ParametersUsed, because it is required with V2 socket server mode
// So, we can assume it based on that bit
}
#endif
else
{
Expand Down Expand Up @@ -1530,6 +1602,9 @@ private bool CollectArgs(string[] args, ref int i)
}

private bool _socketServerMode;
#if !UNIX
private bool _v2SocketServerMode;
#endif
private bool _serverMode;
private bool _namedPipeServerMode;
private bool _sshServerMode;
Expand Down Expand Up @@ -1562,6 +1637,10 @@ private bool CollectArgs(string[] args, ref int i)
private string? _executionPolicy;
private string? _settingsFile;
private string? _workingDirectory;
#if !UNIX
private string? _token;
private DateTimeOffset? _utcTimestamp;
#endif

#if !UNIX
private ProcessWindowStyle? _windowStyle;
Expand Down
51 changes: 50 additions & 1 deletion src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,26 @@ internal static int Start(
}

// Servermode parameter validation check.
if ((s_cpp.ServerMode && s_cpp.NamedPipeServerMode) || (s_cpp.ServerMode && s_cpp.SocketServerMode) || (s_cpp.NamedPipeServerMode && s_cpp.SocketServerMode))
int serverModeCount = 0;
if (s_cpp.ServerMode)
{
serverModeCount++;
}
if (s_cpp.NamedPipeServerMode)
{
serverModeCount++;
}
if (s_cpp.SocketServerMode)
{
serverModeCount++;
}
#if !UNIX
if (s_cpp.V2SocketServerMode)
{
serverModeCount++;
}
#endif
if (serverModeCount > 1)
{
s_tracer.TraceError("Conflicting server mode parameters, parameters must be used exclusively.");
s_theConsoleHost?.ui.WriteErrorLine(ConsoleHostStrings.ConflictingServerModeParameters);
Expand Down Expand Up @@ -242,6 +261,34 @@ internal static int Start(
configurationName: s_cpp.ConfigurationName);
exitCode = 0;
}
#if !UNIX
else if (s_cpp.V2SocketServerMode)
{
if (s_cpp.Token == null)
{
s_tracer.TraceError("Token is required for V2SocketServerMode.");
s_theConsoleHost?.ui.WriteErrorLine(string.Format(CultureInfo.CurrentCulture, ConsoleHostStrings.MissingMandatoryParameter, "-Token", "-V2SocketServerMode"));
return ExitCodeBadCommandLineParameter;
}

if (s_cpp.UTCTimestamp == null)
{
s_tracer.TraceError("UTCTimestamp is required for V2SocketServerMode.");
s_theConsoleHost?.ui.WriteErrorLine(string.Format(CultureInfo.CurrentCulture, ConsoleHostStrings.MissingMandatoryParameter, "-UTCTimestamp", "-v2socketservermode"));
return ExitCodeBadCommandLineParameter;
}

ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("V2SocketServerMode", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-V2SocketServerMode");
HyperVSocketMediator.Run(
initialCommand: s_cpp.InitialCommand,
configurationName: s_cpp.ConfigurationName,
token: s_cpp.Token,
tokenCreationTime: s_cpp.UTCTimestamp.Value);

exitCode = 0;
}
#endif
else if (s_cpp.SocketServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SocketServerMode", s_cpp.ParametersUsedAsDouble);
Expand Down Expand Up @@ -1879,6 +1926,7 @@ private void DoRunspaceInitialization(RunspaceCreationEventArgs args)
{
s_theConsoleHost.UI.WriteLine(ManagedEntranceStrings.ShellBannerCLAuditMode);
}

break;

case PSLanguageMode.NoLanguage:
Expand Down Expand Up @@ -2745,6 +2793,7 @@ e is RemoteException ||
#endif
}
}

// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
// Removed HandleUnexpectedExceptions infrastructure
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,7 @@ Valid formats are:
<data name="InvalidExecutionPolicyArgument" xml:space="preserve">
<value>Invalid ExecutionPolicy value '{0}'.</value>
</data>
<data name="MissingMandatoryArgument" xml:space="preserve">
<value>An argument is required to be supplied to the '{0}' parameter.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,7 @@ The current session does not support debugging; execution will continue.
<data name="PushRunspaceNotRemote" xml:space="preserve">
<value>PushRunspace can only push a remote runspace.</value>
</data>
<data name="MissingMandatoryParameter" xml:space="preserve">
<value>The '{0}' parameter is mandatory and must be specified when using the '{1}' parameter.</value>
</data>
</root>
Loading
Loading