Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal static void ParseCommandLine(string[] args)
}
#endif

if (s_cpp.SettingsFile is not null)
if (!string.IsNullOrEmpty(s_cpp.SettingsFile))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change this. Based on how it's set in TryParseSettingFileHelper, s_cpp.SettingsFile is guaranteed to not be an empty string.

{
PowerShellConfig.Instance.SetSystemConfigFilePath(s_cpp.SettingsFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ internal static void Init()
// * have high disk cost

// We shouldn't create too many tasks.
Task.Run(() =>
{
var jsonDocument = System.Text.Json.Nodes.JsonObject.Parse("1");
});
#if !UNIX
// Amsi initialize can be a little slow
Task.Run(() => AmsiUtils.WinScanContent(content: string.Empty, sourceMetadata: string.Empty, warmUp: true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4532,7 +4532,7 @@ internal static ModuleLoggingGroupPolicyStatus GetModuleLoggingInformation(out I
else if (moduleLogging.EnableModuleLogging == true)
{
status = ModuleLoggingGroupPolicyStatus.Enabled;
moduleNames = moduleLogging.ModuleNames;
moduleNames = moduleLogging.ModuleNames ?? Array.Empty<string>();
}
}

Expand Down
213 changes: 94 additions & 119 deletions src/System.Management.Automation/engine/PSConfiguration.cs

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions test/powershell/Host/Startup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Describe "Validate start of console host" -Tag CI {
'Microsoft.Win32.Primitives.dll'
'Microsoft.Win32.Registry.dll'
'netstandard.dll'
'Newtonsoft.Json.dll'
'pwsh.dll'
'System.Collections.Concurrent.dll'
'System.Collections.dll'
Expand All @@ -33,6 +32,7 @@ Describe "Validate start of console host" -Tag CI {
'System.Net.Mail.dll'
'System.Net.NetworkInformation.dll'
'System.Net.Primitives.dll'
'System.Numerics.Vectors.dll'
'System.ObjectModel.dll'
'System.Private.CoreLib.dll'
'System.Private.Uri.dll'
Expand All @@ -42,14 +42,15 @@ Describe "Validate start of console host" -Tag CI {
'System.Reflection.Primitives.dll'
'System.Runtime.dll'
'System.Runtime.InteropServices.dll'
'System.Runtime.Intrinsics.dll'
'System.Runtime.Loader.dll'
'System.Runtime.Numerics.dll'
'System.Runtime.Serialization.Formatters.dll'
'System.Runtime.Serialization.Primitives.dll'
'System.Security.AccessControl.dll'
'System.Security.Cryptography.dll'
'System.Security.Principal.Windows.dll'
'System.Text.Encoding.Extensions.dll'
'System.Text.Encodings.Web.dll'
'System.Text.Json.dll'
'System.Text.RegularExpressions.dll'
'System.Threading.dll'
'System.Threading.Tasks.Parallel.dll'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,23 +508,23 @@ Describe "Additional tests for Import-Module with WinCompat" -Tag "Feature" {
It "Fails to import incompatible module if implicit WinCompat is disabled in config" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
$ConfigPath = Join-Path $TestDrive 'powershell.config.json'
'{"DisableImplicitWinCompat" : "True"}' | Out-File -Force $ConfigPath
'{"DisableImplicitWinCompat" : true}' | Out-File -Force $ConfigPath
& $pwsh -NoProfile -NonInteractive -settingsFile $ConfigPath -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`');Import-Module $ModuleName2" *> $LogPath
$LogPath | Should -FileContentMatch 'cannot be loaded implicitly using the Windows Compatibility'
}

It "Fails to auto-import incompatible module during CommandDiscovery\ModuleAutoload if implicit WinCompat is Disabled in config" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
$ConfigPath = Join-Path $TestDrive 'powershell.config.json'
'{"DisableImplicitWinCompat" : "True","Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}' | Out-File -Force $ConfigPath
'{"DisableImplicitWinCompat" : true,"Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}' | Out-File -Force $ConfigPath
& $pwsh -NoProfile -NonInteractive -settingsFile $ConfigPath -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`'); Test-$ModuleName2" *> $LogPath
$LogPath | Should -FileContentMatch 'not recognized as a name of a cmdlet'
}

It "Successfully auto-imports incompatible module during CommandDiscovery\ModuleAutoload if implicit WinCompat is Enabled in config" {
$LogPath = Join-Path $TestDrive (New-Guid).ToString()
$ConfigPath = Join-Path $TestDrive 'powershell.config.json'
'{"DisableImplicitWinCompat" : "False","Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}' | Out-File -Force $ConfigPath
'{"DisableImplicitWinCompat" : false,"Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}' | Out-File -Force $ConfigPath
& $pwsh -NoProfile -NonInteractive -settingsFile $ConfigPath -c "[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('TestWindowsPowerShellPSHomeLocation', `'$basePath`'); Test-$ModuleName2" *> $LogPath
$LogPath | Should -FileContentMatch 'True'
}
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ Describe "Verify approved aliases list" -Tags "CI" {
# On Preview releases, Experimental Features may add new cmdlets/aliases, so we get cmdlets/aliases with features disabled
if ($isPreview) {
$emptyConfigPath = Join-Path -Path $TestDrive -ChildPath "test.config.json"
Set-Content -Path $emptyConfigPath -Value "" -Force -ErrorAction Stop
New-Item -Path $emptyConfigPath -ItemType file -Force -ErrorAction Stop | Out-Null
$currentAliasList = & "$PSHOME/pwsh" -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getAliases -args ($moduleList | ConvertTo-Json)
$currentCmdletList = & "$PSHOME/pwsh" -NoProfile -OutputFormat XML -SettingsFile $emptyConfigPath -Command $getCommands -args ($moduleList | ConvertTo-Json)
}
Expand Down
8 changes: 4 additions & 4 deletions test/powershell/engine/Basic/PropertyAccessor.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Describe "User-Specific powershell.config.json Modifications" -Tags "CI" {

BeforeEach {
if ($IsNotSkipped) {
Set-Content -Path $userPropertiesFile -Value '{"Microsoft.PowerShell:ExecutionPolicy":"RemoteSigned"}'
Set-Content -Path $userPropertiesFile -Value '{ "Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}'
}
}

Expand Down Expand Up @@ -83,15 +83,15 @@ Describe "User-Specific powershell.config.json Modifications" -Tags "CI" {
}

It "Verify Writes Update Properties" {
Get-Content -Path $userPropertiesFile | Should -Be '{"Microsoft.PowerShell:ExecutionPolicy":"RemoteSigned"}'
Get-Content -Path $userPropertiesFile | Should -Be '{ "Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned"}'
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass
Get-Content -Path $userPropertiesFile | Should -Be '{"Microsoft.PowerShell:ExecutionPolicy":"Bypass"}'
(Get-Content -Path $userPropertiesFile -Raw) -replace "`r`n?|`n","" | Should -Be '{ "Microsoft.PowerShell:ExecutionPolicy": "Bypass"}'
}

It "Verify Writes Create the File if Not Present" {
Remove-Item $userPropertiesFile -Force
Test-Path $userPropertiesFile | Should -BeFalse
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass
Get-Content -Path $userPropertiesFile | Should -Be '{"Microsoft.PowerShell:ExecutionPolicy":"Bypass"}'
(Get-Content -Path $userPropertiesFile -Raw) -replace "`r`n?|`n","" | Should -Be '{ "Microsoft.PowerShell:ExecutionPolicy": "Bypass"}'
}
}
8 changes: 4 additions & 4 deletions test/xUnit/csharp/test_PSConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Management.Automation.Configuration;
using System.Management.Automation.Internal;
using System.Reflection;
using System.Text.Json.Nodes;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PSTests.Internal;
using Xunit;

Expand Down Expand Up @@ -99,7 +99,7 @@ public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}

protected virtual void Dispose(bool disposing)
{
Expand Down Expand Up @@ -390,8 +390,8 @@ private static void CreateBrokenConfigFile(string fileName)
internal void ForceReadingFromFile()
{
// Reset the cached roots.
FieldInfo roots = typeof(PowerShellConfig).GetField("configRoots", BindingFlags.NonPublic | BindingFlags.Instance);
JObject[] value = (JObject[])roots.GetValue(PowerShellConfig.Instance);
FieldInfo roots = typeof(PowerShellConfig).GetField("_configScopeRoots", BindingFlags.NonPublic | BindingFlags.Instance);
var value = (JsonObject[])roots.GetValue(PowerShellConfig.Instance);
value[0] = null;
value[1] = null;
}
Expand Down