Skip to content

Commit

Permalink
fix #1131 circumvent bug in powershell where string are not properly …
Browse files Browse the repository at this point in the history
…handled

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
  • Loading branch information
chris-rock committed Apr 7, 2017
1 parent 90b985a commit 6f6f398
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/resources/registry_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def registry_key(path)
$properties
}
$path = '#{path}'
InSpec-GetRegistryKey($path) | ConvertTo-Json
InSpec-GetRegistryKey($path) | ConvertTo-Json -Compress
EOH

cmd = inspec.powershell(script)
Expand Down
8 changes: 8 additions & 0 deletions test/cookbooks/os_prepare/recipes/registry_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
:name => 'multistring value',
:type => :multi_string,
:data => ['test', 'multi','string','data']
},{
:name => 'super\/escape',
:type => :string,
:data => '\/value/\\'
},{
:name => 'key.with.dot',
:type => :string,
:data => 'value.with.dot'
}]
recursive true
action :create
Expand Down
3 changes: 1 addition & 2 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ def md.directory?
'env' => cmd.call('env'),
'${Env:PATH}' => cmd.call('$env-PATH'),
# registry key test using winrm 2.0
'2376c7b3d81de9382303356e1efdea99385effb84788562c3e697032d51bf942' => cmd.call('reg_schedule'),
'89b48f91634e7efc40105fc082c5e12693b08c0a7c4a578b1f3a07e34f676c66' => cmd.call('reg_schedule'),
'bd15a11a4b07de0224c4d1ab16c49ad78dd6147650c6ef629152c7093a5ac95e' => cmd.call('reg_schedule'),
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.call('auditpol'),
'/sbin/auditctl -l' => cmd.call('auditctl'),
'/sbin/auditctl -s' => cmd.call('auditctl-s'),
Expand Down
11 changes: 11 additions & 0 deletions test/integration/default/registry_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,14 @@
it { should exist }
it { should have_value('test') }
end

describe registry_key('HKLM\System\Test') do
it { should exist }
its('super\/escape') { should eq '\/value/\\' }

# its('key.with.dot') { should eq 'value.with.dot' }
# does not work due to the . inside the its block
# see https://github.com/chef/inspec/issues/1281
# use the following solution:
it { should have_property_value('key.with.dot', :string, 'value.with.dot') }
end

0 comments on commit 6f6f398

Please sign in to comment.