mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 17:41:14 +10:00
Fix Win11 Creator product-key validation failures (#4791)
* feat: Enhance Win11 Creator with edition ID handling and update autounattend.xml generation * Strengthen Pester coverage for config and function files
This commit is contained in:
+96
-69
@@ -1,83 +1,110 @@
|
||||
# Import Config Files
|
||||
$global:importedconfigs = @{}
|
||||
Get-ChildItem .\config | Where-Object {$_.Extension -eq ".json"} | ForEach-Object {
|
||||
$global:importedconfigs[$psitem.BaseName] = Get-Content $psitem.FullName | ConvertFrom-Json
|
||||
}
|
||||
|
||||
|
||||
#===========================================================================
|
||||
# Tests - Application Installs
|
||||
# Tests - Config Files
|
||||
#===========================================================================
|
||||
|
||||
Describe "Config Files" -ForEach @(
|
||||
@{
|
||||
name = "applications"
|
||||
config = $('{
|
||||
"winget": "value",
|
||||
"choco": "value",
|
||||
"category": "value",
|
||||
"content": "value",
|
||||
"description": "value",
|
||||
"link": "value"
|
||||
}' | ConvertFrom-Json)
|
||||
},
|
||||
@{
|
||||
name = "tweaks"
|
||||
undo = $true
|
||||
}
|
||||
) {
|
||||
Context "$name config file" {
|
||||
It "Imports with no errors" {
|
||||
$global:importedconfigs.$name | should -Not -BeNullOrEmpty
|
||||
$configRoot = Join-Path $PSScriptRoot "..\config"
|
||||
$configCases = @(
|
||||
Get-ChildItem -Path $configRoot -Filter *.json | ForEach-Object {
|
||||
@{
|
||||
Name = $_.Name
|
||||
Path = $_.FullName
|
||||
}
|
||||
if ($config) {
|
||||
It "Imports should be the correct structure" {
|
||||
$applications = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$template = $config | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$result = New-Object System.Collections.Generic.List[System.Object]
|
||||
Foreach ($application in $applications) {
|
||||
$compare = $global:importedconfigs.$name.$application | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
if (-not $compare) {
|
||||
throw "Comparison object for application '$application' is null."
|
||||
}
|
||||
if (-not $template) {
|
||||
throw "Template object for application '$application' is null."
|
||||
}
|
||||
if ($(Compare-Object $compare $template) -ne $null) {
|
||||
$result.Add($application)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$result | Select-String "WPF*" | should -BeNullOrEmpty
|
||||
Describe "Config files" {
|
||||
foreach ($configCase in $configCases) {
|
||||
It "imports $($configCase.Name) with no JSON errors" -TestCases $configCase {
|
||||
param([string]$Name, [string]$Path)
|
||||
|
||||
try {
|
||||
Get-Content -Path $Path -Raw | ConvertFrom-Json | Out-Null
|
||||
} catch {
|
||||
throw "Failed to import ${Name}: $_"
|
||||
}
|
||||
}
|
||||
if($undo) {
|
||||
It "Tweaks should contain original Value" {
|
||||
$tweaks = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
|
||||
$result = New-Object System.Collections.Generic.List[System.Object]
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tweak in $tweaks) {
|
||||
$Originals = @(
|
||||
@{
|
||||
name = "registry"
|
||||
value = "OriginalValue"
|
||||
},
|
||||
@{
|
||||
name = "service"
|
||||
value = "OriginalType"
|
||||
}
|
||||
)
|
||||
Foreach ($original in $Originals) {
|
||||
$TotalCount = ($global:importedconfigs.$name.$tweak.$($original.name)).count
|
||||
$OriginalCount = ($global:importedconfigs.$name.$tweak.$($original.name).$($original.value) | Where-Object {$_}).count
|
||||
if($TotalCount -ne $OriginalCount) {
|
||||
$result.Add("$Tweak,$($original.name)")
|
||||
}
|
||||
}
|
||||
Describe "Applications config" {
|
||||
$testCase = @{ Path = (Join-Path $configRoot "applications.json") }
|
||||
|
||||
It "contains at least one application" -TestCases $testCase {
|
||||
param([string]$Path)
|
||||
|
||||
$applications = Get-Content -Path $Path -Raw | ConvertFrom-Json
|
||||
$applicationEntries = @($applications.PSObject.Properties)
|
||||
|
||||
if ($applicationEntries.Count -eq 0) {
|
||||
throw "applications.json does not contain any application entries."
|
||||
}
|
||||
}
|
||||
|
||||
It "contains required display fields and at least one install source" -TestCases $testCase {
|
||||
param([string]$Path)
|
||||
|
||||
$applications = Get-Content -Path $Path -Raw | ConvertFrom-Json
|
||||
$requiredFields = @("category", "content", "description", "link")
|
||||
$invalidEntries = New-Object System.Collections.Generic.List[string]
|
||||
|
||||
foreach ($entry in $applications.PSObject.Properties) {
|
||||
$entryFields = @($entry.Value.PSObject.Properties.Name)
|
||||
|
||||
foreach ($field in $requiredFields) {
|
||||
if ($entryFields -notcontains $field -or [string]::IsNullOrWhiteSpace([string]$entry.Value.$field)) {
|
||||
$invalidEntries.Add("$($entry.Name) missing $field")
|
||||
}
|
||||
$result | Select-String "WPF*" | should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
$hasInstallSource = $false
|
||||
foreach ($sourceField in @("winget", "choco")) {
|
||||
if ($entryFields -contains $sourceField -and -not [string]::IsNullOrWhiteSpace([string]$entry.Value.$sourceField)) {
|
||||
$hasInstallSource = $true
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $hasInstallSource) {
|
||||
$invalidEntries.Add("$($entry.Name) missing winget/choco install source")
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalidEntries.Count -gt 0) {
|
||||
throw ($invalidEntries -join "`n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Tweaks config" {
|
||||
$testCase = @{ Path = (Join-Path $configRoot "tweaks.json") }
|
||||
|
||||
It "contains undo metadata for registry and service actions" -TestCases $testCase {
|
||||
param([string]$Path)
|
||||
|
||||
$tweaks = Get-Content -Path $Path -Raw | ConvertFrom-Json
|
||||
$invalidTweaks = New-Object System.Collections.Generic.List[string]
|
||||
|
||||
foreach ($tweak in $tweaks.PSObject.Properties) {
|
||||
foreach ($registryEntry in @($tweak.Value.registry)) {
|
||||
if ($null -eq $registryEntry) { continue }
|
||||
|
||||
if ($registryEntry.PSObject.Properties.Name -notcontains "OriginalValue" -or
|
||||
[string]::IsNullOrWhiteSpace([string]$registryEntry.OriginalValue)) {
|
||||
$invalidTweaks.Add("$($tweak.Name),registry")
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($serviceEntry in @($tweak.Value.service)) {
|
||||
if ($null -eq $serviceEntry) { continue }
|
||||
|
||||
if ($serviceEntry.PSObject.Properties.Name -notcontains "OriginalType" -or
|
||||
[string]::IsNullOrWhiteSpace([string]$serviceEntry.OriginalType)) {
|
||||
$invalidTweaks.Add("$($tweak.Name),service")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalidTweaks.Count -gt 0) {
|
||||
throw ($invalidTweaks -join "`n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user