inspec 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -2
- data/README.md +27 -2
- data/docs/resources.rst +49 -3
- data/inspec.gemspec +1 -1
- data/lib/bundles/inspec-compliance/README.md +2 -1
- data/lib/bundles/inspec-compliance/api.rb +60 -102
- data/lib/bundles/inspec-compliance/cli.rb +133 -14
- data/lib/bundles/inspec-compliance/configuration.rb +43 -1
- data/lib/bundles/inspec-compliance/http.rb +80 -0
- data/lib/bundles/inspec-compliance.rb +1 -0
- data/lib/inspec/metadata.rb +40 -27
- data/lib/inspec/objects/test.rb +2 -1
- data/lib/inspec/resource.rb +1 -0
- data/lib/inspec/rspec_json_formatter.rb +1 -1
- data/lib/inspec/runner.rb +19 -13
- data/lib/inspec/runner_rspec.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/matchers/matchers.rb +32 -13
- data/lib/resources/grub_conf.rb +186 -0
- data/lib/resources/json.rb +1 -1
- data/lib/resources/service.rb +9 -3
- data/lib/utils/base_cli.rb +2 -1
- data/lib/utils/hash_map.rb +37 -0
- data/test/functional/inspec_compliance_test.rb +60 -0
- data/test/functional/inspec_exec_test.rb +49 -10
- data/test/helper.rb +3 -0
- data/test/integration/default/compare_matcher_spec.rb +21 -0
- data/test/unit/metadata_test.rb +49 -23
- data/test/unit/mock/cmd/systemctl-show-all-dbus +6 -0
- data/test/unit/mock/files/grub.conf +21 -0
- data/test/unit/mock/profiles/resource-tiny/inspec.yml +10 -0
- data/test/unit/mock/profiles/resource-tiny/libraries/resource.rb +3 -0
- data/test/unit/mock/profiles/supported_inspec/inspec.yml +2 -0
- data/test/unit/mock/profiles/unsupported_inspec/inspec.yml +2 -0
- data/test/unit/profile_test.rb +1 -1
- data/test/unit/resources/grub_conf_test.rb +29 -0
- data/test/unit/resources/service_test.rb +9 -0
- data/test/unit/utils/hash_map_test.rb +63 -0
- metadata +26 -5
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
|
5
|
+
require 'functional/helper'
|
6
|
+
|
7
|
+
# basic testing without availability of any server
|
8
|
+
describe 'inspec compliance' do
|
9
|
+
include FunctionalHelper
|
10
|
+
|
11
|
+
it 'help' do
|
12
|
+
out = inspec('compliance help')
|
13
|
+
out.exit_status.must_equal 0
|
14
|
+
out.stdout.must_include 'inspec compliance exec PROFILE'
|
15
|
+
end
|
16
|
+
|
17
|
+
# ensure we are logged out
|
18
|
+
it 'logout' do
|
19
|
+
out = inspec('compliance logout')
|
20
|
+
out.exit_status.must_equal 0
|
21
|
+
out.stdout.must_include ''
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'login server url missing' do
|
25
|
+
out = inspec('compliance login')
|
26
|
+
#TODO: we need to convince thor that this is an error
|
27
|
+
out.exit_status.must_equal 0
|
28
|
+
out.stderr.must_include 'ERROR: "inspec login" was called with no arguments'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'login server with missing parameters' do
|
32
|
+
out = inspec('compliance login http://example.com')
|
33
|
+
out.exit_status.must_equal 1
|
34
|
+
#TODO: inspec should really use stderr for errors
|
35
|
+
out.stdout.must_include 'Please run `inspec compliance login` with options'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'inspec compliance profiles without authentication' do
|
39
|
+
out = inspec('compliance profile')
|
40
|
+
out.exit_status.must_equal 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'try to upload a profile without directory' do
|
44
|
+
out = inspec('compliance upload')
|
45
|
+
out.stderr.must_include 'ERROR: "inspec upload" was called with no arguments'
|
46
|
+
out.exit_status.must_equal 0
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'try to upload a profile a non-existing path' do
|
50
|
+
out = inspec('compliance upload /path/to/dir')
|
51
|
+
out.stdout.must_include 'Directory /path/to/dir does not exist.'
|
52
|
+
out.exit_status.must_equal 1
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'logout' do
|
56
|
+
out = inspec('compliance logout')
|
57
|
+
out.exit_status.must_equal 0
|
58
|
+
out.stdout.must_include ''
|
59
|
+
end
|
60
|
+
end
|
@@ -29,6 +29,29 @@ describe 'inspec exec' do
|
|
29
29
|
JSON.load(out.stdout).must_be_kind_of Hash
|
30
30
|
end
|
31
31
|
|
32
|
+
let(:example_control) { File.join(example_profile, 'controls', 'example.rb') }
|
33
|
+
|
34
|
+
it 'can execute a simple file with the default formatter' do
|
35
|
+
out = inspec('exec ' + example_control)
|
36
|
+
out.stderr.must_equal ''
|
37
|
+
out.exit_status.must_equal 0
|
38
|
+
out.stdout.must_include '2 examples, 0 failures'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'can execute a simple file with the json formatter' do
|
42
|
+
out = inspec('exec ' + example_control + ' --format json')
|
43
|
+
out.stderr.must_equal ''
|
44
|
+
out.exit_status.must_equal 0
|
45
|
+
JSON.load(out.stdout).must_be_kind_of Hash
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'can execute a simple file with the fulljson formatter' do
|
49
|
+
out = inspec('exec ' + example_control + ' --format fulljson')
|
50
|
+
out.stderr.must_equal ''
|
51
|
+
out.exit_status.must_equal 0
|
52
|
+
JSON.load(out.stdout).must_be_kind_of Hash
|
53
|
+
end
|
54
|
+
|
32
55
|
describe 'execute a profile with json formatting' do
|
33
56
|
let(:json) { JSON.load(inspec('exec ' + example_profile + ' --format json').stdout) }
|
34
57
|
let(:examples) { json['examples'] }
|
@@ -138,26 +161,42 @@ describe 'inspec exec' do
|
|
138
161
|
end
|
139
162
|
end
|
140
163
|
|
164
|
+
describe 'with a profile that is not supported on this OS/platform' do
|
165
|
+
let(:out) { inspec('exec ' + File.join(profile_path, 'skippy-profile-os')) }
|
166
|
+
let(:json) { JSON.load(out.stdout) }
|
167
|
+
|
168
|
+
it 'exits with an error' do
|
169
|
+
out.stderr.must_match /^This OS\/platform \(.+\) is not supported by this profile.$/
|
170
|
+
out.exit_status.must_equal 1
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
141
174
|
describe 'with a profile that is not supported on this OS/platform' do
|
142
175
|
let(:out) { inspec('exec ' + File.join(profile_path, 'skippy-profile-os') + ' --format fulljson') }
|
143
176
|
let(:json) { JSON.load(out.stdout) }
|
144
177
|
|
178
|
+
# TODO: failure handling in json formatters...
|
179
|
+
|
180
|
+
it 'never runs the actual resource' do
|
181
|
+
File.exist?('/tmp/inspec_test_DONT_CREATE').must_equal false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'with a profile that is supported on this version of inspec' do
|
186
|
+
let(:out) { inspec('exec ' + File.join(profile_path, 'supported_inspec')) }
|
187
|
+
|
145
188
|
it 'exits cleanly' do
|
146
189
|
out.stderr.must_equal ''
|
147
190
|
out.exit_status.must_equal 0
|
148
191
|
end
|
192
|
+
end
|
149
193
|
|
150
|
-
|
151
|
-
|
152
|
-
json['summary']['example_count'].must_equal 1
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'delivers the pending message' do
|
156
|
-
json['examples'][0]['pending'].must_match %r{^This OS/platform \([^)]+\) is not supported by this profile\.$}
|
157
|
-
end
|
194
|
+
describe 'with a profile that is not supported on this version of inspec' do
|
195
|
+
let(:out) { inspec('exec ' + File.join(profile_path, 'unsupported_inspec')) }
|
158
196
|
|
159
|
-
it '
|
160
|
-
|
197
|
+
it 'does not support this profile' do
|
198
|
+
out.exit_status.must_equal 1
|
199
|
+
out.stderr.must_equal "This profile requires InSpec version >= 99.0.0. You are running InSpec v#{Inspec::VERSION}.\n"
|
161
200
|
end
|
162
201
|
end
|
163
202
|
end
|
data/test/helper.rb
CHANGED
@@ -106,6 +106,7 @@ class MockLoader
|
|
106
106
|
'/etc/security/limits.conf' => mockfile.call('limits.conf'),
|
107
107
|
'/etc/inetd.conf' => mockfile.call('inetd.conf'),
|
108
108
|
'/etc/group' => mockfile.call('etcgroup'),
|
109
|
+
'/etc/grub.conf' => mockfile.call('grub.conf'),
|
109
110
|
'/etc/audit/auditd.conf' => mockfile.call('auditd.conf'),
|
110
111
|
'/etc/mysql/my.cnf' => mockfile.call('mysql.conf'),
|
111
112
|
'/etc/mysql/mysql2.conf' => mockfile.call('mysql2.conf'),
|
@@ -178,6 +179,8 @@ class MockLoader
|
|
178
179
|
# show ssh service Centos 7
|
179
180
|
'systemctl show --all sshd' => cmd.call('systemctl-show-all-sshd'),
|
180
181
|
'/path/to/systemctl show --all sshd' => cmd.call('systemctl-show-all-sshd'),
|
182
|
+
'systemctl show --all dbus' => cmd.call('systemctl-show-all-dbus'),
|
183
|
+
'/path/to/systemctl show --all dbus' => cmd.call('systemctl-show-all-dbus'),
|
181
184
|
# services on macos
|
182
185
|
'launchctl list' => cmd.call('launchctl-list'),
|
183
186
|
# services on freebsd 10
|
@@ -34,4 +34,25 @@ if os.linux?
|
|
34
34
|
describe len do
|
35
35
|
it { should cmp len.to_s }
|
36
36
|
end
|
37
|
+
|
38
|
+
describe '12' do
|
39
|
+
it { should cmp < 13 }
|
40
|
+
it { should cmp > 11 }
|
41
|
+
it { should_not cmp < 12 }
|
42
|
+
it { should_not cmp > 12 }
|
43
|
+
it { should cmp <= 12 }
|
44
|
+
it { should cmp >= 12 }
|
45
|
+
it { should_not cmp <= 11 }
|
46
|
+
it { should_not cmp >= 13 }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '' do
|
50
|
+
it { should_not cmp >= 3 }
|
51
|
+
it { should_not cmp < 3 }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe nil do
|
55
|
+
it { should_not cmp >= 3 }
|
56
|
+
it { should_not cmp < 3 }
|
57
|
+
end
|
37
58
|
end
|
data/test/unit/metadata_test.rb
CHANGED
@@ -8,6 +8,14 @@ require 'inspec/metadata'
|
|
8
8
|
describe 'metadata with supported operating systems' do
|
9
9
|
let(:logger) { Minitest::Mock.new }
|
10
10
|
|
11
|
+
def supports_meta(params)
|
12
|
+
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
|
13
|
+
# manually inject supported parameters
|
14
|
+
res.params[:supports] = params
|
15
|
+
Inspec::Metadata.finalize(res, 'mock', logger)
|
16
|
+
res
|
17
|
+
end
|
18
|
+
|
11
19
|
describe 'running on ubuntu 14.04' do
|
12
20
|
let (:backend) { MockLoader.new(:ubuntu1404).backend }
|
13
21
|
|
@@ -32,74 +40,92 @@ describe 'metadata with supported operating systems' do
|
|
32
40
|
it 'loads the support field from metadata' do
|
33
41
|
res = Inspec::Metadata.from_yaml('mock',
|
34
42
|
"---\nsupports:\n - os: ubuntu", nil)
|
35
|
-
res.params[:supports].must_equal([{
|
36
|
-
end
|
37
|
-
|
38
|
-
# Description of method
|
39
|
-
#
|
40
|
-
# @param [Type] params describe params
|
41
|
-
# @return [Type] description of returned object
|
42
|
-
def create_meta(params)
|
43
|
-
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
|
44
|
-
# manually inject supported parameters
|
45
|
-
res.params[:supports] = params
|
46
|
-
Inspec::Metadata.finalize(res, 'mock')
|
47
|
-
res
|
43
|
+
res.params[:supports].must_equal([{ os: 'ubuntu' }])
|
48
44
|
end
|
49
45
|
|
50
46
|
it 'load a profile with empty supports clause' do
|
51
|
-
m =
|
47
|
+
m = supports_meta(nil)
|
52
48
|
m.supports_transport?(backend).must_equal true
|
53
49
|
end
|
54
50
|
|
55
51
|
it 'supports legacy simple support style, but warns' do
|
56
52
|
# i.e. setting this to something that would fail:
|
57
|
-
m = create_meta('linux')
|
58
53
|
logger.expect :warn, nil, [
|
59
54
|
'Do not use deprecated `supports: linux` '\
|
60
55
|
'syntax. Instead use `supports: {os-family: linux}`.']
|
56
|
+
m = supports_meta('linux')
|
61
57
|
m.supports_transport?(backend).must_equal true
|
62
58
|
logger.verify
|
63
59
|
end
|
64
60
|
|
65
61
|
it 'loads a profile which supports os ubuntu' do
|
66
|
-
m =
|
62
|
+
m = supports_meta({ 'os' => 'ubuntu' })
|
67
63
|
m.supports_transport?(backend).must_equal true
|
68
64
|
end
|
69
65
|
|
70
66
|
it 'loads a profile which supports os name ubuntu' do
|
71
|
-
m =
|
67
|
+
m = supports_meta({ 'os-name' => 'ubuntu' })
|
72
68
|
m.supports_transport?(backend).must_equal true
|
73
69
|
end
|
74
70
|
|
75
71
|
it 'loads a profile which supports os family linux' do
|
76
|
-
m =
|
72
|
+
m = supports_meta({ 'os-family' => 'linux' })
|
77
73
|
m.supports_transport?(backend).must_equal true
|
78
74
|
end
|
79
75
|
|
80
76
|
it 'loads a profile which supports release 14.04' do
|
81
|
-
m =
|
77
|
+
m = supports_meta({ 'release' => '14.04' })
|
82
78
|
m.supports_transport?(backend).must_equal true
|
83
79
|
end
|
84
80
|
|
85
81
|
it 'rejects a profile which supports release 12.04' do
|
86
|
-
m =
|
82
|
+
m = supports_meta({ 'release' => '12.04' })
|
87
83
|
m.supports_transport?(backend).must_equal false
|
88
84
|
end
|
89
85
|
|
90
86
|
it 'loads a profile which supports ubuntu 14.04' do
|
91
|
-
m =
|
87
|
+
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.04' })
|
92
88
|
m.supports_transport?(backend).must_equal true
|
93
89
|
end
|
94
90
|
|
95
91
|
it 'rejects a profile which supports ubuntu 12.04' do
|
96
|
-
m =
|
92
|
+
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.04' })
|
97
93
|
m.supports_transport?(backend).must_equal false
|
98
94
|
end
|
99
95
|
|
100
96
|
it 'reject unsupported os' do
|
101
|
-
m =
|
97
|
+
m = supports_meta({ 'os-name' => 'windows' })
|
102
98
|
m.supports_transport?(backend).must_equal false
|
103
99
|
end
|
104
100
|
end
|
101
|
+
|
102
|
+
describe 'testing the supported runtime' do
|
103
|
+
let(:current_version) { Inspec::VERSION }
|
104
|
+
let(:next_version) { current_version.sub(/\.\d+$/) { |num| num.to_i.next } }
|
105
|
+
|
106
|
+
it 'returns true on testing the current version' do
|
107
|
+
m = supports_meta({ 'inspec' => current_version })
|
108
|
+
m.supports_runtime?.must_equal true
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns true on testing the current version' do
|
112
|
+
m = supports_meta({ 'inspec' => '= ' + current_version })
|
113
|
+
m.supports_runtime?.must_equal true
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'returns true on testing >= current version' do
|
117
|
+
m = supports_meta({ 'inspec' => '>= ' + current_version })
|
118
|
+
m.supports_runtime?.must_equal true
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns false on testing >= the next version' do
|
122
|
+
m = supports_meta({ 'inspec' => '>= ' + next_version })
|
123
|
+
m.supports_runtime?.must_equal false
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns false on testing > the next version' do
|
127
|
+
m = supports_meta({ 'inspec' => '> ' + next_version })
|
128
|
+
m.supports_runtime?.must_equal false
|
129
|
+
end
|
130
|
+
end
|
105
131
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# grub.conf generated by anaconda
|
2
|
+
#
|
3
|
+
# Note that you do not have to rerun grub after making changes to this file
|
4
|
+
# NOTICE: You have a /boot partition. This means that
|
5
|
+
# all kernel and initrd paths are relative to /boot/, eg.
|
6
|
+
# root (hd0,0)
|
7
|
+
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
|
8
|
+
# initrd /initrd-[generic-]version.img
|
9
|
+
#boot=/dev/sda
|
10
|
+
default=0
|
11
|
+
timeout=5
|
12
|
+
splashimage=(hd0,0)/grub/splash.xpm.gz
|
13
|
+
hiddenmenu
|
14
|
+
title CentOS (2.6.32-573.7.1.el6.x86_64)
|
15
|
+
root (hd0,0)
|
16
|
+
kernel /vmlinuz-2.6.32-573.7.1.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_GB.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet audit=1
|
17
|
+
initrd /initramfs-2.6.32-573.7.1.el6.x86_64.img
|
18
|
+
title CentOS 6 (2.6.32-573.el6.x86_64)
|
19
|
+
root (hd0,0)
|
20
|
+
kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_GB.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet audit=1
|
21
|
+
initrd /initramfs-2.6.32-573.el6.x86_64.img
|
@@ -0,0 +1,10 @@
|
|
1
|
+
name: complete
|
2
|
+
title: complete example profile
|
3
|
+
maintainer: Chef Software, Inc.
|
4
|
+
copyright: Chef Software, Inc.
|
5
|
+
copyright_email: support@chef.io
|
6
|
+
license: Proprietary, All rights reserved
|
7
|
+
summary: Testing stub
|
8
|
+
version: 1.0.0
|
9
|
+
supports:
|
10
|
+
- os-family: linux
|
data/test/unit/profile_test.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Thomas Cate
|
3
|
+
|
4
|
+
require 'helper'
|
5
|
+
require 'inspec/resource'
|
6
|
+
|
7
|
+
describe 'Inspec::Resources::GrubConfig' do
|
8
|
+
|
9
|
+
it 'verify kernel include' do
|
10
|
+
resource = MockLoader.new(:centos6).load_resource('grub_conf')
|
11
|
+
_(resource.kernel).must_be_kind_of Array
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'verify initrd include' do
|
15
|
+
resource = MockLoader.new(:centos6).load_resource('grub_conf')
|
16
|
+
_(resource.initrd).must_be_kind_of String
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'verify default' do
|
20
|
+
resource = MockLoader.new(:centos6).load_resource('grub_conf')
|
21
|
+
_(resource.default).must_equal '0'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'verify timeout' do
|
25
|
+
resource = MockLoader.new(:centos6).load_resource('grub_conf')
|
26
|
+
_(resource.timeout).must_equal '5'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -94,6 +94,15 @@ describe 'Inspec::Resources::Service' do
|
|
94
94
|
_(resource.running?).must_equal true
|
95
95
|
end
|
96
96
|
|
97
|
+
it 'verify centos 7 package parsing with static loaded service' do
|
98
|
+
resource = MockLoader.new(:centos7).load_resource('service', 'dbus')
|
99
|
+
srv = { name: 'dbus.service', description: 'D-Bus System Message Bus', installed: true, running: true, enabled: true, type: 'systemd' }
|
100
|
+
_(resource.info).must_equal srv
|
101
|
+
_(resource.installed?).must_equal true
|
102
|
+
_(resource.enabled?).must_equal true
|
103
|
+
_(resource.running?).must_equal true
|
104
|
+
end
|
105
|
+
|
97
106
|
# freebsd
|
98
107
|
it 'verify freebsd10 package parsing' do
|
99
108
|
resource = MockLoader.new(:freebsd10).load_resource('service', 'sendmail')
|
@@ -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.
|
4
|
+
version: 0.19.0
|
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-04-
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r-train
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3
|
103
|
+
version: '3'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3
|
110
|
+
version: '3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec-its
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- lib/bundles/inspec-compliance/api.rb
|
219
219
|
- lib/bundles/inspec-compliance/cli.rb
|
220
220
|
- lib/bundles/inspec-compliance/configuration.rb
|
221
|
+
- lib/bundles/inspec-compliance/http.rb
|
221
222
|
- lib/bundles/inspec-compliance/target.rb
|
222
223
|
- lib/bundles/inspec-init.rb
|
223
224
|
- lib/bundles/inspec-init/cli.rb
|
@@ -286,6 +287,7 @@ files:
|
|
286
287
|
- lib/resources/file.rb
|
287
288
|
- lib/resources/gem.rb
|
288
289
|
- lib/resources/group.rb
|
290
|
+
- lib/resources/grub_conf.rb
|
289
291
|
- lib/resources/host.rb
|
290
292
|
- lib/resources/inetd_conf.rb
|
291
293
|
- lib/resources/ini.rb
|
@@ -335,6 +337,7 @@ files:
|
|
335
337
|
- lib/utils/filter_array.rb
|
336
338
|
- lib/utils/find_files.rb
|
337
339
|
- lib/utils/hash.rb
|
340
|
+
- lib/utils/hash_map.rb
|
338
341
|
- lib/utils/json_log.rb
|
339
342
|
- lib/utils/modulator.rb
|
340
343
|
- lib/utils/object_traversal.rb
|
@@ -368,6 +371,7 @@ files:
|
|
368
371
|
- test/functional/helper.rb
|
369
372
|
- test/functional/inheritance_test.rb
|
370
373
|
- test/functional/inspec_archive_test.rb
|
374
|
+
- test/functional/inspec_compliance_test.rb
|
371
375
|
- test/functional/inspec_exec_test.rb
|
372
376
|
- test/functional/inspec_json_test.rb
|
373
377
|
- test/functional/inspec_test.rb
|
@@ -479,6 +483,7 @@ files:
|
|
479
483
|
- test/unit/mock/cmd/service-sshd-status
|
480
484
|
- test/unit/mock/cmd/sockstat
|
481
485
|
- test/unit/mock/cmd/success
|
486
|
+
- test/unit/mock/cmd/systemctl-show-all-dbus
|
482
487
|
- test/unit/mock/cmd/systemctl-show-all-sshd
|
483
488
|
- test/unit/mock/cmd/win32_product
|
484
489
|
- test/unit/mock/cmd/yum-repolist-all
|
@@ -487,6 +492,7 @@ files:
|
|
487
492
|
- test/unit/mock/files/bond0
|
488
493
|
- test/unit/mock/files/etcgroup
|
489
494
|
- test/unit/mock/files/example.csv
|
495
|
+
- test/unit/mock/files/grub.conf
|
490
496
|
- test/unit/mock/files/inetd.conf
|
491
497
|
- test/unit/mock/files/kitchen.yml
|
492
498
|
- test/unit/mock/files/limits.conf
|
@@ -517,9 +523,13 @@ files:
|
|
517
523
|
- test/unit/mock/profiles/legacy-empty-metadata/metadata.rb
|
518
524
|
- test/unit/mock/profiles/legacy-simple-metadata/metadata.rb
|
519
525
|
- test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep
|
526
|
+
- test/unit/mock/profiles/resource-tiny/inspec.yml
|
527
|
+
- test/unit/mock/profiles/resource-tiny/libraries/resource.rb
|
520
528
|
- test/unit/mock/profiles/simple-metadata/inspec.yml
|
521
529
|
- test/unit/mock/profiles/skippy-profile-os/controls/one.rb
|
522
530
|
- test/unit/mock/profiles/skippy-profile-os/inspec.yml
|
531
|
+
- test/unit/mock/profiles/supported_inspec/inspec.yml
|
532
|
+
- test/unit/mock/profiles/unsupported_inspec/inspec.yml
|
523
533
|
- test/unit/plugin_test.rb
|
524
534
|
- test/unit/plugins/resource_test.rb
|
525
535
|
- test/unit/profile_context_test.rb
|
@@ -536,6 +546,7 @@ files:
|
|
536
546
|
- test/unit/resources/file_test.rb
|
537
547
|
- test/unit/resources/gem_test.rb
|
538
548
|
- test/unit/resources/group_test.rb
|
549
|
+
- test/unit/resources/grub_conf_test.rb
|
539
550
|
- test/unit/resources/host_test.rb
|
540
551
|
- test/unit/resources/inetd_conf_test.rb
|
541
552
|
- test/unit/resources/ini_test.rb
|
@@ -575,6 +586,7 @@ files:
|
|
575
586
|
- test/unit/source_readers/inspec_test.rb
|
576
587
|
- test/unit/utils/filter_array_test.rb
|
577
588
|
- test/unit/utils/find_files_test.rb
|
589
|
+
- test/unit/utils/hash_map_test.rb
|
578
590
|
- test/unit/utils/passwd_parser_test.rb
|
579
591
|
- test/unit/utils/simpleconfig_test.rb
|
580
592
|
- test/unit/utils/solaris_netstat_parser.rb
|
@@ -598,7 +610,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
598
610
|
version: '0'
|
599
611
|
requirements: []
|
600
612
|
rubyforge_project:
|
601
|
-
rubygems_version: 2.
|
613
|
+
rubygems_version: 2.5.1
|
602
614
|
signing_key:
|
603
615
|
specification_version: 4
|
604
616
|
summary: Infrastructure and compliance testing.
|
@@ -629,6 +641,7 @@ test_files:
|
|
629
641
|
- test/functional/helper.rb
|
630
642
|
- test/functional/inheritance_test.rb
|
631
643
|
- test/functional/inspec_archive_test.rb
|
644
|
+
- test/functional/inspec_compliance_test.rb
|
632
645
|
- test/functional/inspec_exec_test.rb
|
633
646
|
- test/functional/inspec_json_test.rb
|
634
647
|
- test/functional/inspec_test.rb
|
@@ -740,6 +753,7 @@ test_files:
|
|
740
753
|
- test/unit/mock/cmd/service-sshd-status
|
741
754
|
- test/unit/mock/cmd/sockstat
|
742
755
|
- test/unit/mock/cmd/success
|
756
|
+
- test/unit/mock/cmd/systemctl-show-all-dbus
|
743
757
|
- test/unit/mock/cmd/systemctl-show-all-sshd
|
744
758
|
- test/unit/mock/cmd/win32_product
|
745
759
|
- test/unit/mock/cmd/yum-repolist-all
|
@@ -748,6 +762,7 @@ test_files:
|
|
748
762
|
- test/unit/mock/files/bond0
|
749
763
|
- test/unit/mock/files/etcgroup
|
750
764
|
- test/unit/mock/files/example.csv
|
765
|
+
- test/unit/mock/files/grub.conf
|
751
766
|
- test/unit/mock/files/inetd.conf
|
752
767
|
- test/unit/mock/files/kitchen.yml
|
753
768
|
- test/unit/mock/files/limits.conf
|
@@ -778,9 +793,13 @@ test_files:
|
|
778
793
|
- test/unit/mock/profiles/legacy-empty-metadata/metadata.rb
|
779
794
|
- test/unit/mock/profiles/legacy-simple-metadata/metadata.rb
|
780
795
|
- test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep
|
796
|
+
- test/unit/mock/profiles/resource-tiny/inspec.yml
|
797
|
+
- test/unit/mock/profiles/resource-tiny/libraries/resource.rb
|
781
798
|
- test/unit/mock/profiles/simple-metadata/inspec.yml
|
782
799
|
- test/unit/mock/profiles/skippy-profile-os/controls/one.rb
|
783
800
|
- test/unit/mock/profiles/skippy-profile-os/inspec.yml
|
801
|
+
- test/unit/mock/profiles/supported_inspec/inspec.yml
|
802
|
+
- test/unit/mock/profiles/unsupported_inspec/inspec.yml
|
784
803
|
- test/unit/plugin_test.rb
|
785
804
|
- test/unit/plugins/resource_test.rb
|
786
805
|
- test/unit/profile_context_test.rb
|
@@ -797,6 +816,7 @@ test_files:
|
|
797
816
|
- test/unit/resources/file_test.rb
|
798
817
|
- test/unit/resources/gem_test.rb
|
799
818
|
- test/unit/resources/group_test.rb
|
819
|
+
- test/unit/resources/grub_conf_test.rb
|
800
820
|
- test/unit/resources/host_test.rb
|
801
821
|
- test/unit/resources/inetd_conf_test.rb
|
802
822
|
- test/unit/resources/ini_test.rb
|
@@ -836,6 +856,7 @@ test_files:
|
|
836
856
|
- test/unit/source_readers/inspec_test.rb
|
837
857
|
- test/unit/utils/filter_array_test.rb
|
838
858
|
- test/unit/utils/find_files_test.rb
|
859
|
+
- test/unit/utils/hash_map_test.rb
|
839
860
|
- test/unit/utils/passwd_parser_test.rb
|
840
861
|
- test/unit/utils/simpleconfig_test.rb
|
841
862
|
- test/unit/utils/solaris_netstat_parser.rb
|