Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#285] DSC - xRegistry support for '/' in key names #306

Merged
merged 2 commits into from
Jan 25, 2017

Conversation

bozho
Copy link
Contributor

@bozho bozho commented Jan 13, 2017

Replaced usages of Split-Path in New-RegistryKey with String.LastIndexOf
and String.Substring, splitting registry paths on backslash only.


This change is Reviewable

Replaced usages of Split-Path in New-RegistryKey with String.LastIndexOf
and String.Substring, splitting registry paths on backslash only.
@msftclas
Copy link

Hi @bozho, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@msftgits
Copy link

Hi, I am closing and re-opening this PR to bump the CLA bot. Sorry for the inconvenience!

@msftgits msftgits closed this Jan 13, 2017
@msftgits msftgits reopened this Jan 13, 2017
@msftclas
Copy link

Hi @bozho, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

@bozho
Copy link
Contributor Author

bozho commented Jan 13, 2017

Hm,

AppVeyor reported the following error:
fatal: unable to access 'https://github.com/PowerShell/xPSDesiredStateConfiguration.git/': The requested URL returned error: 504
Command exited with code 128

How do I make it re-run tests?

@johlju
Copy link
Member

johlju commented Jan 13, 2017

‪Try force push.

git push myremotename working-branch --force

@kwirkykat
Copy link
Contributor

@bozho Any idea why this test with forward slashes in the path passes with the resource as is? https://github.com/PowerShell/xPSDesiredStateConfiguration/blob/dev/Tests/Integration/MSFT_xRegistryResource.Integration.Tests.ps1#L244

@kwirkykat
Copy link
Contributor

@bozho Or do you know a test we could add to make sure this bug doesn't come up again?

@kwirkykat kwirkykat added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Jan 19, 2017
@bozho
Copy link
Contributor Author

bozho commented Jan 20, 2017

@kwirkykat Ah, I missed that test. The test passes for both the current code and the new code. However, the end result is different.

The current code will create the following path:

HKLM:\
   SYSTEM\
      CurrentControlSet\
         Control\
            Session Manager\
               Environment\
                  TestKey\
                     Test\
                        Key

The new code will create the following path:

HKLM:\
   SYSTEM\
      CurrentControlSet\
         Control\
            Session Manager\
               Environment\
                  TestKey/Test/Key

Where TestKey/Test/Key is the subkey name.

Using standard filesystem cmdlets with registry paths suffers from the fact that forward slashes are valid characters in registry key names and the filesystem cmdlets interpret them as path separators.

Searching for something like "powershell dsc registry forward slash" finds people trying to find a way to use DSC to disable old RC4 ciphers, as per MS security advisory (https://support.microsoft.com/en-us/kb/2868725). Unfortunately, this requires creating registry keys containing slashes :-)

I understand that this can be viewed as a slightly breaking change and that we'd be deviating from using standard filesystem cmdlets for handling registry paths in this one instance. But, it does provide expected behaviour for handling registry paths and solves a problem with a very common DSC use-case.

@kwirkykat
Copy link
Contributor

@bozho Yes this change is definitely needed. Could you add a test or modify the current test so that it fails with the old bug and passes with the new fix?

@bozho
Copy link
Contributor Author

bozho commented Jan 23, 2017

@kwirkykat Sure, I'll try to whip something up during this week.

@bozho
Copy link
Contributor Author

bozho commented Jan 23, 2017

@kwirkykat Huh... I'm not sure how to write the test without altering Test-RegistryValueExists, which may affect all other xRegistry tests.

I've created two subkeys under the same registry key:

HKLM:\
   SYSTEM\
      CurrentControlSet\
         Control\
            Session Manager\
               Environment\
                  TestKey/Key

and

HKLM:\
   SYSTEM\
      CurrentControlSet\
         Control\
            Session Manager\
               Environment\
                  TestKey\
                     Key

Running

Get-ItemProperty -Path $KeyPath -Name $ValueName -ErrorAction 'SilentlyContinue'

on two different paths:

HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\TestKey/Key

and

HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\TestKey\Key

will happily return values from the second key, if both keys exist. If only the first key exists, Get-ItemProperty will return values from it for both paths.

If only the first key and

HKLM:\
   SYSTEM\
      CurrentControlSet\
         Control\
            Session Manager\
               Environment\
                  TestKey

exist, Get-ItemProperty will return nothing for both paths.

@kwirkykat
Copy link
Contributor

@bozho I think this change is important enough to go out in the release today. I will update the tests later since I'm familiar with this resource and its tests

@kwirkykat
Copy link
Contributor

LGTM

@kwirkykat kwirkykat merged commit 3ca3f35 into dsccommunity:dev Jan 25, 2017
@kwirkykat kwirkykat removed the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Jan 25, 2017
@bozho bozho deleted the issue-285-xRegistry-slash-key-name branch February 28, 2017 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants