mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-08-23 08:02:07 +00:00
Improve registry backup safety and add optional backup skipping (#710)
This commit is contained in:
@@ -118,6 +118,14 @@ Describe 'Convert-RegistryKeyToSnapshot' {
|
||||
$snapshot.SubKeys[0].Values[0].Data | Should -Be 'data'
|
||||
$child.Closed | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'fails instead of silently omitting an unreadable child key' {
|
||||
$root = New-FakeRegistryKey -Children @{ Locked = $null }
|
||||
|
||||
{
|
||||
Convert-RegistryKeyToSnapshot -RegistryKey $root -FullPath $root.Name -CaptureAllValues:$true -IncludeSubKeys:$true
|
||||
} | Should -Throw '*Unable to read registry subkey*The backup was not created*'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-RegistryKeySnapshot' {
|
||||
@@ -203,3 +211,26 @@ Describe 'Restore-RegistryKeySnapshot - mutation flow' {
|
||||
$key.Closed | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-RegistryKeySnapshotCanBeRestored' {
|
||||
It 'rejects invalid value data before the live registry is touched' {
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'; Exists = $true
|
||||
Values = @([PSCustomObject]@{ Name = 'TooLarge'; Exists = $true; Kind = 'DWord'; Data = 4294967296 })
|
||||
SubKeys = @()
|
||||
}
|
||||
|
||||
{ Test-RegistryKeySnapshotCanBeRestored -Snapshot $snapshot } |
|
||||
Should -Throw '*Value was either too large or too small*'
|
||||
}
|
||||
|
||||
It 'rejects a descendant that is not directly below its declared parent' {
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'; Exists = $true; Values = @()
|
||||
SubKeys = @([PSCustomObject]@{ Path = 'HKEY_CURRENT_USER\Software\Example\Nested\Child'; Exists = $true; Values = @(); SubKeys = @() })
|
||||
}
|
||||
|
||||
{ Test-RegistryKeySnapshotCanBeRestored -Snapshot $snapshot } |
|
||||
Should -Throw "*is not directly below parent*"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user