1

I have a test :

control "cis-0-0-7" do
  impact 1.0
  title "verify chkconfig"
  desc "verify chkconfig"
  stdout, stderr, status = Open3.capture3('chkconfig | grep active')
     puts stdout
      #stdout { should match /activemq-instance-EL2-ext/ }
   #end
end

This displays the following on stdout:

$inspec exec cookbooks/activemq7/test/linuxcommon_test.rb
activemq-instance-EL2-ext   0:off   1:off   2:on    3:on    4:on    5:on    6:off
activemq-instance-EL2-int   0:off   1:off   2:on    3:on    4:on    5:on    6:off

How do i use Inspec ( if possible ) or use ruby to parse and verify ( assert ) these multiple lines.

as @coderanger suggested i used:

control "cis-0-0-7" do
  impact 1.0
  title "verify chkconfig"
  desc "verify chkconfig"
  #stdout, stderr, status = Open3.capture3('chkconfig | grep active')
  output = command('chkconfig | grep active')
     describe output do
      its('stdout')  { should match /activemq-instance-EL2-ext.*\n/ }
      its('stdout')  { should match /activemq-instance-EL2-int.*\n/ }
   end
end

Works!! thanks

kamal
  • 9,637
  • 30
  • 101
  • 168
  • You still don't need the variable, just `describe command(...)` and now that I bother to read your code, why are you 1) not using a `service()` resource and 2) not using the existing CIS benchmarks modules? – coderanger Jul 13 '17 at 20:12

1 Answers1

2

Why are you using Open3? You want to be using the command resource, not direct Ruby command execution. That said, you would just compare to a string with \n in it.

coderanger
  • 52,400
  • 4
  • 52
  • 75