inspec 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -2
  3. data/Gemfile +2 -3
  4. data/README.md +2 -0
  5. data/Rakefile +8 -0
  6. data/bin/inspec +1 -157
  7. data/docs/resources.rst +79 -78
  8. data/examples/profile/controls/example.rb +3 -1
  9. data/lib/fetchers/mock.rb +27 -0
  10. data/lib/fetchers/tar.rb +3 -2
  11. data/lib/fetchers/zip.rb +3 -1
  12. data/lib/inspec/cli.rb +164 -0
  13. data/lib/inspec/plugins/resource.rb +6 -2
  14. data/lib/inspec/profile.rb +28 -17
  15. data/lib/inspec/resource.rb +5 -1
  16. data/lib/inspec/rspec_json_formatter.rb +42 -0
  17. data/lib/inspec/rule.rb +24 -1
  18. data/lib/inspec/runner.rb +15 -7
  19. data/lib/inspec/runner_mock.rb +6 -1
  20. data/lib/inspec/runner_rspec.rb +29 -1
  21. data/lib/inspec/version.rb +1 -1
  22. data/lib/resources/{script.rb → powershell.rb} +19 -5
  23. data/lib/resources/registry_key.rb +1 -1
  24. data/test/{integration/cookbooks → cookbooks}/os_prepare/files/empty.iso +0 -0
  25. data/test/{integration/cookbooks → cookbooks}/os_prepare/files/example.csv +0 -0
  26. data/test/{integration/cookbooks → cookbooks}/os_prepare/files/example.ini +0 -0
  27. data/test/{integration/cookbooks → cookbooks}/os_prepare/files/example.json +0 -0
  28. data/test/{integration/cookbooks → cookbooks}/os_prepare/files/example.yml +0 -0
  29. data/test/{integration/cookbooks → cookbooks}/os_prepare/metadata.rb +0 -0
  30. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/_runit_service_centos.rb +0 -0
  31. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/_upstart_service_centos.rb +0 -0
  32. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/apache.rb +0 -0
  33. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/apt.rb +0 -0
  34. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/auditctl.rb +0 -0
  35. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/default.rb +0 -0
  36. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/file.rb +0 -0
  37. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/iptables.rb +0 -0
  38. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/json_yaml_csv_ini.rb +0 -0
  39. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/mount.rb +2 -2
  40. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/package.rb +0 -0
  41. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/postgres.rb +6 -0
  42. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/registry_key.rb +0 -0
  43. data/test/{integration/cookbooks → cookbooks}/os_prepare/recipes/service.rb +0 -0
  44. data/test/{integration/cookbooks → cookbooks}/os_prepare/templates/default/sv-default-svlog-run.erb +0 -0
  45. data/test/functional/command_test.rb +390 -0
  46. data/test/helper.rb +6 -0
  47. data/test/integration/{test/integration/default → default}/_debug_spec.rb +0 -0
  48. data/test/integration/{test/integration/default → default}/apache_conf_spec.rb +0 -0
  49. data/test/integration/{test/integration/default → default}/apt_spec.rb +0 -0
  50. data/test/integration/{test/integration/default → default}/auditd_rules_spec.rb +0 -0
  51. data/test/integration/{test/integration/default → default}/compare_matcher_spec.rb +0 -0
  52. data/test/integration/{test/integration/default → default}/csv_spec.rb +0 -0
  53. data/test/integration/{test/integration/default → default}/etc_group_spec.rb +0 -0
  54. data/test/integration/{test/integration/default → default}/file_spec.rb +3 -2
  55. data/test/integration/{test/integration/default → default}/group_spec.rb +0 -0
  56. data/test/integration/{test/integration/default → default}/ini_spec.rb +0 -0
  57. data/test/integration/{test/integration/default → default}/iptables_spec.rb +0 -0
  58. data/test/integration/{test/integration/default → default}/json_spec.rb +0 -0
  59. data/test/integration/{test/integration/default → default}/kernel_module_spec.rb +0 -0
  60. data/test/integration/{test/integration/default → default}/kernel_parameter_spec.rb +0 -0
  61. data/test/integration/{test/integration/default → default}/mount_spec.rb +1 -1
  62. data/test/integration/{test/integration/default → default}/os_spec.rb +0 -0
  63. data/test/integration/{test/integration/default → default}/package_spec.rb +0 -0
  64. data/test/integration/{test/integration/default → default}/port_spec.rb +0 -0
  65. data/test/integration/{test/integration/default → default}/postgres_session_spec.rb +0 -0
  66. data/test/integration/default/powershell_spec.rb +13 -0
  67. data/test/integration/{test/integration/default → default}/registry_key_spec.rb +0 -0
  68. data/test/integration/{test/integration/default → default}/secpol_spec.rb +0 -0
  69. data/test/integration/{test/integration/default → default}/service_spec.rb +0 -0
  70. data/test/integration/{test/integration/default → default}/user_spec.rb +0 -0
  71. data/test/integration/{test/integration/default → default}/yaml_spec.rb +0 -0
  72. data/test/unit/control_test.rb +58 -0
  73. data/test/unit/fetchers/mock_test.rb +43 -0
  74. data/test/unit/plugins/resource_test.rb +60 -0
  75. data/test/unit/resources/{script_test.rb → powershell_test.rb} +10 -1
  76. metadata +107 -101
  77. data/test/integration/.kitchen.ec2.yml +0 -75
  78. data/test/integration/.kitchen.yml +0 -45
  79. data/test/integration/Berksfile +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ca71e169ffd037a7a61f99fc09188424a137168
4
- data.tar.gz: 1aa83936f8b464a2044a7fae20cb14ddce1bdb87
3
+ metadata.gz: 243a577f37796094ac8a136876c11d14ded819c2
4
+ data.tar.gz: 7a95c3d207666f7d91c7ccb10316432d1ba70dd6
5
5
  SHA512:
6
- metadata.gz: 774c8531d3bfdcab1c0a0587f670c09ab39099e89ff07a79e68c37bb3798e1a1a75e0b613c80a7bc7f8fb492c797ec26b04a12298a0493ddfd0d7784059cfb99
7
- data.tar.gz: 4335e3fa250d9b6e3b54e25c82289fb3f232452ced7ad0d1a781349b2ae415d8b9533824c4ffda2f53340a96da0cea3720dd630637b59a6286511021672c3945
6
+ metadata.gz: 4d66e309baed6ba892f9b5fc4c03f488afc7886dc67c88bcf4a9d97e32e2a5cdbbb4e475e792e3f6d4199ea034177fd8a3698063a0d8b4d36d60b626eecfa993
7
+ data.tar.gz: 03d6a852e3d9e3d629e1e1d44555973ea69f66d78d630ebd80bbdcddcff6035a96a03416a58c02fcc757cbc01f838ef36e6b44ef17a41692204d6120d17426e8
data/CHANGELOG.md CHANGED
@@ -1,7 +1,44 @@
1
1
  # Change Log
2
2
 
3
- ## [0.15.0](https://github.com/chef/inspec/tree/0.15.0) (2016-03-09)
4
- [Full Changelog](https://github.com/chef/inspec/compare/v0.14.8...0.15.0)
3
+ ## [0.16.0](https://github.com/chef/inspec/tree/0.16.0) (2016-03-19)
4
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.15.0...0.16.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Read Chef attributes within the tests ? [\#541](https://github.com/chef/inspec/issues/541)
9
+ - A resource to test http GET calls [\#538](https://github.com/chef/inspec/issues/538)
10
+ - rename `script` resource to `powershell` resource [\#553](https://github.com/chef/inspec/pull/553) ([chris-rock](https://github.com/chris-rock))
11
+ - add fulljson formatter [\#552](https://github.com/chef/inspec/pull/552) ([arlimus](https://github.com/arlimus))
12
+ - feature: add tags and refs [\#551](https://github.com/chef/inspec/pull/551) ([arlimus](https://github.com/arlimus))
13
+ - fix detect + add output option to archive command [\#546](https://github.com/chef/inspec/pull/546) ([arlimus](https://github.com/arlimus))
14
+ - adding named resource registry classes [\#540](https://github.com/chef/inspec/pull/540) ([adamleff](https://github.com/adamleff))
15
+ - add output stream to rspec configuration [\#529](https://github.com/chef/inspec/pull/529) ([vjeffrey](https://github.com/vjeffrey))
16
+ - Move integration tests to test/integration [\#468](https://github.com/chef/inspec/pull/468) ([chris-rock](https://github.com/chris-rock))
17
+
18
+ **Fixed bugs:**
19
+
20
+ - fix inspec shell and continuously test it [\#556](https://github.com/chef/inspec/pull/556) ([arlimus](https://github.com/arlimus))
21
+ - bugfix: prevent duplicate loading of library files [\#547](https://github.com/chef/inspec/pull/547) ([arlimus](https://github.com/arlimus))
22
+ - fix detect + add output option to archive command [\#546](https://github.com/chef/inspec/pull/546) ([arlimus](https://github.com/arlimus))
23
+ - bugfix: archive command with inheritance-based profiles [\#545](https://github.com/chef/inspec/pull/545) ([arlimus](https://github.com/arlimus))
24
+
25
+ **Closed issues:**
26
+
27
+ - Add additional metadata to the control definition to allow for more complete mapping to security guidance documents [\#536](https://github.com/chef/inspec/issues/536)
28
+ - CLI: Specifying --profiles-path on check succeeds but displays usage error on archive [\#535](https://github.com/chef/inspec/issues/535)
29
+ - inspec failing to connect to Compliance \(SSL certificate error\) [\#531](https://github.com/chef/inspec/issues/531)
30
+
31
+ **Merged pull requests:**
32
+
33
+ - mock fetcher [\#550](https://github.com/chef/inspec/pull/550) ([arlimus](https://github.com/arlimus))
34
+ - testing: add inspec exec tests with json formatter [\#549](https://github.com/chef/inspec/pull/549) ([arlimus](https://github.com/arlimus))
35
+ - dont generate pretty json by default [\#548](https://github.com/chef/inspec/pull/548) ([arlimus](https://github.com/arlimus))
36
+ - Add title, description, code, and source\_location to example metadata [\#543](https://github.com/chef/inspec/pull/543) ([vjeffrey](https://github.com/vjeffrey))
37
+ - add functional tests for cli [\#542](https://github.com/chef/inspec/pull/542) ([arlimus](https://github.com/arlimus))
38
+ - Add a Gitter chat badge to README.md [\#530](https://github.com/chef/inspec/pull/530) ([gitter-badger](https://github.com/gitter-badger))
39
+
40
+ ## [v0.15.0](https://github.com/chef/inspec/tree/v0.15.0) (2016-03-09)
41
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.14.8...v0.15.0)
5
42
 
6
43
  **Implemented enhancements:**
7
44
 
@@ -20,6 +57,7 @@
20
57
 
21
58
  **Merged pull requests:**
22
59
 
60
+ - 0.15.0 [\#528](https://github.com/chef/inspec/pull/528) ([arlimus](https://github.com/arlimus))
23
61
  - 0.14.9 [\#525](https://github.com/chef/inspec/pull/525) ([arlimus](https://github.com/arlimus))
24
62
 
25
63
  ## [v0.14.8](https://github.com/chef/inspec/tree/v0.14.8) (2016-03-04)
data/Gemfile CHANGED
@@ -19,10 +19,9 @@ end
19
19
 
20
20
  group :integration do
21
21
  gem 'berkshelf', '~> 4.0'
22
- gem 'test-kitchen'
22
+ gem 'test-kitchen', '~> 1.6'
23
23
  gem 'kitchen-vagrant'
24
- gem 'kitchen-inspec'
25
- gem 'winrm-transport', '~> 1.0'
24
+ gem 'kitchen-inspec', '0.12.5'
26
25
  gem 'kitchen-ec2'
27
26
  end
28
27
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # InSpec: Inspect Your Infrastructure
2
2
 
3
+ [![Join the chat at https://gitter.im/chef/inspec](https://badges.gitter.im/chef/inspec.svg)](https://gitter.im/chef/inspec?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
3
5
  InSpec is an open-source testing framework for infrastructure with a human- and machine-readable language for specifying compliance, security and policy requirements.
4
6
 
5
7
  ```ruby
data/Rakefile CHANGED
@@ -35,6 +35,14 @@ namespace :test do
35
35
  end or fail 'Failures'
36
36
  end
37
37
 
38
+ Rake::TestTask.new(:functional) do |t|
39
+ t.libs << 'test'
40
+ t.pattern = 'test/functional/**/*_test.rb'
41
+ t.warning = true
42
+ t.verbose = true
43
+ t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
44
+ end
45
+
38
46
  task :resources do
39
47
  tests = Dir['test/resource/*_test.rb']
40
48
  return if tests.empty?
data/bin/inspec CHANGED
@@ -4,162 +4,6 @@
4
4
  # author: Dominik Richter
5
5
  # author: Christoph Hartmann
6
6
 
7
- require 'thor'
8
- require 'json'
9
- require 'pp'
10
- require_relative '../lib/utils/base_cli'
11
7
  require_relative '../lib/inspec'
12
- require_relative '../lib/utils/json_log'
13
-
14
- class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
15
- class_option :diagnose, type: :boolean,
16
- desc: 'Show diagnostics (versions, configurations)'
17
-
18
- desc 'json PATH', 'read all tests in PATH and generate a JSON summary'
19
- option :id, type: :string,
20
- desc: 'Attach a profile ID to all test results'
21
- option :output, aliases: :o, type: :string,
22
- desc: 'Save the created profile to a path'
23
- profile_options
24
- def json(target)
25
- diagnose
26
- o = opts.dup
27
- o[:ignore_supports] = true
28
-
29
- profile = Inspec::Profile.for_target(target, o)
30
- dst = o[:output].to_s
31
- if dst.empty?
32
- puts JSON.pretty_generate(profile.info)
33
- else
34
- if File.exist? dst
35
- puts "----> updating #{dst}"
36
- else
37
- puts "----> creating #{dst}"
38
- end
39
- fdst = File.expand_path(dst)
40
- File.write(fdst, JSON.dump(profile.info))
41
- end
42
- end
43
-
44
- desc 'check PATH', 'verify all tests at the specified PATH'
45
- option :format, type: :string
46
- profile_options
47
- def check(path) # rubocop:disable Metrics/AbcSize
48
- diagnose
49
- o = opts.dup
50
- # configure_logger(o) # we do not need a logger for check yet
51
- o[:ignore_supports] = true # we check for integrity only
52
-
53
- # run check
54
- profile = Inspec::Profile.for_target(path, o)
55
- result = profile.check
56
-
57
- if opts['format'] == 'json'
58
- puts JSON.generate(result)
59
- else
60
- headline('Summary')
61
- %w{location profile controls timestamp valid}.each { |item|
62
- puts "#{mark_text(item.to_s.capitalize + ':')} #{result[:summary][item.to_sym]}"
63
- }
64
- puts
65
-
66
- %w{errors warnings}.each { |list|
67
- headline(list.to_s.capitalize)
68
- result[list.to_sym].each { |item|
69
- puts "#{item[:file]}:#{item[:line]}:#{item[:column]}: #{item[:msg]} "
70
- }
71
- puts
72
- }
73
- end
74
- exit 1 unless result[:summary][:valid]
75
- end
76
-
77
- desc 'archive PATH', 'archive a profile to tar.gz (default) or zip'
78
- option :zip, type: :boolean, default: false,
79
- desc: 'Generates a zip archive.'
80
- option :tar, type: :boolean, default: false,
81
- desc: 'Generates a tar.gz archive.'
82
- option :overwrite, type: :boolean, default: false,
83
- desc: 'Overwrite existing archive.'
84
- option :ignore_errors, type: :boolean, default: false,
85
- desc: 'Ignore profile warnings.'
86
- def archive(path)
87
- diagnose
88
-
89
- o = opts.dup
90
- o[:logger] = Logger.new(STDOUT)
91
- o[:logger].level = get_log_level(o.log_level)
92
-
93
- profile = Inspec::Profile.for_target(path, o)
94
- result = profile.check
95
-
96
- if result && !opts[:ignore_errors] == false
97
- @logger.info 'Profile check failed. Please fix the profile before generating an archive.'
98
- return exit 1
99
- end
100
-
101
- # generate archive
102
- exit 1 unless profile.archive(opts)
103
- end
104
-
105
- desc 'exec PATHS', 'run all test files at the specified PATH.'
106
- exec_options
107
- def exec(*targets)
108
- diagnose
109
- run_tests(targets, opts)
110
- end
111
-
112
- desc 'detect', 'detect the target OS'
113
- target_options
114
- def detect
115
- diagnose
116
-
117
- rel = File.join(File.dirname(__FILE__), *%w{.. lib utils detect.rb})
118
- detect_util = File.expand_path(rel)
119
- # exits on execution:
120
- runner = Inspec::Runner.new(opts)
121
- profile = Inspec::Profile.for_target(detect_util, opts)
122
- runner.add_profile(profile)
123
- exit runner.run
124
- rescue RuntimeError => e
125
- puts e.message
126
- end
127
-
128
- desc 'shell', 'open an interactive debugging shell'
129
- target_options
130
- option :format, type: :string, default: Inspec::NoSummaryFormatter, hide: true
131
- def shell_func
132
- diagnose
133
- o = opts.dup
134
- o[:logger] = Logger.new(STDOUT)
135
- o[:logger].level = get_log_level(o.log_level)
136
-
137
- runner = Inspec::Runner.new(o)
138
- Inspec::Shell.new(runner).start
139
- rescue RuntimeError => e
140
- puts e.message
141
- end
142
-
143
- desc 'version', 'prints the version of this tool'
144
- def version
145
- puts Inspec::VERSION
146
- end
147
- end
148
-
149
- # Load all plugins on startup
150
- ctl = Inspec::PluginCtl.new
151
- ctl.list.each { |x| ctl.load(x) }
152
-
153
- # load CLI plugins before the Inspec CLI has been started
154
- Inspec::Plugins::CLI.subcommands.each { |_subcommand, params|
155
- Inspec::InspecCLI.register(
156
- params[:klass],
157
- params[:subcommand_name],
158
- params[:usage],
159
- params[:description],
160
- params[:options],
161
- )
162
- }
163
-
164
- # start the CLI
8
+ require_relative '../lib/inspec/cli'
165
9
  Inspec::InspecCLI.start(ARGV)
data/docs/resources.rst CHANGED
@@ -42,9 +42,9 @@ The following InSpec audit resources are available:
42
42
  * `port`_
43
43
  * `postgres_conf`_
44
44
  * `postgres_session`_
45
+ * `powershell`_
45
46
  * `processes`_
46
47
  * `registry_key`_
47
- * `script`_
48
48
  * `security_policy`_
49
49
  * `service`_
50
50
  * `ssh_config`_
@@ -3525,6 +3525,84 @@ The following examples show how to use this InSpec audit resource.
3525
3525
 
3526
3526
 
3527
3527
 
3528
+ powershell
3529
+ =====================================================
3530
+ Use the ``powershell`` |inspec resource| to test a |powershell| script on the |windows| platform.
3531
+
3532
+ **Stability: Experimental**
3533
+
3534
+ Syntax
3535
+ -----------------------------------------------------
3536
+ A ``powershell`` |inspec resource| block declares a script to be tested, and then a command that should be part of that script:
3537
+
3538
+ .. code-block:: ruby
3539
+
3540
+ script = <<-EOH
3541
+ # you powershell script
3542
+ EOH
3543
+
3544
+ describe powershell(script) do
3545
+ its('matcher') { should eq 'output' }
3546
+ end
3547
+
3548
+
3549
+ where
3550
+
3551
+ * ``'script'`` must specify a Powershell script to be run
3552
+ * ``'matcher'`` is one of ``exit_status``, ``stderr``, or ``stdout``
3553
+ * ``'output'`` tests the output of the command run on the system versus the output value stated in the test
3554
+
3555
+
3556
+ Matchers
3557
+ -----------------------------------------------------
3558
+ This InSpec audit resource has the following matchers.
3559
+
3560
+ exit_status
3561
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++
3562
+ The ``exit_status`` matcher tests the exit status for the command:
3563
+
3564
+ .. code-block:: ruby
3565
+
3566
+ its('exit_status') { should eq 123 }
3567
+
3568
+ stderr
3569
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++
3570
+ The ``stderr`` matcher tests results of the command as returned in standard error (stderr):
3571
+
3572
+ .. code-block:: ruby
3573
+
3574
+ its('stderr') { should eq 'error' }
3575
+
3576
+ stdout
3577
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++
3578
+ The ``stdout`` matcher tests results of the command as returned in standard output (stdout):
3579
+
3580
+ .. code-block:: ruby
3581
+
3582
+ its('stdout') { should eq '/^1$/' }
3583
+
3584
+ Examples
3585
+ -----------------------------------------------------
3586
+ The following examples show how to use this InSpec audit resource.
3587
+
3588
+ **Get all groups of Administrator user**
3589
+
3590
+ .. code-block:: ruby
3591
+
3592
+ myscript = <<-EOH
3593
+ # find user
3594
+ $user = Get-WmiObject Win32_UserAccount -filter "Name = 'Administrator'"
3595
+ # get related groups
3596
+ $groups = $user.GetRelated('Win32_Group') | Select-Object -Property Caption, Domain, Name, LocalAccount, SID, SIDType, Status
3597
+ $groups | ConvertTo-Json
3598
+ EOH
3599
+
3600
+ describe script(myscript) do
3601
+ its('stdout') { should_not eq '' }
3602
+ end
3603
+
3604
+
3605
+
3528
3606
  processes
3529
3607
  =====================================================
3530
3608
  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.
3651
3729
  where ``'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule'`` is the full path to the setting.
3652
3730
 
3653
3731
 
3654
- script
3655
- =====================================================
3656
- Use the ``script`` |inspec resource| to test a |powershell| script on the |windows| platform.
3657
-
3658
- **Stability: Experimental**
3659
-
3660
- Syntax
3661
- -----------------------------------------------------
3662
- A ``script`` |inspec resource| block declares a script to be tested, and then a command that should be part of that script:
3663
-
3664
- .. code-block:: ruby
3665
-
3666
- script = <<-EOH
3667
- # you powershell script
3668
- EOH
3669
-
3670
- describe script(script) do
3671
- its('matcher') { should eq 'output' }
3672
- end
3673
-
3674
-
3675
- where
3676
-
3677
- * ``'script'`` must specify a Powershell script to be run
3678
- * ``'matcher'`` is one of ``exit_status``, ``stderr``, or ``stdout``
3679
- * ``'output'`` tests the output of the command run on the system versus the output value stated in the test
3680
-
3681
-
3682
- Matchers
3683
- -----------------------------------------------------
3684
- This InSpec audit resource has the following matchers.
3685
-
3686
- exit_status
3687
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
3688
- The ``exit_status`` matcher tests the exit status for the command:
3689
-
3690
- .. code-block:: ruby
3691
-
3692
- its('exit_status') { should eq 123 }
3693
-
3694
- stderr
3695
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
3696
- The ``stderr`` matcher tests results of the command as returned in standard error (stderr):
3697
-
3698
- .. code-block:: ruby
3699
-
3700
- its('stderr') { should eq 'error' }
3701
-
3702
- stdout
3703
- +++++++++++++++++++++++++++++++++++++++++++++++++++++
3704
- The ``stdout`` matcher tests results of the command as returned in standard output (stdout):
3705
-
3706
- .. code-block:: ruby
3707
-
3708
- its('stdout') { should eq '/^1$/' }
3709
-
3710
- Examples
3711
- -----------------------------------------------------
3712
- The following examples show how to use this InSpec audit resource.
3713
-
3714
- **Get all groups of Administrator user**
3715
-
3716
- .. code-block:: ruby
3717
-
3718
- myscript = <<-EOH
3719
- # find user
3720
- $user = Get-WmiObject Win32_UserAccount -filter "Name = 'Administrator'"
3721
- # get related groups
3722
- $groups = $user.GetRelated('Win32_Group') | Select-Object -Property Caption, Domain, Name, LocalAccount, SID, SIDType, Status
3723
- $groups | ConvertTo-Json
3724
- EOH
3725
-
3726
- describe script(myscript) do
3727
- its('stdout') { should_not eq '' }
3728
- end
3729
-
3730
-
3731
3732
  security_policy
3732
3733
  =====================================================
3733
3734
  Use the ``security_policy`` |inspec resource| to test security policies on the |windows| platform.