mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add package name validation functions with comprehensive tests
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
This commit is contained in:
co-authored by
TravisEz13
parent
b7cac49a74
commit
3241b9802f
@@ -82,7 +82,7 @@ jobs:
|
||||
- pwsh: |
|
||||
$message = @()
|
||||
Get-ChildItem $(System.ArtifactsDirectory)\* -recurse -filter *.pkg | ForEach-Object {
|
||||
if($_.Name -notmatch 'powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]*\.\d+\-)?osx\-(x64|arm64)\.pkg')
|
||||
if($_.Name -notmatch '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?osx\-(x64|arm64)\.pkg$')
|
||||
{
|
||||
$messageInstance = "$($_.Name) is not a valid package name"
|
||||
$message += $messageInstance
|
||||
|
||||
@@ -64,4 +64,204 @@ Describe "Packaging Module Functions" {
|
||||
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
|
||||
}
|
||||
}
|
||||
|
||||
Context "Package Name Validation Functions" {
|
||||
Context "Test-PackageNameRpm" {
|
||||
It "Should accept valid stable RPM names" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0-1.rh.x86_64.rpm" | Should -Be $true
|
||||
Test-PackageNameRpm -PackageName "powershell-7.4.13-1.cm.aarch64.rpm" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid LTS RPM names" {
|
||||
Test-PackageNameRpm -PackageName "powershell-lts-7.4.13-1.rh.x86_64.rpm" | Should -Be $true
|
||||
Test-PackageNameRpm -PackageName "powershell-lts-7.2.0-1.cm.aarch64.rpm" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid preview RPM names" {
|
||||
Test-PackageNameRpm -PackageName "powershell-preview-7.6.0-1.rh.x86_64.rpm" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept RPM names with suffixes" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0_alpha.1-1.rh.x86_64.rpm" | Should -Be $true
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0_preview.6-1.cm.aarch64.rpm" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should reject RPM names with invalid characters in suffix" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0_preview@6-1.rh.x86_64.rpm" | Should -Be $false
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0_preview-6-1.rh.x86_64.rpm" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject RPM names with empty label in suffix" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0_.6-1.rh.x86_64.rpm" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject RPM names with invalid architecture" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0-1.rh.arm64.rpm" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject RPM names with invalid distribution" {
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0-1.ubuntu.x86_64.rpm" | Should -Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Test-PackageNameTarGz" {
|
||||
It "Should accept valid stable tar.gz names" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-x64.tar.gz" | Should -Be $true
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.4.13-osx-arm64.tar.gz" | Should -Be $true
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-musl-x64.tar.gz" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid LTS tar.gz names" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-lts-7.4.13-linux-x64.tar.gz" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept tar.gz names with preview suffix" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-preview.6-linux-x64.tar.gz" | Should -Be $true
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-alpha.1-osx-arm64.tar.gz" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept tar.gz names with various runtimes" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-x64-fxdependent.tar.gz" | Should -Be $true
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-arm32.tar.gz" | Should -Be $true
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-musl-x64-musl-noopt-fxdependent.tar.gz" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should reject tar.gz names with invalid characters in suffix" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-preview@6-linux-x64.tar.gz" | Should -Be $false
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-preview-6-linux-x64.tar.gz" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject tar.gz names with empty label in suffix" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-.6-linux-x64.tar.gz" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject tar.gz names with repeated platform tokens" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linuxlinux-x64.tar.gz" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject tar.gz names with invalid platform" {
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-windows-x64.tar.gz" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject tar.gz names without anchoring (extra text)" {
|
||||
Test-PackageNameTarGz -PackageName "extra-powershell-7.6.0-linux-x64.tar.gz" | Should -Be $false
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-x64.tar.gz-extra" | Should -Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Test-PackageNamePkg" {
|
||||
It "Should accept valid stable PKG names" {
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-osx-x64.pkg" | Should -Be $true
|
||||
Test-PackageNamePkg -PackageName "powershell-7.4.13-osx-arm64.pkg" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid LTS PKG names" {
|
||||
Test-PackageNamePkg -PackageName "powershell-lts-7.4.13-osx-x64.pkg" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept PKG names with preview suffix" {
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-preview.6-osx-x64.pkg" | Should -Be $true
|
||||
Test-PackageNamePkg -PackageName "powershell-7.4.13-rebuild.5-osx-arm64.pkg" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should reject PKG names with invalid characters in suffix" {
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-preview@6-osx-x64.pkg" | Should -Be $false
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-preview-6-osx-x64.pkg" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject PKG names with empty label in suffix" {
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-.6-osx-x64.pkg" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject PKG names with invalid architecture" {
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-osx-x86.pkg" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject PKG names without anchoring (extra text)" {
|
||||
Test-PackageNamePkg -PackageName "extra-powershell-7.6.0-osx-x64.pkg" | Should -Be $false
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-osx-x64.pkg-extra" | Should -Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Test-PackageNameWindowsMsiZip" {
|
||||
It "Should accept valid stable MSI names" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-x64.msi" | Should -Be $true
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.4.13-win-arm64.msi" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid stable ZIP names" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-x64.zip" | Should -Be $true
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.4.13-win-x86.zip" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept MSI/ZIP names with preview suffix" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-preview.6-win-x64.msi" | Should -Be $true
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-alpha.1-win-x64.zip" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept MSI/ZIP names with fxdependent runtime" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-fxdependent.zip" | Should -Be $true
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-fxdependentWinDesktop.zip" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should reject MSI/ZIP names with invalid characters in suffix" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-preview@6-win-x64.msi" | Should -Be $false
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-preview-6-win-x64.zip" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject MSI/ZIP names with empty label in suffix" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-.6-win-x64.msi" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject MSI/ZIP names with wrong case" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "powershell-7.6.0-win-x64.msi" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject MSI/ZIP names without anchoring (extra text)" {
|
||||
Test-PackageNameWindowsMsiZip -PackageName "extra-PowerShell-7.6.0-win-x64.msi" | Should -Be $false
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-x64.msi-extra" | Should -Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Test-PackageNameDeb" {
|
||||
It "Should accept valid stable DEB names" {
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-1.deb_amd64.deb" | Should -Be $true
|
||||
Test-PackageNameDeb -PackageName "powershell_7.4.13-1.deb_arm64.deb" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid preview DEB names" {
|
||||
Test-PackageNameDeb -PackageName "powershell-preview_7.6.0-1.deb_amd64.deb" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept valid LTS DEB names" {
|
||||
Test-PackageNameDeb -PackageName "powershell-lts_7.4.13-1.deb_amd64.deb" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept DEB names with dash suffix" {
|
||||
Test-PackageNameDeb -PackageName "powershell-preview_7.6.0-preview.6-1.deb_amd64.deb" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should accept DEB names with tilde suffix" {
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0~preview.6-1.deb_amd64.deb" | Should -Be $true
|
||||
}
|
||||
|
||||
It "Should reject DEB names with invalid characters in suffix" {
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-preview@6-1.deb_amd64.deb" | Should -Be $false
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-preview-6-1.deb_amd64.deb" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject DEB names with empty label in suffix" {
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-.6-1.deb_amd64.deb" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject DEB names with invalid architecture" {
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-1.deb_x86.deb" | Should -Be $false
|
||||
}
|
||||
|
||||
It "Should reject DEB names without anchoring (extra text)" {
|
||||
Test-PackageNameDeb -PackageName "extra-powershell_7.6.0-1.deb_amd64.deb" | Should -Be $false
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-1.deb_amd64.deb-extra" | Should -Be $false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5808,3 +5808,165 @@ function Test-IsProductFile {
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if a package name matches the expected pattern for RPM packages.
|
||||
|
||||
.DESCRIPTION
|
||||
Validates that RPM package names follow the correct naming convention:
|
||||
- powershell-<version>-1.<dist>.<arch>.rpm
|
||||
- powershell-lts-<version>-1.<dist>.<arch>.rpm
|
||||
- powershell-preview-<version>-1.<dist>.<arch>.rpm
|
||||
Where suffix can be: _<label>.<number> (e.g., _alpha.1)
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the package file to validate.
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameRpm -PackageName "powershell-7.6.0-1.rh.x86_64.rpm"
|
||||
Returns $true
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameRpm -PackageName "powershell-lts-7.4.13-1.cm.aarch64.rpm"
|
||||
Returns $true
|
||||
#>
|
||||
function Test-PackageNameRpm {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
$pattern = '^powershell\-(preview-|lts-)?\d+\.\d+\.\d+(_[a-z]+\.\d+)?-1\.(rh|cm)\.(x86_64|aarch64)\.rpm$'
|
||||
return $PackageName -match $pattern
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if a package name matches the expected pattern for tar.gz packages.
|
||||
|
||||
.DESCRIPTION
|
||||
Validates that tar.gz package names follow the correct naming convention:
|
||||
- powershell-<version>-<platform>-<runtime>.tar.gz
|
||||
- powershell-lts-<version>-<platform>-<runtime>.tar.gz
|
||||
Where suffix can be: <label>.<number>- (e.g., preview.6-)
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the package file to validate.
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-linux-x64.tar.gz"
|
||||
Returns $true
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameTarGz -PackageName "powershell-7.6.0-preview.6-linux-x64.tar.gz"
|
||||
Returns $true
|
||||
#>
|
||||
function Test-PackageNameTarGz {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
$pattern = '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?(linux|osx|linux-musl)\-(x64\-fxdependent|x64|arm32|arm64|x64\-musl-noopt\-fxdependent)\.tar\.gz$'
|
||||
return $PackageName -match $pattern
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if a package name matches the expected pattern for macOS PKG packages.
|
||||
|
||||
.DESCRIPTION
|
||||
Validates that macOS PKG package names follow the correct naming convention:
|
||||
- powershell-<version>-osx-<arch>.pkg
|
||||
- powershell-lts-<version>-osx-<arch>.pkg
|
||||
Where suffix can be: <label>.<number>- (e.g., preview.6-)
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the package file to validate.
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-osx-x64.pkg"
|
||||
Returns $true
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNamePkg -PackageName "powershell-7.6.0-preview.6-osx-x64.pkg"
|
||||
Returns $true
|
||||
#>
|
||||
function Test-PackageNamePkg {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
$pattern = '^powershell-(lts-)?\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?osx\-(x64|arm64)\.pkg$'
|
||||
return $PackageName -match $pattern
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if a package name matches the expected pattern for Windows MSI/ZIP packages.
|
||||
|
||||
.DESCRIPTION
|
||||
Validates that Windows MSI and ZIP package names follow the correct naming convention:
|
||||
- PowerShell-<version>-win-<runtime>.msi
|
||||
- PowerShell-<version>-win-<runtime>.zip
|
||||
Where suffix can be: <label>.<number>- (e.g., preview.6-)
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the package file to validate.
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-win-x64.msi"
|
||||
Returns $true
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameWindowsMsiZip -PackageName "PowerShell-7.6.0-preview.6-win-x64.zip"
|
||||
Returns $true
|
||||
#>
|
||||
function Test-PackageNameWindowsMsiZip {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
$pattern = '^PowerShell-\d+\.\d+\.\d+\-([a-z]+\.\d+\-)?win\-(fxdependent|x64|arm64|x86|fxdependentWinDesktop)\.(msi|zip)$'
|
||||
return $PackageName -cmatch $pattern
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if a package name matches the expected pattern for Debian DEB packages.
|
||||
|
||||
.DESCRIPTION
|
||||
Validates that Debian DEB package names follow the correct naming convention:
|
||||
- powershell_<version>-1.deb_<arch>.deb
|
||||
- powershell-preview_<version>-1.deb_<arch>.deb
|
||||
- powershell-lts_<version>-1.deb_<arch>.deb
|
||||
Where suffix can be: -<label>.<number> or ~<label>.<number> (e.g., -preview.6)
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the package file to validate.
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameDeb -PackageName "powershell_7.6.0-1.deb_amd64.deb"
|
||||
Returns $true
|
||||
|
||||
.EXAMPLE
|
||||
Test-PackageNameDeb -PackageName "powershell-preview_7.6.0-preview.6-1.deb_amd64.deb"
|
||||
Returns $true
|
||||
#>
|
||||
function Test-PackageNameDeb {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
$pattern = '^powershell(-preview|-lts)?_\d+\.\d+\.\d+([\-~][a-z]+\.\d+)?-\d\.deb_(amd64|arm64)\.deb$'
|
||||
return $PackageName -match $pattern
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user