inspec 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -2
- data/lib/inspec/resource.rb +2 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/json.rb +4 -21
- data/lib/resources/port.rb +5 -0
- data/lib/resources/vbscript.rb +54 -0
- data/lib/resources/wmi.rb +75 -0
- data/lib/utils/hash_map.rb +37 -0
- data/lib/utils/object_traversal.rb +23 -0
- data/test/helper.rb +2 -0
- data/test/integration/default/port_spec.rb +2 -0
- data/test/integration/default/powershell_spec.rb +20 -2
- data/test/integration/default/vbscript_spec.rb +15 -0
- data/test/integration/default/wmi_spec.rb +26 -0
- data/test/unit/mock/cmd/get-wmiobject +10 -0
- data/test/unit/resources/port_test.rb +11 -0
- data/test/unit/resources/powershell_test.rb +1 -1
- data/test/unit/resources/vbscript_test.rb +18 -0
- data/test/unit/resources/wmi_test.rb +45 -0
- data/test/unit/utils/hash_map_test.rb +63 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5487adad33ddb0d68d7115f3b5855862ac2269f4
|
4
|
+
data.tar.gz: 856ab3b28b9a5d5ffb3bbed9983095553be1c1e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ff5484ae1c3be74b1380f5521eb8bfb925c94fc0b8cf9bb68baaa9a6b998c6b54875d65b9b1b0c12fe68d7db16794c6b0a113d222d4c6a09c3ceb3536c78445
|
7
|
+
data.tar.gz: 65619588022d504d018a3f25e8cd05adf53305b641143b1175e3a78c8e7aae27212c2a29bd51b78bd36e16a7d42a09ae2520eb4e753672a8e70c5b32dbb8ca96
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.16.
|
4
|
-
[Full Changelog](https://github.com/chef/inspec/compare/v0.
|
3
|
+
## [0.16.1](https://github.com/chef/inspec/tree/0.16.1) (2016-03-22)
|
4
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.16.0...0.16.1)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- undefined method `addresses' for Port [\#555](https://github.com/chef/inspec/issues/555)
|
9
|
+
- add `wmi` resource [\#560](https://github.com/chef/inspec/pull/560) ([chris-rock](https://github.com/chris-rock))
|
10
|
+
- Add `vbscript` resource [\#559](https://github.com/chef/inspec/pull/559) ([chris-rock](https://github.com/chris-rock))
|
11
|
+
|
12
|
+
**Merged pull requests:**
|
13
|
+
|
14
|
+
- add support for addresses in port resource [\#558](https://github.com/chef/inspec/pull/558) ([chris-rock](https://github.com/chris-rock))
|
15
|
+
|
16
|
+
## [v0.16.0](https://github.com/chef/inspec/tree/v0.16.0) (2016-03-19)
|
17
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.15.0...v0.16.0)
|
5
18
|
|
6
19
|
**Implemented enhancements:**
|
7
20
|
|
@@ -17,6 +30,7 @@
|
|
17
30
|
|
18
31
|
**Fixed bugs:**
|
19
32
|
|
33
|
+
- Unable to Handle Spaced Windows File Paths [\#469](https://github.com/chef/inspec/issues/469)
|
20
34
|
- fix inspec shell and continuously test it [\#556](https://github.com/chef/inspec/pull/556) ([arlimus](https://github.com/arlimus))
|
21
35
|
- bugfix: prevent duplicate loading of library files [\#547](https://github.com/chef/inspec/pull/547) ([arlimus](https://github.com/arlimus))
|
22
36
|
- fix detect + add output option to archive command [\#546](https://github.com/chef/inspec/pull/546) ([arlimus](https://github.com/arlimus))
|
@@ -30,6 +44,7 @@
|
|
30
44
|
|
31
45
|
**Merged pull requests:**
|
32
46
|
|
47
|
+
- 0.16.0 [\#557](https://github.com/chef/inspec/pull/557) ([arlimus](https://github.com/arlimus))
|
33
48
|
- mock fetcher [\#550](https://github.com/chef/inspec/pull/550) ([arlimus](https://github.com/arlimus))
|
34
49
|
- testing: add inspec exec tests with json formatter [\#549](https://github.com/chef/inspec/pull/549) ([arlimus](https://github.com/arlimus))
|
35
50
|
- dont generate pretty json by default [\#548](https://github.com/chef/inspec/pull/548) ([arlimus](https://github.com/arlimus))
|
data/lib/inspec/resource.rb
CHANGED
@@ -96,8 +96,10 @@ require 'resources/service'
|
|
96
96
|
require 'resources/shadow'
|
97
97
|
require 'resources/ssh_conf'
|
98
98
|
require 'resources/user'
|
99
|
+
require 'resources/vbscript'
|
99
100
|
require 'resources/windows_feature'
|
100
101
|
require 'resources/xinetd'
|
102
|
+
require 'resources/wmi'
|
101
103
|
require 'resources/yum'
|
102
104
|
|
103
105
|
# file formats, depend on json implementation
|
data/lib/inspec/version.rb
CHANGED
data/lib/resources/json.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# author: Christoph Hartmann
|
3
3
|
# author: Dominik Richter
|
4
4
|
|
5
|
+
require 'utils/object_traversal'
|
6
|
+
|
5
7
|
module Inspec::Resources
|
6
8
|
class JsonConfig < Inspec.resource(1)
|
7
9
|
name 'json'
|
@@ -12,6 +14,8 @@ module Inspec::Resources
|
|
12
14
|
end
|
13
15
|
"
|
14
16
|
|
17
|
+
include ObjectTraverser
|
18
|
+
|
15
19
|
# make params readable
|
16
20
|
attr_reader :params
|
17
21
|
|
@@ -59,26 +63,5 @@ module Inspec::Resources
|
|
59
63
|
def to_s
|
60
64
|
"Json #{@path}"
|
61
65
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def extract_value(keys, value)
|
66
|
-
key = keys.shift
|
67
|
-
return nil if key.nil?
|
68
|
-
|
69
|
-
# if value is an array, iterate over each child
|
70
|
-
if value.is_a?(Array)
|
71
|
-
value = value.map { |i|
|
72
|
-
extract_value([key], i)
|
73
|
-
}
|
74
|
-
else
|
75
|
-
value = value[key.to_s].nil? ? nil : value[key.to_s]
|
76
|
-
end
|
77
|
-
|
78
|
-
# if there are no more keys, just return the value
|
79
|
-
return value if keys.first.nil?
|
80
|
-
# if there are more keys, extract more
|
81
|
-
extract_value(keys.clone, value)
|
82
|
-
end
|
83
66
|
end
|
84
67
|
end
|
data/lib/resources/port.rb
CHANGED
@@ -66,6 +66,11 @@ module Inspec::Resources
|
|
66
66
|
res.size > 0 ? res : nil
|
67
67
|
end
|
68
68
|
|
69
|
+
def addresses
|
70
|
+
res = info.map { |x| x[:address] }.uniq.compact
|
71
|
+
res.size > 0 ? res : nil
|
72
|
+
end
|
73
|
+
|
69
74
|
def pids
|
70
75
|
res = info.map { |x| x[:pid] }.uniq.compact
|
71
76
|
res.size > 0 ? res : nil
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
module Inspec::Resources
|
6
|
+
# This resource allows users to run vbscript on windows machines. We decided
|
7
|
+
# not to use scriptcontrol, due to the fact that it works on 32 bit systems only:
|
8
|
+
# $script = new-object -comobject MSScriptControl.ScriptControl
|
9
|
+
# $script.language = "vbscript"
|
10
|
+
# $script.ExecuteStatement($Cmd)
|
11
|
+
#
|
12
|
+
# For that reason, we call csript.exe directy with the script. Vbscript is
|
13
|
+
# embedded in Powershell to ease the file transfer and reuse powershell
|
14
|
+
# encodedCommand since train does not allow file upload yet.
|
15
|
+
#
|
16
|
+
# We run cscript with /nologo option to get the expected output only with the
|
17
|
+
# version information.
|
18
|
+
#
|
19
|
+
# Since Windows does not delete tmp files automatically, we remove the VBScript
|
20
|
+
# after we executed it
|
21
|
+
# @see https://msdn.microsoft.com/en-us/library/aa364991.aspx
|
22
|
+
class VBScript < PowershellScript
|
23
|
+
name 'vbscript'
|
24
|
+
desc ''
|
25
|
+
example "
|
26
|
+
script = <<-EOH
|
27
|
+
# you vbscript
|
28
|
+
EOH
|
29
|
+
|
30
|
+
describe vbscript(script) do
|
31
|
+
its('stdout') { should eq 'output' }
|
32
|
+
end
|
33
|
+
"
|
34
|
+
|
35
|
+
def initialize(vbscript)
|
36
|
+
return skip_resource 'The `vbscript` resource is not supported on your OS yet.' unless inspec.os.windows?
|
37
|
+
|
38
|
+
cmd = <<-EOH
|
39
|
+
$vbscript = @"
|
40
|
+
#{vbscript}
|
41
|
+
"@
|
42
|
+
$filename = [System.IO.Path]::GetTempFileName() + ".vbs"
|
43
|
+
New-Item $filename -type file -force -value $vbscript | Out-Null
|
44
|
+
cscript.exe /nologo $filename
|
45
|
+
Remove-Item $filename | Out-Null
|
46
|
+
EOH
|
47
|
+
super(cmd)
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
'Windows VBScript'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'utils/object_traversal'
|
6
|
+
|
7
|
+
module Inspec::Resources
|
8
|
+
# This resource simplifies the access to wmi
|
9
|
+
# on CLI you would use:
|
10
|
+
# WMIC /NAMESPACE:\\root\rsop\computer PATH RSOP_SecuritySettingNumeric WHERE "KeyName = 'MinimumPasswordAge' And precedence=1" GET Setting
|
11
|
+
# We use Get-WmiObject via Powershell to retrieve all values.
|
12
|
+
class WMI < Inspec.resource(1)
|
13
|
+
name 'wmi'
|
14
|
+
desc 'request wmi information'
|
15
|
+
example "
|
16
|
+
describe wmi('RSOP_SecuritySettingNumeric', {
|
17
|
+
namespace: 'root\\rsop\\computer',
|
18
|
+
filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
|
19
|
+
}) do
|
20
|
+
its('Setting') { should eq true }
|
21
|
+
end
|
22
|
+
"
|
23
|
+
|
24
|
+
include ObjectTraverser
|
25
|
+
attr_accessor :content
|
26
|
+
|
27
|
+
def initialize(wmiclass, opts = {})
|
28
|
+
# verify that this resource is only supported on Windows
|
29
|
+
return skip_resource 'The `windows_feature` resource is not supported on your OS.' unless inspec.os.windows?
|
30
|
+
|
31
|
+
@wmiclass = wmiclass
|
32
|
+
@wminamespace = opts[:namespace]
|
33
|
+
@wmifilter = opts[:filter]
|
34
|
+
end
|
35
|
+
|
36
|
+
# returns nil, if not existant or value
|
37
|
+
def method_missing(*keys)
|
38
|
+
# catch behavior of rspec its implementation
|
39
|
+
# @see https://github.com/rspec/rspec-its/blob/master/lib/rspec/its.rb#L110
|
40
|
+
keys.shift if keys.is_a?(Array) && keys[0] == :[]
|
41
|
+
|
42
|
+
# map all symbols to strings
|
43
|
+
keys = keys.map(&:to_s) if keys.is_a?(Array)
|
44
|
+
|
45
|
+
value(keys)
|
46
|
+
end
|
47
|
+
|
48
|
+
def value(key)
|
49
|
+
extract_value(key, info)
|
50
|
+
end
|
51
|
+
|
52
|
+
def info
|
53
|
+
return @content if defined?(@content)
|
54
|
+
@content = {}
|
55
|
+
|
56
|
+
# we should abort execution, if wmi class is not given or wmi resource is
|
57
|
+
# executed on a non-windows system
|
58
|
+
return @content if @wmiclass.nil?
|
59
|
+
|
60
|
+
# optional params
|
61
|
+
cmd_namespace = "-namespace #{@wminamespace}" unless @wminamespace.nil?
|
62
|
+
cmd_filter = "-filter \"#{@wmifilter}\"" unless @wmifilter.nil?
|
63
|
+
|
64
|
+
# run wmi command
|
65
|
+
cmd = inspec.command("Get-WmiObject -class #{@wmiclass} #{cmd_namespace} #{cmd_filter} | ConvertTo-Json")
|
66
|
+
@content = JSON.parse(cmd.stdout)
|
67
|
+
rescue JSON::ParserError => _e
|
68
|
+
@content
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_s
|
72
|
+
"WMI #{@wmiclass} where #{@wmifilter}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
|
5
|
+
class HashMap
|
6
|
+
class << self
|
7
|
+
def [](hash, *keys)
|
8
|
+
return hash if keys.empty? || hash.nil?
|
9
|
+
key = keys.shift
|
10
|
+
if hash.is_a?(Array)
|
11
|
+
map = hash.map { |i| [i, key] }
|
12
|
+
else
|
13
|
+
map = hash[key]
|
14
|
+
end
|
15
|
+
[map, *keys]
|
16
|
+
rescue NoMethodError => _
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class StringMap
|
23
|
+
class << self
|
24
|
+
def [](hash, *keys)
|
25
|
+
return hash if keys.empty? || hash.nil?
|
26
|
+
key = keys.shift
|
27
|
+
if hash.is_a?(Array)
|
28
|
+
map = hash.map { |i| [i, key] }
|
29
|
+
else
|
30
|
+
map = hash[key]
|
31
|
+
end
|
32
|
+
[map, *keys]
|
33
|
+
rescue NoMethodError => _
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
module ObjectTraverser
|
5
|
+
def extract_value(keys, value)
|
6
|
+
key = keys.shift
|
7
|
+
return nil if key.nil? || value.nil?
|
8
|
+
|
9
|
+
# if value is an array, iterate over each child
|
10
|
+
if value.is_a?(Array)
|
11
|
+
value = value.map { |i|
|
12
|
+
extract_value([key], i)
|
13
|
+
}
|
14
|
+
else
|
15
|
+
value = value[key.to_s].nil? ? nil : value[key.to_s]
|
16
|
+
end
|
17
|
+
|
18
|
+
# if there are no more keys, just return the value
|
19
|
+
return value if keys.first.nil?
|
20
|
+
# if there are more keys, extract more
|
21
|
+
extract_value(keys.clone, value)
|
22
|
+
end
|
23
|
+
end
|
data/test/helper.rb
CHANGED
@@ -237,6 +237,8 @@ class MockLoader
|
|
237
237
|
'netstat -an -f inet -f inet6' => cmd.call('s11-netstat-an-finet-finet6'),
|
238
238
|
# xinetd configuration
|
239
239
|
'find /etc/xinetd.d -type f' => cmd.call('find-xinetd.d'),
|
240
|
+
# wmi test
|
241
|
+
"Get-WmiObject -class win32_service -filter \"name like '%winrm%'\" | ConvertTo-Json" => cmd.call('get-wmiobject'),
|
240
242
|
}
|
241
243
|
|
242
244
|
@backend
|
@@ -3,11 +3,29 @@ script = <<-EOH
|
|
3
3
|
Write-Output 'hello'
|
4
4
|
EOH
|
5
5
|
|
6
|
+
# Write-Output comes with a newline
|
6
7
|
describe powershell(script) do
|
7
|
-
its('stdout') { should eq
|
8
|
+
its('stdout') { should eq "hello\r\n" }
|
9
|
+
its('stderr') { should eq '' }
|
8
10
|
end
|
9
11
|
|
10
|
-
# legacy test
|
12
|
+
# legacy test with `script` resource
|
11
13
|
describe script(script) do
|
14
|
+
its('stdout') { should eq "hello\r\n" }
|
15
|
+
its('stderr') { should eq '' }
|
16
|
+
end
|
17
|
+
|
18
|
+
# -NoNewLine only works in powershell 5
|
19
|
+
# @see https://blogs.technet.microsoft.com/heyscriptingguy/2015/08/07/the-powershell-5-nonewline-parameter/
|
20
|
+
describe powershell("'hello' | Write-Host -NoNewLine") do
|
12
21
|
its('stdout') { should eq 'hello' }
|
22
|
+
its('stderr') { should eq '' }
|
23
|
+
end
|
24
|
+
|
25
|
+
# test stderr
|
26
|
+
describe powershell("Write-Error \"error\"") do
|
27
|
+
its('stdout') { should eq '' }
|
28
|
+
# this is an xml error for now, if the script is run via WinRM
|
29
|
+
# @see https://github.com/WinRb/WinRM/issues/106
|
30
|
+
# its('stderr') { should eq 'error' }
|
13
31
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# script that may have multiple lines
|
4
|
+
vbscript = <<-EOH
|
5
|
+
WScript.Echo "hello"
|
6
|
+
EOH
|
7
|
+
|
8
|
+
describe vbscript(vbscript) do
|
9
|
+
its('stdout') { should eq "hello\r\n" }
|
10
|
+
end
|
11
|
+
|
12
|
+
# ensure that we do not require a newline
|
13
|
+
describe vbscript("Wscript.Stdout.Write \"hello\"") do
|
14
|
+
its('stdout') { should eq 'hello' }
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Get-WmiObject win32_service
|
4
|
+
# Get-WmiObject -class win32_service
|
5
|
+
# returns an array of service objects
|
6
|
+
describe wmi('win32_service') do
|
7
|
+
its(['Path','ClassName']) { should include 'Win32_Service' }
|
8
|
+
its('DisplayName') { should include 'Windows Remote Management (WS-Management)'}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Use win32_service with filter
|
12
|
+
# this returns a single service object
|
13
|
+
describe wmi('win32_service', {
|
14
|
+
filter: "name like '%winrm%'"
|
15
|
+
}) do
|
16
|
+
its(['Path','ClassName']) { should eq 'Win32_Service' }
|
17
|
+
its('DisplayName') { should eq 'Windows Remote Management (WS-Management)'}
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: this works on domain controllers only
|
21
|
+
describe wmi('RSOP_SecuritySettingNumeric', {
|
22
|
+
namespace: 'root\\rsop\\computer',
|
23
|
+
filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
|
24
|
+
}) do
|
25
|
+
its('Setting') { should eq 1 }
|
26
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"Path": {
|
3
|
+
"ClassName": "Win32_Service"
|
4
|
+
},
|
5
|
+
"Caption": "Windows Remote Management (WS-Management)",
|
6
|
+
"CreationClassName": "Win32_Service",
|
7
|
+
"DisplayName": "Windows Remote Management (WS-Management)",
|
8
|
+
"Name": "WinRM",
|
9
|
+
"PathName": "C:\\Windows\\System32\\svchost.exe -k NetworkService"
|
10
|
+
}
|
@@ -12,6 +12,7 @@ describe 'Inspec::Resources::Port' do
|
|
12
12
|
_(resource.protocols).must_equal %w{ tcp tcp6 }
|
13
13
|
_(resource.pids).must_equal [1]
|
14
14
|
_(resource.processes).must_equal ['sshd']
|
15
|
+
_(resource.addresses).must_equal ["0.0.0.0", "::"]
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'verify UDP port on Ubuntu 14.04' do
|
@@ -20,6 +21,7 @@ describe 'Inspec::Resources::Port' do
|
|
20
21
|
_(resource.protocols).must_equal %w{ udp }
|
21
22
|
_(resource.pids).must_equal [545]
|
22
23
|
_(resource.processes).must_equal ['rpcbind']
|
24
|
+
_(resource.addresses).must_equal ["0.0.0.0"]
|
23
25
|
end
|
24
26
|
|
25
27
|
it 'verify port on MacOs x' do
|
@@ -27,6 +29,7 @@ describe 'Inspec::Resources::Port' do
|
|
27
29
|
_(resource.listening?).must_equal true
|
28
30
|
_(resource.protocols).must_equal ['tcp']
|
29
31
|
_(resource.processes).must_equal ['VBoxHeadl']
|
32
|
+
_(resource.addresses).must_equal ["127.0.0.1"]
|
30
33
|
end
|
31
34
|
|
32
35
|
it 'verify port on Windows' do
|
@@ -34,6 +37,7 @@ describe 'Inspec::Resources::Port' do
|
|
34
37
|
_(resource.listening?).must_equal true
|
35
38
|
_(resource.protocols).must_equal ['tcp']
|
36
39
|
_(resource.processes).must_equal nil
|
40
|
+
_(resource.addresses).must_equal ["::", "192.168.10.157"]
|
37
41
|
end
|
38
42
|
|
39
43
|
it 'verify port on FreeBSD' do
|
@@ -42,6 +46,7 @@ describe 'Inspec::Resources::Port' do
|
|
42
46
|
_(resource.protocols).must_equal %w{ tcp6 tcp }
|
43
47
|
_(resource.pids).must_equal [668]
|
44
48
|
_(resource.processes).must_equal ['sshd']
|
49
|
+
_(resource.addresses).must_equal ["0:0:0:0:0:0:0:0", "0.0.0.0"]
|
45
50
|
end
|
46
51
|
|
47
52
|
it 'verify port on wrlinux' do
|
@@ -49,6 +54,7 @@ describe 'Inspec::Resources::Port' do
|
|
49
54
|
_(resource.listening?).must_equal true
|
50
55
|
_(resource.protocols).must_equal %w{ tcp tcp6 }
|
51
56
|
_(resource.processes).must_equal ['sshd']
|
57
|
+
_(resource.addresses).must_equal ["0.0.0.0", "::"]
|
52
58
|
end
|
53
59
|
|
54
60
|
it 'verify running on undefined' do
|
@@ -57,6 +63,7 @@ describe 'Inspec::Resources::Port' do
|
|
57
63
|
_(resource.protocols).must_equal nil
|
58
64
|
_(resource.pids).must_equal nil
|
59
65
|
_(resource.processes).must_equal nil
|
66
|
+
_(resource.addresses).must_equal nil
|
60
67
|
end
|
61
68
|
|
62
69
|
it 'verify port and interface on Ubuntu 14.04' do
|
@@ -65,20 +72,24 @@ describe 'Inspec::Resources::Port' do
|
|
65
72
|
_(resource.protocols).must_equal %w{ tcp }
|
66
73
|
_(resource.pids).must_equal [1]
|
67
74
|
_(resource.processes).must_equal ['sshd']
|
75
|
+
_(resource.addresses).must_equal ["0.0.0.0"]
|
68
76
|
end
|
69
77
|
|
70
78
|
it 'verify not listening port on interface on Ubuntu 14.04' do
|
71
79
|
resource = MockLoader.new(:ubuntu1404).load_resource('port', '127.0.0.1', 22)
|
72
80
|
_(resource.listening?).must_equal false
|
81
|
+
_(resource.addresses).must_equal nil
|
73
82
|
end
|
74
83
|
|
75
84
|
it 'verify port on Solaris 10' do
|
76
85
|
resource = MockLoader.new(:solaris10).load_resource('port', 22)
|
77
86
|
_(resource.listening?).must_equal true
|
87
|
+
_(resource.addresses).must_equal ["0.0.0.0"]
|
78
88
|
end
|
79
89
|
|
80
90
|
it 'verify port on Solaris 11' do
|
81
91
|
resource = MockLoader.new(:solaris11).load_resource('port', 22)
|
82
92
|
_(resource.listening?).must_equal true
|
93
|
+
_(resource.addresses).must_equal ["0.0.0.0"]
|
83
94
|
end
|
84
95
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
require 'inspec/resource'
|
7
|
+
|
8
|
+
describe 'Inspec::Resources::VbScript' do
|
9
|
+
|
10
|
+
vb_script = <<-EOH
|
11
|
+
WScript.Echo "hello vbscript"
|
12
|
+
EOH
|
13
|
+
|
14
|
+
it 'check if `vbscript` for windows is properly generated ' do
|
15
|
+
resource = MockLoader.new(:windows).load_resource('vbscript', vb_script)
|
16
|
+
_(resource.command).must_equal 'powershell -encodedCommand JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQA9ACcAUwBpAGwAZQBuAHQAbAB5AEMAbwBuAHQAaQBuAHUAZQAnADsAJAB2AGIAcwBjAHIAaQBwAHQAIAA9ACAAQAAiAAoAIAAgACAAIABXAFMAYwByAGkAcAB0AC4ARQBjAGgAbwAgACIAaABlAGwAbABvACAAdgBiAHMAYwByAGkAcAB0ACIACgAKACIAQAAKACQAZgBpAGwAZQBuAGEAbQBlACAAPQAgAFsAUwB5AHMAdABlAG0ALgBJAE8ALgBQAGEAdABoAF0AOgA6AEcAZQB0AFQAZQBtAHAARgBpAGwAZQBOAGEAbQBlACgAKQAgACsAIAAiAC4AdgBiAHMAIgAKAE4AZQB3AC0ASQB0AGUAbQAgACQAZgBpAGwAZQBuAGEAbQBlACAALQB0AHkAcABlACAAZgBpAGwAZQAgAC0AZgBvAHIAYwBlACAALQB2AGEAbAB1AGUAIAAkAHYAYgBzAGMAcgBpAHAAdAAgAHwAIABPAHUAdAAtAE4AdQBsAGwACgBjAHMAYwByAGkAcAB0AC4AZQB4AGUAIAAvAG4AbwBsAG8AZwBvACAAJABmAGkAbABlAG4AYQBtAGUACgBSAGUAbQBvAHYAZQAtAEkAdABlAG0AIAAkAGYAaQBsAGUAbgBhAG0AZQAgAHwAIABPAHUAdAAtAE4AdQBsAGwACgA='
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
require 'inspec/resource'
|
7
|
+
|
8
|
+
describe 'Inspec::Resources::WMI' do
|
9
|
+
|
10
|
+
# Check the following as unit test
|
11
|
+
# describe wmi('win32_service', {
|
12
|
+
# filter: "name like '%winrm%'"
|
13
|
+
# }) do
|
14
|
+
# its(['Path','ClassName']) { should eq 'Win32_Service' }
|
15
|
+
# its('DisplayName') { should eq 'Windows Remote Management (WS-Management)'}
|
16
|
+
# end
|
17
|
+
|
18
|
+
# windows
|
19
|
+
it 'verify wmi parsing on windows' do
|
20
|
+
resource = MockLoader.new(:windows).load_resource('wmi', 'win32_service', { filter: "name like '%winrm%'" })
|
21
|
+
_(resource.send('DisplayName')).must_equal 'Windows Remote Management (WS-Management)'
|
22
|
+
_(resource.send('method_missing', 'Path', 'ClassName')).must_equal 'Win32_Service'
|
23
|
+
end
|
24
|
+
|
25
|
+
# ubuntu 14.04 with upstart
|
26
|
+
it 'fail wmi on ubuntu' do
|
27
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('wmi', 'win32_service', { filter: "name like '%winrm%'" })
|
28
|
+
_(resource.send('DisplayName')).must_equal nil
|
29
|
+
_(resource.send('method_missing', 'Path', 'ClassName')).must_equal nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# centos 7 with systemd
|
33
|
+
it 'fail wmi on centos' do
|
34
|
+
resource = MockLoader.new(:centos7).load_resource('wmi', 'win32_service', { filter: "name like '%winrm%'" })
|
35
|
+
_(resource.send('DisplayName')).must_equal nil
|
36
|
+
_(resource.send('method_missing', 'Path', 'ClassName')).must_equal nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# unknown OS
|
40
|
+
it 'fail wmi on unknown os' do
|
41
|
+
resource = MockLoader.new(:undefined).load_resource('wmi', 'win32_service', { filter: "name like '%winrm%'" })
|
42
|
+
_(resource.send('DisplayName')).must_equal nil
|
43
|
+
_(resource.send('method_missing', 'Path', 'ClassName')).must_equal nil
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
require 'utils/hash_map'
|
7
|
+
|
8
|
+
describe HashMap do
|
9
|
+
describe '#get_value' do
|
10
|
+
it 'returns the source value if no keys are given' do
|
11
|
+
x = rand
|
12
|
+
HashMap[x].must_equal x
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'retrieves a key from a map' do
|
16
|
+
x = { a: rand }
|
17
|
+
HashMap[x, :a].must_equal x[:a]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns nil if the key doesnt exist' do
|
21
|
+
x = { a: rand }
|
22
|
+
HashMap[x, :b].must_be :nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can extract a nil key' do
|
26
|
+
x = { nil => rand }
|
27
|
+
HashMap[x, nil].must_equal x[nil]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'extracts multiple keys' do
|
31
|
+
y = rand
|
32
|
+
x = { a: { b: { c: y }}}
|
33
|
+
HashMap[x, :a, :b, :c].must_equal y
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns nil if a key in a list doesnt exist' do
|
37
|
+
x = { a: { b: { c: rand }}}
|
38
|
+
HashMap[x, :d, :b, :c].must_be :nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'retrieves exact keys by string' do
|
42
|
+
x = { a: rand }
|
43
|
+
HashMap[x, :a].must_equal x[:a]
|
44
|
+
HashMap[x, 'a'].must_be :nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'retrieves exact keys by string' do
|
48
|
+
x = { 'a' => rand }
|
49
|
+
HashMap[x, 'a'].must_equal x['a']
|
50
|
+
HashMap[x, :a].must_be :nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'con retrieve string keys' do
|
54
|
+
x = { 'a' => rand }
|
55
|
+
HashMap.extract_keys(x, ['a'], string_keys: true).must_equal x['a']
|
56
|
+
HashMap.extract_keys(x, [:a], string_keys: true).must_equal x['a']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'as an instance' do
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r-train
|
@@ -315,7 +315,9 @@ files:
|
|
315
315
|
- lib/resources/shadow.rb
|
316
316
|
- lib/resources/ssh_conf.rb
|
317
317
|
- lib/resources/user.rb
|
318
|
+
- lib/resources/vbscript.rb
|
318
319
|
- lib/resources/windows_feature.rb
|
320
|
+
- lib/resources/wmi.rb
|
319
321
|
- lib/resources/xinetd.rb
|
320
322
|
- lib/resources/yaml.rb
|
321
323
|
- lib/resources/yum.rb
|
@@ -327,8 +329,10 @@ files:
|
|
327
329
|
- lib/utils/filter_array.rb
|
328
330
|
- lib/utils/find_files.rb
|
329
331
|
- lib/utils/hash.rb
|
332
|
+
- lib/utils/hash_map.rb
|
330
333
|
- lib/utils/json_log.rb
|
331
334
|
- lib/utils/modulator.rb
|
335
|
+
- lib/utils/object_traversal.rb
|
332
336
|
- lib/utils/parser.rb
|
333
337
|
- lib/utils/plugin_registry.rb
|
334
338
|
- lib/utils/simpleconfig.rb
|
@@ -382,6 +386,8 @@ files:
|
|
382
386
|
- test/integration/default/secpol_spec.rb
|
383
387
|
- test/integration/default/service_spec.rb
|
384
388
|
- test/integration/default/user_spec.rb
|
389
|
+
- test/integration/default/vbscript_spec.rb
|
390
|
+
- test/integration/default/wmi_spec.rb
|
385
391
|
- test/integration/default/yaml_spec.rb
|
386
392
|
- test/resource/command_test.rb
|
387
393
|
- test/resource/dsl_test.rb
|
@@ -426,6 +432,7 @@ files:
|
|
426
432
|
- test/unit/mock/cmd/get-package-ruby
|
427
433
|
- test/unit/mock/cmd/get-service-dhcp
|
428
434
|
- test/unit/mock/cmd/get-windows-feature
|
435
|
+
- test/unit/mock/cmd/get-wmiobject
|
429
436
|
- test/unit/mock/cmd/getent-hosts-example.com
|
430
437
|
- test/unit/mock/cmd/getent-passwd-jfolmer
|
431
438
|
- test/unit/mock/cmd/getent-passwd-root
|
@@ -547,7 +554,9 @@ files:
|
|
547
554
|
- test/unit/resources/shadow_test.rb
|
548
555
|
- test/unit/resources/ssh_conf_test.rb
|
549
556
|
- test/unit/resources/user_test.rb
|
557
|
+
- test/unit/resources/vbscript_test.rb
|
550
558
|
- test/unit/resources/windows_feature.rb
|
559
|
+
- test/unit/resources/wmi_test.rb
|
551
560
|
- test/unit/resources/xinetd_test.rb
|
552
561
|
- test/unit/resources/yaml_test.rb
|
553
562
|
- test/unit/resources/yum_test.rb
|
@@ -556,6 +565,7 @@ files:
|
|
556
565
|
- test/unit/source_readers/inspec_test.rb
|
557
566
|
- test/unit/utils/filter_array_test.rb
|
558
567
|
- test/unit/utils/find_files_test.rb
|
568
|
+
- test/unit/utils/hash_map_test.rb
|
559
569
|
- test/unit/utils/passwd_parser_test.rb
|
560
570
|
- test/unit/utils/simpleconfig_test.rb
|
561
571
|
- test/unit/utils/solaris_netstat_parser.rb
|
@@ -633,6 +643,8 @@ test_files:
|
|
633
643
|
- test/integration/default/secpol_spec.rb
|
634
644
|
- test/integration/default/service_spec.rb
|
635
645
|
- test/integration/default/user_spec.rb
|
646
|
+
- test/integration/default/vbscript_spec.rb
|
647
|
+
- test/integration/default/wmi_spec.rb
|
636
648
|
- test/integration/default/yaml_spec.rb
|
637
649
|
- test/resource/command_test.rb
|
638
650
|
- test/resource/dsl_test.rb
|
@@ -677,6 +689,7 @@ test_files:
|
|
677
689
|
- test/unit/mock/cmd/get-package-ruby
|
678
690
|
- test/unit/mock/cmd/get-service-dhcp
|
679
691
|
- test/unit/mock/cmd/get-windows-feature
|
692
|
+
- test/unit/mock/cmd/get-wmiobject
|
680
693
|
- test/unit/mock/cmd/getent-hosts-example.com
|
681
694
|
- test/unit/mock/cmd/getent-passwd-jfolmer
|
682
695
|
- test/unit/mock/cmd/getent-passwd-root
|
@@ -798,7 +811,9 @@ test_files:
|
|
798
811
|
- test/unit/resources/shadow_test.rb
|
799
812
|
- test/unit/resources/ssh_conf_test.rb
|
800
813
|
- test/unit/resources/user_test.rb
|
814
|
+
- test/unit/resources/vbscript_test.rb
|
801
815
|
- test/unit/resources/windows_feature.rb
|
816
|
+
- test/unit/resources/wmi_test.rb
|
802
817
|
- test/unit/resources/xinetd_test.rb
|
803
818
|
- test/unit/resources/yaml_test.rb
|
804
819
|
- test/unit/resources/yum_test.rb
|
@@ -807,6 +822,7 @@ test_files:
|
|
807
822
|
- test/unit/source_readers/inspec_test.rb
|
808
823
|
- test/unit/utils/filter_array_test.rb
|
809
824
|
- test/unit/utils/find_files_test.rb
|
825
|
+
- test/unit/utils/hash_map_test.rb
|
810
826
|
- test/unit/utils/passwd_parser_test.rb
|
811
827
|
- test/unit/utils/simpleconfig_test.rb
|
812
828
|
- test/unit/utils/solaris_netstat_parser.rb
|