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

Need help with testing registry entries #389

Closed
dandunckelman opened this issue May 17, 2016 · 9 comments
Closed

Need help with testing registry entries #389

dandunckelman opened this issue May 17, 2016 · 9 comments

Comments

@dandunckelman
Copy link

I'm struggling to get testing to work w/ the https://github.com/puppetlabs/puppetlabs-registry module.

I have a manifest that helps setup Chrome as the default browser on Windows 2012, which contains this:

registry_key { 'HKLM\SOFTWARE\Policies\Microsoft\Windows\System':
  ensure => present,
}->

registry_value { 'HKLM\SOFTWARE\Policies\Microsoft\Windows\System\DefaultAssociationsConfiguration':
  data   => 'c:/tmp/defaultapps.xml',
  ensure => present,
  type   => string,
}

And a test like this:

it { should contain_registry_key("HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System")
  .with(
    "ensure" => "present",
  )
}

it { should contain_registry_value("HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System\\DefaultAssociationsConfiguration")
  .with(
    "ensure" => "present",
  )
  .that_requires("Registry_key[HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System]")
}

which results in this failure:

1) CLASS_NAME should contain Registry_value[HKLM\SOFTWARE\Policies\Microsoft\Windows\System\DefaultAssociationsConfiguration] that requires Registry_key[HKLM\SOFTWARE\Policies\Microsoft\Windows\System]
   Failure/Error:
     it { should contain_registry_value("HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System\\DefaultAssociationsConfiguration")
       .with(
         "data"   => 'c:/tmp/defaultapps.xml',
         "ensure" => "present",
         "type"   => "string",
       )
       .that_requires("Registry_key[HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System]")
     }

   NoMethodError:
     undefined method `resource_type' for Registry_key[HKLM\SOFTWARE\Policies\Microsoft\Windows\System]:Puppet::Type::Registry_key
   # ./spec/classes/default_browser_spec.rb:41:in `block (2 levels) in <top (required)>'

The line number, 41, is referring to

.that_requires("Registry_key[HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System]")

I've also tried these:

.that_requires("Registry_key[HKLM/SOFTWARE/Policies/Microsoft/Windows/System]")

# and this:
.that_requires("Registry_key[HKLM\\\\SOFTWARE\\\\Policies\\\\Microsoft\\\\Windows\\\\System]")

And both give errors like this:

expected that the catalogue would contain Registry_value[HKLM\SOFTWARE\Policies\Microsoft\Windows\System\DefaultAssociationsConfiguration] with that requires Registry_key[HKLM/SOFTWARE/Policies/Microsoft/Windows/System]

# and this:
expected that the catalogue would contain Registry_value[HKLM\SOFTWARE\Policies\Microsoft\Windows\System\DefaultAssociationsConfiguration] with that requires Registry_key[HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System]

Unfortunately, I must have the backslashes in the manifest, otherwise it won't work when applied on a node. So this issue is isolated to the test of this particular module (as far as I can tell).

Any help is greatly appreciated. Thanks

@ferventcoder
Copy link

@dandunckelman I think that the wsus_client may have some tests that use registry and do verification with rspec-puppet.

@ferventcoder
Copy link

ferventcoder commented May 17, 2016

@dandunckelman Also, you may consider joining the slack community - https://slack.puppet.com (We have a #windows channel!)

@ferventcoder
Copy link

Here are the specs for wsus that check registry items - https://github.com/puppetlabs/puppetlabs-wsus_client/blob/master/spec/classes/init_spec.rb

@dandunckelman
Copy link
Author

@ferventcoder thanks for finding that spec for me (I probably should've dug around the other windows-related modules). I'll jump on slack ASAP (thx for the tip).

Unfortunately, my failure occurs when ensuring the require relationship:

.that_requires("Registry_key[HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\System]")

and the tests in the wsus_client module doesn't check for those relationships. I'll dig thru the other Windows modules to see if I can find a match for my failure.

Thanks

@ferventcoder
Copy link

Could be a limitation in rspec-puppet not dealing well with backslashes.

@ferventcoder
Copy link

@DavidS ^^

@DavidS
Copy link
Collaborator

DavidS commented May 18, 2016

Hi @dandunckelman , I've tried to reproduce the error you're seeing with your code, the current registry module's master, the current rspec-puppet master, and puppet 4.4.1, and failed. Can you specify more details on your environment?

@dandunckelman
Copy link
Author

@DavidS thanks. I'm glad to hear it works as expected in the latest/greatest.

Here's more info about my environment:

  • Module Version: 1.1.3
  • Ruby: 1.9.3-p484
  • Puppet: 3.7.5
  • RSpec-Puppet: 2.4.0
  • OS: Windows 2012 R2

Please let me know if you'd like any other info.

Thanks

@joeypiccola
Copy link

joeypiccola commented Jul 6, 2018

I wonder if I have hit the same issue. I have the following test.

it {
  is_expected.to contain_registry_value('aes_128_128_enabled').that_requires(
    'registry_key[aes_128_128]',
  )
}

The above test produces the following error.

failed: rspec: ./spec/classes/ciphers/aes_128_128_spec.rb:29: undefined method `resource_type' for #<Puppet::Type::Registry_key:0x00007ffc3b43e628>
  crypto_win::ciphers::aes_128_128 on windows-2008 R2-x64 passes with minimal params should contain Registry_value[aes_128_128_enabled] that requires registry_key[aes_128_128]
  Failure/Error:
          }

          it {
            is_expected.to contain_registry_value('aes_128_128_enabled').that_requires(
              'registry_key[aes_128_128]',

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

No branches or pull requests

4 participants