mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Enforce the 'CompatiblePSEditions' check for modules from the legacy 'System32' module path (#7183)
- Add `%WINDIR%\System32\WindowsPowerShell\v1.0\Modules` (Windows PowerShell $PSHOME) to the end of the default PSCore 6 module path (i.e. the module path as initially set at startup). - Cause an error to be thrown by `Import-Module` when a module with `CompatiblePSEditions` not containing `"Core"` is being loaded from the 'System32' module path. - Suppress output of modules listed by `Get-Module -ListAvailable` from Windows PowerShell $PSHOME when `CompatiblePSEditions` does not contain `"Core"`. - Introduce the `-SkipCompatibilityCheck` switch parameter on both `Import-Module` and `Get-Module` to respectively allow importing incompatible modules and listing incompatible modules. - Adds a `PSEdition` column to the `PSModuleInfo` table view format. - Ensures that completions are not given for incompatible modules on the System32 module path.
This commit is contained in:
@@ -23,6 +23,11 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
}
|
||||
$expectedSystemPath = Join-Path -Path $PSHOME -ChildPath 'Modules'
|
||||
|
||||
if ($IsWindows)
|
||||
{
|
||||
$expectedWindowsPowerShellPSHomePath = Join-Path $env:windir "System32" "WindowsPowerShell" "v1.0" "Modules"
|
||||
}
|
||||
|
||||
## Setup a fake PSHome
|
||||
$fakePSHome = Join-Path -Path $TestDrive -ChildPath 'FakePSHome'
|
||||
$fakePSHomeModuleDir = Join-Path -Path $fakePSHome -ChildPath 'Modules'
|
||||
@@ -48,10 +53,22 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
|
||||
$paths = $defaultModulePath -split [System.IO.Path]::PathSeparator
|
||||
|
||||
$paths.Count | Should -Be 3
|
||||
if ($IsWindows)
|
||||
{
|
||||
$paths.Count | Should -Be 4
|
||||
}
|
||||
else
|
||||
{
|
||||
$paths.Count | Should -Be 3
|
||||
}
|
||||
|
||||
$paths[0].TrimEnd([System.IO.Path]::DirectorySeparatorChar) | Should -Be $expectedUserPath
|
||||
$paths[1].TrimEnd([System.IO.Path]::DirectorySeparatorChar) | Should -Be $expectedSharedPath
|
||||
$paths[2].TrimEnd([System.IO.Path]::DirectorySeparatorChar) | Should -Be $expectedSystemPath
|
||||
if ($IsWindows)
|
||||
{
|
||||
$paths[3].TrimEnd([System.IO.Path]::DirectorySeparatorChar) | Should -Be $expectedWindowsPowerShellPSHomePath
|
||||
}
|
||||
}
|
||||
|
||||
It "ignore pshome module path derived from a different powershell core instance" -Skip:(!$IsCoreCLR) {
|
||||
@@ -68,10 +85,22 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
$newModulePath = & $powershell -nopro -c '$env:PSModulePath'
|
||||
$paths = $newModulePath -split [System.IO.Path]::PathSeparator
|
||||
|
||||
$paths.Count | Should -Be 3
|
||||
if ($IsWindows)
|
||||
{
|
||||
$paths.Count | Should -Be 4
|
||||
}
|
||||
else
|
||||
{
|
||||
$paths.Count | Should -Be 3
|
||||
}
|
||||
|
||||
$paths[0] | Should -Be $expectedUserPath
|
||||
$paths[1] | Should -Be $expectedSharedPath
|
||||
$paths[2] | Should -Be $expectedSystemPath
|
||||
if ($IsWindows)
|
||||
{
|
||||
$paths[3].TrimEnd([System.IO.Path]::DirectorySeparatorChar) | Should -Be $expectedWindowsPowerShellPSHomePath
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
@@ -89,7 +118,14 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
$newModulePath = & $powershell -nopro -c '$env:PSModulePath'
|
||||
$paths = $newModulePath -split [System.IO.Path]::PathSeparator
|
||||
|
||||
$paths.Count | Should -Be 5
|
||||
if ($IsWindows)
|
||||
{
|
||||
$paths.Count | Should -Be 6
|
||||
}
|
||||
else
|
||||
{
|
||||
$paths.Count | Should -Be 5
|
||||
}
|
||||
$paths -contains $fakePSHomeModuleDir | Should -BeTrue
|
||||
$paths -contains $customeModules | Should -BeTrue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user