Skip to content

Commit

Permalink
xRegistry: Fixed an issue that failed to create a registry with ":" i…
Browse files Browse the repository at this point in the history
…n the path. (#672)

* Add unit & intergration tests

* Fix issue #671

* Update CHANGELOG.md
  • Loading branch information
mkht authored and PlagueHO committed Jan 24, 2020
1 parent f03debf commit 7eeec4b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Export `Publish-*` functions in DscPullServerSetup module - Fixes
[issue #673](https://github.com/PowerShell/PSDscResources/issues/673).

- DSC_xRegistryResource
- Fixed an issue that failed to create a registry with ":" in the path.
[issue #671](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/671)


## [9.0.0] - 2020-01-15

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ function Get-PathRoot
$Path
)

$pathParent = Split-Path -Path $Path -Parent
$pathRoot = $Path

while (-not [System.String]::IsNullOrEmpty($pathParent))
if ($Path.Contains('\'))
{
$pathRoot = $Path.Split('\')[0]
}
else
{
$pathRoot = Split-Path -Path $pathParent -Leaf
$pathParent = Split-Path -Path $pathParent -Parent
$pathRoot = $Path
}

return $pathRoot
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/DSC_xRegistryResource.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,33 @@ try
$registryValueExists | Should -BeTrue
}

It 'Should create a new key and value with path containing colons (PSDrive style path)' {
$registryKeyPathWithColons = Join-Path -Path $script:registryKeyPath -ChildPath 'T:e:s:t:K:e:y'
$valueName = 'Testing'
$valueData = 'TestValue'

# Create the new registry key value
Set-TargetResource -Key $registryKeyPathWithColons -ValueName $valueName -ValueData $valueData

# Verify that the registry key value has been created with the correct data and type
$registryValueExists = Test-RegistryValueExists -KeyPath $registryKeyPathWithColons -ValueName $valueName -ValueData $valueData
$registryValueExists | Should -BeTrue
}

It 'Should create a new key and value with path containing colons (Common registry style path)' {
$registryKeyPathWithColons = Join-Path -Path $script:registryKeyPath -ChildPath 'T:e:s:t:K:e:y'
$commonRegistryKeyPathWithColons = $registryKeyPathWithColons -replace 'HKLM:', 'HKEY_LOCAL_MACHINE'
$valueName = 'Testing'
$valueData = 'TestValue'

# Create the new registry key value
Set-TargetResource -Key $commonRegistryKeyPathWithColons -ValueName $valueName -ValueData $valueData

# Verify that the registry key value has been created with the correct data and type
$registryValueExists = Test-RegistryValueExists -KeyPath $registryKeyPathWithColons -ValueName $valueName -ValueData $valueData
$registryValueExists | Should -BeTrue
}

It 'Should overwrite an existing key and value with desired value type' {
$valueName = 'TestValue'
$valueData = '123'
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/DSC_xRegistryResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,25 @@ try
$getPathRootResult | Should -Be $pathRoot
}
}

Context 'Path with colons specified' {
$pathRoot = 'PathRoot'
$pathLeafWithColon = 'Leaf:Colon'

$getPathRootParameters = @{
Path = Join-Path -Path $pathRoot -ChildPath $pathLeafWithColon
}

It 'Should not throw' {
{ $null = Get-PathRoot @getPathRootParameters } | Should -Not -Throw
}

$getPathRootResult = Get-PathRoot @getPathRootParameters

It 'Should return the root of the given path' {
$getPathRootResult | Should -Be $pathRoot
}
}
}

Describe 'xRegistry\ConvertTo-RegistryDriveName' {
Expand Down

0 comments on commit 7eeec4b

Please sign in to comment.