Make wmi resource always return arrays for params

Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
Alex Pop 2020-11-27 23:43:04 +00:00
parent 8a608dac76
commit e71043ee09
2 changed files with 20 additions and 12 deletions

View file

@ -16,7 +16,10 @@ module Inspec::Resources
namespace: 'root\\rsop\\computer',
filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
}) do
its('Setting') { should eq true }
its('Setting') { should cmp true }
end
describe wmi({namespace: "root\\cimv2", query: "SELECT installstate FROM win32_optionalfeature"}) do
its("installstate") { should include 2 }
end
EXAMPLE
@ -66,13 +69,18 @@ module Inspec::Resources
# run wmi command and filter empty wmi
script = <<-EOH
Filter Aggregate
{
$arr = @{}
$_.properties | % {
$arr.Add($_.name, $_.value)
Function Aggregate {
$propsHash = @{}
ForEach ($wmiObj in $Input) {
ForEach ($wmiProp in $wmiObj.properties) {
If($propsHash.ContainsKey($wmiProp.name)) {
$propsHash[$wmiProp.name].add($wmiProp.value) | Out-Null
} Else {
$propsHash[$wmiProp.name] = [System.Collections.ArrayList]@($wmiProp.value)
}
}
$arr
}
$propsHash
}
Get-WmiObject #{params} | Aggregate | ConvertTo-Json
EOH

View file

@ -26,7 +26,7 @@ describe wmi({
namespace: 'root\\rsop\\computer',
filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
}) do
its('Setting') { should eq 1 }
its('Setting') { should eq [1] }
end
# new syntax
@ -34,14 +34,14 @@ describe wmi({
namespace: 'root\rsop\computer',
query: "SELECT Setting FROM RSOP_SecuritySettingBoolean WHERE KeyName='LSAAnonymousNameLookup' AND Precedence=1"
}) do
its('Setting') { should eq false }
its('Setting') { should cmp false }
end
describe wmi({
namespace: 'root\cimv2',
query: 'SELECT filesystem FROM win32_logicaldisk WHERE drivetype=3'
}).params.values.join do
it { should eq 'NTFS' }
it { should cmp 'NTFS' }
end
# deprecated syntax
@ -53,8 +53,8 @@ describe wmi('RSOP_SecuritySettingNumeric', {
namespace: 'root\\rsop\\computer',
filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
}) do
its('Setting') { should eq 1 }
its('setting') { should eq 1 }
its('Setting') { should cmp 1 }
its('setting') { should include 1 }
end
describe wmi('win32_service', {