mitre / microsoft-windows-server-2019-stig-baseline

Microsoft Windows Server 2019 STIG InSpec Profile
Other
14 stars 11 forks source link

V-93037 Add edge case for single OU #83

Closed karikarshivani closed 1 year ago

karikarshivani commented 1 year ago

This code block might be leading to the following error when running the profile against a Domain Controller:

ou_list = json(command: "Get-ADOrganizationalUnit -filter * -SearchBase '#{distinguishedName}' | Select-Object -ExpandProperty distinguishedname | ConvertTo-Json").params

ou_list.each do |ou|
         acl_rules = json(command: "(Get-ACL -Audit -Path AD:'#{ou}').Access | ConvertTo-CSV | ConvertFrom-CSV | ConvertTo-JSON").params

Error:

undefined method `each' for "OU=Domain Controllers,DC=saf,DC=cms":String

Recommendation: Since the tests are 100 lines long, the easiest way to address this would be to set the variable as an array early on so single values don't affect the for loop.

ou_list = []
ou_list << json(command: <cmd>).params
if ou_list.empty?
  <skip>
else
  <for loop with tests>