inspec 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/CHANGELOG.md +23 -2
  4. data/Gemfile +1 -1
  5. data/Rakefile +15 -1
  6. data/docs/resources.rst +1 -1
  7. data/examples/profile/controls/gordon.rb +1 -1
  8. data/examples/resource/controls/tiny.rb +3 -0
  9. data/examples/resource/inspec.yml +10 -0
  10. data/examples/resource/libraries/tiny.rb +3 -0
  11. data/lib/inspec/dsl.rb +17 -17
  12. data/lib/inspec/metadata.rb +3 -8
  13. data/lib/inspec/plugins/resource.rb +1 -1
  14. data/lib/inspec/profile.rb +3 -2
  15. data/lib/inspec/profile_context.rb +2 -2
  16. data/lib/inspec/rule.rb +7 -7
  17. data/lib/inspec/shell.rb +5 -8
  18. data/lib/inspec/targets/dir.rb +1 -1
  19. data/lib/inspec/targets/tar.rb +3 -6
  20. data/lib/inspec/targets/url.rb +15 -9
  21. data/lib/inspec/targets/url.rb.orig +87 -0
  22. data/lib/inspec/version.rb +1 -1
  23. data/lib/matchers/matchers.rb +1 -1
  24. data/lib/resources/audit_policy.rb +1 -1
  25. data/lib/resources/command.rb +3 -3
  26. data/lib/resources/etc_group.rb +1 -1
  27. data/lib/resources/file.rb +4 -3
  28. data/lib/resources/group.rb +14 -18
  29. data/lib/resources/iptables.rb +1 -1
  30. data/lib/resources/json.rb +4 -6
  31. data/lib/resources/kernel_parameter.rb +1 -1
  32. data/lib/resources/os.rb +1 -1
  33. data/lib/resources/package.rb +20 -2
  34. data/lib/resources/passwd.rb +1 -1
  35. data/lib/resources/port.rb +112 -42
  36. data/lib/resources/postgres_conf.rb +1 -1
  37. data/lib/resources/postgres_session.rb +2 -2
  38. data/lib/resources/registry_key.rb +2 -1
  39. data/lib/resources/security_policy.rb +2 -2
  40. data/lib/resources/service.rb +50 -1
  41. data/lib/resources/user.rb +45 -0
  42. data/lib/resources/yum.rb +2 -2
  43. data/lib/utils/convert.rb +1 -1
  44. data/lib/utils/find_files.rb +3 -3
  45. data/lib/utils/parser.rb +2 -2
  46. data/tasks/maintainers.rb +6 -6
  47. data/test/helper.rb +4 -2
  48. data/test/integration/cookbooks/os_prepare/recipes/file.rb +9 -2
  49. data/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb +8 -2
  50. data/test/integration/test/integration/default/etc_group_spec.rb +22 -0
  51. data/test/integration/test/integration/default/file_spec.rb +10 -1
  52. data/test/integration/test/integration/default/group_spec.rb +17 -0
  53. data/test/integration/test/integration/default/package_spec.rb +10 -4
  54. data/test/integration/test/integration/default/port_spec.rb +6 -0
  55. data/test/integration/test/integration/default/service_spec.rb +3 -0
  56. data/test/integration/test/integration/default/user_spec.rb +26 -16
  57. data/test/unit/metadata_test.rb +24 -0
  58. data/test/unit/mock/cmd/lsof-nP-i-FpctPn +63 -0
  59. data/test/unit/mock/cmd/netstat-tulpen +1 -0
  60. data/test/unit/mock/cmd/systemctl-show-all-sshd +1 -1
  61. data/test/unit/mock/profiles/complete-meta/metadata.rb +1 -1
  62. data/test/unit/mock/profiles/custom-resource/libraries/resource.rb +3 -0
  63. data/test/unit/mock/profiles/custom-resource/metadata.rb +7 -0
  64. data/{examples/kitchen-ansible/.kitchen/logs/default-centos-71.log → test/unit/mock/profiles/custom-resource/test/.gitkeep} +0 -0
  65. data/test/unit/profile_test.rb +6 -2
  66. data/test/unit/resources/port_test.rb +8 -0
  67. data/test/unit/targets.rb +132 -0
  68. metadata +19 -551
  69. data/bin/os +0 -23
  70. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1204.log +0 -0
  71. data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1404.log +0 -432
  72. data/examples/kitchen-ansible/.kitchen/logs/kitchen.log +0 -10
  73. data/examples/kitchen-ansible/Gemfile.lock +0 -154
  74. data/examples/kitchen-chef/.kitchen/default-centos-71.yml +0 -6
  75. data/examples/kitchen-chef/.kitchen/default-ubuntu-1204.yml +0 -6
  76. data/examples/kitchen-chef/.kitchen/default-ubuntu-1404.yml +0 -6
  77. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  78. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  79. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/id +0 -1
  80. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  81. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/private_key +0 -27
  82. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  83. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/Vagrantfile +0 -9
  84. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  85. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  86. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +0 -1
  87. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  88. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +0 -27
  89. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  90. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/Vagrantfile +0 -9
  91. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  92. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  93. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +0 -1
  94. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  95. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +0 -27
  96. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  97. data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/Vagrantfile +0 -9
  98. data/examples/kitchen-chef/.kitchen/logs/default-centos-71.log +0 -4
  99. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1204.log +0 -4
  100. data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1404.log +0 -4
  101. data/examples/kitchen-chef/.kitchen/logs/kitchen.log +0 -8
  102. data/examples/kitchen-chef/Berksfile.lock +0 -11
  103. data/examples/kitchen-chef/Gemfile.lock +0 -223
  104. data/examples/kitchen-puppet/.bundle/config +0 -2
  105. data/examples/kitchen-puppet/.kitchen/logs/default-centos-71.log +0 -0
  106. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1204.log +0 -0
  107. data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1404.log +0 -306
  108. data/examples/kitchen-puppet/.kitchen/logs/kitchen.log +0 -10
  109. data/examples/kitchen-puppet/.librarian/puppet/config +0 -2
  110. data/examples/kitchen-puppet/Gemfile.lock +0 -174
  111. data/examples/kitchen-puppet/Puppetfile.lock +0 -2
  112. data/examples/profile/libraries/.DS_Store +0 -0
  113. data/examples/test-kitchen/.kitchen/logs/default-centos-71.log +0 -5
  114. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1204.log +0 -5
  115. data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1404.log +0 -5
  116. data/examples/test-kitchen/.kitchen/logs/kitchen.log +0 -5
  117. data/examples/test-kitchen/Berksfile.lock +0 -11
  118. data/examples/test-kitchen/Gemfile.lock +0 -233
  119. data/lib/.DS_Store +0 -0
  120. data/lib/resources/certificate.rb +0 -0
  121. data/lib/resources/private_key.rb +0 -0
  122. data/test/chefdk/.gitignore +0 -16
  123. data/test/chefdk/.kitchen.yml +0 -27
  124. data/test/chefdk/Policyfile.rb +0 -16
  125. data/test/chefdk/README.md +0 -4
  126. data/test/chefdk/chefignore +0 -100
  127. data/test/chefdk/metadata.rb +0 -7
  128. data/test/chefdk/recipes/default.rb +0 -5
  129. data/test/chefdk/spec/spec_helper.rb +0 -2
  130. data/test/chefdk/spec/unit/recipes/default_spec.rb +0 -20
  131. data/test/chefdk/test/integration/default/serverspec/default_spec.rb +0 -9
  132. data/test/chefdk/test/integration/helpers/serverspec/spec_helper.rb +0 -8
  133. data/test/integration/.DS_Store +0 -0
  134. data/test/integration/.kitchen.local.yml +0 -68
  135. data/test/integration/.kitchen/default-aws-linux.yml +0 -4
  136. data/test/integration/.kitchen/default-centos-511.yml +0 -6
  137. data/test/integration/.kitchen/default-centos-67.yml +0 -6
  138. data/test/integration/.kitchen/default-centos-7.yml +0 -4
  139. data/test/integration/.kitchen/default-centos-71.yml +0 -6
  140. data/test/integration/.kitchen/default-debian-6010.yml +0 -6
  141. data/test/integration/.kitchen/default-debian-78.yml +0 -6
  142. data/test/integration/.kitchen/default-debian-8.yml +0 -4
  143. data/test/integration/.kitchen/default-debian-81.yml +0 -6
  144. data/test/integration/.kitchen/default-fedora-21.yml +0 -6
  145. data/test/integration/.kitchen/default-fedora-22.yml +0 -4
  146. data/test/integration/.kitchen/default-freebsd-102.yml +0 -6
  147. data/test/integration/.kitchen/default-freebsd-93.yml +0 -6
  148. data/test/integration/.kitchen/default-opensuse-132-x86-64.yml +0 -6
  149. data/test/integration/.kitchen/default-redhat-65.yml +0 -4
  150. data/test/integration/.kitchen/default-redhat-71.yml +0 -4
  151. data/test/integration/.kitchen/default-suse-11sp3.yml +0 -4
  152. data/test/integration/.kitchen/default-suse-12.yml +0 -4
  153. data/test/integration/.kitchen/default-ubuntu-1004.yml +0 -6
  154. data/test/integration/.kitchen/default-ubuntu-1204.yml +0 -4
  155. data/test/integration/.kitchen/default-ubuntu-1404.yml +0 -4
  156. data/test/integration/.kitchen/default-ubuntu-1510.yml +0 -4
  157. data/test/integration/.kitchen/default-windows-2012.yml +0 -5
  158. data/test/integration/.kitchen/default-windows-2012r2.yml +0 -6
  159. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  160. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  161. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/id +0 -1
  162. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  163. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/private_key +0 -27
  164. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  165. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/Vagrantfile +0 -9
  166. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67-i386/Vagrantfile +0 -9
  167. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  168. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  169. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/id +0 -1
  170. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  171. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/private_key +0 -27
  172. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  173. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/Vagrantfile +0 -9
  174. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  175. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  176. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/id +0 -1
  177. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  178. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/private_key +0 -27
  179. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  180. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/Vagrantfile +0 -9
  181. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  182. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  183. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/id +0 -1
  184. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  185. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/private_key +0 -27
  186. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  187. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/Vagrantfile +0 -9
  188. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  189. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  190. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/id +0 -1
  191. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  192. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/private_key +0 -27
  193. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  194. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/Vagrantfile +0 -9
  195. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  196. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  197. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/id +0 -1
  198. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  199. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/private_key +0 -27
  200. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  201. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/Vagrantfile +0 -9
  202. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  203. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  204. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/id +0 -1
  205. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  206. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/private_key +0 -27
  207. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  208. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/Vagrantfile +0 -9
  209. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  210. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  211. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/id +0 -1
  212. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  213. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/private_key +0 -27
  214. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  215. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/Vagrantfile +0 -9
  216. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  217. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  218. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/id +0 -1
  219. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  220. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/private_key +0 -27
  221. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  222. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/Vagrantfile +0 -9
  223. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  224. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  225. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/id +0 -1
  226. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  227. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/private_key +0 -27
  228. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  229. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/Vagrantfile +0 -9
  230. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  231. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  232. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/id +0 -1
  233. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  234. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/private_key +0 -27
  235. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  236. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/Vagrantfile +0 -9
  237. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  238. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  239. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/id +0 -1
  240. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  241. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/private_key +0 -27
  242. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  243. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/Vagrantfile +0 -9
  244. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  245. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  246. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +0 -1
  247. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  248. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +0 -27
  249. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  250. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/Vagrantfile +0 -9
  251. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  252. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  253. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +0 -1
  254. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  255. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +0 -27
  256. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  257. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/Vagrantfile +0 -9
  258. data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-new-ubuntu-1404/Vagrantfile +0 -9
  259. data/test/integration/.kitchen/logs/default-aws-linux.log +0 -0
  260. data/test/integration/.kitchen/logs/default-centos-511-i386.log +0 -0
  261. data/test/integration/.kitchen/logs/default-centos-511.log +0 -0
  262. data/test/integration/.kitchen/logs/default-centos-67-i386.log +0 -0
  263. data/test/integration/.kitchen/logs/default-centos-67.log +0 -0
  264. data/test/integration/.kitchen/logs/default-centos-7.log +0 -0
  265. data/test/integration/.kitchen/logs/default-centos-71.log +0 -0
  266. data/test/integration/.kitchen/logs/default-debian-6010-i386.log +0 -0
  267. data/test/integration/.kitchen/logs/default-debian-6010.log +0 -0
  268. data/test/integration/.kitchen/logs/default-debian-78-i386.log +0 -0
  269. data/test/integration/.kitchen/logs/default-debian-78.log +0 -0
  270. data/test/integration/.kitchen/logs/default-debian-8.log +0 -0
  271. data/test/integration/.kitchen/logs/default-debian-81-i386.log +0 -0
  272. data/test/integration/.kitchen/logs/default-debian-81.log +0 -0
  273. data/test/integration/.kitchen/logs/default-fedora-21-i386.log +0 -0
  274. data/test/integration/.kitchen/logs/default-fedora-21.log +0 -0
  275. data/test/integration/.kitchen/logs/default-fedora-22.log +0 -0
  276. data/test/integration/.kitchen/logs/default-freebsd-102.log +0 -0
  277. data/test/integration/.kitchen/logs/default-freebsd-93.log +0 -0
  278. data/test/integration/.kitchen/logs/default-mint-172-cinnamon.log +0 -0
  279. data/test/integration/.kitchen/logs/default-opensuse-132-i386.log +0 -0
  280. data/test/integration/.kitchen/logs/default-opensuse-132-x86-64.log +0 -0
  281. data/test/integration/.kitchen/logs/default-redhat-65.log +0 -0
  282. data/test/integration/.kitchen/logs/default-redhat-71.log +0 -0
  283. data/test/integration/.kitchen/logs/default-suse-11sp3.log +0 -0
  284. data/test/integration/.kitchen/logs/default-suse-12.log +0 -0
  285. data/test/integration/.kitchen/logs/default-ubuntu-1004-i386.log +0 -0
  286. data/test/integration/.kitchen/logs/default-ubuntu-1004.log +0 -0
  287. data/test/integration/.kitchen/logs/default-ubuntu-1204-i386.log +0 -0
  288. data/test/integration/.kitchen/logs/default-ubuntu-1204.log +0 -23
  289. data/test/integration/.kitchen/logs/default-ubuntu-1404-i386.log +0 -0
  290. data/test/integration/.kitchen/logs/default-ubuntu-1404.log +0 -0
  291. data/test/integration/.kitchen/logs/default-ubuntu-1510.log +0 -0
  292. data/test/integration/.kitchen/logs/default-windows-2012.log +0 -0
  293. data/test/integration/.kitchen/logs/default-windows-2012r2.log +0 -0
  294. data/test/integration/.kitchen/logs/kitchen.log +0 -3
  295. data/test/integration/.kitchen/logs/new-centos-511-i386.log +0 -0
  296. data/test/integration/.kitchen/logs/new-centos-511.log +0 -0
  297. data/test/integration/.kitchen/logs/new-centos-67-i386.log +0 -0
  298. data/test/integration/.kitchen/logs/new-centos-67.log +0 -0
  299. data/test/integration/.kitchen/logs/new-centos-71.log +0 -0
  300. data/test/integration/.kitchen/logs/new-debian-6010-i386.log +0 -0
  301. data/test/integration/.kitchen/logs/new-debian-6010.log +0 -0
  302. data/test/integration/.kitchen/logs/new-debian-78-i386.log +0 -0
  303. data/test/integration/.kitchen/logs/new-debian-78.log +0 -0
  304. data/test/integration/.kitchen/logs/new-debian-81-i386.log +0 -0
  305. data/test/integration/.kitchen/logs/new-debian-81.log +0 -0
  306. data/test/integration/.kitchen/logs/new-fedora-21-i386.log +0 -0
  307. data/test/integration/.kitchen/logs/new-fedora-21.log +0 -0
  308. data/test/integration/.kitchen/logs/new-fedora-22.log +0 -0
  309. data/test/integration/.kitchen/logs/new-freebsd-102.log +0 -0
  310. data/test/integration/.kitchen/logs/new-freebsd-93.log +0 -0
  311. data/test/integration/.kitchen/logs/new-opensuse-132-i386.log +0 -0
  312. data/test/integration/.kitchen/logs/new-opensuse-132-x86-64.log +0 -0
  313. data/test/integration/.kitchen/logs/new-ubuntu-1004-i386.log +0 -0
  314. data/test/integration/.kitchen/logs/new-ubuntu-1004.log +0 -0
  315. data/test/integration/.kitchen/logs/new-ubuntu-1204-i386.log +0 -0
  316. data/test/integration/.kitchen/logs/new-ubuntu-1204.log +0 -0
  317. data/test/integration/.kitchen/logs/new-ubuntu-1404-i386.log +0 -0
  318. data/test/integration/.kitchen/logs/new-ubuntu-1404.log +0 -3
  319. data/test/integration/.kitchen/logs/test-centos-511-i386.log +0 -0
  320. data/test/integration/.kitchen/logs/test-centos-511.log +0 -0
  321. data/test/integration/.kitchen/logs/test-centos-67-i386.log +0 -0
  322. data/test/integration/.kitchen/logs/test-centos-67.log +0 -0
  323. data/test/integration/.kitchen/logs/test-centos-71.log +0 -0
  324. data/test/integration/.kitchen/logs/test-debian-6010-i386.log +0 -0
  325. data/test/integration/.kitchen/logs/test-debian-6010.log +0 -0
  326. data/test/integration/.kitchen/logs/test-debian-78-i386.log +0 -0
  327. data/test/integration/.kitchen/logs/test-debian-78.log +0 -0
  328. data/test/integration/.kitchen/logs/test-debian-81-i386.log +0 -0
  329. data/test/integration/.kitchen/logs/test-debian-81.log +0 -0
  330. data/test/integration/.kitchen/logs/test-fedora-21-i386.log +0 -0
  331. data/test/integration/.kitchen/logs/test-fedora-21.log +0 -0
  332. data/test/integration/.kitchen/logs/test-fedora-22.log +0 -0
  333. data/test/integration/.kitchen/logs/test-freebsd-102.log +0 -0
  334. data/test/integration/.kitchen/logs/test-freebsd-93.log +0 -0
  335. data/test/integration/.kitchen/logs/test-opensuse-132-i386.log +0 -0
  336. data/test/integration/.kitchen/logs/test-opensuse-132-x86-64.log +0 -0
  337. data/test/integration/.kitchen/logs/test-ubuntu-1004-i386.log +0 -0
  338. data/test/integration/.kitchen/logs/test-ubuntu-1004.log +0 -0
  339. data/test/integration/.kitchen/logs/test-ubuntu-1204-i386.log +0 -0
  340. data/test/integration/.kitchen/logs/test-ubuntu-1204.log +0 -0
  341. data/test/integration/.kitchen/logs/test-ubuntu-1404-i386.log +0 -0
  342. data/test/integration/.kitchen/logs/test-ubuntu-1404.log +0 -0
  343. data/test/integration/.kitchen/new-ubuntu-1404.yml +0 -1
  344. data/test/integration/Berksfile.lock +0 -11
  345. data/test/integration/TODO.md +0 -15
  346. data/test/integration/test/.DS_Store +0 -0
  347. data/test/integration/test/integration/.DS_Store +0 -0
  348. data/test/integration/test/integration/default/.DS_Store +0 -0
  349. data/test/integration/test/integration/default/certificate_spec.rb +0 -7
  350. data/test/integration/test/integration/default/etc_group.rb +0 -13
  351. data/test/serverspec/.kitchen.yml +0 -18
  352. data/test/serverspec/.kitchen/default-ubuntu-1404.yml +0 -6
  353. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +0 -1
  354. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +0 -1
  355. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +0 -1
  356. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +0 -1
  357. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +0 -27
  358. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +0 -1
  359. data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/Vagrantfile +0 -9
  360. data/test/serverspec/.kitchen/logs/default-ubuntu-1404.log +0 -2
  361. data/test/serverspec/.kitchen/logs/kitchen.log +0 -3
  362. data/test/serverspec/Berksfile +0 -3
  363. data/test/serverspec/Berksfile.lock +0 -5
  364. data/test/serverspec/TODO.md +0 -2
  365. data/test/serverspec/test/integration/default/serverspec/os_spec.rb +0 -25
  366. data/test/serverspec/test/integration/default/serverspec/spec_helper.rb +0 -48
  367. data/test/serverspec/test/integration/default/serverspec/sysctl_spec.rb +0 -37
  368. data/test/unit/mock/cmd/lsof-np-itcp +0 -4
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.9.8'
6
+ VERSION = '0.9.9'.freeze
7
7
  end
@@ -70,7 +70,7 @@ end
70
70
  # matcher to check /etc/passwd, /etc/shadow and /etc/group
71
71
  RSpec::Matchers.define :contain_legacy_plus do
72
72
  match do |file|
73
- file.content.match(/^\+:/)
73
+ file.content =~ /^\+:/
74
74
  end
75
75
  end
76
76
 
@@ -44,7 +44,7 @@ class AuditPolicy < Inspec.resource(1)
44
44
  # find line
45
45
  target = nil
46
46
  result.each_line {|s|
47
- target = s.strip if s.match(/\b.*#{key}.*\b/)
47
+ target = s.strip if s =~ /\b.*#{key}.*\b/
48
48
  }
49
49
 
50
50
  # extract value
@@ -39,15 +39,15 @@ class Cmd < Inspec.resource(1)
39
39
  end
40
40
 
41
41
  def exist?
42
+ # silent for mock resources
43
+ return false if inspec.os[:family].to_s == 'unknown'
44
+
42
45
  if inspec.os.linux?
43
46
  res = inspec.backend.run_command("bash -c 'type \"#{@command}\"'")
44
47
  elsif inspec.os.windows?
45
48
  res = inspec.backend.run_command("where.exe \"#{@command}\"")
46
49
  elsif inspec.os.unix?
47
50
  res = inspec.backend.run_command("type \"#{@command}\"")
48
- elsif inspec.os[:family].to_s == 'unknown'
49
- # silent for mock resources
50
- return false
51
51
  else
52
52
  warn "`command(#{@command}).exist?` is not suported on you OS: #{inspec.os[:family]}"
53
53
  return false
@@ -45,7 +45,7 @@ class EtcGroup < Inspec.resource(1)
45
45
 
46
46
  # skip resource if it is not supported on current OS
47
47
  return skip_resource 'The `etc_group` resource is not supported on your OS.' \
48
- unless %w{ubuntu debian redhat fedora centos arch darwin freebsd wrlinux}.include?(inspec.os[:family])
48
+ unless %w{ubuntu debian redhat fedora centos arch darwin freebsd wrlinux aix}.include?(inspec.os[:family])
49
49
  end
50
50
 
51
51
  def groups(filter = nil)
@@ -92,9 +92,8 @@ module Inspec::Resources
92
92
  def file_permission_granted?(flag, by_usergroup, by_specific_user)
93
93
  fail 'Checking file permissions is not supported on your os' unless unix?
94
94
 
95
- usergroup = usergroup_for(by_usergroup, by_specific_user)
96
-
97
- if by_specific_user.nil?
95
+ if by_specific_user.nil? || by_specific_user.empty?
96
+ usergroup = usergroup_for(by_usergroup, by_specific_user)
98
97
  check_file_permission_by_mask(usergroup, flag)
99
98
  else
100
99
  check_file_permission_by_user(by_specific_user, flag)
@@ -113,6 +112,8 @@ module Inspec::Resources
113
112
  perm_cmd = "su -s /bin/sh -c \"test -#{flag} #{path}\" #{user}"
114
113
  elsif family == 'freebsd'
115
114
  perm_cmd = "sudo -u #{user} test -#{flag} #{path}"
115
+ elsif family == 'aix'
116
+ perm_cmd = "su #{user} -c test -#{flag} #{path}"
116
117
  else
117
118
  return skip_resource 'The `file` resource does not support `by_user` on your OS.'
118
119
  end
@@ -48,15 +48,13 @@ class Group < Inspec.resource(1)
48
48
  end
49
49
 
50
50
  def gid
51
- if group_info.nil? || group_info.size == 0
52
- return nil
53
- elsif group_info.size == 1
54
- # the default case should be one group
55
- return group_info[0][:gid]
56
- else
57
- # return array if we got multiple gids
58
- return group_info.map { |grp| grp[:gid] }
59
- end
51
+ return nil if group_info.nil? || group_info.size == 0
52
+
53
+ # the default case should be one group
54
+ return group_info[0][:gid] if group_info.size == 1
55
+
56
+ # return array if we got multiple gids
57
+ group_info.map { |grp| grp[:gid] }
60
58
  end
61
59
 
62
60
  # implements rspec has matcher, to be compatible with serverspec
@@ -65,15 +63,13 @@ class Group < Inspec.resource(1)
65
63
  end
66
64
 
67
65
  def local
68
- if group_info.nil? || group_info.size == 0
69
- return nil
70
- elsif group_info.size == 1
71
- # the default case should be one group
72
- return group_info[0][:local]
73
- else
74
- # return array if we got multiple gids
75
- return group_info.map { |grp| grp[:local] }
76
- end
66
+ return nil if group_info.nil? || group_info.size == 0
67
+
68
+ # the default case should be one group
69
+ return group_info[0][:local] if group_info.size == 1
70
+
71
+ # return array if we got multiple gids
72
+ group_info.map { |grp| grp[:local] }
77
73
  end
78
74
 
79
75
  def to_s
@@ -47,7 +47,7 @@ class IpTables < Inspec.resource(1)
47
47
  retrieve_rules.each { |line|
48
48
  # checks if the rule is part of the ruleset
49
49
  # for now, we expect an excact match
50
- found = true if line.downcase == rule.downcase
50
+ found = true if line.casecmp(rule) == 0
51
51
  }
52
52
  found
53
53
  end
@@ -74,11 +74,9 @@ class JsonConfig < Inspec.resource(1)
74
74
  value = value[key.to_s].nil? ? nil : value[key.to_s]
75
75
  end
76
76
 
77
- # check if further keys exist
78
- if !keys.first.nil?
79
- return extract_value(keys.clone, value)
80
- else
81
- return value
82
- end
77
+ # if there are no more keys, just return the value
78
+ return value if keys.first.nil?
79
+ # if there are more keys, extract more
80
+ extract_value(keys.clone, value)
83
81
  end
84
82
  end
@@ -24,7 +24,7 @@ class KernelParameter < Inspec.resource(1)
24
24
  # remove whitespace
25
25
  cmd = cmd.stdout.chomp.strip
26
26
  # convert to number if possible
27
- cmd = cmd.to_i if cmd.match(/^\d+$/)
27
+ cmd = cmd.to_i if cmd =~ /^\d+$/
28
28
  cmd
29
29
  end
30
30
 
@@ -13,7 +13,7 @@ class OS < Inspec.resource(1)
13
13
 
14
14
  # reuse helper methods from backend
15
15
  %w{redhat? debian? suse? bsd? solaris? linux? unix? windows?}.each do |os_family|
16
- define_method((os_family).to_sym) do
16
+ define_method(os_family.to_sym) do
17
17
  inspec.backend.os.send(os_family)
18
18
  end
19
19
  end
@@ -36,6 +36,8 @@ class Package < Inspec.resource(1)
36
36
  @pkgman = Brew.new(inspec)
37
37
  when 'windows'
38
38
  @pkgman = WindowsPkg.new(inspec)
39
+ when 'aix'
40
+ @pkgman = BffPkg.new(inspec)
39
41
  else
40
42
  return skip_resource 'The `package` resource is not supported on your OS yet.'
41
43
  end
@@ -134,9 +136,9 @@ class Brew < PkgManagement
134
136
  # parse data
135
137
  pkg = JSON.parse(cmd.stdout)[0]
136
138
  {
137
- name: "#{pkg.name}",
139
+ name: pkg.name.to_s,
138
140
  installed: true,
139
- version: "#{pkg.installed.version}",
141
+ version: pkg.installed.version.to_s,
140
142
  type: 'brew',
141
143
  }
142
144
  end
@@ -186,3 +188,19 @@ class WindowsPkg < PkgManagement
186
188
  }
187
189
  end
188
190
  end
191
+
192
+ # AIX
193
+ class BffPkg < PkgManagement
194
+ def info(package_name)
195
+ cmd = inspec.command("lslpp -cL #{package_name}")
196
+ return nil if cmd.exit_status.to_i != 0
197
+
198
+ bff_pkg = cmd.stdout.split("\n").last.split(':')
199
+ {
200
+ name: bff_pkg[1],
201
+ installed: true,
202
+ version: bff_pkg[2],
203
+ type: 'bff',
204
+ }
205
+ end
206
+ end
@@ -87,7 +87,7 @@ end
87
87
  class PasswdUid
88
88
  def initialize(passwd, uid)
89
89
  @passwd = passwd
90
- @users = @passwd.parsed.select { |x| x['uid'] == "#{uid}" }
90
+ @users = @passwd.parsed.select { |x| x['uid'] == uid.to_s }
91
91
  end
92
92
 
93
93
  def username
@@ -34,8 +34,11 @@ class Port < Inspec.resource(1)
34
34
  case inspec.os[:family]
35
35
  when 'ubuntu', 'debian', 'redhat', 'fedora', 'centos', 'arch', 'wrlinux'
36
36
  @port_manager = LinuxPorts.new(inspec)
37
- when 'darwin'
38
- @port_manager = DarwinPorts.new(inspec)
37
+ when 'darwin', 'aix'
38
+ # AIX: see http://www.ibm.com/developerworks/aix/library/au-lsof.html#resources
39
+ # and https://www-01.ibm.com/marketing/iwm/iwm/web/reg/pick.do?source=aixbp
40
+ # Darwin: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html
41
+ @port_manager = LsofPorts.new(inspec)
39
42
  when 'windows'
40
43
  @port_manager = WindowsPorts.new(inspec)
41
44
  when 'freebsd'
@@ -129,44 +132,110 @@ class WindowsPorts < PortsInfo
129
132
  end
130
133
  end
131
134
 
132
- # extracts udp and tcp ports from macos
133
- class DarwinPorts < PortsInfo
134
- def info
135
- # collects UDP and TCP information
136
- cmd = inspec.command('lsof -nP -iTCP -iUDP -sTCP:LISTEN')
137
- return nil if cmd.exit_status.to_i != 0
135
+ # extracts udp and tcp ports from the lsof command
136
+ class LsofPorts < PortsInfo
137
+ attr_reader :lsof
138
138
 
139
+ def initialize(inspec, lsofpath = nil)
140
+ @lsof = lsofpath || 'lsof'
141
+ super(inspec)
142
+ end
143
+
144
+ def info
139
145
  ports = []
140
- # split on each newline
141
- cmd.stdout.each_line do |line|
142
- # parse each line
143
- # 1 - COMMAND, 2 - PID, 3 - USER, 4 - FD, 5 - TYPE, 6 - DEVICE, 7 - SIZE/OFF, 8 - NODE, 9 - NAME
144
- parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$/.match(line)
145
- # extract network info
146
- net_addr = parsed[9].split(':')
147
- # convert to number if possible
148
- net_port = net_addr[1]
149
- net_port = net_port.to_i if /^\d+$/.match(net_port)
150
- protocol = parsed[8].downcase
151
-
152
- # add version to protocol
153
- type = parsed[5].downcase
154
- protocol += '6' if type == 'IPv6'
155
-
156
- # map data
157
- port_info = {
158
- port: net_port,
159
- address: net_addr[0],
160
- protocol: protocol,
161
- process: parsed[1],
162
- pid: parsed[2].to_i,
163
- }
164
146
 
165
- # push data, if not headerfile
166
- ports.push(port_info) if %w{tcp tcp6 udp udp6}.include?(protocol)
147
+ # check that lsof is available, otherwise fail
148
+ fail 'Please ensure `lsof` is available on the machine.' if !inspec.command(@lsof.to_s).exist?
149
+
150
+ # -F p=pid, c=command, P=protocol name, t=type, n=internet addresses
151
+ # see 'OUTPUT FOR OTHER PROGRAMS' in LSOF(8)
152
+ lsof_cmd = inspec.command("#{@lsof} -nP -i -FpctPn")
153
+ return nil if lsof_cmd.exit_status.to_i != 0
154
+
155
+ # map to desired return struct
156
+ lsof_parser(lsof_cmd).each do |process, port_ids|
157
+ pid, cmd = process.split(':')
158
+ port_ids.each do |port_str|
159
+ # should not break on ipv6 addresses
160
+ ipv, proto, port, host = port_str.split(':', 4)
161
+ ports.push({ port: port.to_i,
162
+ address: host,
163
+ protocol: ipv == 'ipv6' ? proto + '6' : proto,
164
+ process: cmd,
165
+ pid: pid.to_i })
166
+ end
167
167
  end
168
+
168
169
  ports
169
170
  end
171
+
172
+ # rubocop:disable Metrics/CyclomaticComplexity
173
+ # rubocop:disable Metrics/AbcSize
174
+ def lsof_parser(lsof_cmd)
175
+ procs = {}
176
+ # build this with formatted output (-F) from lsof
177
+ # procs = {
178
+ # '123:sshd' => [
179
+ # 'ipv4:tcp:22:127.0.0.1',
180
+ # 'ipv6:tcp:22:::1',
181
+ # 'ipv4:tcp:*',
182
+ # 'ipv6:tcp:*',
183
+ # ],
184
+ # '456:ntpd' => [
185
+ # 'ipv4:udp:123:*',
186
+ # 'ipv6:udp:123:*',
187
+ # ]
188
+ # }
189
+ proc_id = port_id = nil
190
+ lsof_cmd.stdout.each_line do |line|
191
+ line.chomp!
192
+ key = line.slice!(0)
193
+ case key
194
+ when 'p'
195
+ proc_id = line
196
+ port_id = nil
197
+ when 'c'
198
+ proc_id += ':' + line
199
+ when 't'
200
+ port_id = line.downcase
201
+ when 'P'
202
+ port_id += ':' + line.downcase
203
+ when 'n'
204
+ src, dst = line.split('->')
205
+
206
+ # skip active comm streams
207
+ next if dst
208
+
209
+ host, port = /^(\S+):(\d+|\*)$/.match(src)[1, 2]
210
+
211
+ # skip channels from port 0 - what does this mean?
212
+ next if port == '*'
213
+
214
+ # create new array stub if !exist?
215
+ procs[proc_id] = [] unless procs.key?(proc_id)
216
+
217
+ # change address '*' to zero
218
+ host = (port_id =~ /^ipv6:/) ? '[::]' : '0.0.0.0' if host == '*'
219
+ # entrust URI to scrub the host and port
220
+ begin
221
+ uri = URI("addr://#{host}:#{port}")
222
+ uri.host && uri.port
223
+ rescue => e
224
+ warn "could not parse URI 'addr://#{host}:#{port}' - #{e}"
225
+ next
226
+ end
227
+
228
+ # e.g. 'ipv4:tcp:22:127.0.0.1'
229
+ # strip ipv6 squares for inspec
230
+ port_id += ':' + port + ':' + host.gsub(/^\[|\]$/, '')
231
+
232
+ # lsof will give us another port unless it's done
233
+ procs[proc_id] << port_id
234
+ end
235
+ end
236
+
237
+ procs
238
+ end
170
239
  end
171
240
 
172
241
  # extract port information from netstat
@@ -192,17 +261,18 @@ class LinuxPorts < PortsInfo
192
261
  # prep for URI parsing, parse ip6 port
193
262
  ip6 = /^(\S+):(\d+)$/.match(net_addr)
194
263
  ip6addr = ip6[1]
195
- ip6addr = '::' if /^:::$/.match(ip6addr)
264
+ ip6addr = '::' if ip6addr =~ /^:::$/
196
265
  # build uri
197
266
  ip_addr = URI("addr://[#{ip6addr}]:#{ip6[2]}")
198
267
  # replace []
199
268
  host = ip_addr.host[1..ip_addr.host.size-2]
200
- port = ip_addr.port
201
269
  else
202
270
  ip_addr = URI('addr://'+net_addr)
203
271
  host = ip_addr.host
204
- port = ip_addr.port
205
272
  end
273
+
274
+ port = ip_addr.port
275
+
206
276
  [host, port]
207
277
  rescue URI::InvalidURIError => e
208
278
  warn "Could not parse #{net_addr}, #{e}"
@@ -212,7 +282,7 @@ class LinuxPorts < PortsInfo
212
282
  def parse_netstat_line(line)
213
283
  # parse each line
214
284
  # 1 - Proto, 2 - Recv-Q, 3 - Send-Q, 4 - Local Address, 5 - Foreign Address, 6 - State, 7 - Inode, 8 - PID/Program name
215
- parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/.match(line)
285
+ parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?\s+(\S+)\s+(\S+)\s+(\S+)/.match(line)
216
286
 
217
287
  return {} if parsed.nil? || line.match(/^proto/i)
218
288
 
@@ -228,7 +298,7 @@ class LinuxPorts < PortsInfo
228
298
  # extract PID
229
299
  process = parsed[9].split('/')
230
300
  pid = process[0]
231
- pid = pid.to_i if /^\d+$/.match(pid)
301
+ pid = pid.to_i if pid =~ /^\d+$/
232
302
  process = process[1]
233
303
 
234
304
  # map data
@@ -264,14 +334,14 @@ class FreeBsdPorts < PortsInfo
264
334
  case protocol
265
335
  when 'tcp4', 'udp4'
266
336
  # replace * with 0.0.0.0
267
- net_addr = net_addr.gsub(/^\*:/, '0.0.0.0:') if /^*:(\d+)$/.match(net_addr)
337
+ net_addr = net_addr.gsub(/^\*:/, '0.0.0.0:') if net_addr =~ /^*:(\d+)$/
268
338
  ip_addr = URI('addr://'+net_addr)
269
339
  host = ip_addr.host
270
340
  port = ip_addr.port
271
341
  when 'tcp6', 'udp6'
272
342
  return [] if net_addr == '*:*' # abort for now
273
343
  # replace * with 0:0:0:0:0:0:0:0
274
- net_addr = net_addr.gsub(/^\*:/, '0:0:0:0:0:0:0:0:') if /^*:(\d+)$/.match(net_addr)
344
+ net_addr = net_addr.gsub(/^\*:/, '0:0:0:0:0:0:0:0:') if net_addr =~ /^*:(\d+)$/
275
345
  # extract port
276
346
  ip6 = /^(\S+):(\d+)$/.match(net_addr)
277
347
  ip6addr = ip6[1]
@@ -301,7 +371,7 @@ class FreeBsdPorts < PortsInfo
301
371
 
302
372
  # extract PID
303
373
  pid = parsed[3]
304
- pid = pid.to_i if /^\d+$/.match(pid)
374
+ pid = pid.to_i if pid =~ /^\d+$/
305
375
 
306
376
  # map tcp4 and udp4
307
377
  protocol = 'tcp' if protocol.eql?('tcp4')
@@ -21,7 +21,7 @@ class PostgresConf < Inspec.resource(1)
21
21
 
22
22
  def initialize(conf_path = nil)
23
23
  @conf_path = conf_path || inspec.postgres.conf_path
24
- @conf_dir = File.expand_path(File.dirname @conf_path)
24
+ @conf_dir = File.expand_path(File.dirname(@conf_path))
25
25
  @files_contents = {}
26
26
  @content = nil
27
27
  @params = nil