vbscript

Use the vbscript InSpec audit resource to test a VBScript on the Windows platform.

Syntax

A vbscript resource block tests the output of a VBScript on the Windows platform:

describe vbscript('script contents') do
  its('stdout') { should eq 'output' }
end

where

  • 'script_name' is the name of the VBScript to test
  • ('output') is the expected output of the VBScript

Matchers

This InSpec audit resource has the following matchers:

be

Use the be matcher to use a comparison operator—= (equal to), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to)—to compare two values: its('value') { should be >= value }, its('value') { should be < value }, and so on.

cmp

Use the cmp matcher compare two values, such as comparing strings to numbers, comparing a single value to an array of values, comparing an array of strings to a regular expression, improving the printing of octal values, and comparing while ignoring case sensitivity.

Compare a single value to an array:

describe some_resource do
  its('users') { should cmp 'root' }
  its('users') { should cmp ['root'] }
end

Compare strings and regular expressions:

describe some_resource do
  its('setting') { should cmp /raw/i }
end

Compare strings and numbers:

describe some_resource do
  its('setting') { should eq '2' }
end

vs:

describe some_resource do
  its('setting') { should cmp '2' }
  its('setting') { should cmp 2 }
end

Ignoring case sensitivity:

describe some_resource do
  its('setting') { should cmp 'raw' }
  its('setting') { should cmp 'RAW' }
end

Printing octal values:

describe some_resource('/proc/cpuinfo') do
  its('mode') { should cmp '0345' }
end

expected: 0345
got: 0444

eq

Use the eq matcher to test the equality of two values: its('Port') { should eq '22' }.

Using its('Port') { should eq 22 } will fail because 22 is not a string value! Use the cmp matcher for less restrictive value comparisons.

include

Use the include matcher to verify that a string value is included in a list: its('list') { should include 'string' }.

match

Use the match matcher to check if a string matches a regular expression: its('string') { should_not match /regex/ }.

Examples

The following examples show how to use this InSpec audit resource.

Test a VBScript

A VBScript file similar to:

script = <<-EOH
  WScript.Echo "hello"
EOH

may be tested for multiple lines:

describe vbscript(script) do
  its('stdout') { should eq "hello\r\n" }
end

and tested for whitespace removal from standard output:

describe vbscript(script) do
  its('strip') { should eq "hello" }
end