inspec 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -2
  3. data/Gemfile +2 -1
  4. data/docs/cli.rst +1 -17
  5. data/docs/resources.rst +128 -0
  6. data/docs/shell.rst +130 -0
  7. data/inspec.gemspec +3 -4
  8. data/lib/bundles/inspec-compliance/.kitchen.yml +0 -1
  9. data/lib/bundles/inspec-compliance/README.md +8 -3
  10. data/lib/bundles/inspec-compliance/api.rb +21 -6
  11. data/lib/bundles/inspec-compliance/bootstrap.sh +13 -9
  12. data/lib/bundles/inspec-compliance/cli.rb +23 -19
  13. data/lib/bundles/inspec-compliance/target.rb +1 -0
  14. data/lib/bundles/inspec-compliance/test/integration/default/cli.rb +42 -5
  15. data/lib/bundles/inspec-init/cli.rb +9 -0
  16. data/lib/bundles/inspec-supermarket/cli.rb +9 -0
  17. data/lib/bundles/inspec-supermarket/target.rb +2 -1
  18. data/lib/fetchers/local.rb +5 -2
  19. data/lib/fetchers/url.rb +1 -0
  20. data/lib/inspec/base_cli.rb +2 -1
  21. data/lib/inspec/cli.rb +14 -5
  22. data/lib/inspec/dependencies/dependency_set.rb +38 -0
  23. data/lib/inspec/dependencies/requirement.rb +103 -0
  24. data/lib/inspec/{dependencies.rb → dependencies/resolver.rb} +13 -132
  25. data/lib/inspec/dependencies/vendor_index.rb +98 -0
  26. data/lib/inspec/plugins/source_reader.rb +4 -0
  27. data/lib/inspec/profile.rb +2 -2
  28. data/lib/inspec/resource.rb +2 -0
  29. data/lib/inspec/runner.rb +13 -1
  30. data/lib/inspec/runner_mock.rb +4 -0
  31. data/lib/inspec/runner_rspec.rb +6 -2
  32. data/lib/inspec/shell.rb +22 -1
  33. data/lib/inspec/version.rb +1 -1
  34. data/lib/resources/iis_site.rb +107 -0
  35. data/lib/resources/port.rb +11 -4
  36. data/lib/resources/ssh_conf.rb +10 -2
  37. data/lib/resources/ssl.rb +94 -0
  38. data/lib/resources/xinetd.rb +11 -2
  39. data/lib/utils/parser.rb +6 -1
  40. metadata +17 -561
  41. data/lib/utils/hash_map.rb +0 -37
  42. data/tasks/maintainers.rb +0 -213
  43. data/test/bench/startup/startup.flat.txt +0 -1005
  44. data/test/bench/startup/startup.graph.html +0 -71958
  45. data/test/bench/startup/startup.grind.dat +0 -101602
  46. data/test/bench/startup/startup.stack.html +0 -24516
  47. data/test/bench/startup.flat.txt +0 -998
  48. data/test/bench/startup.graph.html +0 -71420
  49. data/test/bench/startup.grind.dat +0 -103554
  50. data/test/bench/startup.stack.html +0 -25015
  51. data/test/cookbooks/os_prepare/attributes/default.rb +0 -2
  52. data/test/cookbooks/os_prepare/files/empty.iso +0 -0
  53. data/test/cookbooks/os_prepare/files/example.csv +0 -7
  54. data/test/cookbooks/os_prepare/files/example.ini +0 -6
  55. data/test/cookbooks/os_prepare/files/example.json +0 -12
  56. data/test/cookbooks/os_prepare/files/example.yml +0 -7
  57. data/test/cookbooks/os_prepare/metadata.rb +0 -13
  58. data/test/cookbooks/os_prepare/recipes/_runit_service_centos.rb +0 -34
  59. data/test/cookbooks/os_prepare/recipes/_upstart_service_centos.rb +0 -25
  60. data/test/cookbooks/os_prepare/recipes/apache.rb +0 -14
  61. data/test/cookbooks/os_prepare/recipes/apt.rb +0 -20
  62. data/test/cookbooks/os_prepare/recipes/auditctl.rb +0 -8
  63. data/test/cookbooks/os_prepare/recipes/default.rb +0 -29
  64. data/test/cookbooks/os_prepare/recipes/file.rb +0 -46
  65. data/test/cookbooks/os_prepare/recipes/iptables.rb +0 -13
  66. data/test/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb +0 -34
  67. data/test/cookbooks/os_prepare/recipes/mount.rb +0 -33
  68. data/test/cookbooks/os_prepare/recipes/package.rb +0 -25
  69. data/test/cookbooks/os_prepare/recipes/postgres.rb +0 -20
  70. data/test/cookbooks/os_prepare/recipes/prep_container.rb +0 -15
  71. data/test/cookbooks/os_prepare/recipes/registry_key.rb +0 -87
  72. data/test/cookbooks/os_prepare/recipes/service.rb +0 -19
  73. data/test/cookbooks/os_prepare/templates/default/sv-default-svlog-run.erb +0 -2
  74. data/test/docker_run.rb +0 -162
  75. data/test/docker_test.rb +0 -58
  76. data/test/functional/helper.rb +0 -37
  77. data/test/functional/inheritance_test.rb +0 -62
  78. data/test/functional/inspec_archive_test.rb +0 -80
  79. data/test/functional/inspec_compliance_test.rb +0 -61
  80. data/test/functional/inspec_exec_json_test.rb +0 -122
  81. data/test/functional/inspec_exec_jsonmin_test.rb +0 -59
  82. data/test/functional/inspec_exec_test.rb +0 -123
  83. data/test/functional/inspec_json_profile_test.rb +0 -103
  84. data/test/functional/inspec_test.rb +0 -91
  85. data/test/helper.rb +0 -329
  86. data/test/integration/default/_debug_spec.rb +0 -8
  87. data/test/integration/default/apache_conf_spec.rb +0 -21
  88. data/test/integration/default/apt_spec.rb +0 -37
  89. data/test/integration/default/auditd_rules_spec.rb +0 -32
  90. data/test/integration/default/cmp_matcher_spec.rb +0 -115
  91. data/test/integration/default/csv_spec.rb +0 -11
  92. data/test/integration/default/etc_group_spec.rb +0 -29
  93. data/test/integration/default/file_spec.rb +0 -195
  94. data/test/integration/default/group_spec.rb +0 -59
  95. data/test/integration/default/ini_spec.rb +0 -11
  96. data/test/integration/default/iptables_spec.rb +0 -29
  97. data/test/integration/default/json_spec.rb +0 -11
  98. data/test/integration/default/kernel_module_spec.rb +0 -23
  99. data/test/integration/default/kernel_parameter_spec.rb +0 -60
  100. data/test/integration/default/mount_spec.rb +0 -19
  101. data/test/integration/default/os_spec.rb +0 -13
  102. data/test/integration/default/package_spec.rb +0 -30
  103. data/test/integration/default/port_spec.rb +0 -27
  104. data/test/integration/default/postgres_session_spec.rb +0 -13
  105. data/test/integration/default/powershell_spec.rb +0 -42
  106. data/test/integration/default/registry_key_spec.rb +0 -109
  107. data/test/integration/default/secpol_spec.rb +0 -11
  108. data/test/integration/default/service_spec.rb +0 -128
  109. data/test/integration/default/user_spec.rb +0 -96
  110. data/test/integration/default/vbscript_spec.rb +0 -22
  111. data/test/integration/default/wmi_spec.rb +0 -66
  112. data/test/integration/default/yaml_spec.rb +0 -11
  113. data/test/resource/command_test.rb +0 -33
  114. data/test/resource/dsl_test.rb +0 -45
  115. data/test/resource/file_test.rb +0 -146
  116. data/test/resource/ssh_config.rb +0 -9
  117. data/test/resource/sshd_config.rb +0 -9
  118. data/test/test-extra.yaml +0 -11
  119. data/test/test.yaml +0 -11
  120. data/test/unit/control_test.rb +0 -58
  121. data/test/unit/fetchers/local_test.rb +0 -67
  122. data/test/unit/fetchers/mock_test.rb +0 -43
  123. data/test/unit/fetchers/tar_test.rb +0 -36
  124. data/test/unit/fetchers/url_test.rb +0 -152
  125. data/test/unit/fetchers/zip_test.rb +0 -36
  126. data/test/unit/fetchers_test.rb +0 -65
  127. data/test/unit/metadata_test.rb +0 -137
  128. data/test/unit/mock/cmd/$env-PATH +0 -1
  129. data/test/unit/mock/cmd/Get-NetAdapter +0 -24
  130. data/test/unit/mock/cmd/GetUserAccount +0 -33
  131. data/test/unit/mock/cmd/GetWin32Group +0 -23
  132. data/test/unit/mock/cmd/Resolve-DnsName +0 -26
  133. data/test/unit/mock/cmd/Test-NetConnection +0 -4
  134. data/test/unit/mock/cmd/auditctl +0 -3
  135. data/test/unit/mock/cmd/auditctl-legacy +0 -7
  136. data/test/unit/mock/cmd/auditctl-s +0 -8
  137. data/test/unit/mock/cmd/auditpol +0 -2
  138. data/test/unit/mock/cmd/brew-info-jq +0 -1
  139. data/test/unit/mock/cmd/chage-l-root +0 -7
  140. data/test/unit/mock/cmd/dpkg-s-curl +0 -21
  141. data/test/unit/mock/cmd/dscl +0 -5
  142. data/test/unit/mock/cmd/env +0 -1
  143. data/test/unit/mock/cmd/etc-apt +0 -7
  144. data/test/unit/mock/cmd/find-apache2-conf-enabled +0 -1
  145. data/test/unit/mock/cmd/find-apache2-ports-conf +0 -1
  146. data/test/unit/mock/cmd/find-etc-rc-d-name-S +0 -12
  147. data/test/unit/mock/cmd/find-net-interface +0 -9
  148. data/test/unit/mock/cmd/find-xinetd.d +0 -2
  149. data/test/unit/mock/cmd/gem-list-local-a-q-rubocop +0 -1
  150. data/test/unit/mock/cmd/get-net-tcpconnection +0 -24
  151. data/test/unit/mock/cmd/get-netadapter-binding-bridge +0 -4
  152. data/test/unit/mock/cmd/get-package-firefox +0 -30
  153. data/test/unit/mock/cmd/get-package-ruby +0 -18
  154. data/test/unit/mock/cmd/get-service-dhcp +0 -10
  155. data/test/unit/mock/cmd/get-windows-feature +0 -7
  156. data/test/unit/mock/cmd/get-wmiobject +0 -9
  157. data/test/unit/mock/cmd/getent-hosts-example.com +0 -1
  158. data/test/unit/mock/cmd/getent-passwd-jfolmer +0 -1
  159. data/test/unit/mock/cmd/getent-passwd-root +0 -1
  160. data/test/unit/mock/cmd/hpux-netstat-inet +0 -10
  161. data/test/unit/mock/cmd/hpux-netstat-inet6 +0 -11
  162. data/test/unit/mock/cmd/id-chartmann +0 -1
  163. data/test/unit/mock/cmd/id-jfolmer +0 -1
  164. data/test/unit/mock/cmd/id-root +0 -1
  165. data/test/unit/mock/cmd/initctl--version +0 -5
  166. data/test/unit/mock/cmd/initctl-show-config-ssh +0 -3
  167. data/test/unit/mock/cmd/initctl-status-ssh +0 -1
  168. data/test/unit/mock/cmd/iptables-s +0 -6
  169. data/test/unit/mock/cmd/launchctl-list +0 -3
  170. data/test/unit/mock/cmd/logins-x +0 -4
  171. data/test/unit/mock/cmd/ls-1-etc-init.d +0 -2
  172. data/test/unit/mock/cmd/ls-sys-class-net-br +0 -2
  173. data/test/unit/mock/cmd/lsmod +0 -2
  174. data/test/unit/mock/cmd/lsof-nP-i-FpctPn +0 -63
  175. data/test/unit/mock/cmd/mount +0 -1
  176. data/test/unit/mock/cmd/mount-multiple +0 -2
  177. data/test/unit/mock/cmd/netstat-an.utf8 +0 -13
  178. data/test/unit/mock/cmd/netstat-tulpen +0 -6
  179. data/test/unit/mock/cmd/npm-ls-g--json-bower +0 -9
  180. data/test/unit/mock/cmd/pacman-qi-curl +0 -21
  181. data/test/unit/mock/cmd/ping-example.com +0 -6
  182. data/test/unit/mock/cmd/pip-show-jinja2 +0 -11
  183. data/test/unit/mock/cmd/pkg-info-system-file-system-zfs +0 -8
  184. data/test/unit/mock/cmd/pkginfo-l-SUNWzfsr +0 -7
  185. data/test/unit/mock/cmd/ps-aux +0 -5
  186. data/test/unit/mock/cmd/ps-auxZ +0 -3
  187. data/test/unit/mock/cmd/pw-usershow-root-7 +0 -1
  188. data/test/unit/mock/cmd/reg_schedule +0 -6
  189. data/test/unit/mock/cmd/rpm-qia-curl +0 -24
  190. data/test/unit/mock/cmd/s11-netstat-an-finet-finet6 +0 -32
  191. data/test/unit/mock/cmd/sbin_sysctl +0 -1
  192. data/test/unit/mock/cmd/secedit-export +0 -7
  193. data/test/unit/mock/cmd/service-e +0 -2
  194. data/test/unit/mock/cmd/service-sendmail-onestatus +0 -3
  195. data/test/unit/mock/cmd/service-sshd-status +0 -1
  196. data/test/unit/mock/cmd/sockstat +0 -5
  197. data/test/unit/mock/cmd/success +0 -0
  198. data/test/unit/mock/cmd/swlist-l-product +0 -1
  199. data/test/unit/mock/cmd/systemctl-show-all-dbus +0 -6
  200. data/test/unit/mock/cmd/systemctl-show-all-sshd +0 -7
  201. data/test/unit/mock/cmd/win32_product +0 -8
  202. data/test/unit/mock/cmd/yum-repolist-all +0 -52
  203. data/test/unit/mock/files/apache2.conf +0 -14
  204. data/test/unit/mock/files/auditd.conf +0 -4
  205. data/test/unit/mock/files/bond0 +0 -37
  206. data/test/unit/mock/files/etcgroup +0 -3
  207. data/test/unit/mock/files/example.csv +0 -6
  208. data/test/unit/mock/files/grub.conf +0 -21
  209. data/test/unit/mock/files/inetd.conf +0 -2
  210. data/test/unit/mock/files/kitchen.yml +0 -7
  211. data/test/unit/mock/files/limits.conf +0 -5
  212. data/test/unit/mock/files/login.defs +0 -5
  213. data/test/unit/mock/files/mysql.conf +0 -8
  214. data/test/unit/mock/files/mysql2.conf +0 -2
  215. data/test/unit/mock/files/ntp.conf +0 -5
  216. data/test/unit/mock/files/passwd +0 -2
  217. data/test/unit/mock/files/policyfile.lock.json +0 -12
  218. data/test/unit/mock/files/ports.conf +0 -6
  219. data/test/unit/mock/files/rootwrap.conf +0 -7
  220. data/test/unit/mock/files/serve-cgi-bin.conf +0 -20
  221. data/test/unit/mock/files/shadow +0 -2
  222. data/test/unit/mock/files/ssh_config +0 -5
  223. data/test/unit/mock/files/sshd_config +0 -7
  224. data/test/unit/mock/files/sysctl.conf +0 -7
  225. data/test/unit/mock/files/xinetd.conf +0 -9
  226. data/test/unit/mock/files/xinetd.d/.gitkeep +0 -0
  227. data/test/unit/mock/files/xinetd.d_chargen-dgram +0 -9
  228. data/test/unit/mock/files/xinetd.d_chargen-stream +0 -9
  229. data/test/unit/mock/profiles/complete-metadata/inspec.yml +0 -7
  230. data/test/unit/mock/profiles/complete-profile/controls/filesystem_spec.rb +0 -16
  231. data/test/unit/mock/profiles/complete-profile/inspec.yml +0 -10
  232. data/test/unit/mock/profiles/complete-profile/libraries/testlib.rb +0 -1
  233. data/test/unit/mock/profiles/empty-metadata/inspec.yml +0 -0
  234. data/test/unit/mock/profiles/legacy-complete-metadata/metadata.rb +0 -7
  235. data/test/unit/mock/profiles/legacy-complete-metadata/test/.gitkeep +0 -0
  236. data/test/unit/mock/profiles/legacy-empty-metadata/controls/.gitkeep +0 -0
  237. data/test/unit/mock/profiles/legacy-empty-metadata/metadata.rb +0 -0
  238. data/test/unit/mock/profiles/legacy-simple-metadata/metadata.rb +0 -1
  239. data/test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep +0 -0
  240. data/test/unit/mock/profiles/library/controls/filesystem_spec.rb +0 -7
  241. data/test/unit/mock/profiles/library/inspec.yml +0 -10
  242. data/test/unit/mock/profiles/library/libraries/gordonlib.rb +0 -2
  243. data/test/unit/mock/profiles/library/libraries/testlib.rb +0 -12
  244. data/test/unit/mock/profiles/resource-tiny/inspec.yml +0 -10
  245. data/test/unit/mock/profiles/resource-tiny/libraries/resource.rb +0 -3
  246. data/test/unit/mock/profiles/simple-metadata/inspec.yml +0 -1
  247. data/test/unit/mock/profiles/skippy-profile-os/controls/one.rb +0 -3
  248. data/test/unit/mock/profiles/skippy-profile-os/inspec.yml +0 -5
  249. data/test/unit/mock/profiles/spec_only/specfile.rb +0 -11
  250. data/test/unit/mock/profiles/supported_inspec/inspec.yml +0 -2
  251. data/test/unit/mock/profiles/unsupported_inspec/inspec.yml +0 -2
  252. data/test/unit/objects_test.rb +0 -65
  253. data/test/unit/plugin_test.rb +0 -44
  254. data/test/unit/plugins/resource_test.rb +0 -60
  255. data/test/unit/profile_context_test.rb +0 -345
  256. data/test/unit/profile_test.rb +0 -252
  257. data/test/unit/resources/apache_conf_test.rb +0 -31
  258. data/test/unit/resources/apt_test.rb +0 -46
  259. data/test/unit/resources/audit_policy_test.rb +0 -13
  260. data/test/unit/resources/auditd_conf_test.rb +0 -15
  261. data/test/unit/resources/auditd_rules_test.rb +0 -91
  262. data/test/unit/resources/bash_test.rb +0 -29
  263. data/test/unit/resources/bond_test.rb +0 -24
  264. data/test/unit/resources/bridge_test.rb +0 -56
  265. data/test/unit/resources/csv_test.rb +0 -35
  266. data/test/unit/resources/etc_group_test.rb +0 -37
  267. data/test/unit/resources/file_test.rb +0 -202
  268. data/test/unit/resources/gem_test.rb +0 -20
  269. data/test/unit/resources/group_test.rb +0 -96
  270. data/test/unit/resources/grub_conf_test.rb +0 -29
  271. data/test/unit/resources/host_test.rb +0 -38
  272. data/test/unit/resources/inetd_conf_test.rb +0 -15
  273. data/test/unit/resources/ini_test.rb +0 -16
  274. data/test/unit/resources/interface_test.rb +0 -54
  275. data/test/unit/resources/iptables_test.rb +0 -35
  276. data/test/unit/resources/json_test.rb +0 -36
  277. data/test/unit/resources/kernel_module_test.rb +0 -23
  278. data/test/unit/resources/kernel_parameter_test.rb +0 -13
  279. data/test/unit/resources/limits_conf_test.rb +0 -14
  280. data/test/unit/resources/login_def_test.rb +0 -16
  281. data/test/unit/resources/mount_test.rb +0 -26
  282. data/test/unit/resources/mysql_conf_test.rb +0 -14
  283. data/test/unit/resources/npm_test.rb +0 -20
  284. data/test/unit/resources/ntp_conf_test.rb +0 -16
  285. data/test/unit/resources/oneget_test.rb +0 -45
  286. data/test/unit/resources/os_env_test.rb +0 -18
  287. data/test/unit/resources/os_test.rb +0 -40
  288. data/test/unit/resources/package_test.rb +0 -87
  289. data/test/unit/resources/parse_config_test.rb +0 -26
  290. data/test/unit/resources/passwd_test.rb +0 -111
  291. data/test/unit/resources/pip_test.rb +0 -15
  292. data/test/unit/resources/port_test.rb +0 -165
  293. data/test/unit/resources/powershell_test.rb +0 -32
  294. data/test/unit/resources/processes_test.rb +0 -72
  295. data/test/unit/resources/registry_key_test.rb +0 -18
  296. data/test/unit/resources/security_policy_test.rb +0 -16
  297. data/test/unit/resources/service_test.rb +0 -305
  298. data/test/unit/resources/shadow_test.rb +0 -67
  299. data/test/unit/resources/ssh_conf_test.rb +0 -33
  300. data/test/unit/resources/user_test.rb +0 -124
  301. data/test/unit/resources/vbscript_test.rb +0 -18
  302. data/test/unit/resources/windows_feature.rb +0 -17
  303. data/test/unit/resources/wmi_test.rb +0 -42
  304. data/test/unit/resources/xinetd_test.rb +0 -60
  305. data/test/unit/resources/yaml_test.rb +0 -34
  306. data/test/unit/resources/yum_test.rb +0 -68
  307. data/test/unit/shell_detector_test.rb +0 -78
  308. data/test/unit/source_reader_test.rb +0 -17
  309. data/test/unit/source_readers/flat_test.rb +0 -61
  310. data/test/unit/source_readers/inspec_test.rb +0 -38
  311. data/test/unit/utils/filter_array_test.rb +0 -59
  312. data/test/unit/utils/filter_table_test.rb +0 -177
  313. data/test/unit/utils/find_files_test.rb +0 -23
  314. data/test/unit/utils/passwd_parser_test.rb +0 -32
  315. data/test/unit/utils/simpleconfig_test.rb +0 -80
  316. data/test/unit/utils/solaris_netstat_parser.rb +0 -124
data/test/docker_test.rb DELETED
@@ -1,58 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
-
4
- require_relative 'docker_run'
5
- require_relative '../lib/inspec'
6
- #
7
- # BUGON: These requires are to get around concurrency issues with
8
- # autoloading in Ruby
9
- #
10
- require 'train'
11
- require 'train/plugins'
12
- require 'train/plugins/transport'
13
- require 'train/transports/docker'
14
-
15
- tests = ARGV
16
- if tests.empty?
17
- puts 'Nothing to do.'
18
- exit 0
19
- end
20
-
21
- class DockerTester
22
- def initialize(tests)
23
- @tests = tests
24
- @docker = DockerRunner.new
25
- end
26
-
27
- def run
28
- puts ['Running tests:', @tests].flatten.join("\n- ")
29
- puts ''
30
-
31
- conf = RSpec.configuration
32
- reporter = conf.reporter
33
- results = nil
34
-
35
- # start reporting loop
36
- reporter.report(0) do |report|
37
- results = @docker.run_all do |name, container|
38
- status = test_container(container, report)
39
- status.all? ? nil : "Failed to run tests on #{name}"
40
- end
41
- end
42
-
43
- # check if we were successful
44
- failures = results.compact
45
- failures.each { |f| puts "\033[31;1m#{f}\033[0m\n\n" }
46
- failures.empty? or fail 'Test failures'
47
- end
48
-
49
- def test_container(container, report)
50
- puts "--> run test on docker #{container.id}"
51
- opts = { 'target' => "docker://#{container.id}" }
52
- runner = Inspec::Runner.new(opts)
53
- @tests.each { |test| runner.add_target(test, opts) }
54
- runner.tests.map { |g| g.run(report) }
55
- end
56
- end
57
-
58
- DockerTester.new(tests).run
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'helper'
6
-
7
- require 'minitest/hell'
8
- class Minitest::Test
9
- parallelize_me!
10
- end
11
-
12
- class Module
13
- include Minitest::Spec::DSL
14
- end
15
-
16
- module FunctionalHelper
17
- let(:repo_path) { File.expand_path(File.join( __FILE__, '..', '..', '..')) }
18
- let(:exec_inspec) { File.join(repo_path, 'bin', 'inspec') }
19
- let(:profile_path) { File.join(repo_path, 'test', 'unit', 'mock', 'profiles') }
20
- let(:examples_path) { File.join(repo_path, 'examples') }
21
-
22
- let(:example_profile) { File.join(examples_path, 'profile') }
23
- let(:example_control) { File.join(example_profile, 'controls', 'example.rb') }
24
- let(:inheritance_profile) { File.join(examples_path, 'profile') }
25
-
26
- let(:dst) {
27
- # create a temporary path, but we only want an auto-clean helper
28
- # so remove the file and give back the path
29
- res = Tempfile.new('inspec-shred')
30
- FileUtils.rm(res.path)
31
- TMP_CACHE[res.path] = res
32
- }
33
-
34
- def inspec(commandline)
35
- CMD.run_command("#{exec_inspec} #{commandline}")
36
- end
37
- end
@@ -1,62 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- describe 'example inheritance profile' do
8
- include FunctionalHelper
9
- let(:path) { File.join(examples_path, 'inheritance') }
10
-
11
- it 'check succeeds with --profiles-path' do
12
- out = inspec('check ' + path + ' --profiles-path ' + examples_path)
13
- out.stderr.must_equal ''
14
- out.stdout.must_match /Valid.*true/
15
- out.exit_status.must_equal 0
16
- end
17
-
18
- it 'check succeeds without --profiles-path using inspec.yml' do
19
- out = inspec('check ' + path)
20
- out.stderr.must_equal ''
21
- out.stdout.must_match /Valid.*true/
22
- out.exit_status.must_equal 0
23
- end
24
-
25
- it 'archive is successful with --profiles-path' do
26
- out = inspec('archive ' + path + ' --output ' + dst.path + ' --profiles-path ' + examples_path)
27
- out.stderr.must_equal ''
28
- out.stdout.must_include 'Generate archive '+dst.path
29
- out.stdout.must_include 'Finished archive generation.'
30
- out.exit_status.must_equal 0
31
- File.exist?(dst.path).must_equal true
32
- end
33
-
34
- it 'archive is successful without --profiles-path using inspec.yml' do
35
- out = inspec('archive ' + path + ' --output ' + dst.path)
36
- out.stderr.must_equal ''
37
- out.stdout.must_include 'Generate archive '+dst.path
38
- out.stdout.must_include 'Finished archive generation.'
39
- out.exit_status.must_equal 0
40
- File.exist?(dst.path).must_equal true
41
- end
42
-
43
- it 'read the profile json with --profiles-path' do
44
- out = inspec('json ' + path + ' --profiles-path '+examples_path)
45
- out.stderr.must_equal ''
46
- out.exit_status.must_equal 0
47
- s = out.stdout
48
- hm = JSON.load(s)
49
- hm['name'].must_equal 'inheritance'
50
- hm['controls'].length.must_equal 3
51
- end
52
-
53
- it 'read the profile json without --profiles-path using inspec.yml' do
54
- out = inspec('json ' + path)
55
- out.stderr.must_equal ''
56
- out.exit_status.must_equal 0
57
- s = out.stdout
58
- hm = JSON.load(s)
59
- hm['name'].must_equal 'inheritance'
60
- hm['controls'].length.must_equal 3
61
- end
62
- end
@@ -1,80 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- describe 'inspec archive' do
8
- include FunctionalHelper
9
-
10
- it 'archive is successful' do
11
- out = inspec('archive ' + example_profile + ' --overwrite')
12
- out.exit_status.must_equal 0
13
- out.stdout.must_match /Generate archive [^ ]*profile.tar.gz/
14
- out.stdout.must_include 'Finished archive generation.'
15
- end
16
-
17
- it 'archives to output file' do
18
- out = inspec('archive ' + example_profile + ' --output ' + dst.path)
19
- out.stderr.must_equal ''
20
- out.stdout.must_include 'Generate archive '+dst.path
21
- out.stdout.must_include 'Finished archive generation.'
22
- out.exit_status.must_equal 0
23
- File.exist?(dst.path).must_equal true
24
- end
25
-
26
- it 'auto-archives when no --output is given' do
27
- auto_dst = File.join(repo_path, 'profile.tar.gz')
28
- out = inspec('archive ' + example_profile + ' --overwrite')
29
- out.stderr.must_equal ''
30
- out.stdout.must_include 'Generate archive '+auto_dst
31
- out.stdout.must_include 'Finished archive generation.'
32
- out.exit_status.must_equal 0
33
- File.exist?(auto_dst).must_equal true
34
- end
35
-
36
- it 'archive on invalid archive' do
37
- out = inspec('archive /proc --output ' + dst.path)
38
- # out.stdout.must_equal '' => we have partial stdout output right now
39
- out.stderr.must_include "Don't understand inspec profile in \"/proc\""
40
- out.exit_status.must_equal 1
41
- File.exist?(dst.path).must_equal false
42
- end
43
-
44
- it 'archive wont overwrite existing files' do
45
- x = rand.to_s
46
- File.write(dst.path, x)
47
- out = inspec('archive ' + example_profile + ' --output ' + dst.path)
48
- out.stderr.must_equal '' # uh...
49
- out.stdout.must_include "Archive #{dst.path} exists already. Use --overwrite."
50
- out.exit_status.must_equal 1
51
- File.read(dst.path).must_equal x
52
- end
53
-
54
- it 'archive will overwrite files if necessary' do
55
- x = rand.to_s
56
- File.write(dst.path, x)
57
- out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --overwrite')
58
- out.stderr.must_equal ''
59
- out.stdout.must_include 'Generate archive '+dst.path
60
- out.exit_status.must_equal 0
61
- File.read(dst.path).wont_equal x
62
- end
63
-
64
- it 'creates valid tar.gz archives' do
65
- out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --tar')
66
- out.stderr.must_equal ''
67
- out.stdout.must_include 'Generate archive '+dst.path
68
- out.exit_status.must_equal 0
69
- t = Zlib::GzipReader.open(dst.path)
70
- Gem::Package::TarReader.new(t).entries.map(&:header).map(&:name).must_include 'inspec.yml'
71
- end
72
-
73
- it 'creates valid zip archives' do
74
- out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --zip')
75
- out.stderr.must_equal ''
76
- out.stdout.must_include 'Generate archive '+dst.path
77
- out.exit_status.must_equal 0
78
- Zip::File.new(dst.path).entries.map(&:name).must_include 'inspec.yml'
79
- end
80
- end
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- # basic testing without availability of any server
8
- describe 'inspec compliance' do
9
- include FunctionalHelper
10
-
11
- it 'help' do
12
- out = inspec('compliance help')
13
- out.exit_status.must_equal 0
14
- out.stdout.must_include 'inspec compliance exec PROFILE'
15
- end
16
-
17
- # ensure we are logged out
18
- it 'logout' do
19
- out = inspec('compliance logout')
20
- out.exit_status.must_equal 0
21
- out.stdout.must_include ''
22
- end
23
-
24
- it 'login server url missing' do
25
- out = inspec('compliance login')
26
- #TODO: we need to convince thor that this is an error
27
- out.exit_status.must_equal 0
28
- out.stderr.must_include 'ERROR: "inspec login" was called with no arguments'
29
- end
30
-
31
- it 'login server with missing parameters' do
32
- out = inspec('compliance login http://example.com')
33
- out.exit_status.must_equal 1
34
- #TODO: inspec should really use stderr for errors
35
- out.stdout.must_include 'Please run `inspec compliance login` with options'
36
- end
37
-
38
- it 'inspec compliance profiles without authentication' do
39
- out = inspec('compliance profile')
40
- out.stdout.must_include 'You need to login first with `inspec compliance login`'
41
- out.exit_status.must_equal 0
42
- end
43
-
44
- it 'try to upload a profile without directory' do
45
- out = inspec('compliance upload')
46
- out.stderr.must_include 'ERROR: "inspec upload" was called with no arguments'
47
- out.exit_status.must_equal 0
48
- end
49
-
50
- it 'try to upload a profile a non-existing path' do
51
- out = inspec('compliance upload /path/to/dir')
52
- out.stdout.must_include 'You need to login first with `inspec compliance login`'
53
- out.exit_status.must_equal 0
54
- end
55
-
56
- it 'logout' do
57
- out = inspec('compliance logout')
58
- out.exit_status.must_equal 0
59
- out.stdout.must_include ''
60
- end
61
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- describe 'inspec exec with json formatter' do
8
- include FunctionalHelper
9
-
10
- it 'can execute a simple file with the json formatter' do
11
- out = inspec('exec ' + example_control + ' --format json')
12
- out.stderr.must_equal ''
13
- out.exit_status.must_equal 0
14
- JSON.load(out.stdout).must_be_kind_of Hash
15
- end
16
-
17
- it 'can execute the profile with the json formatter' do
18
- out = inspec('exec ' + example_profile + ' --format json')
19
- out.stderr.must_equal ''
20
- out.exit_status.must_equal 0
21
- JSON.load(out.stdout).must_be_kind_of Hash
22
- end
23
-
24
- describe 'execute a profile with json formatting' do
25
- let(:json) { JSON.load(inspec('exec ' + example_profile + ' --format json').stdout) }
26
- let(:profile) { json['profiles']['profile'] }
27
- let(:controls) { profile['controls'] }
28
- let(:ex1) { controls['tmp-1.0'] }
29
- let(:ex2) {
30
- k = controls.keys.find { |x| x =~ /generated/ }
31
- controls[k]
32
- }
33
- let(:ex3) { profile['controls']['gordon-1.0'] }
34
- let(:check_result) {
35
- ex3['results'].find { |x| x['resource'] == 'gordon_config' }
36
- }
37
-
38
- it 'has all the metadata' do
39
- actual = profile.dup
40
- key = actual.delete('controls').keys
41
- .find { |x| x =~ /generated from example.rb/ }
42
- actual.must_equal({
43
- "name" => "profile",
44
- "title" => "InSpec Example Profile",
45
- "maintainer" => "Chef Software, Inc.",
46
- "copyright" => "Chef Software, Inc.",
47
- "copyright_email" => "support@chef.io",
48
- "license" => "Apache 2 license",
49
- "summary" => "Demonstrates the use of InSpec Compliance Profile",
50
- "version" => "1.0.0",
51
- "supports" => [{"os-family" => "unix"}],
52
- "groups" => {
53
- "controls/meta.rb" => {"title"=>"SSH Server Configuration", "controls"=>["ssh-1"]},
54
- "controls/example.rb" => {"title"=>"/tmp profile", "controls"=>["tmp-1.0", key]},
55
- "controls/gordon.rb" => {"title"=>"Gordon Config Checks", "controls"=>["gordon-1.0"]},
56
- },
57
- "attributes" => []
58
- })
59
- end
60
-
61
- it 'must have 4 controls' do
62
- controls.length.must_equal 4
63
- end
64
-
65
- it 'has an id for every control' do
66
- controls.keys.find(&:nil?).must_be :nil?
67
- end
68
-
69
- it 'has no missing checks' do
70
- json['other_checks'].must_equal([])
71
- end
72
-
73
- it 'has results for every control' do
74
- ex1['results'].length.must_equal 1
75
- ex2['results'].length.must_equal 1
76
- ex3['results'].length.must_equal 2
77
- end
78
-
79
- it 'has the right result for tmp-1.0' do
80
- actual = ex1.dup
81
-
82
- src = actual.delete('source_location')
83
- src['ref'].must_match %r{examples/profile/controls/example.rb$}
84
- src['line'].must_equal 8
85
-
86
- result = actual.delete('results')[0]
87
- result.wont_be :nil?
88
- result['status'].must_equal 'passed'
89
- result['code_desc'].must_equal 'File /tmp should be directory'
90
- result['run_time'].wont_be :nil?
91
- result['start_time'].wont_be :nil?
92
-
93
- actual.must_equal({
94
- "title" => "Create /tmp directory",
95
- "desc" => "An optional description...",
96
- "impact" => 0.7,
97
- "refs" => [
98
- {
99
- "url" => "http://...",
100
- "ref" => "Document A-12"
101
- }
102
- ],
103
- "tags" => {
104
- "data" => "temp data",
105
- "security" => nil
106
- },
107
- "code" => "control \"tmp-1.0\" do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title \"Create /tmp directory\" # A human-readable title\n desc \"An optional description...\" # Describe why this is needed\n tag data: \"temp data\" # A tag allows you to associate key information\n tag \"security\" # to the test\n ref \"Document A-12\", url: 'http://...' # Additional references\n\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n",
108
- })
109
- end
110
- end
111
-
112
- describe 'with a profile that is not supported on this OS/platform' do
113
- let(:out) { inspec('exec ' + File.join(profile_path, 'skippy-profile-os') + ' --format json') }
114
- let(:json) { JSON.load(out.stdout) }
115
-
116
- # TODO: failure handling in json formatters...
117
-
118
- it 'never runs the actual resource' do
119
- File.exist?('/tmp/inspec_test_DONT_CREATE').must_equal false
120
- end
121
- end
122
- end
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- describe 'inspec exec' do
8
- include FunctionalHelper
9
-
10
- it 'can execute the profile with the mini json formatter' do
11
- out = inspec('exec ' + example_profile + ' --format json-min')
12
- out.stderr.must_equal ''
13
- out.exit_status.must_equal 0
14
- JSON.load(out.stdout).must_be_kind_of Hash
15
- end
16
-
17
- it 'can execute a simple file with the mini json formatter' do
18
- out = inspec('exec ' + example_control + ' --format json-min')
19
- out.stderr.must_equal ''
20
- out.exit_status.must_equal 0
21
- JSON.load(out.stdout).must_be_kind_of Hash
22
- end
23
-
24
- describe 'execute a profile with mini json formatting' do
25
- let(:json) { JSON.load(inspec('exec ' + example_profile + ' --format json-min').stdout) }
26
- let(:controls) { json['controls'] }
27
- let(:ex1) { controls.find{|x| x['id'] == 'tmp-1.0'} }
28
- let(:ex2) { controls.find{|x| x['id'] =~ /generated/} }
29
- let(:ex3) { controls.find{|x| x['id'] == 'gordon-1.0'} }
30
-
31
- it 'must have 5 examples' do
32
- json['controls'].length.must_equal 5
33
- end
34
-
35
- it 'has an id' do
36
- controls.find { |ex| !ex.key? 'id' }.must_be :nil?
37
- end
38
-
39
- it 'has a profile_id' do
40
- controls.find { |ex| !ex.key? 'profile_id' }.must_be :nil?
41
- end
42
-
43
- it 'has a code_desc' do
44
- ex1['code_desc'].must_equal 'File /tmp should be directory'
45
- controls.find { |ex| !ex.key? 'code_desc' }.must_be :nil?
46
- end
47
-
48
- it 'has a status' do
49
- ex1['status'].must_equal 'passed'
50
- ex3['status'].must_equal 'skipped'
51
- end
52
-
53
- it 'has a skip_message' do
54
- ex1['skip_message'].must_be :nil?
55
- ex3['skip_message'].must_equal "Can't find file \"/tmp/gordon/config.yaml\""
56
- end
57
- end
58
-
59
- end
@@ -1,123 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'functional/helper'
6
-
7
- describe 'inspec exec' do
8
- include FunctionalHelper
9
-
10
- it 'can execute the profile' do
11
- out = inspec('exec ' + example_profile)
12
- out.stderr.must_equal ''
13
- out.exit_status.must_equal 0
14
- stdout = out.stdout.force_encoding(Encoding::UTF_8)
15
- stdout.must_include "\n\e[32m ✔ ssh-1: Allow only SSH Protocol 2\e[0m\n"
16
- stdout.must_include "\n\e[32m ✔ tmp-1.0: Create /tmp directory\e[0m\n"
17
- stdout.must_include "
18
- \e[37m ○ gordon-1.0: Verify the version number of Gordon (1 skipped)\e[0m
19
- \e[37m Can't find file \"/tmp/gordon/config.yaml\"\e[0m
20
- "
21
- stdout.must_include "\nSummary: \e[32m4 successful\e[0m, \e[31m0 failures\e[0m, \e[37m1 skipped\e[0m\n"
22
- end
23
-
24
- it 'executes a minimum metadata-only profile' do
25
- out = inspec('exec ' + File.join(profile_path, 'simple-metadata'))
26
- out.stderr.must_equal ''
27
- out.exit_status.must_equal 0
28
- out.stdout.must_equal "
29
- Profile: yumyum profile
30
- Version: unknown
31
- Target: local://
32
-
33
- No tests executed.\e[0m
34
-
35
- Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
36
- "
37
- end
38
-
39
- it 'executes a metadata-only profile' do
40
- out = inspec('exec ' + File.join(profile_path, 'complete-metadata'))
41
- out.stderr.must_equal ''
42
- out.exit_status.must_equal 0
43
- out.stdout.must_equal "
44
- Profile: title (name)
45
- Version: 1.2.3
46
- Target: local://
47
-
48
- No tests executed.\e[0m
49
-
50
- Summary: \e[32m0 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
51
- "
52
- end
53
-
54
- it 'executes a specs-only profile' do
55
- out = inspec('exec ' + File.join(profile_path, 'spec_only'))
56
- out.stderr.must_equal ''
57
- out.exit_status.must_equal 1
58
- out.stdout.force_encoding(Encoding::UTF_8).must_equal "
59
- Target: local://
60
-
61
- \e[32m ✔ working should eq \"working\"\e[0m
62
- \e[37m ○ skippy This will be skipped intentionally.\e[0m
63
- \e[31m ✖ failing should eq \"as intended\" (
64
- expected: \"as intended\"
65
- got: \"failing\"
66
-
67
- (compared using ==)
68
- )\e[0m
69
-
70
- Summary: \e[32m1 successful\e[0m, \e[31m1 failures\e[0m, \e[37m1 skipped\e[0m
71
- "
72
- end
73
-
74
- it 'executes only specified controls' do
75
- out = inspec('exec ' + example_profile + ' --controls tmp-1.0')
76
- out.stderr.must_equal ''
77
- out.exit_status.must_equal 0
78
- out.stdout.must_include "\nSummary: \e[32m1 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
79
- end
80
-
81
- it 'can execute a simple file with the default formatter' do
82
- out = inspec('exec ' + example_control)
83
- out.stderr.must_equal ''
84
- out.exit_status.must_equal 0
85
- out.stdout.must_include "\nSummary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m\n"
86
- end
87
-
88
- describe 'with a profile that is not supported on this OS/platform' do
89
- let(:out) { inspec('exec ' + File.join(profile_path, 'skippy-profile-os')) }
90
- let(:json) { JSON.load(out.stdout) }
91
-
92
- it 'exits with an error' do
93
- out.stderr.must_match /^This OS\/platform \(.+\) is not supported by this profile.$/
94
- out.exit_status.must_equal 1
95
- end
96
- end
97
-
98
- describe 'with a profile that is supported on this version of inspec' do
99
- let(:out) { inspec('exec ' + File.join(profile_path, 'supported_inspec')) }
100
-
101
- it 'exits cleanly' do
102
- out.stderr.must_equal ''
103
- out.exit_status.must_equal 0
104
- end
105
- end
106
-
107
- describe 'with a profile that is not supported on this version of inspec' do
108
- let(:out) { inspec('exec ' + File.join(profile_path, 'unsupported_inspec')) }
109
-
110
- it 'does not support this profile' do
111
- out.exit_status.must_equal 1
112
- out.stderr.must_equal "This profile requires InSpec version >= 99.0.0. You are running InSpec v#{Inspec::VERSION}.\n"
113
- end
114
- end
115
-
116
- describe 'with a profile that loads a library and reference' do
117
- let(:out) { inspec('exec ' + File.join(profile_path, 'library')) }
118
-
119
- it 'executes the profile without error' do
120
- out.exit_status.must_equal 0
121
- end
122
- end
123
- end