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
@@ -6,4 +6,5 @@ require 'inspec/targets/core'
6
6
  require 'inspec/targets/file'
7
7
  require 'inspec/targets/folder'
8
8
  require 'inspec/targets/url'
9
- require 'inspec/targets/dir'
9
+ require 'inspec/targets/zip'
10
+ require 'inspec/targets/tar'
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+
5
+ require 'rubygems/package'
6
+ require 'zlib'
7
+
8
+ module Inspec::Targets
9
+ class ArchiveHelper
10
+ def resolve(target, _opts = {})
11
+ files, rootdir = structure(target)
12
+
13
+ # remove trailing slashes
14
+ files = files.collect { |f| f.chomp('/') }
15
+
16
+ # remove leading directory
17
+ files = files.collect { |f|
18
+ Pathname(f).relative_path_from(Pathname(rootdir)).to_s
19
+ }
20
+
21
+ helper = DirsHelper.get_handler(files)
22
+ if helper.nil?
23
+ fail "Don't know how to handle folder #{target}"
24
+ end
25
+
26
+ # get all test file contents
27
+ raw_files = helper.get_filenames(files)
28
+ tests = content(target, raw_files, rootdir, base_folder: target)
29
+
30
+ libs = []
31
+ if helper.respond_to? :get_libraries
32
+ raw_libs = helper.get_libraries(files)
33
+ libs = content(target, raw_libs, rootdir, base_folder: target, as: :library)
34
+ end
35
+
36
+ libs + tests
37
+ end
38
+ end
39
+ end
@@ -14,13 +14,13 @@ module Inspec
14
14
  end.flatten
15
15
  end
16
16
 
17
- def self.resolve(targets)
17
+ def self.resolve(targets, opts = {})
18
18
  Array(targets).map do |target|
19
19
  handler = modules.values.find { |m| m.handles?(target) }
20
20
  if handler.nil?
21
21
  fail "Don't know how to handle target: #{target}"
22
22
  end
23
- handler.resolve(target)
23
+ handler.resolve(target, opts)
24
24
  end.flatten
25
25
  end
26
26
  end
@@ -4,9 +4,20 @@
4
4
 
5
5
  module Inspec::Targets
6
6
  module DirsHelper
7
+ # InSpec profile Loader
8
+ # Previous versions used the `test` directory instead of the new `controls`
9
+ # directory. Usage of the test directory is deprecated and not recommended
10
+ # anymore. Support for `test` will be removed in InSpec 1.0
11
+ # TODO: remove `test` support for InSpec 1.0
7
12
  class ProfileDir
8
13
  def handles?(paths)
9
- paths.include?('test') && paths.include?('metadata.rb')
14
+ (
15
+ !paths.grep(/^controls/).empty? ||
16
+ !paths.grep(/^test/).empty?
17
+ ) && (
18
+ paths.include?('inspec.yml') ||
19
+ paths.include?('metadata.rb')
20
+ )
10
21
  end
11
22
 
12
23
  def get_libraries(paths)
@@ -17,9 +28,14 @@ module Inspec::Targets
17
28
 
18
29
  def get_filenames(paths)
19
30
  paths.find_all do |path|
20
- path.start_with?('test') && path.end_with?('.rb')
31
+ (path.start_with?('controls') || path.start_with?('test')) && path.end_with?('.rb')
21
32
  end
22
33
  end
34
+
35
+ def get_metadata(paths)
36
+ return 'inspec.yml' if paths.include?('inspec.yml')
37
+ return 'metadata.rb' if paths.include?('metadata.rb')
38
+ end
23
39
  end
24
40
 
25
41
  class ChefAuditDir
@@ -23,6 +23,10 @@ module Inspec::Targets
23
23
  resolve(target, opts)
24
24
  end
25
25
  end
26
+
27
+ def to_s
28
+ 'File Loader'
29
+ end
26
30
  end
27
31
 
28
32
  Inspec::Targets.add_module('file', FileHelper.new)
@@ -11,7 +11,7 @@ module Inspec::Targets
11
11
  File.directory?(target)
12
12
  end
13
13
 
14
- def resolve(target)
14
+ def resolve(target, _opts = {})
15
15
  # find all files in the folder
16
16
  files = Dir[File.join(target, '**', '*')]
17
17
  # remove the prefix
@@ -25,17 +25,27 @@ module Inspec::Targets
25
25
 
26
26
  # get all test file contents
27
27
  file_handler = Inspec::Targets.modules['file']
28
- raw_files = helper.get_filenames(files)
29
- tests = file_handler.resolve_all(raw_files, base_folder: target)
30
-
31
- libs = []
32
- if helper.respond_to? :get_libraries
33
- raw_libs = helper.get_libraries(files)
34
- libs = file_handler.resolve_all(raw_libs,
35
- base_folder: target, as: :library)
36
- end
28
+ res = {
29
+ test: collect(helper, files, :get_filenames),
30
+ library: collect(helper, files, :get_libraries),
31
+ metadata: collect(helper, files, :get_metadata),
32
+ }.map { |as, list|
33
+ file_handler.resolve_all(list, base_folder: target, as: as)
34
+ }
35
+
36
+ # flatten the outer list layer
37
+ res.inject(&:+)
38
+ end
39
+
40
+ def to_s
41
+ 'Folder Loader'
42
+ end
43
+
44
+ private
37
45
 
38
- libs + tests
46
+ def collect(helper, files, getter)
47
+ return [] unless helper.respond_to? getter
48
+ helper.method(getter).call(files)
39
49
  end
40
50
  end
41
51
 
@@ -4,25 +4,50 @@
4
4
 
5
5
  require 'rubygems/package'
6
6
  require 'zlib'
7
+ require 'inspec/targets/archive'
7
8
 
8
9
  module Inspec::Targets
9
- class TarHelper
10
+ class TarHelper < ArchiveHelper
11
+ def handles?(target)
12
+ File.file?(target) and (
13
+ target.end_with?('.tar.gz') ||
14
+ target.end_with?('.tgz')
15
+ )
16
+ end
17
+
10
18
  def structure(input)
11
19
  files = []
20
+ rootdir = ''
12
21
  Gem::Package::TarReader.new(Zlib::GzipReader.open input) do |tar|
13
22
  files = tar.map(&:full_name)
14
23
  end
15
- files
24
+
25
+ # find root dir of profile
26
+ files.each { |f|
27
+ pn = Pathname(f)
28
+ rootdir = pn.dirname.to_s if pn.basename.to_s == 'inspec.yml' || pn.basename.to_s == 'metadata.rb'
29
+ }
30
+
31
+ # stores the rootdir of metadata.rb or inspec.yml
32
+ rootdir += '/' if !rootdir.empty?
33
+ [files, rootdir]
16
34
  end
17
35
 
18
- def content(input)
19
- content = {}
36
+ def content(input, files, rootdir = nil, opts = {})
37
+ content = []
20
38
  Gem::Package::TarReader.new(Zlib::GzipReader.open input) do |tar|
21
39
  tar.each do |entry|
22
40
  if entry.directory?
23
41
  # nothing to do
24
42
  elsif entry.file?
25
- content[entry.full_name] = entry.read
43
+ if files.include?(entry.full_name.gsub(rootdir, ''))
44
+ h = {
45
+ content: entry.read,
46
+ type: opts[:as] || :test,
47
+ # ref: File.join(input, entry.name),
48
+ }
49
+ content.push(h)
50
+ end
26
51
  elsif entry.header.typeflag == '2'
27
52
  # ignore symlinks for now
28
53
  end
@@ -30,5 +55,11 @@ module Inspec::Targets
30
55
  end
31
56
  content
32
57
  end
58
+
59
+ def to_s
60
+ 'tar.gz Loader'
61
+ end
33
62
  end
63
+
64
+ Inspec::Targets.add_module('tar', TarHelper.new)
34
65
  end
@@ -15,24 +15,56 @@ module Inspec::Targets
15
15
  %{ http https }.include? uri.scheme
16
16
  end
17
17
 
18
- def resolve(target)
19
- return nil unless target.start_with? 'https://github.com' and
20
- target.end_with? '.git'
18
+ def resolve(target, opts = {})
19
+ # abort if the target does not start with http or https
20
+ return nil unless target.start_with? 'https://' or target.start_with? 'http://'
21
21
 
22
- url = target.sub(/.git$/, '') + '/archive/master.zip'
23
- resolve_zip(url)
22
+ # support for github https url
23
+ if target.start_with? 'https://github.com' and target.end_with? '.git'
24
+ url = target.sub(/.git$/, '') + '/archive/master.tar.gz'
25
+ else
26
+ url = target
27
+ end
28
+
29
+ resolve_zip(url, opts)
24
30
  end
25
31
 
26
- def resolve_zip(url)
27
- zipfile = Tempfile.new('inspec-dl-')
28
- zipfile.binmode
29
- zipfile.write(open(url).read)
30
- zipfile.rewind
31
- content = ZipHelper.new.resolve(zipfile.path)
32
- zipfile.close
33
- zipfile.unlink
32
+ def resolve_zip(url, opts)
33
+ archive = Tempfile.new(['inspec-dl-', '.tar.gz'])
34
+ archive.binmode
35
+
36
+ remote = open(
37
+ url,
38
+ http_basic_authentication: [opts['user'] || '', opts['password'] || ''],
39
+ )
40
+
41
+ # download content
42
+ archive.write(remote.read)
43
+ archive.rewind
44
+ archive.close
45
+
46
+ content_type = remote.meta['content-type']
47
+ # replace extension with zip if we detected a zip content type
48
+ if ['application/x-zip-compressed', 'application/zip'].include?(content_type)
49
+ # rename file for proper detection in DirHelper
50
+ pn = Pathname.new(archive.path)
51
+ new_path = pn.dirname.join(pn.basename.to_s.gsub('tar.gz', 'zip'))
52
+ File.rename(pn.to_s, new_path.to_s)
53
+
54
+ content = ZipHelper.new.resolve(new_path)
55
+ File.unlink(new_path)
56
+ # use tar helper as default
57
+ elsif ['application/x-gzip', 'application/gzip'].include?(content_type)
58
+ content = TarHelper.new.resolve(archive.path)
59
+ archive.unlink
60
+ end
61
+
34
62
  content
35
63
  end
64
+
65
+ def to_s
66
+ 'URL Loader'
67
+ end
36
68
  end
37
69
 
38
70
  Inspec::Targets.add_module('url', UrlHelper.new)
@@ -4,16 +4,23 @@
4
4
 
5
5
  require 'zip'
6
6
  require 'inspec/targets/dir'
7
+ require 'inspec/targets/archive'
7
8
 
8
9
  module Inspec::Targets
9
- class ZipHelper
10
- def content(input, _filter)
10
+ class ZipHelper < ArchiveHelper
11
+ def handles?(target)
12
+ File.file?(target) and target.end_with?('.zip')
13
+ end
14
+
15
+ def content(input, files, rootdir = nil, opts = {})
11
16
  content = []
12
17
  ::Zip::InputStream.open(input) do |io|
13
18
  while (entry = io.get_next_entry)
19
+ next if !files.include?(entry.name.gsub(rootdir, ''))
14
20
  h = {
15
21
  content: io.read,
16
- ref: File.join(input, entry.name),
22
+ type: opts[:as] || :test,
23
+ # ref: File.join(input, entry.name),
17
24
  }
18
25
  content.push(h)
19
26
  end
@@ -23,25 +30,25 @@ module Inspec::Targets
23
30
 
24
31
  def structure(input)
25
32
  files = []
33
+ rootdir = ''
34
+
26
35
  ::Zip::InputStream.open(input) do |io|
27
36
  while (entry = io.get_next_entry)
37
+ pn = Pathname(entry.name)
38
+ rootdir = pn.dirname.to_s if pn.basename.to_s == 'inspec.yml' || pn.basename.to_s == 'metadata.rb'
28
39
  files.push(entry.name)
29
40
  end
30
41
  end
31
- files
42
+
43
+ # stores the rootdir of metadata.rb or inspec.yml
44
+ rootdir += '/' if !rootdir.empty?
45
+ [files, rootdir]
32
46
  end
33
47
 
34
- def resolve(path)
35
- files = structure(path)
36
- helper = DirsHelper.get_handler(files)
37
- if helper.nil?
38
- fail "Don't know how to handle folder #{path}"
39
- end
40
- # get all file contents
41
- # @TODO
42
- _file_handler = Inspec::Targets.modules['file']
43
- test_files = helper.get_filenames(files)
44
- content(path, test_files)
48
+ def to_s
49
+ 'zip Loader'
45
50
  end
46
51
  end
52
+
53
+ Inspec::Targets.add_module('zip', ZipHelper.new)
47
54
  end
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.9.7'
6
+ VERSION = '0.9.8'
7
7
  end
@@ -271,3 +271,33 @@ RSpec::Matchers.define :cmp do |expected|
271
271
  "\nexpected: value != #{expected}\n got: #{actual}\n\n(compared using `cmp` matcher)\n"
272
272
  end
273
273
  end
274
+
275
+ # user resource matcher for serverspec compatibility
276
+ # This matcher will be deprecated in future
277
+ RSpec::Matchers.define :be_mounted do
278
+ match do |path|
279
+ if !@options.nil?
280
+ path.mounted?(@options, @identical)
281
+ else
282
+ path.mounted?
283
+ end
284
+ end
285
+
286
+ chain :with do |attr|
287
+ @options = attr
288
+ @identical = false
289
+ end
290
+
291
+ chain :only_with do |attr|
292
+ @options = attr
293
+ @identical = true
294
+ end
295
+
296
+ failure_message do |path|
297
+ if !@options.nil?
298
+ "\n#{path} is not mounted with the options\n expected: #{@options}\n got: #{path.mount_options}\n"
299
+ else
300
+ "\n#{path} is not mounted\n"
301
+ end
302
+ end
303
+ end
File without changes
@@ -26,7 +26,7 @@ require 'utils/parser'
26
26
 
27
27
  class EtcGroup < Inspec.resource(1)
28
28
  include Converter
29
- include ContentParser
29
+ include CommentParser
30
30
 
31
31
  name 'etc_group'
32
32
  desc 'Use the etc_group InSpec audit resource to test groups that are defined on Linux and UNIX platforms. The /etc/group file stores details about each group---group name, password, group identifier, along with a comma-separate list of users that belong to the group.'
@@ -5,7 +5,7 @@
5
5
  # license: All rights reserved
6
6
 
7
7
  module Inspec::Resources
8
- class File < Inspec.resource(1)
8
+ class File < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
9
9
  name 'file'
10
10
  desc 'Use the file InSpec audit resource to test all system file types, including files, directories, symbolic links, named pipes, sockets, character devices, block devices, and doors.'
11
11
  example "
@@ -18,8 +18,9 @@ module Inspec::Resources
18
18
  its('mode') { should eq 0644 }
19
19
  end
20
20
  "
21
+ include MountParser
21
22
 
22
- attr_reader :file, :path
23
+ attr_reader :file, :path, :mount_options
23
24
  def initialize(path)
24
25
  @path = path
25
26
  @file = inspec.backend.file(@path)
@@ -28,7 +29,7 @@ module Inspec::Resources
28
29
  %w{
29
30
  type exist? file? block_device? character_device? socket? directory?
30
31
  symlink? pipe? mode mode? owner owned_by? group grouped_into? link_target
31
- link_path linked_to? content mtime size selinux_label mounted? immutable?
32
+ link_path linked_to? content mtime size selinux_label immutable?
32
33
  product_version file_version version? md5sum sha256sum
33
34
  }.each do |m|
34
35
  define_method m.to_sym do |*args|
@@ -58,6 +59,30 @@ module Inspec::Resources
58
59
  file_permission_granted?('x', by_usergroup, by_specific_user)
59
60
  end
60
61
 
62
+ def mounted?(expected_options = nil, identical = false)
63
+ mounted = file.mounted
64
+
65
+ # return if no additional parameters have been provided
66
+ return file.mounted? if expected_options.nil?
67
+
68
+ # deprecation warning, this functionality will be removed in future version
69
+ warn "[DEPRECATION] `be_mounted.with and be_mounted.only_with` are deprecated. Please use `mount('#{path}')` instead."
70
+
71
+ # we cannot read mount data on non-Linux systems
72
+ return nil if !inspec.os.linux?
73
+
74
+ # parse content if we are on linux
75
+ @mount_options ||= parse_mount_options(mounted.stdout, true)
76
+
77
+ if identical
78
+ # check if the options should be identical
79
+ @mount_options == expected_options
80
+ else
81
+ # otherwise compare the selected values
82
+ @mount_options.contains(expected_options)
83
+ end
84
+ end
85
+
61
86
  def to_s
62
87
  "File #{path}"
63
88
  end