inspec 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -2
  3. data/README.md +5 -1
  4. data/bin/os +23 -0
  5. data/examples/kitchen-ansible/.kitchen/default-centos-71.yml +6 -0
  6. data/examples/kitchen-ansible/.kitchen/default-ubuntu-1204.yml +6 -0
  7. data/examples/kitchen-ansible/.kitchen/default-ubuntu-1404.yml +6 -0
  8. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  9. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  10. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
  11. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  12. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
  13. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  14. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-centos-71/Vagrantfile +9 -0
  15. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  16. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  17. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
  18. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  19. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
  20. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  21. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1204/Vagrantfile +9 -0
  22. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  23. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  24. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  25. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  26. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  27. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  28. data/examples/kitchen-ansible/.kitchen/kitchen-vagrant/kitchen-kitchen-ansible-default-ubuntu-1404/Vagrantfile +9 -0
  29. data/examples/kitchen-ansible/.kitchen/logs/default-centos-71.log +4 -0
  30. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1204.log +4 -0
  31. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1404.log +4 -0
  32. data/examples/kitchen-ansible/.kitchen/logs/kitchen.log +8 -0
  33. data/examples/kitchen-ansible/Gemfile.lock +154 -0
  34. data/examples/kitchen-chef/.kitchen/default-centos-71.yml +6 -0
  35. data/examples/kitchen-chef/.kitchen/default-ubuntu-1204.yml +6 -0
  36. data/examples/kitchen-chef/.kitchen/default-ubuntu-1404.yml +6 -0
  37. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  38. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  39. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
  40. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  41. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
  42. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  43. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/Vagrantfile +9 -0
  44. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  45. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  46. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
  47. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  48. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
  49. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  50. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/Vagrantfile +9 -0
  51. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  52. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  53. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  54. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  55. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  56. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  57. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/Vagrantfile +9 -0
  58. data/examples/kitchen-chef/.kitchen/logs/default-centos-71.log +4 -0
  59. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1204.log +4 -0
  60. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1404.log +4 -0
  61. data/examples/kitchen-chef/.kitchen/logs/kitchen.log +8 -0
  62. data/examples/kitchen-chef/Berksfile.lock +11 -0
  63. data/examples/kitchen-chef/Gemfile.lock +223 -0
  64. data/examples/kitchen-puppet/.bundle/config +2 -0
  65. data/examples/kitchen-puppet/.kitchen/logs/default-centos-71.log +5 -0
  66. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1204.log +5 -0
  67. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1404.log +5 -0
  68. data/examples/kitchen-puppet/.kitchen/logs/kitchen.log +5 -0
  69. data/examples/kitchen-puppet/.librarian/puppet/config +2 -0
  70. data/examples/kitchen-puppet/Gemfile.lock +174 -0
  71. data/examples/kitchen-puppet/Puppetfile.lock +2 -0
  72. data/examples/profile/libraries/.DS_Store +0 -0
  73. data/examples/test-kitchen/.kitchen/logs/default-centos-71.log +5 -0
  74. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1204.log +5 -0
  75. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1404.log +5 -0
  76. data/examples/test-kitchen/.kitchen/logs/kitchen.log +5 -0
  77. data/examples/test-kitchen/Berksfile.lock +11 -0
  78. data/examples/test-kitchen/Gemfile.lock +233 -0
  79. data/inspec.gemspec +2 -2
  80. data/lib/.DS_Store +0 -0
  81. data/lib/extras/compliance/README.md +15 -0
  82. data/lib/extras/compliance/compliance.rb +245 -0
  83. data/lib/inspec/metadata.rb +3 -1
  84. data/lib/inspec/profile.rb +2 -0
  85. data/lib/inspec/profile_context.rb +34 -63
  86. data/lib/inspec/resource.rb +23 -0
  87. data/lib/inspec/runner.rb +17 -35
  88. data/lib/inspec/runner_mock.rb +31 -0
  89. data/lib/inspec/runner_rspec.rb +94 -0
  90. data/lib/inspec/targets/dir.rb +2 -4
  91. data/lib/inspec/version.rb +1 -1
  92. data/{test/unit/mock/profiles/complete-meta/test/.gitkeep → lib/resources/certificate.rb} +0 -0
  93. data/lib/resources/command.rb +1 -1
  94. data/lib/resources/postgres_session.rb +10 -15
  95. data/{test/unit/mock/profiles/custom-resource/test/.gitkeep → lib/resources/private_key.rb} +0 -0
  96. data/lib/resources/registry_key.rb +10 -6
  97. data/lib/resources/service.rb +232 -63
  98. data/test/chefdk/.gitignore +16 -0
  99. data/test/chefdk/.kitchen.yml +27 -0
  100. data/test/chefdk/Policyfile.rb +16 -0
  101. data/test/chefdk/README.md +4 -0
  102. data/test/chefdk/chefignore +100 -0
  103. data/test/chefdk/metadata.rb +7 -0
  104. data/test/chefdk/recipes/default.rb +5 -0
  105. data/test/chefdk/spec/spec_helper.rb +2 -0
  106. data/test/chefdk/spec/unit/recipes/default_spec.rb +20 -0
  107. data/test/chefdk/test/integration/default/serverspec/default_spec.rb +9 -0
  108. data/test/chefdk/test/integration/helpers/serverspec/spec_helper.rb +8 -0
  109. data/test/docker_run.rb +5 -1
  110. data/test/docker_test.rb +1 -2
  111. data/test/helper.rb +1 -0
  112. data/test/integration/.kitchen/default-aws-linux.yml +4 -0
  113. data/test/integration/.kitchen/default-centos-7.yml +4 -0
  114. data/test/integration/.kitchen/default-debian-8.yml +4 -0
  115. data/test/integration/.kitchen/default-fedora-22.yml +4 -0
  116. data/test/integration/.kitchen/default-redhat-65.yml +4 -0
  117. data/test/integration/.kitchen/default-redhat-71.yml +4 -0
  118. data/test/integration/.kitchen/default-suse-11sp3.yml +4 -0
  119. data/test/integration/.kitchen/default-suse-12.yml +4 -0
  120. data/test/integration/.kitchen/default-ubuntu-1204.yml +3 -0
  121. data/test/integration/.kitchen/default-ubuntu-1404.yml +4 -0
  122. data/test/integration/.kitchen/default-windows-2012.yml +1 -0
  123. data/test/integration/.kitchen/default-windows-2012r2.yml +2 -0
  124. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67-i386/Vagrantfile +9 -0
  125. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  126. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  127. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/id +1 -0
  128. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  129. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/private_key +27 -0
  130. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  131. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/Vagrantfile +9 -0
  132. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-modernIE-w10-edge/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  133. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-modernIE-w10-edge/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  134. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-modernIE-w10-edge/.vagrant/machines/default/virtualbox/id +1 -0
  135. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-modernIE-w10-edge/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  136. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-modernIE-w10-edge/Vagrantfile +8 -0
  137. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  138. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  139. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
  140. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  141. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
  142. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  143. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/Vagrantfile +9 -0
  144. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  145. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  146. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  147. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  148. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  149. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  150. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/Vagrantfile +9 -0
  151. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-windows-2012R2-matt/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  152. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-windows-2012R2-matt/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  153. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-windows-2012R2-matt/.vagrant/machines/default/virtualbox/id +1 -0
  154. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-windows-2012R2-matt/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  155. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-windows-2012R2-matt/Vagrantfile +8 -0
  156. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-new-ubuntu-1404/Vagrantfile +9 -0
  157. data/test/{unit/mock/profiles/empty/metadata.rb → integration/.kitchen/logs/default-aws-linux.log} +0 -0
  158. data/test/integration/.kitchen/logs/default-centos-511-i386.log +2 -0
  159. data/test/integration/.kitchen/logs/default-centos-511.log +2 -0
  160. data/test/integration/.kitchen/logs/default-centos-67-i386.log +2 -0
  161. data/test/integration/.kitchen/logs/default-centos-67.log +2 -0
  162. data/test/integration/.kitchen/logs/default-centos-7.log +0 -0
  163. data/test/integration/.kitchen/logs/default-centos-71.log +2 -0
  164. data/test/integration/.kitchen/logs/default-debian-6010-i386.log +2 -0
  165. data/test/integration/.kitchen/logs/default-debian-6010.log +2 -0
  166. data/test/integration/.kitchen/logs/default-debian-78-i386.log +2 -0
  167. data/test/integration/.kitchen/logs/default-debian-78.log +2 -0
  168. data/test/integration/.kitchen/logs/default-debian-8.log +0 -0
  169. data/test/integration/.kitchen/logs/default-debian-81-i386.log +2 -0
  170. data/test/integration/.kitchen/logs/default-debian-81.log +2 -0
  171. data/test/integration/.kitchen/logs/default-fedora-21-i386.log +2 -0
  172. data/test/integration/.kitchen/logs/default-fedora-21.log +2 -0
  173. data/test/integration/.kitchen/logs/default-fedora-22.log +0 -0
  174. data/test/integration/.kitchen/logs/default-freebsd-102.log +2 -0
  175. data/test/integration/.kitchen/logs/default-freebsd-93.log +2 -0
  176. data/test/integration/.kitchen/logs/default-mint-172-cinnamon.log +2 -0
  177. data/test/integration/.kitchen/logs/default-modernIE-w10-edge.log +2 -0
  178. data/test/integration/.kitchen/logs/default-modernIE-w7-ie11.log +2 -0
  179. data/test/integration/.kitchen/logs/default-modernIE-w81-ie11.log +2 -0
  180. data/test/integration/.kitchen/logs/default-opensuse-132-i386.log +2 -0
  181. data/test/integration/.kitchen/logs/default-opensuse-132-x86-64.log +2 -0
  182. data/test/integration/.kitchen/logs/default-opentable-win-2008r2-standard-amd64-nocm.log +0 -0
  183. data/test/integration/.kitchen/logs/default-opentable-win-2012r2-standard-amd64-nocm.log +0 -0
  184. data/test/integration/.kitchen/logs/default-redhat-65.log +0 -0
  185. data/test/integration/.kitchen/logs/default-redhat-71.log +0 -0
  186. data/test/integration/.kitchen/logs/default-suse-11sp3.log +0 -0
  187. data/test/integration/.kitchen/logs/default-suse-12.log +0 -0
  188. data/test/integration/.kitchen/logs/default-ubuntu-1004-i386.log +2 -0
  189. data/test/integration/.kitchen/logs/default-ubuntu-1004.log +2 -0
  190. data/test/integration/.kitchen/logs/default-ubuntu-1204-i386.log +2 -0
  191. data/test/integration/.kitchen/logs/default-ubuntu-1204.log +0 -0
  192. data/test/integration/.kitchen/logs/default-ubuntu-1404-i386.log +2 -0
  193. data/test/integration/.kitchen/logs/default-ubuntu-1404.log +0 -0
  194. data/test/integration/.kitchen/logs/default-ubuntu-1510.log +0 -0
  195. data/test/integration/.kitchen/logs/default-windows-2008-opentable.log +2 -0
  196. data/test/integration/.kitchen/logs/default-windows-2008.log +0 -0
  197. data/test/integration/.kitchen/logs/default-windows-2012.log +0 -0
  198. data/test/integration/.kitchen/logs/default-windows-2012R2-matt.log +2 -0
  199. data/test/integration/.kitchen/logs/default-windows-2012r2-opentable.log +2 -0
  200. data/test/integration/.kitchen/logs/default-windows-2012r2.log +41 -0
  201. data/test/integration/.kitchen/logs/kitchen.log +0 -0
  202. data/test/integration/.kitchen/logs/new-centos-511-i386.log +0 -0
  203. data/test/integration/.kitchen/logs/new-centos-511.log +0 -0
  204. data/test/integration/.kitchen/logs/new-centos-67-i386.log +0 -0
  205. data/test/integration/.kitchen/logs/new-centos-67.log +0 -0
  206. data/test/integration/.kitchen/logs/new-centos-71.log +0 -0
  207. data/test/integration/.kitchen/logs/new-debian-6010-i386.log +0 -0
  208. data/test/integration/.kitchen/logs/new-debian-6010.log +0 -0
  209. data/test/integration/.kitchen/logs/new-debian-78-i386.log +0 -0
  210. data/test/integration/.kitchen/logs/new-debian-78.log +0 -0
  211. data/test/integration/.kitchen/logs/new-debian-81-i386.log +0 -0
  212. data/test/integration/.kitchen/logs/new-debian-81.log +0 -0
  213. data/test/integration/.kitchen/logs/new-fedora-21-i386.log +0 -0
  214. data/test/integration/.kitchen/logs/new-fedora-21.log +0 -0
  215. data/test/integration/.kitchen/logs/new-fedora-22.log +0 -0
  216. data/test/integration/.kitchen/logs/new-freebsd-102.log +0 -0
  217. data/test/integration/.kitchen/logs/new-freebsd-93.log +0 -0
  218. data/test/integration/.kitchen/logs/new-opensuse-132-i386.log +0 -0
  219. data/test/integration/.kitchen/logs/new-opensuse-132-x86-64.log +0 -0
  220. data/test/integration/.kitchen/logs/new-ubuntu-1004-i386.log +0 -0
  221. data/test/integration/.kitchen/logs/new-ubuntu-1004.log +0 -0
  222. data/test/integration/.kitchen/logs/new-ubuntu-1204-i386.log +0 -0
  223. data/test/integration/.kitchen/logs/new-ubuntu-1204.log +0 -0
  224. data/test/integration/.kitchen/logs/new-ubuntu-1404-i386.log +0 -0
  225. data/test/integration/.kitchen/logs/new-ubuntu-1404.log +3 -0
  226. data/test/integration/.kitchen/logs/test-centos-511-i386.log +0 -0
  227. data/test/integration/.kitchen/logs/test-centos-511.log +0 -0
  228. data/test/integration/.kitchen/logs/test-centos-67-i386.log +0 -0
  229. data/test/integration/.kitchen/logs/test-centos-67.log +0 -0
  230. data/test/integration/.kitchen/logs/test-centos-71.log +0 -0
  231. data/test/integration/.kitchen/logs/test-debian-6010-i386.log +0 -0
  232. data/test/integration/.kitchen/logs/test-debian-6010.log +0 -0
  233. data/test/integration/.kitchen/logs/test-debian-78-i386.log +0 -0
  234. data/test/integration/.kitchen/logs/test-debian-78.log +0 -0
  235. data/test/integration/.kitchen/logs/test-debian-81-i386.log +0 -0
  236. data/test/integration/.kitchen/logs/test-debian-81.log +0 -0
  237. data/test/integration/.kitchen/logs/test-fedora-21-i386.log +0 -0
  238. data/test/integration/.kitchen/logs/test-fedora-21.log +0 -0
  239. data/test/integration/.kitchen/logs/test-fedora-22.log +0 -0
  240. data/test/integration/.kitchen/logs/test-freebsd-102.log +0 -0
  241. data/test/integration/.kitchen/logs/test-freebsd-93.log +0 -0
  242. data/test/integration/.kitchen/logs/test-opensuse-132-i386.log +0 -0
  243. data/test/integration/.kitchen/logs/test-opensuse-132-x86-64.log +0 -0
  244. data/test/integration/.kitchen/logs/test-ubuntu-1004-i386.log +0 -0
  245. data/test/integration/.kitchen/logs/test-ubuntu-1004.log +0 -0
  246. data/test/integration/.kitchen/logs/test-ubuntu-1204-i386.log +0 -0
  247. data/test/integration/.kitchen/logs/test-ubuntu-1204.log +0 -0
  248. data/test/integration/.kitchen/logs/test-ubuntu-1404-i386.log +0 -0
  249. data/test/integration/.kitchen/logs/test-ubuntu-1404.log +0 -0
  250. data/test/integration/.kitchen/new-ubuntu-1404.yml +1 -0
  251. data/test/integration/Berksfile +1 -0
  252. data/test/integration/Berksfile.lock +27 -0
  253. data/test/integration/TODO.md +15 -0
  254. data/test/integration/cookbooks/os_prepare/files/empty.iso +0 -0
  255. data/test/integration/cookbooks/os_prepare/metadata.rb +2 -0
  256. data/test/integration/cookbooks/os_prepare/recipes/_runit_service_centos.rb +34 -0
  257. data/test/integration/cookbooks/os_prepare/recipes/default.rb +1 -0
  258. data/test/integration/cookbooks/os_prepare/recipes/mount.rb +5 -5
  259. data/test/integration/cookbooks/os_prepare/recipes/postgres.rb +12 -0
  260. data/test/integration/cookbooks/os_prepare/recipes/service.rb +6 -2
  261. data/test/integration/cookbooks/os_prepare/templates/default/sv-default-svlog-run.erb +3 -0
  262. data/test/integration/test/.DS_Store +0 -0
  263. data/test/integration/test/integration/.DS_Store +0 -0
  264. data/test/integration/test/integration/default/.DS_Store +0 -0
  265. data/test/integration/test/integration/default/certificate_spec.rb +7 -0
  266. data/test/integration/test/integration/default/file_spec.rb +2 -2
  267. data/test/integration/test/integration/default/mount_spec.rb +1 -1
  268. data/test/integration/test/integration/default/postgres_session_spec.rb +9 -0
  269. data/test/integration/test/integration/default/service_spec.rb +34 -0
  270. data/test/mac/service_spec.rb +5 -0
  271. data/test/serverspec/.kitchen.yml +18 -0
  272. data/test/serverspec/.kitchen/default-ubuntu-1404.yml +6 -0
  273. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  274. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  275. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  276. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  277. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  278. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  279. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/Vagrantfile +9 -0
  280. data/test/serverspec/.kitchen/logs/default-ubuntu-1404.log +2 -0
  281. data/test/serverspec/.kitchen/logs/kitchen.log +3 -0
  282. data/test/serverspec/Berksfile +3 -0
  283. data/test/serverspec/Berksfile.lock +5 -0
  284. data/test/serverspec/TODO.md +2 -0
  285. data/test/serverspec/test/integration/default/serverspec/os_spec.rb +25 -0
  286. data/test/serverspec/test/integration/default/serverspec/spec_helper.rb +48 -0
  287. data/test/serverspec/test/integration/default/serverspec/sysctl_spec.rb +37 -0
  288. data/test/unit/metadata_test.rb +13 -1
  289. data/test/unit/mock/profiles/complete-metadata/inspec.yml +7 -0
  290. data/test/unit/mock/profiles/empty-metadata/inspec.yml +0 -0
  291. data/test/unit/mock/profiles/{complete-meta → legacy-complete-metadata}/metadata.rb +0 -0
  292. data/test/unit/mock/profiles/legacy-complete-metadata/test/.gitkeep +0 -0
  293. data/test/unit/mock/profiles/legacy-empty-metadata/controls/.gitkeep +0 -0
  294. data/test/unit/mock/profiles/legacy-empty-metadata/metadata.rb +0 -0
  295. data/test/unit/mock/profiles/{metadata → legacy-simple-metadata}/metadata.rb +0 -0
  296. data/test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep +0 -0
  297. data/test/unit/mock/profiles/simple-metadata/inspec.yml +1 -0
  298. data/test/unit/profile_test.rb +82 -31
  299. data/test/unit/resources/service_test.rb +67 -3
  300. metadata +466 -23
  301. data/examples/resource/controls/tiny.rb +0 -3
  302. data/examples/resource/inspec.yml +0 -10
  303. data/examples/resource/libraries/tiny.rb +0 -3
  304. data/lib/inspec/targets/url.rb.orig +0 -87
  305. data/test/unit/mock/profiles/custom-resource/libraries/resource.rb +0 -3
  306. data/test/unit/mock/profiles/custom-resource/metadata.rb +0 -7
@@ -11,8 +11,31 @@ module Inspec
11
11
  def self.registry
12
12
  @registry ||= {}
13
13
  end
14
+
15
+ # Creates the inner DSL which includes all resources for
16
+ # creating tests. It is always connected to one target,
17
+ # which is specified via the backend argument.
18
+ #
19
+ # @param backend [BackendRunner] exposing the target to resources
20
+ # @return [ResourcesDSL]
21
+ def self.create_dsl(backend)
22
+ # need the local name, to use it in the module creation further down
23
+ my_registry = registry
24
+ Module.new do
25
+ my_registry.each do |id, r|
26
+ define_method id.to_sym do |*args|
27
+ r.new(backend, id.to_s, *args)
28
+ end
29
+ end
30
+ end
31
+ end
14
32
  end
15
33
 
34
+ # Retrieve the base class for creating a new resource.
35
+ # Create classes that inherit from this class.
36
+ #
37
+ # @param [int] version the resource version to use
38
+ # @return [Resource] base class for creating a new resource
16
39
  def self.resource(version)
17
40
  if version != 1
18
41
  fail 'Only resource version 1 is supported!'
data/lib/inspec/runner.rb CHANGED
@@ -10,27 +10,28 @@ require 'inspec/profile_context'
10
10
  require 'inspec/targets'
11
11
  require 'inspec/metadata'
12
12
  # spec requirements
13
- require 'rspec'
14
- require 'rspec/its'
15
- require 'inspec/rspec_json_formatter'
16
13
 
17
14
  module Inspec
18
15
  class Runner # rubocop:disable Metrics/ClassLength
19
- attr_reader :tests, :backend, :rules
16
+ attr_reader :backend, :rules
20
17
  def initialize(conf = {})
21
18
  @rules = {}
22
19
  @profile_id = conf[:id]
23
20
  @conf = conf.dup
24
21
  @conf[:logger] ||= Logger.new(nil)
25
- @tests = RSpec::Core::World.new
26
22
 
27
- # resets "pending examples" in reporter
28
- RSpec.configuration.reset
23
+ @test_collector = @conf.delete(:test_collector) || begin
24
+ require 'inspec/runner_rspec'
25
+ RunnerRspec.new(@conf)
26
+ end
29
27
 
30
- configure_output
31
28
  configure_transport
32
29
  end
33
30
 
31
+ def tests
32
+ @test_collector.tests
33
+ end
34
+
34
35
  def normalize_map(hm)
35
36
  res = {}
36
37
  hm.each {|k, v|
@@ -39,10 +40,6 @@ module Inspec
39
40
  res
40
41
  end
41
42
 
42
- def configure_output
43
- RSpec.configuration.add_formatter(@conf['format'] || 'progress')
44
- end
45
-
46
43
  def configure_transport
47
44
  @backend = Inspec::Backend.create(@conf)
48
45
  end
@@ -105,16 +102,12 @@ module Inspec
105
102
 
106
103
  # process the resulting rules
107
104
  ctx.rules.each do |rule_id, rule|
108
- register_rule(ctx, rule_id, rule)
105
+ register_rule(rule_id, rule)
109
106
  end
110
107
  end
111
108
 
112
- def run
113
- run_with(RSpec::Core::Runner.new(nil))
114
- end
115
-
116
- def run_with(rspec_runner)
117
- rspec_runner.run_specs(@tests.ordered_example_groups)
109
+ def run(with = nil)
110
+ @test_collector.run(with)
118
111
  end
119
112
 
120
113
  private
@@ -130,14 +123,14 @@ module Inspec
130
123
  if !arg.empty? &&
131
124
  arg[0].respond_to?(:resource_skipped) &&
132
125
  !arg[0].resource_skipped.nil?
133
- return RSpec::Core::ExampleGroup.describe(*arg, opts) do
126
+ return @test_collector.example_group(*arg, opts) do
134
127
  it arg[0].resource_skipped
135
128
  end
136
129
  else
137
130
  # add the resource
138
131
  case method_name
139
132
  when 'describe'
140
- return RSpec::Core::ExampleGroup.describe(*arg, opts, &block)
133
+ return @test_collector.example_group(*arg, opts, &block)
141
134
  when 'expect'
142
135
  return block.example_group
143
136
  else
@@ -148,7 +141,7 @@ module Inspec
148
141
  nil
149
142
  end
150
143
 
151
- def register_rule(ctx, rule_id, rule)
144
+ def register_rule(rule_id, rule)
152
145
  @rules[rule_id] = rule
153
146
  checks = rule.instance_variable_get(:@checks)
154
147
  checks.each do |m, a, b|
@@ -161,21 +154,10 @@ module Inspec
161
154
  # the scope of this run, thus not gaining ony of the DSL pieces.
162
155
  # To circumvent this, the full DSL is attached to the example's
163
156
  # scope.
164
- dsl = ctx.method(:create_inner_dsl).call(backend)
157
+ dsl = Inspec::Resource.create_dsl(backend)
165
158
  example.send(:include, dsl)
166
159
 
167
- set_rspec_ids(example, rule_id)
168
- @tests.register(example)
169
- end
170
- end
171
-
172
- def set_rspec_ids(example, id)
173
- example.metadata[:id] = id
174
- example.filtered_examples.each do |e|
175
- e.metadata[:id] = id
176
- end
177
- example.children.each do |child|
178
- set_rspec_ids(child, id)
160
+ @test_collector.add_test(example, rule_id)
179
161
  end
180
162
  end
181
163
  end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+
5
+ module Inspec
6
+ class RunnerMock
7
+ attr_reader :tests
8
+ def initialize
9
+ @tests = []
10
+ end
11
+
12
+ def add_test(example, _rule_id)
13
+ @tests.push(example)
14
+ end
15
+
16
+ def example_group(*in_args, &in_block)
17
+ Class.new do
18
+ define_method :args do
19
+ in_args
20
+ end
21
+ define_method :block do
22
+ in_block
23
+ end
24
+ end
25
+ end
26
+
27
+ def run(_with = nil)
28
+ puts 'uhm.... nothing or something... dunno, ask your admin'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+
5
+ require 'rspec/core'
6
+ require 'rspec/its'
7
+ require 'inspec/rspec_json_formatter'
8
+
9
+ # There be dragons!! Or borgs, or something...
10
+ # This file and all its contents cannot yet be tested. Once it is included
11
+ # in our unit test suite, it deactivates all other checks completely.
12
+ # To circumvent this, we need functional tests which tackle the RSpec runner
13
+ # or a separate suite of unit tests to which get along with this.
14
+
15
+ module Inspec
16
+ class RunnerRspec
17
+ def initialize(conf)
18
+ @conf = conf
19
+ reset_tests
20
+ configure_output
21
+ end
22
+
23
+ # Create a new RSpec example group from arguments and block.
24
+ #
25
+ # @param [Type] *args list of arguments for this example
26
+ # @param [Type] &block the block associated with this example group
27
+ # @return [RSpecExampleGroup]
28
+ def example_group(*args, &block)
29
+ RSpec::Core::ExampleGroup.describe(*args, &block)
30
+ end
31
+
32
+ # Add an example group to the list of registered tests.
33
+ #
34
+ # @param [RSpecExampleGroup] example test
35
+ # @param [String] rule_id the ID associated with this check
36
+ # @return [nil]
37
+ def add_test(example, rule_id)
38
+ set_rspec_ids(example, rule_id)
39
+ @tests.register(example)
40
+ end
41
+
42
+ # Retrieve the list of tests that have been added.
43
+ #
44
+ # @return [Array] full list of tests
45
+ def tests
46
+ @tests.ordered_example_groups
47
+ end
48
+
49
+ # Run all registered tests with an optional test runner.
50
+ #
51
+ # @param [RSpecRunner] with is an optional RSpecRunner
52
+ # @return [int] 0 if all went well; otherwise nonzero
53
+ def run(with = nil)
54
+ with ||= RSpec::Core::Runner.new(nil)
55
+ with.run_specs(tests)
56
+ end
57
+
58
+ private
59
+
60
+ # Empty the list of registered tests.
61
+ #
62
+ # @return [nil]
63
+ def reset_tests
64
+ @tests = RSpec::Core::World.new
65
+ # resets "pending examples" in reporter
66
+ RSpec.configuration.reset
67
+ end
68
+
69
+ # Configure the output formatter and stream to be used with RSpec.
70
+ #
71
+ # @return [nil]
72
+ def configure_output
73
+ RSpec.configuration.add_formatter(@conf['format'] || 'progress')
74
+ end
75
+
76
+ # Make sure that all RSpec example groups use the provided ID.
77
+ # At the time of creation, we didn't yet have full ID support in RSpec,
78
+ # which is why they were added to metadata directly. This is evaluated
79
+ # by the InSpec adjusted json formatter (rspec_json_formatter).
80
+ #
81
+ # @param [RSpecExampleGroup] example object which contains a check
82
+ # @param [Type] id describe id
83
+ # @return [Type] description of returned object
84
+ def set_rspec_ids(example, id)
85
+ example.metadata[:id] = id
86
+ example.filtered_examples.each do |e|
87
+ e.metadata[:id] = id
88
+ end
89
+ example.children.each do |child|
90
+ set_rspec_ids(child, id)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -11,13 +11,11 @@ module Inspec::Targets
11
11
  # TODO: remove `test` support for InSpec 1.0
12
12
  class ProfileDir
13
13
  def handles?(paths)
14
+ return true if paths.include?('inspec.yml')
14
15
  (
15
16
  !paths.grep(/^controls/).empty? ||
16
17
  !paths.grep(/^test/).empty?
17
- ) && (
18
- paths.include?('inspec.yml') ||
19
- paths.include?('metadata.rb')
20
- )
18
+ ) && paths.include?('metadata.rb')
21
19
  end
22
20
 
23
21
  def get_libraries(paths)
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.9.9'.freeze
6
+ VERSION = '0.9.10'.freeze
7
7
  end
@@ -49,7 +49,7 @@ class Cmd < Inspec.resource(1)
49
49
  elsif inspec.os.unix?
50
50
  res = inspec.backend.run_command("type \"#{@command}\"")
51
51
  else
52
- warn "`command(#{@command}).exist?` is not suported on you OS: #{inspec.os[:family]}"
52
+ warn "`command(#{@command}).exist?` is not suported on your OS: #{inspec.os[:family]}"
53
53
  return false
54
54
  end
55
55
  res.exit_status.to_i == 0
@@ -5,17 +5,15 @@
5
5
  # license: All rights reserved
6
6
 
7
7
  class Lines
8
+ attr_reader :output
9
+
8
10
  def initialize(raw, desc)
9
- @raw = raw
11
+ @output = raw
10
12
  @desc = desc
11
13
  end
12
14
 
13
- def output
14
- @raw
15
- end
16
-
17
15
  def lines
18
- @raw.split("\n")
16
+ output.split("\n")
19
17
  end
20
18
 
21
19
  def to_s
@@ -39,29 +37,26 @@ class PostgresSession < Inspec.resource(1)
39
37
  @pass = pass
40
38
  end
41
39
 
42
- def query(query, db = [], &block)
40
+ def query(query, db = [])
43
41
  dbs = db.map { |x| "-d #{x}" }.join(' ')
44
42
  # TODO: simple escape, must be handled by a library
45
43
  # that does this securely
46
44
  escaped_query = query.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
47
45
  # run the query
48
- cmd = inspec.command("PGPASSWORD='#{@pass}' psql -U #{@user} #{dbs} -c \"#{escaped_query}\"")
46
+ cmd = inspec.command("PGPASSWORD='#{@pass}' psql -U #{@user} #{dbs} -h localhost -c \"#{escaped_query}\"")
49
47
  out = cmd.stdout + "\n" + cmd.stderr
50
- if out =~ /could not connect to .*/ or
48
+ if cmd.exit_status != 0 or
49
+ out =~ /could not connect to .*/ or
51
50
  out.downcase =~ /^error/
52
51
  # skip this test if the server can't run the query
53
- RSpec.describe(cmd) do
54
- it 'is skipped', skip: out do
55
- end
56
- end
52
+ skip_resource "Can't read run query #{query.inspect} on postgres_session: #{out}"
57
53
  else
58
54
  # remove the whole header (i.e. up to the first ^-----+------+------$)
59
55
  # remove the tail
60
56
  lines = cmd.stdout
61
57
  .sub(/(.*\n)+([-]+[+])*[-]+\n/, '')
62
58
  .sub(/\n[^\n]*\n\n$/, '')
63
- l = Lines.new(lines.strip, "PostgreSQL query: #{query}")
64
- RSpec.__send__('describe', l, &block)
59
+ Lines.new(lines.strip, "PostgreSQL query: #{query}")
65
60
  end
66
61
  end
67
62
  end
@@ -69,22 +69,26 @@ class RegistryKey < Inspec.resource(1)
69
69
 
70
70
  private
71
71
 
72
+ def prep_prop(property)
73
+ property.to_s.downcase
74
+ end
75
+
72
76
  def registry_property_exists(regkey, property)
73
77
  return false if regkey.nil? || property.nil?
74
78
  # always ensure the key is lower case
75
- !regkey[property.to_s.downcase].nil?
79
+ !regkey[prep_prop(property)].nil?
76
80
  end
77
81
 
78
82
  def registry_property_value(regkey, property)
79
- return nil if regkey.nil? || property.nil?
83
+ return nil if !registry_property_exists(regkey, property)
80
84
  # always ensure the key is lower case
81
- regkey[property.to_s.downcase]['value']
85
+ regkey[prep_prop(property)]['value']
82
86
  end
83
87
 
84
88
  def registry_property_type(regkey, property)
85
- return nil if regkey.nil? || property.nil?
89
+ return nil if !registry_property_exists(regkey, property)
86
90
  # always ensure the key is lower case
87
- regkey[property.to_s.downcase]['type']
91
+ regkey[prep_prop(property)]['type']
88
92
  end
89
93
 
90
94
  def registry_key(path)
@@ -174,6 +178,6 @@ class WindowsRegistryKey < RegistryKey
174
178
  end
175
179
 
176
180
  def deprecated
177
- warn '[DEPRECATION] `yumrepo(reponame)` is deprecated. Please use `yum.repo(reponame)` instead.'
181
+ warn '[DEPRECATION] `windows_registry_key(reg_key)` is deprecated. Please use `registry_key(\'path\to\key\')` instead.'
178
182
  end
179
183
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # author: Christoph Hartmann
3
3
  # author: Dominik Richter
4
+ # author: Stephan Renatus
4
5
  # license: All rights reserved
5
6
 
6
7
  # Usage:
@@ -30,14 +31,19 @@ class Service < Inspec.resource(1)
30
31
  end
31
32
  "
32
33
 
33
- def initialize(service_name)
34
+ attr_reader :service_ctl
35
+
36
+ def initialize(service_name, service_ctl = nil)
34
37
  @service_name = service_name
35
38
  @service_mgmt = nil
39
+ @service_ctl ||= service_ctl
36
40
  @cache = nil
37
- select_package_manager
41
+ @service_mgmt = select_service_mgmt
42
+
43
+ return skip_resource 'The `service` resource is not supported on your OS yet.' if @service_mgmt.nil?
38
44
  end
39
45
 
40
- def select_package_manager # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
46
+ def select_service_mgmt # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
41
47
  family = inspec.os[:family]
42
48
 
43
49
  case family
@@ -52,45 +58,42 @@ class Service < Inspec.resource(1)
52
58
  when 'ubuntu'
53
59
  version = inspec.os[:release].to_f
54
60
  if version < 15.04
55
- @service_mgmt = Upstart.new(inspec)
61
+ Upstart.new(inspec, service_ctl)
56
62
  else
57
- @service_mgmt = Systemd.new(inspec)
63
+ Systemd.new(inspec, service_ctl)
58
64
  end
59
65
  when 'debian'
60
66
  version = inspec.os[:release].to_i
61
67
  if version > 7
62
- @service_mgmt = Systemd.new(inspec)
68
+ Systemd.new(inspec, service_ctl)
63
69
  else
64
- @service_mgmt = SysV.new(inspec)
70
+ SysV.new(inspec, service_ctl || '/usr/sbin/service')
65
71
  end
66
72
  when 'redhat', 'fedora', 'centos'
67
73
  version = inspec.os[:release].to_i
68
74
  if (%w{ redhat centos }.include?(family) && version >= 7) || (family == 'fedora' && version >= 15)
69
- @service_mgmt = Systemd.new(inspec)
75
+ Systemd.new(inspec, service_ctl)
70
76
  else
71
- @service_mgmt = SysV.new(inspec)
77
+ SysV.new(inspec, service_ctl || '/sbin/service')
72
78
  end
73
79
  when 'wrlinux'
74
- @service_mgmt = SysV.new(inspec)
80
+ SysV.new(inspec, service_ctl)
75
81
  when 'darwin'
76
- @service_mgmt = LaunchCtl.new(inspec)
82
+ LaunchCtl.new(inspec, service_ctl)
77
83
  when 'windows'
78
- @service_mgmt = WindowsSrv.new(inspec)
84
+ WindowsSrv.new(inspec)
79
85
  when 'freebsd'
80
- @service_mgmt = BSDInit.new(inspec)
86
+ BSDInit.new(inspec, service_ctl)
81
87
  when 'arch', 'opensuse'
82
- @service_mgmt = Systemd.new(inspec)
88
+ Systemd.new(inspec, service_ctl)
83
89
  when 'aix'
84
- @service_mgmt = SrcMstr.new(inspec)
90
+ SrcMstr.new(inspec)
85
91
  end
86
-
87
- return skip_resource 'The `service` resource is not supported on your OS yet.' if @service_mgmt.nil?
88
92
  end
89
93
 
90
94
  def info
91
- return @cache if !@cache.nil?
92
95
  return nil if @service_mgmt.nil?
93
- @cache = @service_mgmt.info(@service_name)
96
+ @cache ||= @service_mgmt.info(@service_name)
94
97
  end
95
98
 
96
99
  # verifies the service is enabled
@@ -117,17 +120,23 @@ class Service < Inspec.resource(1)
117
120
  end
118
121
 
119
122
  class ServiceManager
120
- attr_reader :inspec
121
- def initialize(inspec)
123
+ attr_reader :inspec, :service_ctl
124
+ def initialize(inspec, service_ctl = nil)
122
125
  @inspec = inspec
126
+ @service_ctl ||= service_ctl
123
127
  end
124
128
  end
125
129
 
126
130
  # @see: http://www.freedesktop.org/software/systemd/man/systemctl.html
127
131
  # @see: http://www.freedesktop.org/software/systemd/man/systemd-system.conf.html
128
132
  class Systemd < ServiceManager
133
+ def initialize(inspec, service_ctl = nil)
134
+ @service_ctl ||= 'systemctl'
135
+ super
136
+ end
137
+
129
138
  def info(service_name)
130
- cmd = inspec.command("systemctl show --all #{service_name}")
139
+ cmd = inspec.command("#{service_ctl} show --all #{service_name}")
131
140
  return nil if cmd.exit_status.to_i != 0
132
141
 
133
142
  # parse data
@@ -138,13 +147,13 @@ class Systemd < ServiceManager
138
147
  ).params
139
148
 
140
149
  # LoadState values eg. loaded, not-found
141
- params['LoadState'] == 'loaded' ? (installed = true) : (installed = false)
150
+ installed = params['LoadState'] == 'loaded'
142
151
  # test via 'systemctl is-active service'
143
152
  # SubState values running
144
- params['SubState'] == 'running' ? (running = true) : (running = false)
153
+ running = params['SubState'] == 'running'
145
154
  # test via systemctl --quiet is-enabled
146
155
  # ActiveState values eg.g inactive, active
147
- params['UnitFileState'] == 'enabled' ? (enabled = true) : (enabled = false)
156
+ enabled = params['UnitFileState'] == 'enabled'
148
157
 
149
158
  {
150
159
  name: params['Id'],
@@ -190,25 +199,26 @@ class SrcMstr < ServiceManager
190
199
 
191
200
  # #rubocop:disable Style/TrailingComma
192
201
  def enabled_rc_tcpip?
193
- if inspec.command(
194
- "grep -v ^# /etc/rc.tcpip | grep 'start ' | grep -Eq '(/{0,1}| )#{@name} '",
202
+ inspec.command(
203
+ "grep -v ^# /etc/rc.tcpip | grep 'start ' | grep -Eq '(/{0,1}| )#{name} '",
195
204
  ).exit_status == 0
196
- true
197
- else
198
- false
199
- end
200
205
  end
201
206
 
202
207
  def enabled_inittab?
203
- inspec.command("lsitab #{@name}").exit_status.to_i == 0 ? true : false
208
+ inspec.command("lsitab #{name}").exit_status == 0
204
209
  end
205
210
  end
206
211
 
207
212
  # @see: http://upstart.ubuntu.com
208
213
  class Upstart < ServiceManager
214
+ def initialize(service_name, service_ctl = nil)
215
+ @service_ctl ||= 'initctl'
216
+ super
217
+ end
218
+
209
219
  def info(service_name)
210
220
  # get the status of upstart service
211
- status = inspec.command("initctl status #{service_name}")
221
+ status = inspec.command("#{service_ctl} status #{service_name}")
212
222
 
213
223
  # fallback for systemv services, those are not handled via `initctl`
214
224
  return SysV.new(inspec).info(service_name) if status.exit_status.to_i != 0
@@ -235,7 +245,7 @@ class Upstart < ServiceManager
235
245
  # $ initctl show-config $job | grep -q "^ start on" && echo enabled || echo disabled
236
246
  # Ubuntu 10.04 show-config is not supported
237
247
  # @see http://manpages.ubuntu.com/manpages/maverick/man8/initctl.8.html
238
- config = inspec.command("initctl show-config #{service_name}")
248
+ config = inspec.command("#{service_ctl} show-config #{service_name}")
239
249
  enabled = !config.stdout[/^\s*start on/].nil?
240
250
 
241
251
  # implement fallback for Ubuntu 10.04
@@ -251,6 +261,11 @@ class Upstart < ServiceManager
251
261
  end
252
262
 
253
263
  class SysV < ServiceManager
264
+ def initialize(service_name, service_ctl = nil)
265
+ @service_ctl ||= 'service'
266
+ super
267
+ end
268
+
254
269
  def info(service_name)
255
270
  # check if service is installed
256
271
  # read all available services via ls /etc/init.d/
@@ -270,19 +285,14 @@ class SysV < ServiceManager
270
285
  enabled_services = enabled_services_cmd.stdout.split("\n").select { |line|
271
286
  /(^.*#{service_name}.*)/.match(line)
272
287
  }
273
- enabled_services.empty? ? enabled = false : enabled = true
288
+ enabled = !enabled_services.empty?
274
289
 
275
290
  # check if service is really running
276
291
  # service throws an exit code if the service is not installed or
277
292
  # not enabled
278
293
 
279
- # on debian service is located /usr/sbin/service, on centos it is located here /sbin/service
280
- service_cmd = 'service'
281
- service_cmd = '/usr/sbin/service' if inspec.os[:family] == 'debian'
282
- service_cmd = '/sbin/service' if inspec.os[:family] == 'centos'
283
-
284
- cmd = inspec.command("#{service_cmd} #{service_name} status")
285
- cmd.exit_status == 0 ? (running = true) : (running = false)
294
+ cmd = inspec.command("#{service_ctl} #{service_name} status")
295
+ running = cmd.exit_status == 0
286
296
  {
287
297
  name: service_name,
288
298
  description: nil,
@@ -297,6 +307,11 @@ end
297
307
  # @see: https://www.freebsd.org/doc/en/articles/linux-users/startup.html
298
308
  # @see: https://www.freebsd.org/cgi/man.cgi?query=rc.conf&sektion=5
299
309
  class BSDInit < ServiceManager
310
+ def initialize(service_name, service_ctl = nil)
311
+ @service_ctl ||= 'service'
312
+ super
313
+ end
314
+
300
315
  def info(service_name)
301
316
  # check if service is enabled
302
317
  # services are enabled in /etc/rc.conf and /etc/defaults/rc.conf
@@ -304,7 +319,7 @@ class BSDInit < ServiceManager
304
319
  # service SERVICE status returns the following result if not activated:
305
320
  # Cannot 'status' sshd. Set sshd_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
306
321
  # gather all enabled services
307
- cmd = inspec.command('service -e')
322
+ cmd = inspec.command("#{service_ctl} -e")
308
323
  return nil if cmd.exit_status != 0
309
324
 
310
325
  # search for the service
@@ -314,8 +329,8 @@ class BSDInit < ServiceManager
314
329
 
315
330
  # check if the service is running
316
331
  # if the service is not available or not running, we always get an error code
317
- cmd = inspec.command("service #{service_name} onestatus")
318
- cmd.exit_status == 0 ? (running = true) : (running = false)
332
+ cmd = inspec.command("#{service_ctl} #{service_name} onestatus")
333
+ running = cmd.exit_status == 0
319
334
 
320
335
  {
321
336
  name: service_name,
@@ -328,12 +343,43 @@ class BSDInit < ServiceManager
328
343
  end
329
344
  end
330
345
 
346
+ class Runit < ServiceManager
347
+ def initialize(service_name, service_ctl = nil)
348
+ @service_ctl ||= 'sv'
349
+ super
350
+ end
351
+
352
+ def info(service_name)
353
+ # get the status of runit service
354
+ cmd = inspec.command("#{service_ctl} status #{service_name}")
355
+ # return nil unless cmd.exit_status == 0 # NOTE(sr) why do we do this?
356
+
357
+ installed = cmd.exit_status == 0
358
+ running = installed && (cmd.stdout =~ /^run:/)
359
+ enabled = installed && (running || (cmd.stdout =~ /normally up/) || (cmd.stdout =~ /want up/))
360
+
361
+ {
362
+ name: service_name,
363
+ description: nil,
364
+ installed: installed,
365
+ running: running,
366
+ enabled: enabled,
367
+ type: 'runit',
368
+ }
369
+ end
370
+ end
371
+
331
372
  # MacOS / Darwin
332
373
  # new launctl on macos 10.10
333
374
  class LaunchCtl < ServiceManager
375
+ def initialize(service_name, service_ctl = nil)
376
+ @service_ctl ||= 'launchctl'
377
+ super
378
+ end
379
+
334
380
  def info(service_name)
335
381
  # get the status of upstart service
336
- cmd = inspec.command('launchctl list')
382
+ cmd = inspec.command("#{service_ctl} list")
337
383
  return nil if cmd.exit_status != 0
338
384
 
339
385
  # search for the service
@@ -341,15 +387,15 @@ class LaunchCtl < ServiceManager
341
387
  return nil if srv.nil? || srv[0].nil?
342
388
 
343
389
  # extract values from service
344
- parsed_srv = /^([0-9]+)\s*(\w*)\s*(\S*)/.match(srv[0])
345
- !parsed_srv.nil? ? (enabled = true) : (enabled = false)
390
+ parsed_srv = /^(?<pid>[0-9-]+)\t(?<exit>[0-9]+)\t(?<name>\S*)$/.match(srv[0])
391
+ enabled = !parsed_srv['name'].nil? # it's in the list
346
392
 
347
393
  # check if the service is running
348
- pid = parsed_srv[0]
349
- !pid.nil? ? (running = true) : (running = false)
394
+ pid = parsed_srv['pid']
395
+ running = pid != '-'
350
396
 
351
397
  # extract service label
352
- srv = parsed_srv[3] || service_name
398
+ srv = parsed_srv['name'] || service_name
353
399
 
354
400
  {
355
401
  name: srv,
@@ -423,22 +469,145 @@ class WindowsSrv < ServiceManager
423
469
 
424
470
  # detect if service is enabled
425
471
  def service_enabled?(service)
426
- if !service['WMI'].nil? &&
427
- !service['WMI']['StartMode'].nil? &&
428
- service['WMI']['StartMode'] == 'Auto'
429
- true
430
- else
431
- false
432
- end
472
+ !service['WMI'].nil? &&
473
+ !service['WMI']['StartMode'].nil? &&
474
+ service['WMI']['StartMode'] == 'Auto'
433
475
  end
434
476
 
435
477
  # detect if service is running
436
478
  def service_running?(service)
437
- if !service['Service']['Status'].nil? &&
438
- service['Service']['Status'] == 4
439
- true
440
- else
441
- false
479
+ !service['Service']['Status'].nil? && service['Service']['Status'] == 4
480
+ end
481
+ end
482
+
483
+ class SystemdService < Service
484
+ name 'systemd_service'
485
+ desc 'Use the systemd_service InSpec audit resource to test if the named service (controlled by systemd) is installed, running and/or enabled.'
486
+ example "
487
+ # to override service mgmt auto-detection
488
+ describe systemd_service('service_name') do
489
+ it { should be_installed }
490
+ it { should be_enabled }
491
+ it { should be_running }
492
+ end
493
+
494
+ # to set a non-standard systemctl path
495
+ describe systemd_service('service_name', '/path/to/systemctl') do
496
+ it { should be_running }
497
+ end
498
+ "
499
+
500
+ def select_service_mgmt
501
+ Systemd.new(inspec, service_ctl)
502
+ end
503
+ end
504
+
505
+ class UpstartService < Service
506
+ name 'upstart_service'
507
+ desc 'Use the upstart_service InSpec audit resource to test if the named service (controlled by upstart) is installed, running and/or enabled.'
508
+ example "
509
+ # to override service mgmt auto-detection
510
+ describe upstart_service('service_name') do
511
+ it { should be_installed }
512
+ it { should be_enabled }
513
+ it { should be_running }
514
+ end
515
+
516
+ # to set a non-standard initctl path
517
+ describe upstart_service('service_name', '/path/to/initctl') do
518
+ it { should be_running }
519
+ end
520
+ "
521
+
522
+ def select_service_mgmt
523
+ Upstart.new(inspec, service_ctl)
524
+ end
525
+ end
526
+
527
+ class SysVService < Service
528
+ name 'sysv_service'
529
+ desc 'Use the sysv_service InSpec audit resource to test if the named service (controlled by SysV) is installed, running and/or enabled.'
530
+ example "
531
+ # to override service mgmt auto-detection
532
+ describe sysv_service('service_name') do
533
+ it { should be_installed }
534
+ it { should be_enabled }
535
+ it { should be_running }
536
+ end
537
+
538
+ # to set a non-standard service path
539
+ describe sysv_service('service_name', '/path/to/service') do
540
+ it { should be_running }
442
541
  end
542
+ "
543
+
544
+ def select_service_mgmt
545
+ SysV.new(inspec, service_ctl)
546
+ end
547
+ end
548
+
549
+ class BSDService < Service
550
+ name 'bsd_service'
551
+ desc 'Use the bsd_service InSpec audit resource to test if the named service (controlled by BSD init) is installed, running and/or enabled.'
552
+ example "
553
+ # to override service mgmt auto-detection
554
+ describe bsd_service('service_name') do
555
+ it { should be_installed }
556
+ it { should be_enabled }
557
+ it { should be_running }
558
+ end
559
+
560
+ # to set a non-standard service path
561
+ describe bsd_service('service_name', '/path/to/service') do
562
+ it { should be_running }
563
+ end
564
+ "
565
+
566
+ def select_service_mgmt
567
+ BSDInit.new(inspec, service_ctl)
568
+ end
569
+ end
570
+
571
+ class LaunchdService < Service
572
+ name 'launchd_service'
573
+ desc 'Use the launchd_service InSpec audit resource to test if the named service (controlled by launchd) is installed, running and/or enabled.'
574
+ example "
575
+ # to override service mgmt auto-detection
576
+ describe launchd_service('service_name') do
577
+ it { should be_installed }
578
+ it { should be_enabled }
579
+ it { should be_running }
580
+ end
581
+
582
+ # to set a non-standard launchctl path
583
+ describe launchd_service('service_name', '/path/to/launchctl') do
584
+ it { should be_running }
585
+ end
586
+ "
587
+
588
+ def select_service_mgmt
589
+ LaunchCtl.new(inspec, service_ctl)
590
+ end
591
+ end
592
+
593
+ class RunitService < Service
594
+ name 'runit_service'
595
+ desc 'Use the runit_service InSpec audit resource to test if the named service (controlled by runit) is installed, running and/or enabled.'
596
+ example "
597
+ # to override service mgmt auto-detection
598
+ describe runit_service('service_name') do
599
+ it { should be_installed }
600
+ it { should be_enabled }
601
+ it { should be_running }
602
+ end
603
+
604
+ # to set a non-standard sv path
605
+ describe runit_service('service_name', '/path/to/sv') do
606
+ it { should be_running }
607
+ end
608
+ "
609
+
610
+ def select_service_mgmt
611
+ Runit.new(inspec, service_ctl)
443
612
  end
444
613
  end