From f4448c5662858f2c1ca1ed3288b998e1d45deadf Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 13:53:23 +0200 Subject: [PATCH] Accept signed integer values in registry declarations --- TASKS.md | 1 + src/Adapters.psm1 | 4 ++-- tests/Adapters.Tests.ps1 | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/TASKS.md b/TASKS.md index dcdd2da..e929a31 100644 --- a/TASKS.md +++ b/TASKS.md @@ -131,3 +131,4 @@ open until it is run on disposable machines with the required account setups. - [x] Replace bootstrap exit-code exceptions with friendly partial-success, reboot, and busy summaries while preserving automation status. - [x] Avoid null temporary-file cleanup after registry deployment or config adoption; preserve original per-item errors. - [x] Report CLI exceptions concisely on stderr without throwing from the error handler; preserve exit code 2 and JSON errors. +- [x] Accept signed registry DWORD/QWORD exports and validate the complete MPC-HC declaration with mocked registry writes. diff --git a/src/Adapters.psm1 b/src/Adapters.psm1 index 4d834e0..ebf9f64 100644 --- a/src/Adapters.psm1 +++ b/src/Adapters.psm1 @@ -196,8 +196,8 @@ function Set-RegistryDeclaration { $path = if ([string]::IsNullOrWhiteSpace([string]$entry.path)) { $Root } else { Join-Path $Root $entry.path } [void](New-Item -Path $path -Force) $value = switch ($entry.type) { - 'DWord' { [uint32]$entry.value } - 'QWord' { [uint64]$entry.value } + 'DWord' { if ($entry.value -lt 0) { [int32]$entry.value } else { [uint32]$entry.value } } + 'QWord' { if ($entry.value -lt 0) { [int64]$entry.value } else { [uint64]$entry.value } } 'Binary' { [byte[]]@($entry.value) } 'MultiString' { [string[]]@($entry.value) } default { [string]$entry.value } diff --git a/tests/Adapters.Tests.ps1 b/tests/Adapters.Tests.ps1 index 47f9bfd..1ed5b89 100644 --- a/tests/Adapters.Tests.ps1 +++ b/tests/Adapters.Tests.ps1 @@ -50,3 +50,42 @@ Describe 'Application configuration adapters' { { Read-RegistryDeclaration -Path $invalid } | Should -Throw '*Unsafe registry subpath*' } } + +Describe 'Registry integer deployment' { + It 'accepts signed exported DWORD and QWORD values without changing their bits' { + InModuleScope Adapters { + Mock New-Item {} + Mock New-ItemProperty {} + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'Dword'; type = 'DWord'; value = -1 }, + [pscustomobject]@{ path = ''; name = 'Qword'; type = 'QWord'; value = [long]::MinValue } + ) } + Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration + Should -Invoke New-ItemProperty -Times 1 -ParameterFilter { $Name -eq 'Dword' -and $Value -eq -1 -and $Value -is [int32] } + Should -Invoke New-ItemProperty -Times 1 -ParameterFilter { $Name -eq 'Qword' -and $Value -eq [long]::MinValue -and $Value -is [int64] } + } + } + + It 'deploys every checked-in MPC-HC value through mocked registry operations' { + $declaration = Read-RegistryDeclaration -Path "$PSScriptRoot/../configs/mpc-hc/settings.json" + InModuleScope Adapters -Parameters @{ Declaration = $declaration; Root = $TestDrive } { + param($Declaration, $Root) + Mock New-Item {} + Mock New-ItemProperty {} + { Set-RegistryDeclaration -Root $Root -Declaration $Declaration } | Should -Not -Throw + Should -Invoke New-ItemProperty -Times $Declaration.values.Count -Exactly + } + } + + It 'rejects negative values outside the DWORD range' { + InModuleScope Adapters { + Mock New-Item {} + Mock New-ItemProperty {} + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'Invalid'; type = 'DWord'; value = -2147483649 } + ) } + { Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration } | Should -Throw + Should -Invoke New-ItemProperty -Times 0 + } + } +}