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:
@@ -0,0 +1,61 @@
|
||||
BeforeAll {
|
||||
function Get-RegistryBackupCapturePlans {}
|
||||
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Registry-BackupValidation.ps1')
|
||||
}
|
||||
|
||||
Describe 'Test-RegistryBackupMatchesSelectedFeatures' {
|
||||
BeforeEach {
|
||||
$script:Features = @{
|
||||
ApplyFeature = [PSCustomObject]@{ RegistryKey = 'apply.reg'; RegistryUndoKey = 'undo.reg' }
|
||||
}
|
||||
$script:CapturePlanCalls = [System.Collections.Generic.List[bool]]::new()
|
||||
Mock Get-RegistryBackupCapturePlans {
|
||||
param($SelectedRegistryFeatures, $UndoRegistryFeatures, $UseSysprepRegFiles)
|
||||
$script:CapturePlanCalls.Add([bool]$UseSysprepRegFiles)
|
||||
@([PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'
|
||||
IncludeSubKeys = $false
|
||||
CaptureAllValues = $false
|
||||
ValueNames = @('Enabled')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
It 'derives an allow list from selected features and accepts a matching snapshot' {
|
||||
$snapshot = [PSCustomObject]@{
|
||||
Path = 'HKEY_CURRENT_USER\Software\Example'
|
||||
Values = @([PSCustomObject]@{ Name = 'Enabled'; Exists = $true; Kind = 'DWord'; Data = 1 })
|
||||
SubKeys = @()
|
||||
}
|
||||
|
||||
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('ApplyFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @($snapshot))
|
||||
|
||||
$errors | Should -BeNullOrEmpty
|
||||
$script:CapturePlanCalls | Should -Be @($false)
|
||||
}
|
||||
|
||||
It 'uses Sysprep registry files when restoring a user-profile backup' {
|
||||
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('ApplyFeature') -SelectedUndoFeatureIds @() -Target 'User:Alice' -RegistryKeys @())
|
||||
|
||||
$errors | Should -BeNullOrEmpty
|
||||
$script:CapturePlanCalls | Should -Be @($true)
|
||||
}
|
||||
|
||||
It 'reports unknown selected features without deriving capture plans' {
|
||||
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('UnknownFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @())
|
||||
|
||||
$errors | Should -Contain "Selected feature 'UnknownFeature' was not found in the current feature catalog."
|
||||
$script:CapturePlanCalls | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'rejects registry snapshots when no feature definitions are loaded' {
|
||||
$script:Features = @{}
|
||||
$snapshot = [PSCustomObject]@{ Path = 'HKEY_CURRENT_USER\Software\Example'; Values = @(); SubKeys = @() }
|
||||
|
||||
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('ApplyFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @($snapshot))
|
||||
|
||||
$errors | Should -Contain 'Unable to validate registry backup allowlist because feature definitions are not loaded.'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user