rename script to powershell

This commit is contained in:
Christoph Hartmann 2016-03-18 12:29:36 +01:00
parent f0312f4abe
commit e2466d0dbb
4 changed files with 100 additions and 85 deletions

View file

@ -42,9 +42,9 @@ The following InSpec audit resources are available:
* `port`_
* `postgres_conf`_
* `postgres_session`_
* `powershell`_
* `processes`_
* `registry_key`_
* `script`_
* `security_policy`_
* `service`_
* `ssh_config`_
@ -3525,6 +3525,84 @@ The following examples show how to use this InSpec audit resource.
powershell
=====================================================
Use the ``powershell`` |inspec resource| to test a |powershell| script on the |windows| platform.
**Stability: Experimental**
Syntax
-----------------------------------------------------
A ``powershell`` |inspec resource| block declares a script to be tested, and then a command that should be part of that script:
.. code-block:: ruby
script = <<-EOH
# you powershell script
EOH
describe powershell(script) do
its('matcher') { should eq 'output' }
end
where
* ``'script'`` must specify a Powershell script to be run
* ``'matcher'`` is one of ``exit_status``, ``stderr``, or ``stdout``
* ``'output'`` tests the output of the command run on the system versus the output value stated in the test
Matchers
-----------------------------------------------------
This InSpec audit resource has the following matchers.
exit_status
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``exit_status`` matcher tests the exit status for the command:
.. code-block:: ruby
its('exit_status') { should eq 123 }
stderr
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``stderr`` matcher tests results of the command as returned in standard error (stderr):
.. code-block:: ruby
its('stderr') { should eq 'error' }
stdout
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``stdout`` matcher tests results of the command as returned in standard output (stdout):
.. code-block:: ruby
its('stdout') { should eq '/^1$/' }
Examples
-----------------------------------------------------
The following examples show how to use this InSpec audit resource.
**Get all groups of Administrator user**
.. code-block:: ruby
myscript = <<-EOH
# find user
$user = Get-WmiObject Win32_UserAccount -filter "Name = 'Administrator'"
# get related groups
$groups = $user.GetRelated('Win32_Group') | Select-Object -Property Caption, Domain, Name, LocalAccount, SID, SIDType, Status
$groups | ConvertTo-Json
EOH
describe script(myscript) do
its('stdout') { should_not eq '' }
end
processes
=====================================================
Use the ``processes`` |inspec resource| to test properties for programs that are running on the system.
@ -3651,83 +3729,6 @@ The following examples show how to use this InSpec audit resource.
where ``'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule'`` is the full path to the setting.
script
=====================================================
Use the ``script`` |inspec resource| to test a |powershell| script on the |windows| platform.
**Stability: Experimental**
Syntax
-----------------------------------------------------
A ``script`` |inspec resource| block declares a script to be tested, and then a command that should be part of that script:
.. code-block:: ruby
script = <<-EOH
# you powershell script
EOH
describe script(script) do
its('matcher') { should eq 'output' }
end
where
* ``'script'`` must specify a Powershell script to be run
* ``'matcher'`` is one of ``exit_status``, ``stderr``, or ``stdout``
* ``'output'`` tests the output of the command run on the system versus the output value stated in the test
Matchers
-----------------------------------------------------
This InSpec audit resource has the following matchers.
exit_status
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``exit_status`` matcher tests the exit status for the command:
.. code-block:: ruby
its('exit_status') { should eq 123 }
stderr
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``stderr`` matcher tests results of the command as returned in standard error (stderr):
.. code-block:: ruby
its('stderr') { should eq 'error' }
stdout
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The ``stdout`` matcher tests results of the command as returned in standard output (stdout):
.. code-block:: ruby
its('stdout') { should eq '/^1$/' }
Examples
-----------------------------------------------------
The following examples show how to use this InSpec audit resource.
**Get all groups of Administrator user**
.. code-block:: ruby
myscript = <<-EOH
# find user
$user = Get-WmiObject Win32_UserAccount -filter "Name = 'Administrator'"
# get related groups
$groups = $user.GetRelated('Win32_Group') | Select-Object -Property Caption, Domain, Name, LocalAccount, SID, SIDType, Status
$groups | ConvertTo-Json
EOH
describe script(myscript) do
its('stdout') { should_not eq '' }
end
security_policy
=====================================================
Use the ``security_policy`` |inspec resource| to test security policies on the |windows| platform.

View file

@ -88,9 +88,9 @@ require 'resources/port'
require 'resources/postgres'
require 'resources/postgres_conf'
require 'resources/postgres_session'
require 'resources/powershell'
require 'resources/processes'
require 'resources/registry_key'
require 'resources/script'
require 'resources/security_policy'
require 'resources/service'
require 'resources/shadow'

View file

@ -5,15 +5,15 @@
# license: All rights reserved
module Inspec::Resources
class Script < Cmd
name 'script'
desc 'Use the script InSpec audit resource to test a Windows PowerShell script on the Microsoft Windows platform.'
class PowershellScript < Cmd
name 'powershell'
desc 'Use the powershell InSpec audit resource to test a Windows PowerShell script on the Microsoft Windows platform.'
example "
script = <<-EOH
# you powershell script
EOH
describe script(script) do
describe powershell(script) do
its('matcher') { should eq 'output' }
end
"
@ -37,7 +37,21 @@ module Inspec::Resources
end
def to_s
'Script'
'Powershell'
end
end
# this is deprecated syntax and will be removed in future versions
class LegacyPowershellScript < PowershellScript
name 'script'
def initialize(script)
deprecated
super(script)
end
def deprecated
warn '[DEPRECATION] `script(script)` is deprecated. Please use `powershell(script)` instead.'
end
end
end

View file

@ -111,7 +111,7 @@ module Inspec::Resources
$object | ConvertTo-Json
EOH
cmd = inspec.script(script)
cmd = inspec.powershell(script)
# cannot rely on exit code for now, successful command returns exit code 1
# return nil if cmd.exit_status != 0, try to parse json