inspec 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (365) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -2
  3. data/Gemfile +1 -0
  4. data/README.md +21 -2
  5. data/Rakefile +1 -1
  6. data/bin/inspec +25 -3
  7. data/bin/os +23 -0
  8. data/docs/dsl_resource.rst +90 -0
  9. data/docs/profiles.rst +167 -0
  10. data/docs/resources.rst +79 -0
  11. data/examples/README.md +1 -0
  12. data/examples/kitchen-ansible/.kitchen/logs/default-centos-71.log +0 -0
  13. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1204.log +0 -0
  14. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1404.log +432 -0
  15. data/examples/kitchen-ansible/.kitchen/logs/kitchen.log +10 -0
  16. data/examples/kitchen-ansible/Gemfile.lock +154 -0
  17. data/examples/kitchen-chef/.kitchen/default-centos-71.yml +6 -0
  18. data/examples/kitchen-chef/.kitchen/default-ubuntu-1204.yml +6 -0
  19. data/examples/kitchen-chef/.kitchen/default-ubuntu-1404.yml +6 -0
  20. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  21. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  22. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
  23. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  24. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
  25. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  26. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/Vagrantfile +9 -0
  27. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  28. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  29. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
  30. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  31. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
  32. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  33. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/Vagrantfile +9 -0
  34. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  35. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  36. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  37. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  38. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  39. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  40. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/Vagrantfile +9 -0
  41. data/examples/kitchen-chef/.kitchen/logs/default-centos-71.log +4 -0
  42. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1204.log +4 -0
  43. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1404.log +4 -0
  44. data/examples/kitchen-chef/.kitchen/logs/kitchen.log +8 -0
  45. data/examples/kitchen-chef/Berksfile.lock +11 -0
  46. data/examples/kitchen-chef/Gemfile.lock +223 -0
  47. data/examples/kitchen-puppet/.bundle/config +2 -0
  48. data/examples/kitchen-puppet/.kitchen/logs/default-centos-71.log +0 -0
  49. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1204.log +0 -0
  50. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1404.log +306 -0
  51. data/examples/kitchen-puppet/.kitchen/logs/kitchen.log +10 -0
  52. data/examples/kitchen-puppet/.librarian/puppet/config +2 -0
  53. data/examples/kitchen-puppet/Gemfile.lock +174 -0
  54. data/examples/kitchen-puppet/Puppetfile.lock +2 -0
  55. data/examples/profile/README.md +30 -0
  56. data/examples/profile/controls/example.rb +14 -0
  57. data/examples/profile/controls/gordon.rb +20 -0
  58. data/examples/profile/inspec.yml +10 -0
  59. data/examples/profile/libraries/.DS_Store +0 -0
  60. data/examples/profile/libraries/gordon_config.rb +17 -0
  61. data/examples/test-kitchen/.kitchen/logs/default-centos-71.log +5 -0
  62. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1204.log +5 -0
  63. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1404.log +5 -0
  64. data/examples/test-kitchen/.kitchen/logs/kitchen.log +5 -0
  65. data/examples/test-kitchen/Berksfile.lock +11 -0
  66. data/examples/test-kitchen/Gemfile.lock +233 -0
  67. data/inspec.gemspec +1 -1
  68. data/lib/.DS_Store +0 -0
  69. data/lib/inspec/archive/tar.rb +29 -0
  70. data/lib/inspec/archive/zip.rb +19 -0
  71. data/lib/inspec/metadata.rb +110 -15
  72. data/lib/inspec/profile.rb +88 -19
  73. data/lib/inspec/profile_context.rb +10 -4
  74. data/lib/inspec/resource.rb +1 -0
  75. data/lib/inspec/runner.rb +21 -4
  76. data/lib/inspec/targets.rb +2 -1
  77. data/lib/inspec/targets/archive.rb +39 -0
  78. data/lib/inspec/targets/core.rb +2 -2
  79. data/lib/inspec/targets/dir.rb +18 -2
  80. data/lib/inspec/targets/file.rb +4 -0
  81. data/lib/inspec/targets/folder.rb +21 -11
  82. data/lib/inspec/targets/tar.rb +36 -5
  83. data/lib/inspec/targets/url.rb +45 -13
  84. data/lib/inspec/targets/zip.rb +22 -15
  85. data/lib/inspec/version.rb +1 -1
  86. data/lib/matchers/matchers.rb +30 -0
  87. data/lib/resources/certificate.rb +0 -0
  88. data/lib/resources/etc_group.rb +1 -1
  89. data/lib/resources/file.rb +28 -3
  90. data/lib/resources/mount.rb +57 -0
  91. data/lib/resources/passwd.rb +1 -1
  92. data/lib/resources/private_key.rb +0 -0
  93. data/lib/resources/user.rb +3 -2
  94. data/lib/utils/hash.rb +29 -1
  95. data/lib/utils/parser.rb +34 -1
  96. data/lib/utils/simpleconfig.rb +1 -1
  97. data/test/chefdk/.gitignore +16 -0
  98. data/test/chefdk/.kitchen.yml +27 -0
  99. data/test/chefdk/Policyfile.rb +16 -0
  100. data/test/chefdk/README.md +4 -0
  101. data/test/chefdk/chefignore +100 -0
  102. data/test/chefdk/metadata.rb +7 -0
  103. data/test/chefdk/recipes/default.rb +5 -0
  104. data/test/chefdk/spec/spec_helper.rb +2 -0
  105. data/test/chefdk/spec/unit/recipes/default_spec.rb +20 -0
  106. data/test/chefdk/test/integration/default/serverspec/default_spec.rb +9 -0
  107. data/test/chefdk/test/integration/helpers/serverspec/spec_helper.rb +8 -0
  108. data/test/helper.rb +3 -1
  109. data/test/integration/.DS_Store +0 -0
  110. data/test/integration/.kitchen.ec2.yml +67 -0
  111. data/test/integration/.kitchen.local.yml +68 -0
  112. data/test/integration/.kitchen/default-aws-linux.yml +4 -0
  113. data/test/integration/.kitchen/default-centos-511.yml +6 -0
  114. data/test/integration/.kitchen/default-centos-67.yml +6 -0
  115. data/test/integration/.kitchen/default-centos-7.yml +4 -0
  116. data/test/integration/.kitchen/default-centos-71.yml +6 -0
  117. data/test/integration/.kitchen/default-debian-6010.yml +6 -0
  118. data/test/integration/.kitchen/default-debian-78.yml +6 -0
  119. data/test/integration/.kitchen/default-debian-8.yml +4 -0
  120. data/test/integration/.kitchen/default-debian-81.yml +6 -0
  121. data/test/integration/.kitchen/default-fedora-21.yml +6 -0
  122. data/test/integration/.kitchen/default-fedora-22.yml +4 -0
  123. data/test/integration/.kitchen/default-freebsd-102.yml +6 -0
  124. data/test/integration/.kitchen/default-freebsd-93.yml +6 -0
  125. data/test/integration/.kitchen/default-opensuse-132-x86-64.yml +6 -0
  126. data/test/integration/.kitchen/default-redhat-65.yml +4 -0
  127. data/test/integration/.kitchen/default-redhat-71.yml +4 -0
  128. data/test/integration/.kitchen/default-suse-11sp3.yml +4 -0
  129. data/test/integration/.kitchen/default-suse-12.yml +4 -0
  130. data/test/integration/.kitchen/default-ubuntu-1004.yml +6 -0
  131. data/test/integration/.kitchen/default-ubuntu-1204.yml +4 -0
  132. data/test/integration/.kitchen/default-ubuntu-1404.yml +4 -0
  133. data/test/integration/.kitchen/default-ubuntu-1510.yml +4 -0
  134. data/test/integration/.kitchen/default-windows-2012.yml +5 -0
  135. data/test/integration/.kitchen/default-windows-2012r2.yml +6 -0
  136. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  137. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  138. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/id +1 -0
  139. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  140. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/private_key +27 -0
  141. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  142. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/Vagrantfile +9 -0
  143. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67-i386/Vagrantfile +9 -0
  144. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  145. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  146. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/id +1 -0
  147. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  148. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/private_key +27 -0
  149. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  150. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/Vagrantfile +9 -0
  151. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  152. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  153. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
  154. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  155. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
  156. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  157. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/Vagrantfile +9 -0
  158. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  159. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  160. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/id +1 -0
  161. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  162. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/private_key +27 -0
  163. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  164. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/Vagrantfile +9 -0
  165. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  166. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  167. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/id +1 -0
  168. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  169. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/private_key +27 -0
  170. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  171. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/Vagrantfile +9 -0
  172. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  173. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  174. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/id +1 -0
  175. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  176. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/private_key +27 -0
  177. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  178. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/Vagrantfile +9 -0
  179. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  180. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  181. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/id +1 -0
  182. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  183. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/private_key +27 -0
  184. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  185. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/Vagrantfile +9 -0
  186. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  187. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  188. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/id +1 -0
  189. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  190. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/private_key +27 -0
  191. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  192. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/Vagrantfile +9 -0
  193. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  194. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  195. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/id +1 -0
  196. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  197. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/private_key +27 -0
  198. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  199. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/Vagrantfile +9 -0
  200. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  201. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  202. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/id +1 -0
  203. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  204. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/private_key +27 -0
  205. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  206. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/Vagrantfile +9 -0
  207. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  208. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  209. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/id +1 -0
  210. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  211. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/private_key +27 -0
  212. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  213. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/Vagrantfile +9 -0
  214. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  215. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  216. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/id +1 -0
  217. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  218. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/private_key +27 -0
  219. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  220. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/Vagrantfile +9 -0
  221. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  222. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  223. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
  224. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  225. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
  226. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  227. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/Vagrantfile +9 -0
  228. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  229. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  230. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  231. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  232. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  233. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  234. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/Vagrantfile +9 -0
  235. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-new-ubuntu-1404/Vagrantfile +9 -0
  236. data/test/integration/.kitchen/logs/default-aws-linux.log +0 -0
  237. data/test/integration/.kitchen/logs/default-centos-511-i386.log +0 -0
  238. data/test/integration/.kitchen/logs/default-centos-511.log +0 -0
  239. data/test/integration/.kitchen/logs/default-centos-67-i386.log +0 -0
  240. data/test/integration/.kitchen/logs/default-centos-67.log +0 -0
  241. data/test/integration/.kitchen/logs/default-centos-7.log +0 -0
  242. data/test/integration/.kitchen/logs/default-centos-71.log +0 -0
  243. data/test/integration/.kitchen/logs/default-debian-6010-i386.log +0 -0
  244. data/test/integration/.kitchen/logs/default-debian-6010.log +0 -0
  245. data/test/integration/.kitchen/logs/default-debian-78-i386.log +0 -0
  246. data/test/integration/.kitchen/logs/default-debian-78.log +0 -0
  247. data/test/integration/.kitchen/logs/default-debian-8.log +0 -0
  248. data/test/integration/.kitchen/logs/default-debian-81-i386.log +0 -0
  249. data/test/integration/.kitchen/logs/default-debian-81.log +0 -0
  250. data/test/integration/.kitchen/logs/default-fedora-21-i386.log +0 -0
  251. data/test/integration/.kitchen/logs/default-fedora-21.log +0 -0
  252. data/test/integration/.kitchen/logs/default-fedora-22.log +0 -0
  253. data/test/integration/.kitchen/logs/default-freebsd-102.log +0 -0
  254. data/test/integration/.kitchen/logs/default-freebsd-93.log +0 -0
  255. data/test/integration/.kitchen/logs/default-mint-172-cinnamon.log +0 -0
  256. data/test/integration/.kitchen/logs/default-opensuse-132-i386.log +0 -0
  257. data/test/integration/.kitchen/logs/default-opensuse-132-x86-64.log +0 -0
  258. data/test/integration/.kitchen/logs/default-redhat-65.log +0 -0
  259. data/test/integration/.kitchen/logs/default-redhat-71.log +0 -0
  260. data/test/integration/.kitchen/logs/default-suse-11sp3.log +0 -0
  261. data/test/integration/.kitchen/logs/default-suse-12.log +0 -0
  262. data/test/integration/.kitchen/logs/default-ubuntu-1004-i386.log +0 -0
  263. data/test/integration/.kitchen/logs/default-ubuntu-1004.log +0 -0
  264. data/test/integration/.kitchen/logs/default-ubuntu-1204-i386.log +0 -0
  265. data/test/integration/.kitchen/logs/default-ubuntu-1204.log +23 -0
  266. data/test/integration/.kitchen/logs/default-ubuntu-1404-i386.log +0 -0
  267. data/test/integration/.kitchen/logs/default-ubuntu-1404.log +0 -0
  268. data/test/integration/.kitchen/logs/default-ubuntu-1510.log +0 -0
  269. data/test/integration/.kitchen/logs/default-windows-2012.log +0 -0
  270. data/test/integration/.kitchen/logs/default-windows-2012r2.log +0 -0
  271. data/test/integration/.kitchen/logs/kitchen.log +3 -0
  272. data/test/integration/.kitchen/logs/new-centos-511-i386.log +0 -0
  273. data/test/integration/.kitchen/logs/new-centos-511.log +0 -0
  274. data/test/integration/.kitchen/logs/new-centos-67-i386.log +0 -0
  275. data/test/integration/.kitchen/logs/new-centos-67.log +0 -0
  276. data/test/integration/.kitchen/logs/new-centos-71.log +0 -0
  277. data/test/integration/.kitchen/logs/new-debian-6010-i386.log +0 -0
  278. data/test/integration/.kitchen/logs/new-debian-6010.log +0 -0
  279. data/test/integration/.kitchen/logs/new-debian-78-i386.log +0 -0
  280. data/test/integration/.kitchen/logs/new-debian-78.log +0 -0
  281. data/test/integration/.kitchen/logs/new-debian-81-i386.log +0 -0
  282. data/test/integration/.kitchen/logs/new-debian-81.log +0 -0
  283. data/test/integration/.kitchen/logs/new-fedora-21-i386.log +0 -0
  284. data/test/integration/.kitchen/logs/new-fedora-21.log +0 -0
  285. data/test/integration/.kitchen/logs/new-fedora-22.log +0 -0
  286. data/test/integration/.kitchen/logs/new-freebsd-102.log +0 -0
  287. data/test/integration/.kitchen/logs/new-freebsd-93.log +0 -0
  288. data/test/integration/.kitchen/logs/new-opensuse-132-i386.log +0 -0
  289. data/test/integration/.kitchen/logs/new-opensuse-132-x86-64.log +0 -0
  290. data/test/integration/.kitchen/logs/new-ubuntu-1004-i386.log +0 -0
  291. data/test/integration/.kitchen/logs/new-ubuntu-1004.log +0 -0
  292. data/test/integration/.kitchen/logs/new-ubuntu-1204-i386.log +0 -0
  293. data/test/integration/.kitchen/logs/new-ubuntu-1204.log +0 -0
  294. data/test/integration/.kitchen/logs/new-ubuntu-1404-i386.log +0 -0
  295. data/test/integration/.kitchen/logs/new-ubuntu-1404.log +3 -0
  296. data/test/integration/.kitchen/logs/test-centos-511-i386.log +0 -0
  297. data/test/integration/.kitchen/logs/test-centos-511.log +0 -0
  298. data/test/integration/.kitchen/logs/test-centos-67-i386.log +0 -0
  299. data/test/integration/.kitchen/logs/test-centos-67.log +0 -0
  300. data/test/integration/.kitchen/logs/test-centos-71.log +0 -0
  301. data/test/integration/.kitchen/logs/test-debian-6010-i386.log +0 -0
  302. data/test/integration/.kitchen/logs/test-debian-6010.log +0 -0
  303. data/test/integration/.kitchen/logs/test-debian-78-i386.log +0 -0
  304. data/test/integration/.kitchen/logs/test-debian-78.log +0 -0
  305. data/test/integration/.kitchen/logs/test-debian-81-i386.log +0 -0
  306. data/test/integration/.kitchen/logs/test-debian-81.log +0 -0
  307. data/test/integration/.kitchen/logs/test-fedora-21-i386.log +0 -0
  308. data/test/integration/.kitchen/logs/test-fedora-21.log +0 -0
  309. data/test/integration/.kitchen/logs/test-fedora-22.log +0 -0
  310. data/test/integration/.kitchen/logs/test-freebsd-102.log +0 -0
  311. data/test/integration/.kitchen/logs/test-freebsd-93.log +0 -0
  312. data/test/integration/.kitchen/logs/test-opensuse-132-i386.log +0 -0
  313. data/test/integration/.kitchen/logs/test-opensuse-132-x86-64.log +0 -0
  314. data/test/integration/.kitchen/logs/test-ubuntu-1004-i386.log +0 -0
  315. data/test/integration/.kitchen/logs/test-ubuntu-1004.log +0 -0
  316. data/test/integration/.kitchen/logs/test-ubuntu-1204-i386.log +0 -0
  317. data/test/integration/.kitchen/logs/test-ubuntu-1204.log +0 -0
  318. data/test/integration/.kitchen/logs/test-ubuntu-1404-i386.log +0 -0
  319. data/test/integration/.kitchen/logs/test-ubuntu-1404.log +0 -0
  320. data/test/integration/.kitchen/new-ubuntu-1404.yml +1 -0
  321. data/test/integration/Berksfile.lock +11 -0
  322. data/test/integration/TODO.md +15 -0
  323. data/test/integration/cookbooks/os_prepare/recipes/default.rb +1 -0
  324. data/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb +13 -6
  325. data/test/integration/cookbooks/os_prepare/recipes/mount.rb +29 -0
  326. data/test/integration/test/.DS_Store +0 -0
  327. data/test/integration/test/integration/.DS_Store +0 -0
  328. data/test/integration/test/integration/default/.DS_Store +0 -0
  329. data/test/integration/test/integration/default/certificate_spec.rb +7 -0
  330. data/test/integration/test/integration/default/csv_spec.rb +7 -1
  331. data/test/integration/test/integration/default/file_spec.rb +29 -0
  332. data/test/integration/test/integration/default/ini_spec.rb +7 -1
  333. data/test/integration/test/integration/default/json_spec.rb +7 -1
  334. data/test/integration/test/integration/default/mount_spec.rb +10 -0
  335. data/test/integration/test/integration/default/yaml_spec.rb +7 -1
  336. data/test/serverspec/.kitchen.yml +18 -0
  337. data/test/serverspec/.kitchen/default-ubuntu-1404.yml +6 -0
  338. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
  339. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
  340. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
  341. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
  342. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
  343. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
  344. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/Vagrantfile +9 -0
  345. data/test/serverspec/.kitchen/logs/default-ubuntu-1404.log +2 -0
  346. data/test/serverspec/.kitchen/logs/kitchen.log +3 -0
  347. data/test/serverspec/Berksfile +3 -0
  348. data/test/serverspec/Berksfile.lock +5 -0
  349. data/test/serverspec/TODO.md +2 -0
  350. data/test/serverspec/test/integration/default/serverspec/os_spec.rb +25 -0
  351. data/test/serverspec/test/integration/default/serverspec/spec_helper.rb +48 -0
  352. data/test/serverspec/test/integration/default/serverspec/sysctl_spec.rb +37 -0
  353. data/test/unit/metadata_test.rb +69 -0
  354. data/test/unit/mock/cmd/mount +1 -0
  355. data/test/unit/mock/cmd/mount-multiple +2 -0
  356. data/test/unit/mock/profiles/complete-meta/metadata.rb +7 -0
  357. data/test/unit/mock/profiles/complete-meta/test/.gitkeep +0 -0
  358. data/test/unit/mock/profiles/complete-profile/controls/filesystem_spec.rb +16 -0
  359. data/test/unit/mock/profiles/complete-profile/inspec.yml +10 -0
  360. data/test/unit/profile_context_test.rb +2 -2
  361. data/test/unit/profile_test.rb +63 -6
  362. data/test/unit/resources/file_test.rb +4 -0
  363. data/test/unit/resources/mount_test.rb +26 -0
  364. data/test/unit/utils/{content_parser_test.rb → passwd_parser_test.rb} +2 -2
  365. metadata +588 -5
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'r-train', '~> 0.9'
27
+ spec.add_dependency 'r-train', '~> 0.9', '>= 0.9.3'
28
28
  spec.add_dependency 'thor', '~> 0.19'
29
29
  spec.add_dependency 'json', '~> 1.8'
30
30
  spec.add_dependency 'rainbow', '~> 2'
Binary file
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # author: Christoph Hartmann
3
+ # author: Dominik Richter
4
+
5
+ require 'rubygems/package'
6
+
7
+ module Inspec::Archive
8
+ class TarArchiveGenerator
9
+ def archive(base_dir, files, archive)
10
+ File.open(archive, 'wb') do |file|
11
+ Zlib::GzipWriter.wrap(file) do |gz|
12
+ Gem::Package::TarWriter.new(gz) do |tar|
13
+ files.each do |input_filename|
14
+ path = Pathname.new(base_dir).join(input_filename)
15
+ stat = File.stat(path)
16
+ if path.directory?
17
+ tar.mkdir(input_filename, stat.mode)
18
+ else
19
+ tar.add_file_simple(input_filename, stat.mode, stat.size) do |io|
20
+ io.write(File.read(path))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ # author: Christoph Hartmann
3
+ # author: Dominik Richter
4
+
5
+ require 'rubygems'
6
+ require 'zip'
7
+ require 'pathname'
8
+
9
+ module Inspec::Archive
10
+ class ZipArchiveGenerator
11
+ def archive(base_dir, files, archive)
12
+ Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
13
+ files.each do |input_filename|
14
+ zipfile.add(input_filename, Pathname.new(base_dir).join(input_filename))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,9 +7,11 @@ require 'logger'
7
7
 
8
8
  module Inspec
9
9
  # Extract metadata.rb information
10
- class Metadata
11
- attr_reader :params
12
- def initialize(logger = nil)
10
+ class Metadata # rubocop:disable Metrics/ClassLength
11
+ attr_reader :ref
12
+ attr_accessor :params
13
+ def initialize(ref, logger = nil)
14
+ @ref = ref
13
15
  @logger = logger || Logger.new(nil)
14
16
  @params = {}
15
17
  @missing_methods = []
@@ -35,45 +37,138 @@ module Inspec
35
37
  def supports(sth, version = nil)
36
38
  params[:supports] ||= []
37
39
  params[:supports].push(
40
+ # do not use hash syntax for `-` to work properly with ruby 1.9.3 parser
38
41
  {
39
- os: sth,
42
+ :'os-name' => sth, # rubocop:disable Style/HashSyntax, Lint/UnneededDisable
40
43
  version: version,
41
44
  },
42
45
  )
43
46
  end
44
47
 
48
+ def is_supported(os, entry)
49
+ name, family, release = support_fields(entry)
50
+
51
+ # return true if the backend matches the supported OS's
52
+ # fields act as masks, i.e. any value configured for os-name, os-family,
53
+ # or release must be met by the backend; any field that is nil acts as
54
+ # a glob expression i.e. is true
55
+
56
+ # os name is both saved in :family and :name, so check both
57
+ name_ok = name.nil? ||
58
+ os[:name] == name || os[:family] == name
59
+
60
+ family_check = family.to_s + '?'
61
+ family_ok = family.nil? || os[:family] == family ||
62
+ (
63
+ os.respond_to?(family_check) &&
64
+ # this call will return true if the family matches
65
+ os.method(family_check).call
66
+ )
67
+
68
+ release_ok = release.nil? || os[:release] == release
69
+
70
+ # we want to make sure that all matchers are true
71
+ name_ok && family_ok && release_ok
72
+ end
73
+
74
+ def support_fields(entry)
75
+ if entry.is_a?(Hash)
76
+ try_support = self.class.symbolize_keys(entry)
77
+ name = try_support[:'os-name'] || try_support[:os]
78
+ family = try_support[:'os-family']
79
+ release = try_support[:release]
80
+ elsif entry.is_a?(String)
81
+ @logger.warn("Using deprecated `supports` syntax: using `#{entry}` as OS family")
82
+ family = entry
83
+ end
84
+
85
+ [name, family, release]
86
+ end
87
+
88
+ def supports_transport?(backend)
89
+ # make sure the supports field is always an array
90
+ supp = params[:supports]
91
+ supp = supp.is_a?(Hash) ? [supp] : Array(supp)
92
+
93
+ # with no supports specified, always return true, as there are no
94
+ # constraints on the supported backend; it is equivalent to putting
95
+ # all fields into accept-all mode
96
+ return true if supp.empty?
97
+
98
+ found = supp.find do |entry|
99
+ is_supported(backend.os, entry)
100
+ end
101
+
102
+ # finally, if we found a supported entry, we are good to go
103
+ !found.nil?
104
+ end
105
+
45
106
  def valid?
46
107
  is_valid = true
47
- %w{ name title version summary }.each do |field|
108
+ %w{ name version }.each do |field|
48
109
  next unless params[field.to_sym].nil?
49
- @logger.error("Missing profile #{field} in metadata.rb")
110
+ @logger.error("Missing profile #{field} in #{ref}")
50
111
  is_valid = false
51
112
  end
52
- %w{ maintainer copyright }.each do |field|
113
+ %w{ title summary maintainer copyright }.each do |field|
53
114
  next unless params[field.to_sym].nil?
54
- @logger.warn("Missing profile #{field} in metadata.rb")
115
+ @logger.warn("Missing profile #{field} in #{ref}")
55
116
  is_valid = false
56
117
  end
57
118
  is_valid && @missing_methods.empty?
58
119
  end
59
120
 
60
121
  def method_missing(sth, *args)
61
- @logger.warn "metadata.rb doesn't support: #{sth} #{args}"
122
+ @logger.warn "#{ref} doesn't support: #{sth} #{args}"
62
123
  @missing_methods.push(sth)
63
124
  end
64
125
 
65
- def self.from_file(path, profile_id, logger = nil)
66
- logger ||= Logger.new(nil)
126
+ def self.symbolize_keys(hash)
127
+ hash.each_with_object({}) {|(k, v), h|
128
+ v = symbolize_keys(v) if v.is_a?(Hash)
129
+ h[k.to_sym] = v
130
+ }
131
+ end
132
+
133
+ def self.finalize(metadata, profile_id)
134
+ metadata.params['name'] = profile_id.to_s unless profile_id.to_s.empty?
135
+ metadata.params = symbolize_keys(metadata.params || {})
136
+ metadata
137
+ end
138
+
139
+ def self.from_yaml(ref, contents, profile_id, logger = nil)
140
+ res = Metadata.new(ref, logger)
141
+ res.params = YAML.load(contents)
142
+ finalize(res, profile_id)
143
+ end
144
+
145
+ def self.from_ruby(ref, contents, profile_id, logger = nil)
146
+ res = Metadata.new(ref, logger)
147
+ res.instance_eval(contents, ref, 1)
148
+ finalize(res, profile_id)
149
+ end
67
150
 
151
+ def self.from_ref(ref, contents, profile_id, logger = nil)
152
+ case File.basename(ref)
153
+ when 'inspec.yml'
154
+ from_yaml(ref, contents, profile_id, logger)
155
+ when 'metadata.rb'
156
+ from_ruby(ref, contents, profile_id, logger)
157
+ else
158
+ logger ||= Logger.new(nil)
159
+ logger.error "Don't know how to handle metadata in #{ref}"
160
+ nil
161
+ end
162
+ end
163
+
164
+ def self.from_file(path, profile_id, logger = nil)
68
165
  unless File.file?(path)
166
+ logger ||= Logger.new(nil)
69
167
  logger.error "Can't find metadata file #{path}"
70
168
  return nil
71
169
  end
72
170
 
73
- res = Metadata.new(logger)
74
- res.instance_eval(File.read(path), path, 1)
75
- res.params[:name] = profile_id.to_s unless profile_id.to_s.empty?
76
- res
171
+ from_ref(File.basename(path), File.read(path), profile_id, logger)
77
172
  end
78
173
  end
79
174
  end
@@ -4,6 +4,7 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  require 'inspec/metadata'
7
+ require 'pathname'
7
8
 
8
9
  module Inspec
9
10
  class Profile # rubocop:disable Metrics/ClassLength
@@ -15,11 +16,11 @@ module Inspec
15
16
  end
16
17
 
17
18
  attr_reader :params
18
- attr_reader :metadata
19
+ attr_reader :path
19
20
 
20
21
  def initialize(options = nil)
21
22
  @options = options || {}
22
- @profile_id = options[:id] || nil
23
+
23
24
  @params = {}
24
25
  @logger = options[:logger] || Logger.new(nil)
25
26
 
@@ -28,14 +29,16 @@ module Inspec
28
29
  fail "Cannot find directory #{@path}" unless File.directory?(@path)
29
30
 
30
31
  @metadata = read_metadata
31
- @params = @metadata.params unless @metadata.nil?
32
+ @params = @metadata.params
33
+ # use the id from parameter, name or fallback to nil
34
+ @profile_id = options[:id] || params[:name] || nil
32
35
 
33
36
  @params[:rules] = rules = {}
34
37
  @runner = Runner.new(
35
38
  id: @profile_id,
36
39
  backend: :mock,
37
40
  )
38
- @runner.add_tests([@path])
41
+ @runner.add_tests([@path], @options)
39
42
  @runner.rules.each do |id, rule|
40
43
  file = rule.instance_variable_get(:@__file)
41
44
  rules[file] ||= {}
@@ -92,23 +95,23 @@ module Inspec
92
95
 
93
96
  @logger.info "Checking profile in #{@path}"
94
97
 
95
- if @params[:name].to_s.empty?
96
- error.call('No profile name defined')
97
- elsif !(@params[:name].to_s =~ %r{^\S+\/\S+$})
98
- error.call('Profile name must be defined as: OWNER/ID')
98
+ if Pathname.new(path).join('metadata.rb').exist?
99
+ warn.call('The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
99
100
  end
100
101
 
101
- warn.call('No version defined') if @params[:name].to_s.empty?
102
- warn.call('No title defined') if @params[:name].to_s.empty?
103
- warn.call('No maintainer defined') if @params[:name].to_s.empty?
104
- warn.call('No supports defined') if @params[:name].empty?
105
- @logger.info 'Metadata OK.' if no_warnings
102
+ @logger.info 'Metadata OK.' if @metadata.valid?
106
103
 
107
- no_warnings = true
108
- if @params[:name].empty?
109
- warn.call('No rules were found.')
104
+ # check if the profile is using the old test directory instead of the
105
+ # new controls directory
106
+ if Pathname.new(path).join('test').exist? && !Pathname.new(path).join('controls').exist?
107
+ warn.call('Profile uses deprecated `test` directory, rename it to `controls`')
108
+ end
109
+
110
+ count = rules_count
111
+ if count == 0
112
+ warn.call('No controls or tests were defined.')
110
113
  else
111
- @logger.debug "Found #{@params[:name].length} rules."
114
+ @logger.info("Found #{count} rules.")
112
115
  end
113
116
 
114
117
  # iterate over hash of groups
@@ -116,6 +119,7 @@ module Inspec
116
119
  @logger.debug "Verify all rules in #{group}"
117
120
  rules_array.each do |id, rule|
118
121
  error.call('Avoid rules with empty IDs') if id.nil? or id.empty?
122
+ next if id.start_with? '(generated '
119
123
  warn.call("Rule #{id} has no title") if rule[:title].to_s.empty?
120
124
  warn.call("Rule #{id} has no description") if rule[:desc].to_s.empty?
121
125
  warn.call("Rule #{id} has impact > 1.0") if rule[:impact].to_f > 1.0
@@ -128,11 +132,76 @@ module Inspec
128
132
  no_errors
129
133
  end
130
134
 
135
+ def rules_count
136
+ @params[:rules].values.map { |hm| hm.values.length }.inject(:+) || 0
137
+ end
138
+
139
+ # generates a archive of a folder profile
140
+ def archive(opts) # rubocop:disable Metrics/AbcSize
141
+ check_result = check
142
+
143
+ if check_result && !opts.ignore_errors == false
144
+ @logger.info 'Profile check failed. Please fix the profile before generating an archive.'
145
+ return false
146
+ end
147
+
148
+ profile_name = @params[:name]
149
+
150
+ opts[:zip] ? ext='zip' : ext='tar.gz'
151
+ slug = profile_name.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '_')
152
+ archive = Pathname.new(File.dirname(__FILE__)).join('../..', "#{slug}.#{ext}")
153
+
154
+ # check if file exists otherwise overwrite the archive
155
+ if archive.exist? && !opts[:overwrite]
156
+ @logger.info "Archive #{archive} exists already. Use --overwrite."
157
+ return false
158
+ end
159
+
160
+ # remove existing archive
161
+ File.delete(archive) if archive.exist?
162
+
163
+ @logger.info "Profile check finished. Generate archive #{archive}."
164
+
165
+ # find all files
166
+ files = Dir.glob("#{path}/**/*")
167
+
168
+ # filter files that should not be part of the profile
169
+ # TODO ignore all .files, but add the files to debug output
170
+
171
+ # map absolute paths to relative paths
172
+ files = files.collect { |f| Pathname.new(f).relative_path_from(Pathname.new(path)).to_s }
173
+
174
+ # display all files that will be part of the archive
175
+ @logger.debug 'Add the following files to archive:'
176
+ files.each { |f|
177
+ @logger.debug ' ' + f
178
+ }
179
+
180
+ if opts[:zip]
181
+ # generate zip archive
182
+ require 'inspec/archive/zip'
183
+ zag = Inspec::Archive::ZipArchiveGenerator.new
184
+ zag.archive(path, files, archive)
185
+ else
186
+ # generate tar archive
187
+ require 'inspec/archive/tar'
188
+ tag = Inspec::Archive::TarArchiveGenerator.new
189
+ tag.archive(path, files, archive)
190
+ end
191
+
192
+ @logger.info 'Finished archive generation.'
193
+ true
194
+ end
195
+
131
196
  private
132
197
 
133
198
  def read_metadata
134
- mpath = File.join(@path, 'metadata.rb')
135
- @metadata = Metadata.from_file(mpath, @profile_id, @logger)
199
+ mpath = Pathname.new(path).join('inspec.yml')
200
+
201
+ # fallback to metadata.rb if inspec.yml does not exist
202
+ # TODO deprecated, will be removed in InSpec 1.0
203
+ mpath = File.join(@path, 'metadata.rb') if !mpath.exist?
204
+ Metadata.from_file(mpath, @profile_id, @logger)
136
205
  end
137
206
  end
138
207
  end
@@ -19,11 +19,15 @@ module Inspec
19
19
  @profile_id = profile_id
20
20
  @rules = profile_registry
21
21
  @only_ifs = only_ifs
22
+ @backend = backend
22
23
 
23
- dsl = create_inner_dsl(backend)
24
+ reload_dsl
25
+ end
26
+
27
+ def reload_dsl
28
+ dsl = create_inner_dsl(@backend)
24
29
  outer_dsl = create_outer_dsl(dsl)
25
30
  ctx = create_context(outer_dsl)
26
-
27
31
  @profile_context = ctx.new
28
32
  end
29
33
 
@@ -111,7 +115,7 @@ module Inspec
111
115
  define_method :describe do |*args, &block|
112
116
  path = block.source_location[0]
113
117
  line = block.source_location[1]
114
- id = "#{File.basename(path)}:#{line} #{SecureRandom.hex}"
118
+ id = "(generated from #{File.basename(path)}:#{line} #{SecureRandom.hex})"
115
119
  rule = rule_class.new(id, {}) do
116
120
  describe(*args, &block)
117
121
  end
@@ -123,10 +127,12 @@ module Inspec
123
127
  nil
124
128
  end
125
129
 
126
- def skip_rule(id)
130
+ def skip_control(id)
127
131
  __unregister_rule id
128
132
  end
129
133
 
134
+ alias_method :skip_rule, :skip_control
135
+
130
136
  def only_if(&block)
131
137
  return unless block_given?
132
138
  @skip_profile = !block.call
@@ -44,6 +44,7 @@ require 'resources/kernel_module'
44
44
  require 'resources/kernel_parameter'
45
45
  require 'resources/limits_conf'
46
46
  require 'resources/login_def'
47
+ require 'resources/mount'
47
48
  require 'resources/mysql'
48
49
  require 'resources/mysql_conf'
49
50
  require 'resources/mysql_session'
@@ -8,6 +8,7 @@ require 'uri'
8
8
  require 'inspec/backend'
9
9
  require 'inspec/profile_context'
10
10
  require 'inspec/targets'
11
+ require 'inspec/metadata'
11
12
  # spec requirements
12
13
  require 'rspec'
13
14
  require 'rspec/its'
@@ -46,10 +47,22 @@ module Inspec
46
47
  @backend = Inspec::Backend.create(@conf)
47
48
  end
48
49
 
49
- def add_tests(tests)
50
+ def add_test_profile(test, ignore_supports = false)
51
+ assets = Inspec::Targets.resolve(test, @conf)
52
+ meta_assets = assets.find_all { |a| a[:type] == :metadata }
53
+ metas = meta_assets.map do |x|
54
+ Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger])
55
+ end
56
+ metas.each do |meta|
57
+ return [] unless ignore_supports || meta.supports_transport?(@backend)
58
+ end
59
+ assets
60
+ end
61
+
62
+ def add_tests(tests, options = {})
50
63
  # retrieve the raw ruby code of all tests
51
64
  items = tests.map do |test|
52
- Inspec::Targets.resolve(test)
65
+ add_test_profile(test, options[:ignore_supports])
53
66
  end.flatten
54
67
 
55
68
  tests = items.find_all { |i| i[:type] == :test }
@@ -59,8 +72,11 @@ module Inspec
59
72
  # will ensure traditional RSpec-isms like `require 'spec_helper'`
60
73
  # continue to work.
61
74
  tests.flatten.each do |test|
62
- test_directory = File.dirname(test[:ref])
63
- $LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory)
75
+ # do not load path for virtual files, eg. from zip
76
+ if !test[:ref].nil?
77
+ test_directory = File.dirname(test[:ref])
78
+ $LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory)
79
+ end
64
80
  end
65
81
 
66
82
  # add all tests (raw) to the runtime
@@ -81,6 +97,7 @@ module Inspec
81
97
  ctx = create_context
82
98
  libs.each do |lib|
83
99
  ctx.load(lib[:content].to_s, lib[:ref], lib[:line] || 1)
100
+ ctx.reload_dsl
84
101
  end
85
102
 
86
103
  # evaluate the test content