mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-26 07:26:18 +01:00
Improve backup validation (#849)
This commit is contained in:
@@ -153,6 +153,16 @@ Describe 'Get-NormalizedRegistryValueName' {
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-RegistryValueKindNameSupported' {
|
||||
It 'rejects unsupported kind <KindName>' -ForEach @('99', '-2', 'Unknown', 'None', '') {
|
||||
Test-RegistryValueKindNameSupported -KindName $_ | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'accepts defined kind <KindName>' -ForEach @('String', 'expandstring', 'Binary', 'DWord', 'QWord', 'MultiString', '1') {
|
||||
Test-RegistryValueKindNameSupported -KindName $_ | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Normalize-RegistryKeySnapshot' {
|
||||
It 'normalizes nested snapshots and supplies value defaults' {
|
||||
$snapshot = [PSCustomObject]@{
|
||||
@@ -188,6 +198,19 @@ Describe 'Normalize-RegistryKeySnapshot' {
|
||||
{ Normalize-RegistryKeySnapshot -Snapshot ([PSCustomObject]@{ Exists = $true }) } |
|
||||
Should -Throw 'Backup validation failed: Registry key snapshot is missing Path.'
|
||||
}
|
||||
|
||||
It 'rejects a <Case> key existence flag' -ForEach @(
|
||||
@{ Case = 'missing'; Properties = @{} }
|
||||
@{ Case = 'null'; Properties = @{ Exists = $null } }
|
||||
@{ Case = 'string'; Properties = @{ Exists = 'false' } }
|
||||
@{ Case = 'numeric'; Properties = @{ Exists = 0 } }
|
||||
) {
|
||||
$propertiesWithPath = @{ Path = 'HKEY_CURRENT_USER\Software\Example' }
|
||||
foreach ($entry in $Properties.GetEnumerator()) { $propertiesWithPath[$entry.Key] = $entry.Value }
|
||||
|
||||
{ Normalize-RegistryKeySnapshot -Snapshot ([PSCustomObject]$propertiesWithPath) } |
|
||||
Should -Throw '*must define Exists as a Boolean*'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-RegistrySnapshotAgainstAllowList' {
|
||||
@@ -223,6 +246,7 @@ Describe 'Test-RegistrySnapshotAgainstAllowList' {
|
||||
$errors = New-Object 'System.Collections.Generic.List[string]'
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'
|
||||
Exists = $true
|
||||
Values = @([PSCustomObject]@{ Name = 'Enabled'; Exists = $true; Kind = 'DWord'; Data = 1 })
|
||||
SubKeys = @()
|
||||
}
|
||||
@@ -244,6 +268,7 @@ Describe 'Test-RegistrySnapshotAgainstAllowList' {
|
||||
$errors = New-Object 'System.Collections.Generic.List[string]'
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'
|
||||
Exists = $true
|
||||
Values = @([PSCustomObject]@{ Name = 'Bytes'; Exists = $true; Kind = 'Binary'; Data = @(1, 256) })
|
||||
SubKeys = @()
|
||||
}
|
||||
@@ -266,6 +291,7 @@ Describe 'Test-RegistrySnapshotAgainstAllowList' {
|
||||
$errors = New-Object 'System.Collections.Generic.List[string]'
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example\Child'
|
||||
Exists = $true
|
||||
Values = @([PSCustomObject]@{ Name = 'Unlisted'; Exists = $true; Kind = 'String'; Data = 'value' })
|
||||
SubKeys = @()
|
||||
}
|
||||
@@ -287,11 +313,13 @@ Describe 'Test-RegistrySnapshotAgainstAllowList' {
|
||||
$errors = New-Object 'System.Collections.Generic.List[string]'
|
||||
$unexpectedPathSnapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Unexpected'
|
||||
Exists = $true
|
||||
Values = @()
|
||||
SubKeys = @()
|
||||
}
|
||||
$unexpectedValueSnapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'
|
||||
Exists = $true
|
||||
Values = @([PSCustomObject]@{ Name = 'Unexpected'; Exists = $true; Kind = 'String'; Data = 'value' })
|
||||
SubKeys = @()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user