inspec 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +65 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +33 -0
- data/LICENSE +201 -0
- data/MAINTAINERS.md +28 -0
- data/MAINTAINERS.toml +42 -0
- data/README.md +257 -0
- data/Rakefile +47 -0
- data/bin/inspec +109 -0
- data/docs/ctl_inspec.rst +195 -0
- data/docs/dsl_inspec.rst +182 -0
- data/docs/readme.rst +100 -0
- data/docs/resources.rst +4319 -0
- data/docs/template.rst +51 -0
- data/examples/test-kitchen/.kitchen.yml +20 -0
- data/examples/test-kitchen/Berksfile +3 -0
- data/examples/test-kitchen/Gemfile +21 -0
- data/examples/test-kitchen/README.md +27 -0
- data/examples/test-kitchen/metadata.rb +7 -0
- data/examples/test-kitchen/recipes/default.rb +6 -0
- data/examples/test-kitchen/recipes/nginx.rb +30 -0
- data/examples/test-kitchen/test/integration/default/web_spec.rb +28 -0
- data/inspec.gemspec +30 -0
- data/lib/inspec.rb +20 -0
- data/lib/inspec/backend.rb +42 -0
- data/lib/inspec/dsl.rb +151 -0
- data/lib/inspec/log.rb +34 -0
- data/lib/inspec/metadata.rb +79 -0
- data/lib/inspec/plugins.rb +9 -0
- data/lib/inspec/plugins/resource.rb +62 -0
- data/lib/inspec/profile.rb +138 -0
- data/lib/inspec/profile_context.rb +170 -0
- data/lib/inspec/resource.rb +76 -0
- data/lib/inspec/rspec_json_formatter.rb +27 -0
- data/lib/inspec/rule.rb +170 -0
- data/lib/inspec/runner.rb +154 -0
- data/lib/inspec/shell.rb +66 -0
- data/lib/inspec/targets.rb +9 -0
- data/lib/inspec/targets/core.rb +27 -0
- data/lib/inspec/targets/dir.rb +67 -0
- data/lib/inspec/targets/file.rb +29 -0
- data/lib/inspec/targets/folder.rb +43 -0
- data/lib/inspec/targets/tar.rb +34 -0
- data/lib/inspec/targets/url.rb +39 -0
- data/lib/inspec/targets/zip.rb +47 -0
- data/lib/inspec/version.rb +7 -0
- data/lib/matchers/matchers.rb +221 -0
- data/lib/resources/apache.rb +29 -0
- data/lib/resources/apache_conf.rb +113 -0
- data/lib/resources/apt.rb +140 -0
- data/lib/resources/audit_policy.rb +63 -0
- data/lib/resources/auditd_conf.rb +56 -0
- data/lib/resources/auditd_rules.rb +53 -0
- data/lib/resources/bond.rb +65 -0
- data/lib/resources/bridge.rb +114 -0
- data/lib/resources/command.rb +57 -0
- data/lib/resources/csv.rb +32 -0
- data/lib/resources/directory.rb +15 -0
- data/lib/resources/etc_group.rb +150 -0
- data/lib/resources/file.rb +110 -0
- data/lib/resources/gem.rb +46 -0
- data/lib/resources/group.rb +132 -0
- data/lib/resources/host.rb +143 -0
- data/lib/resources/inetd_conf.rb +56 -0
- data/lib/resources/interface.rb +127 -0
- data/lib/resources/iptables.rb +65 -0
- data/lib/resources/json.rb +64 -0
- data/lib/resources/kernel_module.rb +40 -0
- data/lib/resources/kernel_parameter.rb +55 -0
- data/lib/resources/limits_conf.rb +55 -0
- data/lib/resources/login_def.rb +60 -0
- data/lib/resources/mysql.rb +81 -0
- data/lib/resources/mysql_conf.rb +116 -0
- data/lib/resources/mysql_session.rb +52 -0
- data/lib/resources/npm.rb +44 -0
- data/lib/resources/ntp_conf.rb +58 -0
- data/lib/resources/oneget.rb +63 -0
- data/lib/resources/os.rb +22 -0
- data/lib/resources/os_env.rb +34 -0
- data/lib/resources/package.rb +169 -0
- data/lib/resources/parse_config.rb +75 -0
- data/lib/resources/passwd.rb +93 -0
- data/lib/resources/pip.rb +75 -0
- data/lib/resources/port.rb +296 -0
- data/lib/resources/postgres.rb +37 -0
- data/lib/resources/postgres_conf.rb +87 -0
- data/lib/resources/postgres_session.rb +59 -0
- data/lib/resources/processes.rb +57 -0
- data/lib/resources/registry_key.rb +54 -0
- data/lib/resources/script.rb +34 -0
- data/lib/resources/security_policy.rb +73 -0
- data/lib/resources/service.rb +379 -0
- data/lib/resources/ssh_conf.rb +75 -0
- data/lib/resources/user.rb +374 -0
- data/lib/resources/windows_feature.rb +77 -0
- data/lib/resources/yaml.rb +23 -0
- data/lib/resources/yum.rb +154 -0
- data/lib/utils/convert.rb +12 -0
- data/lib/utils/detect.rb +15 -0
- data/lib/utils/find_files.rb +36 -0
- data/lib/utils/hash.rb +13 -0
- data/lib/utils/modulator.rb +12 -0
- data/lib/utils/parser.rb +61 -0
- data/lib/utils/simpleconfig.rb +115 -0
- data/tasks/maintainers.rb +213 -0
- data/test/docker_run.rb +156 -0
- data/test/docker_test.rb +51 -0
- data/test/helper.rb +200 -0
- data/test/integration/.kitchen.yml +42 -0
- data/test/integration/Berksfile +4 -0
- data/test/integration/cookbooks/os_prepare/metadata.rb +8 -0
- data/test/integration/cookbooks/os_prepare/recipes/apt.rb +20 -0
- data/test/integration/cookbooks/os_prepare/recipes/default.rb +9 -0
- data/test/integration/cookbooks/os_prepare/recipes/file.rb +21 -0
- data/test/integration/cookbooks/os_prepare/recipes/package.rb +26 -0
- data/test/integration/default/_debug_spec.rb +1 -0
- data/test/integration/default/apt_spec.rb +42 -0
- data/test/integration/default/file_spec.rb +109 -0
- data/test/integration/default/group_spec.rb +32 -0
- data/test/integration/default/kernel_module_spec.rb +17 -0
- data/test/integration/default/kernel_parameter_spec.rb +56 -0
- data/test/integration/default/package_spec.rb +11 -0
- data/test/integration/default/service_spec.rb +28 -0
- data/test/integration/default/user_spec.rb +44 -0
- data/test/resource/command_test.rb +33 -0
- data/test/resource/dsl_test.rb +45 -0
- data/test/resource/file_test.rb +130 -0
- data/test/resource/ssh_config.rb +9 -0
- data/test/resource/sshd_config.rb +9 -0
- data/test/test-extra.yaml +11 -0
- data/test/test.yaml +11 -0
- data/test/unit/mock/cmd/Get-NetAdapter +24 -0
- data/test/unit/mock/cmd/GetUserAccount +33 -0
- data/test/unit/mock/cmd/GetWin32Group +23 -0
- data/test/unit/mock/cmd/PATH +1 -0
- data/test/unit/mock/cmd/Resolve-DnsName +26 -0
- data/test/unit/mock/cmd/Test-NetConnection +4 -0
- data/test/unit/mock/cmd/auditctl +7 -0
- data/test/unit/mock/cmd/auditpol +2 -0
- data/test/unit/mock/cmd/brew-info-jq +1 -0
- data/test/unit/mock/cmd/chage-l-root +7 -0
- data/test/unit/mock/cmd/dpkg-s-curl +21 -0
- data/test/unit/mock/cmd/dscl +5 -0
- data/test/unit/mock/cmd/etc-apt +7 -0
- data/test/unit/mock/cmd/find-etc-rc-d-name-S +12 -0
- data/test/unit/mock/cmd/find-net-interface +9 -0
- data/test/unit/mock/cmd/gem-list-local-a-q-rubocop +1 -0
- data/test/unit/mock/cmd/get-net-tcpconnection +24 -0
- data/test/unit/mock/cmd/get-netadapter-binding-bridge +4 -0
- data/test/unit/mock/cmd/get-package-firefox +30 -0
- data/test/unit/mock/cmd/get-package-ruby +18 -0
- data/test/unit/mock/cmd/get-service-dhcp +10 -0
- data/test/unit/mock/cmd/get-windows-feature +7 -0
- data/test/unit/mock/cmd/getent-hosts-example.com +1 -0
- data/test/unit/mock/cmd/getent-passwd-root +1 -0
- data/test/unit/mock/cmd/id-chartmann +1 -0
- data/test/unit/mock/cmd/id-root +1 -0
- data/test/unit/mock/cmd/initctl-show-config-ssh +3 -0
- data/test/unit/mock/cmd/initctl-status-ssh +1 -0
- data/test/unit/mock/cmd/iptables-s +6 -0
- data/test/unit/mock/cmd/launchctl-list +3 -0
- data/test/unit/mock/cmd/ls-1-etc-init.d +2 -0
- data/test/unit/mock/cmd/ls-sys-class-net-br +2 -0
- data/test/unit/mock/cmd/lsmod +2 -0
- data/test/unit/mock/cmd/lsof-np-itcp +4 -0
- data/test/unit/mock/cmd/netstat-tulpen +5 -0
- data/test/unit/mock/cmd/npm-ls-g--json-bower +9 -0
- data/test/unit/mock/cmd/pacman-qi-curl +21 -0
- data/test/unit/mock/cmd/ping-example.com +6 -0
- data/test/unit/mock/cmd/pip-show-jinja2 +11 -0
- data/test/unit/mock/cmd/ps-aux +3 -0
- data/test/unit/mock/cmd/pw-usershow-root-7 +1 -0
- data/test/unit/mock/cmd/reg_schedule +1 -0
- data/test/unit/mock/cmd/rpm-qia-curl +24 -0
- data/test/unit/mock/cmd/sbin_sysctl +1 -0
- data/test/unit/mock/cmd/secedit-export +7 -0
- data/test/unit/mock/cmd/service-e +2 -0
- data/test/unit/mock/cmd/service-sendmail-onestatus +3 -0
- data/test/unit/mock/cmd/service-sshd-status +1 -0
- data/test/unit/mock/cmd/sockstat +5 -0
- data/test/unit/mock/cmd/success +0 -0
- data/test/unit/mock/cmd/systemctl-show-all-sshd +6 -0
- data/test/unit/mock/cmd/win32_product +8 -0
- data/test/unit/mock/cmd/yum-repolist-all +52 -0
- data/test/unit/mock/files/auditd.conf +4 -0
- data/test/unit/mock/files/bond0 +37 -0
- data/test/unit/mock/files/etcgroup +3 -0
- data/test/unit/mock/files/example.csv +6 -0
- data/test/unit/mock/files/inetd.conf +2 -0
- data/test/unit/mock/files/kitchen.yml +7 -0
- data/test/unit/mock/files/limits.conf +5 -0
- data/test/unit/mock/files/login.defs +5 -0
- data/test/unit/mock/files/mysql.conf +8 -0
- data/test/unit/mock/files/mysql2.conf +2 -0
- data/test/unit/mock/files/ntp.conf +5 -0
- data/test/unit/mock/files/passwd +2 -0
- data/test/unit/mock/files/policyfile.lock.json +12 -0
- data/test/unit/mock/files/ssh_config +5 -0
- data/test/unit/mock/files/sshd_config +7 -0
- data/test/unit/mock/profiles/empty/metadata.rb +0 -0
- data/test/unit/mock/profiles/metadata/metadata.rb +1 -0
- data/test/unit/profile_context_test.rb +140 -0
- data/test/unit/profile_test.rb +49 -0
- data/test/unit/resources/apt_test.rb +46 -0
- data/test/unit/resources/audit_policy_test.rb +13 -0
- data/test/unit/resources/auditd_conf_test.rb +15 -0
- data/test/unit/resources/auditd_rules_test.rb +21 -0
- data/test/unit/resources/bond_test.rb +24 -0
- data/test/unit/resources/bridge_test.rb +56 -0
- data/test/unit/resources/csv_test.rb +35 -0
- data/test/unit/resources/etc_group_test.rb +37 -0
- data/test/unit/resources/gem_test.rb +20 -0
- data/test/unit/resources/group_test.rb +96 -0
- data/test/unit/resources/host_test.rb +38 -0
- data/test/unit/resources/inetd_conf_test.rb +15 -0
- data/test/unit/resources/interface_test.rb +54 -0
- data/test/unit/resources/iptables_test.rb +30 -0
- data/test/unit/resources/json_test.rb +36 -0
- data/test/unit/resources/kernel_module_test.rb +23 -0
- data/test/unit/resources/kernel_parameter_test.rb +13 -0
- data/test/unit/resources/limits_conf_test.rb +14 -0
- data/test/unit/resources/login_def_test.rb +16 -0
- data/test/unit/resources/mysql_conf_test.rb +14 -0
- data/test/unit/resources/npm_test.rb +20 -0
- data/test/unit/resources/ntp_conf_test.rb +16 -0
- data/test/unit/resources/oneget_test.rb +45 -0
- data/test/unit/resources/os_env_test.rb +13 -0
- data/test/unit/resources/package_test.rb +51 -0
- data/test/unit/resources/passwd_test.rb +24 -0
- data/test/unit/resources/pip_test.rb +15 -0
- data/test/unit/resources/port_test.rb +46 -0
- data/test/unit/resources/processes_test.rb +32 -0
- data/test/unit/resources/registry_key_test.rb +19 -0
- data/test/unit/resources/script_test.rb +19 -0
- data/test/unit/resources/security_policy_test.rb +16 -0
- data/test/unit/resources/service_test.rb +116 -0
- data/test/unit/resources/ssh_conf_test.rb +33 -0
- data/test/unit/resources/user_test.rb +93 -0
- data/test/unit/resources/windows_feature.rb +17 -0
- data/test/unit/resources/yaml_test.rb +34 -0
- data/test/unit/resources/yum_test.rb +68 -0
- data/test/unit/simpleconfig_test.rb +80 -0
- data/test/unit/utils/content_parser_test.rb +30 -0
- metadata +555 -0
@@ -0,0 +1,56 @@
|
|
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::Bridge' do
|
9
|
+
|
10
|
+
it 'check linux bridge on ubuntu' do
|
11
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('bridge', 'br0')
|
12
|
+
_(resource.exists?).must_equal true
|
13
|
+
|
14
|
+
# check network interfaced attached to bridge
|
15
|
+
_(resource.has_interface?('eth0')).must_equal false
|
16
|
+
_(resource.has_interface?('eth1')).must_equal true
|
17
|
+
_(resource.has_interface?('eth2')).must_equal true
|
18
|
+
|
19
|
+
# get associated interfaces
|
20
|
+
_(resource.interfaces).must_equal %w{eth1 eth2}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'check linux bridge on centos 7' do
|
24
|
+
resource = MockLoader.new(:centos7).load_resource('bridge', 'br0')
|
25
|
+
_(resource.exists?).must_equal true
|
26
|
+
|
27
|
+
# check network interfaced attached to bridge
|
28
|
+
_(resource.has_interface?('eth0')).must_equal false
|
29
|
+
_(resource.has_interface?('eth1')).must_equal true
|
30
|
+
_(resource.has_interface?('eth2')).must_equal true
|
31
|
+
|
32
|
+
# get associated interfaces
|
33
|
+
_(resource.interfaces).must_equal %w{eth1 eth2}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'check windows bridge' do
|
37
|
+
resource = MockLoader.new(:windows).load_resource('bridge', 'Network Bridge')
|
38
|
+
_(resource.exists?).must_equal true
|
39
|
+
|
40
|
+
# get associated interfaces is not supported on windows
|
41
|
+
_(resource.interfaces).must_equal nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'check bridge on unsupported os' do
|
45
|
+
resource = MockLoader.new(:undefined).load_resource('bridge', 'br0')
|
46
|
+
_(resource.exists?).must_equal false
|
47
|
+
|
48
|
+
# check network interfaced attached to bridge
|
49
|
+
_(resource.has_interface?('eth0')).must_equal false
|
50
|
+
_(resource.has_interface?('eth1')).must_equal false
|
51
|
+
_(resource.has_interface?('eth2')).must_equal false
|
52
|
+
|
53
|
+
# get associated interfaces
|
54
|
+
_(resource.interfaces).must_equal nil
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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::CSV' do
|
9
|
+
describe 'when loading a valid csv' do
|
10
|
+
let (:resource) { load_resource('csv', 'example.csv') }
|
11
|
+
let (:params) {
|
12
|
+
{}
|
13
|
+
}
|
14
|
+
|
15
|
+
it 'captures an array of params' do
|
16
|
+
_(resource.params).must_be_kind_of Array
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'gets all value lines' do
|
20
|
+
_(resource.params.length).must_equal 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'captures a hashmap of entries of a line' do
|
24
|
+
_(resource.params[0]).must_be_kind_of Hash
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gets params by header fields' do
|
28
|
+
_(resource.params[0]['addressable']).must_equal 'ast'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'retrieves nil if a param is missing' do
|
32
|
+
_(resource.params[0]['missing']).must_be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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::EtcGroup' do
|
9
|
+
let(:resource) { load_resource('etc_group') }
|
10
|
+
|
11
|
+
it 'verify /etc/group config parsing' do
|
12
|
+
_(resource.gids).must_equal [0, 33]
|
13
|
+
_(resource.groups).must_equal %w{ root www-data }
|
14
|
+
_(resource.users).must_equal %w{ www-data root }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'verify group filter with no users' do
|
18
|
+
root_filter = resource.where(name: 'root')
|
19
|
+
_(root_filter.gids).must_equal [0]
|
20
|
+
_(root_filter.groups).must_equal ['root']
|
21
|
+
_(root_filter.users).must_equal []
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'verify group filter with users' do
|
25
|
+
www_filter = resource.where(name: 'www-data')
|
26
|
+
_(www_filter.gids).must_equal [33]
|
27
|
+
_(www_filter.groups).must_equal ['www-data']
|
28
|
+
_(www_filter.users).must_equal ['www-data', 'root']
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'verify group filter with wrong group' do
|
32
|
+
wrong_filter = resource.where(name: 'wrong_group')
|
33
|
+
_(wrong_filter.gids).must_equal []
|
34
|
+
_(wrong_filter.groups).must_equal []
|
35
|
+
_(wrong_filter.users).must_equal []
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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::Gem' do
|
9
|
+
it 'verify gem package detail parsing' do
|
10
|
+
resource = load_resource('gem', 'rubocop')
|
11
|
+
pkg = {
|
12
|
+
name: 'rubocop',
|
13
|
+
version: '0.33.0',
|
14
|
+
type: 'gem',
|
15
|
+
installed: true,
|
16
|
+
}
|
17
|
+
_(resource.installed?).must_equal true
|
18
|
+
_(resource.info).must_equal pkg
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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::Group' do
|
9
|
+
|
10
|
+
# ubuntu 14.04
|
11
|
+
it 'verify group on ubuntu' do
|
12
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('group', 'root')
|
13
|
+
_(resource.exists?).must_equal true
|
14
|
+
_(resource.gid).must_equal 0
|
15
|
+
_(resource.has_gid?(0)).must_equal true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'verify group on ubuntu with UPPER CASE' do
|
19
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('group', 'ROOT')
|
20
|
+
_(resource.exists?).must_equal true
|
21
|
+
_(resource.gid).must_equal 0
|
22
|
+
_(resource.has_gid?(0)).must_equal true
|
23
|
+
end
|
24
|
+
|
25
|
+
# ubuntu with non-existent group
|
26
|
+
it 'verify group on ubuntu' do
|
27
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('group', 'nogroup')
|
28
|
+
_(resource.exists?).must_equal false
|
29
|
+
_(resource.gid).must_equal nil
|
30
|
+
_(resource.has_gid?(0)).must_equal false
|
31
|
+
end
|
32
|
+
|
33
|
+
# mac
|
34
|
+
it 'verify group on mac' do
|
35
|
+
resource = MockLoader.new(:osx104).load_resource('group', 'root')
|
36
|
+
_(resource.exists?).must_equal true
|
37
|
+
_(resource.gid).must_equal 0
|
38
|
+
_(resource.has_gid?(0)).must_equal true
|
39
|
+
end
|
40
|
+
|
41
|
+
# freebsd
|
42
|
+
it 'verify group on freebsd' do
|
43
|
+
resource = MockLoader.new(:freebsd10).load_resource('group', 'root')
|
44
|
+
_(resource.exists?).must_equal true
|
45
|
+
_(resource.gid).must_equal 0
|
46
|
+
_(resource.has_gid?(0)).must_equal true
|
47
|
+
end
|
48
|
+
|
49
|
+
# windows with local group
|
50
|
+
it 'verify group on windows' do
|
51
|
+
resource = MockLoader.new(:windows).load_resource('group', 'Administrators')
|
52
|
+
_(resource.exists?).must_equal true
|
53
|
+
_(resource.gid).must_equal nil
|
54
|
+
_(resource.has_gid?(0)).must_equal false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'verify group on windows' do
|
58
|
+
resource = MockLoader.new(:windows).load_resource('group', 'Administrators', 'WIN-K0AKLED332V')
|
59
|
+
_(resource.exists?).must_equal true
|
60
|
+
_(resource.gid).must_equal nil
|
61
|
+
_(resource.has_gid?(0)).must_equal false
|
62
|
+
end
|
63
|
+
|
64
|
+
# windows with domain group
|
65
|
+
it 'verify domain group on windows' do
|
66
|
+
resource = MockLoader.new(:windows).load_resource('group', 'Domain Admins', 'EXAMPLE')
|
67
|
+
_(resource.exists?).must_equal true
|
68
|
+
_(resource.gid).must_equal nil
|
69
|
+
_(resource.has_gid?(0)).must_equal false
|
70
|
+
end
|
71
|
+
|
72
|
+
# windows with domain group
|
73
|
+
it 'verify domain group on windows wiht lower case' do
|
74
|
+
resource = MockLoader.new(:windows).load_resource('group', 'domain admins', 'example')
|
75
|
+
_(resource.exists?).must_equal true
|
76
|
+
_(resource.gid).must_equal nil
|
77
|
+
_(resource.has_gid?(0)).must_equal false
|
78
|
+
end
|
79
|
+
|
80
|
+
# windows non-existent group
|
81
|
+
it 'verify non-existing group on windows' do
|
82
|
+
resource = MockLoader.new(:windows).load_resource('group', 'dhcp')
|
83
|
+
_(resource.exists?).must_equal false
|
84
|
+
_(resource.gid).must_equal nil
|
85
|
+
_(resource.has_gid?(0)).must_equal false
|
86
|
+
end
|
87
|
+
|
88
|
+
# undefined
|
89
|
+
it 'verify package handling on unsupported os' do
|
90
|
+
resource = MockLoader.new(:undefined).load_resource('group', 'root')
|
91
|
+
_(resource.exists?).must_equal false
|
92
|
+
_(resource.gid).must_equal nil
|
93
|
+
_(resource.has_gid?(0)).must_equal false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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::Host' do
|
9
|
+
|
10
|
+
it 'check host on ubuntu' do
|
11
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('host', 'example.com')
|
12
|
+
_(resource.resolvable?).must_equal true
|
13
|
+
_(resource.reachable?).must_equal true
|
14
|
+
_(resource.ipaddress).must_equal ['2606:2800:220:1:248:1893:25c8:1946']
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'check host on centos 7' do
|
18
|
+
resource = MockLoader.new(:centos7).load_resource('host', 'example.com')
|
19
|
+
_(resource.resolvable?).must_equal true
|
20
|
+
_(resource.reachable?).must_equal true
|
21
|
+
_(resource.ipaddress).must_equal ['2606:2800:220:1:248:1893:25c8:1946']
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'check host on windows' do
|
25
|
+
resource = MockLoader.new(:windows).load_resource('host', 'microsoft.com')
|
26
|
+
_(resource.resolvable?).must_equal true
|
27
|
+
_(resource.reachable?).must_equal false
|
28
|
+
_(resource.ipaddress).must_equal ['134.170.185.46', '134.170.188.221']
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'check host on unsupported os' do
|
32
|
+
resource = MockLoader.new(:undefined).load_resource('host', 'example.com')
|
33
|
+
_(resource.resolvable?).must_equal false
|
34
|
+
_(resource.reachable?).must_equal false
|
35
|
+
_(resource.ipaddress).must_equal nil
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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::InetdConf' do
|
9
|
+
it 'verify limits.conf config parsing' do
|
10
|
+
resource = load_resource('inetd_conf')
|
11
|
+
_(resource.send('shell')).must_equal nil
|
12
|
+
_(resource.send('login')).must_equal nil
|
13
|
+
_(resource.send('ftp')).must_equal %w{stream tcp nowait root /usr/sbin/in.ftpd in.ftpd}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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::Interface' do
|
9
|
+
|
10
|
+
# ubuntu 14.04
|
11
|
+
it 'verify interface on ubuntu' do
|
12
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('interface', 'eth0')
|
13
|
+
_(resource.exists?).must_equal true
|
14
|
+
_(resource.up?).must_equal true
|
15
|
+
_(resource.speed).must_equal 10000
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'verify invalid interface on ubuntu' do
|
19
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('interface', 'eth1')
|
20
|
+
_(resource.exists?).must_equal false
|
21
|
+
_(resource.up?).must_equal false
|
22
|
+
_(resource.speed).must_equal nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'verify interface on windows' do
|
26
|
+
resource = MockLoader.new(:windows).load_resource('interface', 'ethernet0')
|
27
|
+
_(resource.exists?).must_equal true
|
28
|
+
_(resource.up?).must_equal false
|
29
|
+
_(resource.speed).must_equal 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'verify interface on windows' do
|
33
|
+
resource = MockLoader.new(:windows).load_resource('interface', 'vEthernet (Intel(R) PRO 1000 MT Network Connection - Virtual Switch)')
|
34
|
+
_(resource.exists?).must_equal true
|
35
|
+
_(resource.up?).must_equal true
|
36
|
+
_(resource.speed).must_equal 10000000
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'verify invalid interface on windows' do
|
40
|
+
resource = MockLoader.new(:windows).load_resource('interface', 'eth1')
|
41
|
+
_(resource.exists?).must_equal false
|
42
|
+
_(resource.up?).must_equal false
|
43
|
+
_(resource.speed).must_equal nil
|
44
|
+
end
|
45
|
+
|
46
|
+
# undefined
|
47
|
+
it 'verify interface on unsupported os' do
|
48
|
+
resource = MockLoader.new(:undefined).load_resource('interface', 'eth0')
|
49
|
+
_(resource.exists?).must_equal false
|
50
|
+
_(resource.up?).must_equal false
|
51
|
+
_(resource.speed).must_equal nil
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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::Iptables' do
|
9
|
+
|
10
|
+
# ubuntu 14.04
|
11
|
+
it 'verify iptables on ubuntu' do
|
12
|
+
resource = MockLoader.new(:ubuntu1404).load_resource('iptables')
|
13
|
+
_(resource.has_rule?('-P OUTPUT ACCEPT')).must_equal true
|
14
|
+
_(resource.has_rule?('-P OUTPUT DROP')).must_equal false
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'verify iptables on windows' do
|
18
|
+
resource = MockLoader.new(:windows).load_resource('iptables')
|
19
|
+
_(resource.has_rule?('-P OUTPUT ACCEPT')).must_equal false
|
20
|
+
_(resource.has_rule?('-P OUTPUT DROP')).must_equal false
|
21
|
+
end
|
22
|
+
|
23
|
+
# undefined
|
24
|
+
it 'verify iptables on unsupported os' do
|
25
|
+
resource = MockLoader.new(:undefined).load_resource('iptables')
|
26
|
+
_(resource.has_rule?('-P OUTPUT ACCEPT')).must_equal false
|
27
|
+
_(resource.has_rule?('-P OUTPUT DROP')).must_equal false
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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::JSON' do
|
9
|
+
describe 'when loading a valid json' do
|
10
|
+
let (:resource) { load_resource('json', 'policyfile.lock.json') }
|
11
|
+
|
12
|
+
it 'gets params as a hashmap' do
|
13
|
+
_(resource.params).must_be_kind_of Hash
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'retrieves nil if a param is missing' do
|
17
|
+
_(resource.params['missing']).must_be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'retrieves params by name' do
|
21
|
+
_(resource.send('name')).must_equal 'demo'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'retrieves an array by name' do
|
25
|
+
_(resource.send('run_list')).must_equal %w{a b}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'doesnt resolve dot-notation names' do
|
29
|
+
_(resource.send('x.y.z')).must_be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'doesnt resolve symbol-notation names' do
|
33
|
+
_(resource.send(:'x.y.z')).must_be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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::KernelModule' do
|
9
|
+
it 'verify kernel_module parsing' do
|
10
|
+
resource = load_resource('kernel_module', 'bridge')
|
11
|
+
_(resource.loaded?).must_equal true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'verify kernel_module parsing' do
|
15
|
+
resource = load_resource('kernel_module', 'bridges')
|
16
|
+
_(resource.loaded?).must_equal false
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'verify kernel_module parsing' do
|
20
|
+
resource = load_resource('kernel_module', 'dhcp')
|
21
|
+
_(resource.loaded?).must_equal false
|
22
|
+
end
|
23
|
+
end
|