Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Pester 5 does not load on PowerShell 6.0.4

Open lupino3 opened this issue 3 years ago • 3 comments
trafficstars

Checklist

What is the issue?

I'm trying to test a PowerShell module across multiple PowerShell versions. When I try to load Pester on PowerShell 6.0.4, I get this error:

Could not load file or assembly 'System.Management.Automation, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Expected Behavior

I'd expect Pester to load.

Steps To Reproduce

I suggest reproducing with the PowerShell Core 6.0.4 Docker image:

➜ docker pull  mcr.microsoft.com/powershell:6.0.4-ubuntu-16.04
➜ docker run -it mcr.microsoft.com/powershell:6.0.4-ubuntu-16.04
➜ docker run -it mcr.microsoft.com/powershell:6.0.4-ubuntu-16.04
PowerShell v6.0.4
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.
PS />  import-module pester
import-module : The specified module 'pester' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ import-module pester
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (pester:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS /> Install-Module -Name Pester -Force -SkipPublisherCheck
PS /> Import-Module Pester
The following exception occurred while retrieving member "CreateRuntimeDefinedParameterDictionary": "Could not load file or assembly 'System.Management.Automation, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
"
At /usr/local/share/powershell/Modules/Pester/5.3.3/Pester.psm1:137 char:1
+ $script:AssertionDynamicParams = [Pester.Factory]::CreateRuntimeDefin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember

The first Import-Module is there to show that no Pester version is installed in the machine. As you can see from the logs, 5.3.3 is pulled and installed. I tried other 5.x versions and I get the same error. 4.x works fine.

Describe your environment

PS /> (Invoke-WebRequest -Uri "https://git.io/JTinj" -UseBasicParsing).Content | Invoke-Expression
Pester version     : 5.3.3 /usr/local/share/powershell/Modules/Pester/5.3.3/Pester.psm1
PowerShell version : 6.0.4
OS version         : Unix 5.10.102.1
PS />                    

The Docker image runs on Windows 11, using WSL 2. Same issue if the same code runs on Github's runners.

Possible Solution?

No response

lupino3 avatar Jul 09 '22 07:07 lupino3

Thanks for the report.

Pester 5 depend on System.Management.Automation 6.1.0 for the module dll used in PowerShell 6+, so that's probably the cause. The lowest available version for on nuget is 6.0.4. @nohwnd might remember if 6.1.0 was used for a specific reason.

However PowerShell 6.0 was end-of-support February 13, 2019 and has a known critical security vulnerability so the obvious solution is to upgrade to a supported PowerShell-version which atm. is 7.0+ on unix. 🙂

fflaten avatar Jul 09 '22 14:07 fflaten

Thanks @fflaten, 100% agree on 6.x being end-of-support. I also don't have any reasons to run software on PowerShell 6, just the desire to have my module as compatible as possible.

I thought it'd be valuable to at least have an issue filed for Pester so that other folks that may find this bug can find it and realize it's a known issue. It would be very understandable if you were not willing to fix it!

lupino3 avatar Jul 10 '22 08:07 lupino3

I'll leave this open for @nohwnd.

Pester currently supports PS3 and above except for 6.0.x because of this dependency so if it wasn't intentional then we should fix it. 🙂

fflaten avatar Jul 10 '22 11:07 fflaten

I don't think I chose 6.1.0 for any specific reason, probably I just grabbed the latest 6.x nuget that was available at the time, thinking that any can be used for 6.x powershell.

nohwnd avatar Aug 11 '22 09:08 nohwnd

@lupino3 I've tried to build Pester and get warnings about System.Management.Automation having vulnerabilities, and the first patched version is 6.1.6 which would break you. Are you still supporting powershell 6.0.4 in your module or we can upgrade?

nohwnd avatar Oct 14 '23 11:10 nohwnd

IIRC it was related to web calls and we only rely on types but no code execution through the dependency. So I don't believe we're vulnerable, or?

fflaten avatar Oct 14 '23 12:10 fflaten

I will reply in a couple of days, currently OOO and I'd like to understand the implication on some older production environments. Thanks!

If there is a vulnerability and you think you could be affected, please go ahead and update! Worst case, I lose the ability to test under some environments, which is worse than being exposed to a vulnerability.

lupino3 avatar Oct 16 '23 16:10 lupino3

Sorry for the delay. The known production uses for my library are restricted to Windows PowerShell 5.1 and PowerShell 7.x, so we don't care much about 6.x. Thanks for checking!

lupino3 avatar Nov 09 '23 14:11 lupino3