inspec 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +65 -0
  4. data/.travis.yml +23 -0
  5. data/CHANGELOG.md +38 -0
  6. data/Gemfile +33 -0
  7. data/LICENSE +201 -0
  8. data/MAINTAINERS.md +28 -0
  9. data/MAINTAINERS.toml +42 -0
  10. data/README.md +257 -0
  11. data/Rakefile +47 -0
  12. data/bin/inspec +109 -0
  13. data/docs/ctl_inspec.rst +195 -0
  14. data/docs/dsl_inspec.rst +182 -0
  15. data/docs/readme.rst +100 -0
  16. data/docs/resources.rst +4319 -0
  17. data/docs/template.rst +51 -0
  18. data/examples/test-kitchen/.kitchen.yml +20 -0
  19. data/examples/test-kitchen/Berksfile +3 -0
  20. data/examples/test-kitchen/Gemfile +21 -0
  21. data/examples/test-kitchen/README.md +27 -0
  22. data/examples/test-kitchen/metadata.rb +7 -0
  23. data/examples/test-kitchen/recipes/default.rb +6 -0
  24. data/examples/test-kitchen/recipes/nginx.rb +30 -0
  25. data/examples/test-kitchen/test/integration/default/web_spec.rb +28 -0
  26. data/inspec.gemspec +30 -0
  27. data/lib/inspec.rb +20 -0
  28. data/lib/inspec/backend.rb +42 -0
  29. data/lib/inspec/dsl.rb +151 -0
  30. data/lib/inspec/log.rb +34 -0
  31. data/lib/inspec/metadata.rb +79 -0
  32. data/lib/inspec/plugins.rb +9 -0
  33. data/lib/inspec/plugins/resource.rb +62 -0
  34. data/lib/inspec/profile.rb +138 -0
  35. data/lib/inspec/profile_context.rb +170 -0
  36. data/lib/inspec/resource.rb +76 -0
  37. data/lib/inspec/rspec_json_formatter.rb +27 -0
  38. data/lib/inspec/rule.rb +170 -0
  39. data/lib/inspec/runner.rb +154 -0
  40. data/lib/inspec/shell.rb +66 -0
  41. data/lib/inspec/targets.rb +9 -0
  42. data/lib/inspec/targets/core.rb +27 -0
  43. data/lib/inspec/targets/dir.rb +67 -0
  44. data/lib/inspec/targets/file.rb +29 -0
  45. data/lib/inspec/targets/folder.rb +43 -0
  46. data/lib/inspec/targets/tar.rb +34 -0
  47. data/lib/inspec/targets/url.rb +39 -0
  48. data/lib/inspec/targets/zip.rb +47 -0
  49. data/lib/inspec/version.rb +7 -0
  50. data/lib/matchers/matchers.rb +221 -0
  51. data/lib/resources/apache.rb +29 -0
  52. data/lib/resources/apache_conf.rb +113 -0
  53. data/lib/resources/apt.rb +140 -0
  54. data/lib/resources/audit_policy.rb +63 -0
  55. data/lib/resources/auditd_conf.rb +56 -0
  56. data/lib/resources/auditd_rules.rb +53 -0
  57. data/lib/resources/bond.rb +65 -0
  58. data/lib/resources/bridge.rb +114 -0
  59. data/lib/resources/command.rb +57 -0
  60. data/lib/resources/csv.rb +32 -0
  61. data/lib/resources/directory.rb +15 -0
  62. data/lib/resources/etc_group.rb +150 -0
  63. data/lib/resources/file.rb +110 -0
  64. data/lib/resources/gem.rb +46 -0
  65. data/lib/resources/group.rb +132 -0
  66. data/lib/resources/host.rb +143 -0
  67. data/lib/resources/inetd_conf.rb +56 -0
  68. data/lib/resources/interface.rb +127 -0
  69. data/lib/resources/iptables.rb +65 -0
  70. data/lib/resources/json.rb +64 -0
  71. data/lib/resources/kernel_module.rb +40 -0
  72. data/lib/resources/kernel_parameter.rb +55 -0
  73. data/lib/resources/limits_conf.rb +55 -0
  74. data/lib/resources/login_def.rb +60 -0
  75. data/lib/resources/mysql.rb +81 -0
  76. data/lib/resources/mysql_conf.rb +116 -0
  77. data/lib/resources/mysql_session.rb +52 -0
  78. data/lib/resources/npm.rb +44 -0
  79. data/lib/resources/ntp_conf.rb +58 -0
  80. data/lib/resources/oneget.rb +63 -0
  81. data/lib/resources/os.rb +22 -0
  82. data/lib/resources/os_env.rb +34 -0
  83. data/lib/resources/package.rb +169 -0
  84. data/lib/resources/parse_config.rb +75 -0
  85. data/lib/resources/passwd.rb +93 -0
  86. data/lib/resources/pip.rb +75 -0
  87. data/lib/resources/port.rb +296 -0
  88. data/lib/resources/postgres.rb +37 -0
  89. data/lib/resources/postgres_conf.rb +87 -0
  90. data/lib/resources/postgres_session.rb +59 -0
  91. data/lib/resources/processes.rb +57 -0
  92. data/lib/resources/registry_key.rb +54 -0
  93. data/lib/resources/script.rb +34 -0
  94. data/lib/resources/security_policy.rb +73 -0
  95. data/lib/resources/service.rb +379 -0
  96. data/lib/resources/ssh_conf.rb +75 -0
  97. data/lib/resources/user.rb +374 -0
  98. data/lib/resources/windows_feature.rb +77 -0
  99. data/lib/resources/yaml.rb +23 -0
  100. data/lib/resources/yum.rb +154 -0
  101. data/lib/utils/convert.rb +12 -0
  102. data/lib/utils/detect.rb +15 -0
  103. data/lib/utils/find_files.rb +36 -0
  104. data/lib/utils/hash.rb +13 -0
  105. data/lib/utils/modulator.rb +12 -0
  106. data/lib/utils/parser.rb +61 -0
  107. data/lib/utils/simpleconfig.rb +115 -0
  108. data/tasks/maintainers.rb +213 -0
  109. data/test/docker_run.rb +156 -0
  110. data/test/docker_test.rb +51 -0
  111. data/test/helper.rb +200 -0
  112. data/test/integration/.kitchen.yml +42 -0
  113. data/test/integration/Berksfile +4 -0
  114. data/test/integration/cookbooks/os_prepare/metadata.rb +8 -0
  115. data/test/integration/cookbooks/os_prepare/recipes/apt.rb +20 -0
  116. data/test/integration/cookbooks/os_prepare/recipes/default.rb +9 -0
  117. data/test/integration/cookbooks/os_prepare/recipes/file.rb +21 -0
  118. data/test/integration/cookbooks/os_prepare/recipes/package.rb +26 -0
  119. data/test/integration/default/_debug_spec.rb +1 -0
  120. data/test/integration/default/apt_spec.rb +42 -0
  121. data/test/integration/default/file_spec.rb +109 -0
  122. data/test/integration/default/group_spec.rb +32 -0
  123. data/test/integration/default/kernel_module_spec.rb +17 -0
  124. data/test/integration/default/kernel_parameter_spec.rb +56 -0
  125. data/test/integration/default/package_spec.rb +11 -0
  126. data/test/integration/default/service_spec.rb +28 -0
  127. data/test/integration/default/user_spec.rb +44 -0
  128. data/test/resource/command_test.rb +33 -0
  129. data/test/resource/dsl_test.rb +45 -0
  130. data/test/resource/file_test.rb +130 -0
  131. data/test/resource/ssh_config.rb +9 -0
  132. data/test/resource/sshd_config.rb +9 -0
  133. data/test/test-extra.yaml +11 -0
  134. data/test/test.yaml +11 -0
  135. data/test/unit/mock/cmd/Get-NetAdapter +24 -0
  136. data/test/unit/mock/cmd/GetUserAccount +33 -0
  137. data/test/unit/mock/cmd/GetWin32Group +23 -0
  138. data/test/unit/mock/cmd/PATH +1 -0
  139. data/test/unit/mock/cmd/Resolve-DnsName +26 -0
  140. data/test/unit/mock/cmd/Test-NetConnection +4 -0
  141. data/test/unit/mock/cmd/auditctl +7 -0
  142. data/test/unit/mock/cmd/auditpol +2 -0
  143. data/test/unit/mock/cmd/brew-info-jq +1 -0
  144. data/test/unit/mock/cmd/chage-l-root +7 -0
  145. data/test/unit/mock/cmd/dpkg-s-curl +21 -0
  146. data/test/unit/mock/cmd/dscl +5 -0
  147. data/test/unit/mock/cmd/etc-apt +7 -0
  148. data/test/unit/mock/cmd/find-etc-rc-d-name-S +12 -0
  149. data/test/unit/mock/cmd/find-net-interface +9 -0
  150. data/test/unit/mock/cmd/gem-list-local-a-q-rubocop +1 -0
  151. data/test/unit/mock/cmd/get-net-tcpconnection +24 -0
  152. data/test/unit/mock/cmd/get-netadapter-binding-bridge +4 -0
  153. data/test/unit/mock/cmd/get-package-firefox +30 -0
  154. data/test/unit/mock/cmd/get-package-ruby +18 -0
  155. data/test/unit/mock/cmd/get-service-dhcp +10 -0
  156. data/test/unit/mock/cmd/get-windows-feature +7 -0
  157. data/test/unit/mock/cmd/getent-hosts-example.com +1 -0
  158. data/test/unit/mock/cmd/getent-passwd-root +1 -0
  159. data/test/unit/mock/cmd/id-chartmann +1 -0
  160. data/test/unit/mock/cmd/id-root +1 -0
  161. data/test/unit/mock/cmd/initctl-show-config-ssh +3 -0
  162. data/test/unit/mock/cmd/initctl-status-ssh +1 -0
  163. data/test/unit/mock/cmd/iptables-s +6 -0
  164. data/test/unit/mock/cmd/launchctl-list +3 -0
  165. data/test/unit/mock/cmd/ls-1-etc-init.d +2 -0
  166. data/test/unit/mock/cmd/ls-sys-class-net-br +2 -0
  167. data/test/unit/mock/cmd/lsmod +2 -0
  168. data/test/unit/mock/cmd/lsof-np-itcp +4 -0
  169. data/test/unit/mock/cmd/netstat-tulpen +5 -0
  170. data/test/unit/mock/cmd/npm-ls-g--json-bower +9 -0
  171. data/test/unit/mock/cmd/pacman-qi-curl +21 -0
  172. data/test/unit/mock/cmd/ping-example.com +6 -0
  173. data/test/unit/mock/cmd/pip-show-jinja2 +11 -0
  174. data/test/unit/mock/cmd/ps-aux +3 -0
  175. data/test/unit/mock/cmd/pw-usershow-root-7 +1 -0
  176. data/test/unit/mock/cmd/reg_schedule +1 -0
  177. data/test/unit/mock/cmd/rpm-qia-curl +24 -0
  178. data/test/unit/mock/cmd/sbin_sysctl +1 -0
  179. data/test/unit/mock/cmd/secedit-export +7 -0
  180. data/test/unit/mock/cmd/service-e +2 -0
  181. data/test/unit/mock/cmd/service-sendmail-onestatus +3 -0
  182. data/test/unit/mock/cmd/service-sshd-status +1 -0
  183. data/test/unit/mock/cmd/sockstat +5 -0
  184. data/test/unit/mock/cmd/success +0 -0
  185. data/test/unit/mock/cmd/systemctl-show-all-sshd +6 -0
  186. data/test/unit/mock/cmd/win32_product +8 -0
  187. data/test/unit/mock/cmd/yum-repolist-all +52 -0
  188. data/test/unit/mock/files/auditd.conf +4 -0
  189. data/test/unit/mock/files/bond0 +37 -0
  190. data/test/unit/mock/files/etcgroup +3 -0
  191. data/test/unit/mock/files/example.csv +6 -0
  192. data/test/unit/mock/files/inetd.conf +2 -0
  193. data/test/unit/mock/files/kitchen.yml +7 -0
  194. data/test/unit/mock/files/limits.conf +5 -0
  195. data/test/unit/mock/files/login.defs +5 -0
  196. data/test/unit/mock/files/mysql.conf +8 -0
  197. data/test/unit/mock/files/mysql2.conf +2 -0
  198. data/test/unit/mock/files/ntp.conf +5 -0
  199. data/test/unit/mock/files/passwd +2 -0
  200. data/test/unit/mock/files/policyfile.lock.json +12 -0
  201. data/test/unit/mock/files/ssh_config +5 -0
  202. data/test/unit/mock/files/sshd_config +7 -0
  203. data/test/unit/mock/profiles/empty/metadata.rb +0 -0
  204. data/test/unit/mock/profiles/metadata/metadata.rb +1 -0
  205. data/test/unit/profile_context_test.rb +140 -0
  206. data/test/unit/profile_test.rb +49 -0
  207. data/test/unit/resources/apt_test.rb +46 -0
  208. data/test/unit/resources/audit_policy_test.rb +13 -0
  209. data/test/unit/resources/auditd_conf_test.rb +15 -0
  210. data/test/unit/resources/auditd_rules_test.rb +21 -0
  211. data/test/unit/resources/bond_test.rb +24 -0
  212. data/test/unit/resources/bridge_test.rb +56 -0
  213. data/test/unit/resources/csv_test.rb +35 -0
  214. data/test/unit/resources/etc_group_test.rb +37 -0
  215. data/test/unit/resources/gem_test.rb +20 -0
  216. data/test/unit/resources/group_test.rb +96 -0
  217. data/test/unit/resources/host_test.rb +38 -0
  218. data/test/unit/resources/inetd_conf_test.rb +15 -0
  219. data/test/unit/resources/interface_test.rb +54 -0
  220. data/test/unit/resources/iptables_test.rb +30 -0
  221. data/test/unit/resources/json_test.rb +36 -0
  222. data/test/unit/resources/kernel_module_test.rb +23 -0
  223. data/test/unit/resources/kernel_parameter_test.rb +13 -0
  224. data/test/unit/resources/limits_conf_test.rb +14 -0
  225. data/test/unit/resources/login_def_test.rb +16 -0
  226. data/test/unit/resources/mysql_conf_test.rb +14 -0
  227. data/test/unit/resources/npm_test.rb +20 -0
  228. data/test/unit/resources/ntp_conf_test.rb +16 -0
  229. data/test/unit/resources/oneget_test.rb +45 -0
  230. data/test/unit/resources/os_env_test.rb +13 -0
  231. data/test/unit/resources/package_test.rb +51 -0
  232. data/test/unit/resources/passwd_test.rb +24 -0
  233. data/test/unit/resources/pip_test.rb +15 -0
  234. data/test/unit/resources/port_test.rb +46 -0
  235. data/test/unit/resources/processes_test.rb +32 -0
  236. data/test/unit/resources/registry_key_test.rb +19 -0
  237. data/test/unit/resources/script_test.rb +19 -0
  238. data/test/unit/resources/security_policy_test.rb +16 -0
  239. data/test/unit/resources/service_test.rb +116 -0
  240. data/test/unit/resources/ssh_conf_test.rb +33 -0
  241. data/test/unit/resources/user_test.rb +93 -0
  242. data/test/unit/resources/windows_feature.rb +17 -0
  243. data/test/unit/resources/yaml_test.rb +34 -0
  244. data/test/unit/resources/yum_test.rb +68 -0
  245. data/test/unit/simpleconfig_test.rb +80 -0
  246. data/test/unit/utils/content_parser_test.rb +30 -0
  247. metadata +555 -0
@@ -0,0 +1,13 @@
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::KernelParameter' do
9
+ it 'verify kernel_parameter parsing' do
10
+ resource = load_resource('kernel_parameter', 'net.ipv4.conf.all.forwarding')
11
+ _(resource.value).must_equal 1
12
+ end
13
+ end
@@ -0,0 +1,14 @@
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::LimitsConf' do
9
+ it 'verify limits.conf config parsing' do
10
+ resource = load_resource('limits_conf')
11
+ _(resource.send('*')).must_equal [['soft', 'core', '0'], ['hard', 'rss', '10000']]
12
+ _(resource.send('ftp')).must_equal [["hard", "nproc", "0"]]
13
+ end
14
+ end
@@ -0,0 +1,16 @@
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::LoginDef' do
9
+ it 'verify login.def config parsing' do
10
+ resource = load_resource('login_defs')
11
+ _(resource.UMASK).must_equal '022'
12
+ _(resource.PASS_MIN_DAYS).must_equal '0'
13
+ _(resource.PASS_WARN_AGE).must_equal '7'
14
+ _(resource.USERDEL_CMD).must_equal nil
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ # author: Christoph Hartmann
3
+ # author: Dominik Richter
4
+
5
+ require 'helper'
6
+
7
+ describe 'Inspec::Resources::MysqlConf' do
8
+ it 'verify mysql.conf config parsing' do
9
+ resource = load_resource('mysql_conf', '/etc/mysql/my.cnf')
10
+ _(resource.client['port']).must_equal '3306'
11
+ _(resource.mysqld['user']).must_equal 'mysql'
12
+ _(resource.mysqld['key_buffer_size']).must_equal '16M'
13
+ end
14
+ 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::Npm' do
9
+ it 'verify npm package detail parsing' do
10
+ resource = load_resource('npm', 'bower')
11
+ pkg = {
12
+ name: 'bower',
13
+ version: '1.4.1',
14
+ type: 'npm',
15
+ installed: true,
16
+ }
17
+ _(resource.installed?).must_equal true
18
+ _(resource.info).must_equal pkg
19
+ end
20
+ end
@@ -0,0 +1,16 @@
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::NtpConf' do
9
+ it 'verify ntp config parsing' do
10
+ resource = load_resource('ntp_conf')
11
+ _(resource.driftfile).must_equal '/var/lib/ntp/ntp.drift'
12
+ _(resource.server).must_equal %w{
13
+ 0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org
14
+ }
15
+ end
16
+ 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::OneGet' do
9
+
10
+ it 'verify oneget package detail parsing' do
11
+ resource = MockLoader.new(:windows).load_resource('oneget', 'Mozilla Firefox')
12
+ pkg = {
13
+ name: 'Mozilla Firefox 40.0.3 (x86 en-US)',
14
+ version: '40.0.3',
15
+ type: 'oneget',
16
+ installed: true,
17
+ }
18
+ _(resource.installed?).must_equal true
19
+ _(resource.version).must_equal '40.0.3'
20
+ _(resource.info).must_equal pkg
21
+ end
22
+
23
+ # catch cases where we recieve multiple return values
24
+ # eg. happens if you do 'choco install ruby'
25
+ it 'filter dups of Get-Package' do
26
+ resource = MockLoader.new(:windows).load_resource('oneget', 'Ruby 2.1.6-p336-x64')
27
+ pkg = {
28
+ name: 'Ruby 2.1.6-p336-x64',
29
+ version: '2.1.6-p336',
30
+ type: 'oneget',
31
+ installed: true,
32
+ }
33
+ _(resource.installed?).must_equal true
34
+ _(resource.version).must_equal '2.1.6-p336'
35
+ _(resource.info).must_equal pkg
36
+ end
37
+
38
+ it 'should skip on linux' do
39
+ resource = MockLoader.new(:centos7).load_resource('oneget', 'Not available')
40
+ pkg = { type: 'oneget', installed: false }
41
+ _(resource.installed?).must_equal false
42
+ _(resource.version).must_equal nil
43
+ _(resource.info).must_equal pkg
44
+ end
45
+ end
@@ -0,0 +1,13 @@
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::OsEnv' do
9
+ it 'verify ntp config parsing' do
10
+ resource = load_resource('os_env', 'PATH')
11
+ _(resource.split).must_equal %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}
12
+ end
13
+ end
@@ -0,0 +1,51 @@
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::Package' do
9
+ # arch linux
10
+ it 'verify arch linux package parsing' do
11
+ resource = MockLoader.new(:arch).load_resource('package', 'curl')
12
+ pkg = { name: 'curl', installed: true, version: '7.37.0-1', type: 'pacman' }
13
+ _(resource.installed?).must_equal true
14
+ _(resource.version).must_equal '7.37.0-1'
15
+ _(resource.info).must_equal pkg
16
+ end
17
+
18
+ # ubuntu
19
+ it 'verify ubuntu package parsing' do
20
+ resource = MockLoader.new(:ubuntu1404).load_resource('package', 'curl')
21
+ pkg = { name: 'curl', installed: true, version: '7.35.0-1ubuntu2', type: 'deb' }
22
+ _(resource.installed?).must_equal true
23
+ _(resource.version).must_equal '7.35.0-1ubuntu2'
24
+ _(resource.info).must_equal pkg
25
+ end
26
+
27
+ # centos
28
+ it 'verify centos package parsing' do
29
+ resource = MockLoader.new(:centos7).load_resource('package', 'curl')
30
+ pkg = { name: 'curl', installed: true, version: '7.29.0', type: 'rpm' }
31
+ _(resource.installed?).must_equal true
32
+ _(resource.version).must_equal '7.29.0'
33
+ _(resource.info).must_equal pkg
34
+ end
35
+
36
+ # windows
37
+ it 'verify windows package parsing' do
38
+ resource = MockLoader.new(:windows).load_resource('package', 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161')
39
+ pkg = { name: 'Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161', installed: true, version: '9.0.30729.6161', type: 'windows' }
40
+ _(resource.installed?).must_equal true
41
+ _(resource.version).must_equal '9.0.30729.6161'
42
+ _(resource.info).must_equal pkg
43
+ end
44
+
45
+ # undefined
46
+ it 'verify package handling on unsupported os' do
47
+ resource = MockLoader.new(:undefined).load_resource('package', 'curl')
48
+ _(resource.installed?).must_equal false
49
+ _(resource.info).must_equal nil
50
+ end
51
+ end
@@ -0,0 +1,24 @@
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::Passwd' do
9
+ it 'verify passwd parsing' do
10
+ resource = load_resource('passwd')
11
+ _(resource.usernames).must_equal %w{root www-data}
12
+ _(resource.uids).must_equal %w{0 33}
13
+
14
+ # verify root passwd resource
15
+ root = resource.uid(0)
16
+ _(root.username).must_equal 'root'
17
+ _(root.count).must_equal 1
18
+
19
+ # verify www-data resource
20
+ www = resource.uid(33)
21
+ _(www.username).must_equal 'www-data'
22
+ _(www.count).must_equal 1
23
+ end
24
+ 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::Pip' do
9
+ it 'verify pip package detail parsing' do
10
+ resource = load_resource('pip', 'jinja2')
11
+ pkg = {:name=>'Jinja2', :installed=>true, :version=>'2.8', :type=>'pip'}
12
+ _(resource.installed?).must_equal true
13
+ _(resource.info).must_equal pkg
14
+ end
15
+ end
@@ -0,0 +1,46 @@
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::Port' do
9
+ it 'verify port on Ubuntu 14.04' do
10
+ resource = MockLoader.new(:ubuntu1404).load_resource('port', 22)
11
+ _(resource.listening?).must_equal true
12
+ _(resource.protocol).must_equal %w{ tcp tcp6 }
13
+ _(resource.pid).must_equal [1]
14
+ _(resource.process).must_equal ['sshd']
15
+ end
16
+
17
+ it 'verify port on MacOs x' do
18
+ resource = MockLoader.new(:osx104).load_resource('port', 2022)
19
+ _(resource.listening?).must_equal true
20
+ _(resource.protocol).must_equal ['tcp']
21
+ _(resource.process).must_equal ['VBoxHeadl']
22
+ end
23
+
24
+ it 'verify port on Windows' do
25
+ resource = MockLoader.new(:windows).load_resource('port', 135)
26
+ _(resource.listening?).must_equal true
27
+ _(resource.protocol).must_equal ['tcp']
28
+ _(resource.process).must_equal nil
29
+ end
30
+
31
+ it 'verify port on FreeBSD' do
32
+ resource = MockLoader.new(:freebsd10).load_resource('port', 22)
33
+ _(resource.listening?).must_equal true
34
+ _(resource.protocol).must_equal %w{ tcp6 tcp }
35
+ _(resource.pid).must_equal [668]
36
+ _(resource.process).must_equal ['sshd']
37
+ end
38
+
39
+ it 'verify running on undefined' do
40
+ resource = MockLoader.new(:undefined).load_resource('port', 22)
41
+ _(resource.listening?).must_equal false
42
+ _(resource.protocol).must_equal nil
43
+ _(resource.pid).must_equal nil
44
+ _(resource.process).must_equal nil
45
+ end
46
+ end
@@ -0,0 +1,32 @@
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::Processes' do
9
+ it 'handles empty process results' do
10
+ resource = load_resource('processes', 'nothing')
11
+ _(resource.list).must_equal []
12
+ end
13
+
14
+ it 'verify processes resource' do
15
+ resource = load_resource('processes', '/bin/bash')
16
+ _(resource.list).must_equal [{
17
+ user: 'root',
18
+ pid: '1',
19
+ cpu: '0.0',
20
+ mem: '0.0',
21
+ vsz: '18084',
22
+ rss: '3228',
23
+ tty: '?',
24
+ stat: 'Ss',
25
+ start: '14:15',
26
+ time: '0:00',
27
+ command: '/bin/bash',
28
+ }]
29
+
30
+ _(resource.list.length).must_equal 1
31
+ end
32
+ end
@@ -0,0 +1,19 @@
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::RegistryKey' do
9
+ let(:resource) { load_resource('registry_key', 'Task Scheduler', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
10
+ let(:resource_without_name) { load_resource('registry_key', 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') }
11
+
12
+ it 'read reg key with human readable name' do
13
+ _(resource.Start).must_equal 2
14
+ end
15
+
16
+ it 'read reg key without human readable name' do
17
+ _(resource_without_name.Start).must_equal 2
18
+ end
19
+ end
@@ -0,0 +1,19 @@
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::Script' do
9
+
10
+ ps1_script = <<-EOH
11
+ # call help for get command
12
+ Get-Help Get-Command
13
+ EOH
14
+
15
+ it 'check if script for windows is properly generated ' do
16
+ resource = MockLoader.new(:windows).load_resource('script', ps1_script)
17
+ _(resource.command).must_equal 'powershell -encodedCommand IAAgACAAIAAjACAAYwBhAGwAbAAgAGgAZQBsAHAAIABmAG8AcgAgAGcAZQB0ACAAYwBvAG0AbQBhAG4AZAAKACAAIAAgACAARwBlAHQALQBIAGUAbABwACAARwBlAHQALQBDAG8AbQBtAGEAbgBkAAoA'
18
+ end
19
+ end
@@ -0,0 +1,16 @@
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::SecurityPolicy' do
9
+ it 'verify processes resource' do
10
+ resource = load_resource('security_policy')
11
+ _(resource.MaximumPasswordAge).must_equal 42
12
+ _(resource.send('MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SecurityLevel')).must_equal '4,0'
13
+ _(resource.SeUndockPrivilege).must_equal '*S-1-5-32-544'
14
+ _(resource.SeRemoteInteractiveLogonRight).must_equal '*S-1-5-32-544,*S-1-5-32-555'
15
+ end
16
+ end
@@ -0,0 +1,116 @@
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::Service' do
9
+
10
+ # windows
11
+ it 'verify service parsing' do
12
+ resource = MockLoader.new(:windows).load_resource('service', 'dhcp')
13
+ srv = { name: 'dhcp', description: 'DHCP Client', installed: true, running: true, enabled: true, type: 'windows' }
14
+ _(resource.info).must_equal srv
15
+ _(resource.installed?).must_equal true
16
+ _(resource.enabled?).must_equal true
17
+ _(resource.running?).must_equal true
18
+ end
19
+
20
+ # ubuntu 14.04 with upstart
21
+ it 'verify ubuntu package parsing' do
22
+ resource = MockLoader.new(:ubuntu1404).load_resource('service', 'ssh')
23
+ srv = { name: 'ssh', description: nil, installed: true, running: true, enabled: true, type: 'upstart' }
24
+ _(resource.info).must_equal srv
25
+ _(resource.installed?).must_equal true
26
+ _(resource.enabled?).must_equal true
27
+ _(resource.running?).must_equal true
28
+ end
29
+
30
+ # ubuntu 15.04 with systemd
31
+ it 'verify ubuntu package parsing' do
32
+ resource = MockLoader.new(:ubuntu1504).load_resource('service', 'sshd')
33
+ srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
34
+ _(resource.info).must_equal srv
35
+ _(resource.installed?).must_equal true
36
+ _(resource.enabled?).must_equal true
37
+ _(resource.running?).must_equal true
38
+ end
39
+
40
+ # centos 6 with systemv
41
+ it 'verify centos 6 package parsing' do
42
+ resource = MockLoader.new(:centos6).load_resource('service', 'sshd')
43
+ srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, type: 'sysv' }
44
+ _(resource.info).must_equal srv
45
+ _(resource.installed?).must_equal true
46
+ _(resource.enabled?).must_equal true
47
+ _(resource.running?).must_equal true
48
+ end
49
+
50
+ # centos 7 with systemd
51
+ it 'verify centos 7 package parsing' do
52
+ resource = MockLoader.new(:centos7).load_resource('service', 'sshd')
53
+ srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
54
+ _(resource.info).must_equal srv
55
+ _(resource.installed?).must_equal true
56
+ _(resource.enabled?).must_equal true
57
+ _(resource.running?).must_equal true
58
+ end
59
+
60
+ # freebsd
61
+ it 'verify freebsd10 package parsing' do
62
+ resource = MockLoader.new(:freebsd10).load_resource('service', 'sendmail')
63
+ srv = { name: 'sendmail', description: nil, installed: true, running: true, enabled: true, type: 'bsd-init' }
64
+ _(resource.info).must_equal srv
65
+ _(resource.installed?).must_equal true
66
+ _(resource.enabled?).must_equal true
67
+ _(resource.running?).must_equal true
68
+ end
69
+
70
+ # arch linux with systemd
71
+ it 'verify arch linux package parsing' do
72
+ resource = MockLoader.new(:arch).load_resource('service', 'sshd')
73
+ srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
74
+ _(resource.info).must_equal srv
75
+ _(resource.installed?).must_equal true
76
+ _(resource.enabled?).must_equal true
77
+ _(resource.running?).must_equal true
78
+ end
79
+
80
+ # debian 7 with systemv
81
+ it 'verify debian 7 package parsing' do
82
+ resource = MockLoader.new(:debian7).load_resource('service', 'sshd')
83
+ srv = { name: 'sshd', description: nil, installed: true, running: true, enabled: true, type: 'sysv' }
84
+ _(resource.info).must_equal srv
85
+ _(resource.installed?).must_equal true
86
+ _(resource.enabled?).must_equal true
87
+ _(resource.running?).must_equal true
88
+ end
89
+
90
+ # debian 8 with systemd
91
+ it 'verify arch linux package parsing' do
92
+ resource = MockLoader.new(:debian8).load_resource('service', 'sshd')
93
+ srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' }
94
+ _(resource.info).must_equal srv
95
+ _(resource.installed?).must_equal true
96
+ _(resource.enabled?).must_equal true
97
+ _(resource.running?).must_equal true
98
+ end
99
+
100
+ # macos test
101
+ it 'verify arch linux package parsing' do
102
+ resource = MockLoader.new(:osx104).load_resource('service', 'ssh')
103
+ srv = { name: 'org.openbsd.ssh-agent', description: nil, installed: true, running: true, enabled: true, type: 'darwin' }
104
+ _(resource.info).must_equal srv
105
+ _(resource.installed?).must_equal true
106
+ _(resource.enabled?).must_equal true
107
+ _(resource.running?).must_equal true
108
+ end
109
+
110
+ # unknown OS
111
+ it 'verify package handling on unsupported os' do
112
+ resource = MockLoader.new(:undefined).load_resource('service', 'dhcp')
113
+ _(resource.installed?).must_equal false
114
+ _(resource.info).must_equal nil
115
+ end
116
+ end