mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Support array syntax for registry_key resource (#2160)
Users cannot query for registry keys that have periods in them because of how rspec-its works. This change enables Array-style syntax for the registry_key resource so users can use that as a workaround. Signed-off-by: Adam Leff <adam@leff.co>
This commit is contained in:
parent
e57977612e
commit
adf25ae783
3 changed files with 20 additions and 2 deletions
|
@ -106,10 +106,19 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
# returns nil, if not existant or value
|
||||
def method_missing(meth)
|
||||
def method_missing(*keys)
|
||||
# allow the use of array syntax in an `its` block so that users
|
||||
# can use it to query for keys with . characters in them
|
||||
if keys.is_a?(Array)
|
||||
keys.shift if keys[0] == :[]
|
||||
key = keys.first
|
||||
else
|
||||
key = keys
|
||||
end
|
||||
|
||||
# get data
|
||||
val = registry_key(@options[:path])
|
||||
registry_property_value(val, meth)
|
||||
registry_property_value(val, key)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -2,5 +2,9 @@
|
|||
"Start": {
|
||||
"value": 2,
|
||||
"type": 4
|
||||
},
|
||||
"key.with.period": {
|
||||
"value": 12345,
|
||||
"type": 4
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ describe 'Inspec::Resources::RegistryKey' do
|
|||
_(resource_without_name.Start).must_equal 2
|
||||
end
|
||||
|
||||
it 'supports array syntax for keys with periods in them' do
|
||||
resource = MockLoader.new(:windows).load_resource('registry_key', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule')
|
||||
_(resource.send(:[], "key.with.period")).must_equal 12345
|
||||
end
|
||||
|
||||
it 'generates a proper path from options' do
|
||||
resource = MockLoader.new(:windows).load_resource(
|
||||
'registry_key',
|
||||
|
|
Loading…
Add table
Reference in a new issue