inspec-core 4.7.3 → 4.7.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bundles/inspec-supermarket/api.rb +2 -1
  3. data/lib/bundles/inspec-supermarket/cli.rb +6 -6
  4. data/lib/bundles/inspec-supermarket/target.rb +1 -0
  5. data/lib/fetchers/git.rb +3 -1
  6. data/lib/fetchers/mock.rb +1 -0
  7. data/lib/fetchers/url.rb +6 -3
  8. data/lib/inspec/backend.rb +1 -0
  9. data/lib/inspec/base_cli.rb +4 -1
  10. data/lib/inspec/cli.rb +5 -4
  11. data/lib/inspec/config.rb +9 -1
  12. data/lib/inspec/control_eval_context.rb +1 -0
  13. data/lib/inspec/dependencies/cache.rb +1 -0
  14. data/lib/inspec/dependencies/dependency_set.rb +2 -0
  15. data/lib/inspec/dependencies/lockfile.rb +1 -0
  16. data/lib/inspec/dependencies/requirement.rb +8 -7
  17. data/lib/inspec/dependencies/resolver.rb +3 -3
  18. data/lib/inspec/describe.rb +1 -0
  19. data/lib/inspec/dsl.rb +1 -1
  20. data/lib/inspec/dsl_shared.rb +1 -1
  21. data/lib/inspec/env_printer.rb +4 -4
  22. data/lib/inspec/fetcher.rb +4 -2
  23. data/lib/inspec/file_provider.rb +18 -8
  24. data/lib/inspec/formatters/base.rb +5 -0
  25. data/lib/inspec/impact.rb +2 -0
  26. data/lib/inspec/input_registry.rb +14 -13
  27. data/lib/inspec/metadata.rb +6 -2
  28. data/lib/inspec/method_source.rb +1 -1
  29. data/lib/inspec/objects/control.rb +4 -1
  30. data/lib/inspec/objects/describe.rb +3 -1
  31. data/lib/inspec/objects/input.rb +6 -5
  32. data/lib/inspec/objects/list.rb +2 -0
  33. data/lib/inspec/objects/test.rb +3 -2
  34. data/lib/inspec/plugin/v1/plugin_types/resource.rb +7 -0
  35. data/lib/inspec/plugin/v1/plugins.rb +4 -3
  36. data/lib/inspec/plugin/v1/registry.rb +3 -2
  37. data/lib/inspec/plugin/v2.rb +1 -0
  38. data/lib/inspec/plugin/v2/activator.rb +2 -0
  39. data/lib/inspec/plugin/v2/config_file.rb +4 -1
  40. data/lib/inspec/plugin/v2/filter.rb +1 -0
  41. data/lib/inspec/plugin/v2/installer.rb +9 -7
  42. data/lib/inspec/plugin/v2/loader.rb +2 -0
  43. data/lib/inspec/plugin/v2/plugin_base.rb +1 -0
  44. data/lib/inspec/plugin/v2/plugin_types/cli.rb +2 -2
  45. data/lib/inspec/plugin/v2/registry.rb +3 -1
  46. data/lib/inspec/profile.rb +13 -6
  47. data/lib/inspec/profile_context.rb +4 -2
  48. data/lib/inspec/reporters/cli.rb +14 -10
  49. data/lib/inspec/reporters/json.rb +1 -0
  50. data/lib/inspec/reporters/json_automate.rb +3 -0
  51. data/lib/inspec/reporters/json_min.rb +2 -0
  52. data/lib/inspec/resource.rb +2 -0
  53. data/lib/inspec/resources/aide_conf.rb +4 -3
  54. data/lib/inspec/resources/apache_conf.rb +1 -1
  55. data/lib/inspec/resources/apt.rb +2 -0
  56. data/lib/inspec/resources/auditd.rb +19 -18
  57. data/lib/inspec/resources/bridge.rb +5 -2
  58. data/lib/inspec/resources/chocolatey_package.rb +2 -0
  59. data/lib/inspec/resources/command.rb +1 -1
  60. data/lib/inspec/resources/crontab.rb +9 -8
  61. data/lib/inspec/resources/csv.rb +1 -1
  62. data/lib/inspec/resources/dh_params.rb +6 -0
  63. data/lib/inspec/resources/docker.rb +37 -34
  64. data/lib/inspec/resources/docker_container.rb +1 -0
  65. data/lib/inspec/resources/docker_image.rb +1 -0
  66. data/lib/inspec/resources/docker_plugin.rb +1 -0
  67. data/lib/inspec/resources/docker_service.rb +1 -0
  68. data/lib/inspec/resources/elasticsearch.rb +24 -24
  69. data/lib/inspec/resources/etc_fstab.rb +8 -7
  70. data/lib/inspec/resources/etc_group.rb +4 -0
  71. data/lib/inspec/resources/etc_hosts.rb +4 -4
  72. data/lib/inspec/resources/etc_hosts_allow_deny.rb +5 -3
  73. data/lib/inspec/resources/file.rb +4 -1
  74. data/lib/inspec/resources/filesystem.rb +5 -3
  75. data/lib/inspec/resources/firewalld.rb +7 -4
  76. data/lib/inspec/resources/groups.rb +6 -4
  77. data/lib/inspec/resources/grub_conf.rb +3 -0
  78. data/lib/inspec/resources/host.rb +5 -3
  79. data/lib/inspec/resources/http.rb +6 -4
  80. data/lib/inspec/resources/iis_app.rb +1 -0
  81. data/lib/inspec/resources/iis_app_pool.rb +1 -1
  82. data/lib/inspec/resources/iis_site.rb +4 -3
  83. data/lib/inspec/resources/interface.rb +10 -7
  84. data/lib/inspec/resources/json.rb +1 -1
  85. data/lib/inspec/resources/kernel_module.rb +1 -1
  86. data/lib/inspec/resources/kernel_parameter.rb +2 -1
  87. data/lib/inspec/resources/key_rsa.rb +5 -0
  88. data/lib/inspec/resources/mount.rb +3 -1
  89. data/lib/inspec/resources/mysql_conf.rb +3 -1
  90. data/lib/inspec/resources/mysql_session.rb +2 -0
  91. data/lib/inspec/resources/nginx.rb +1 -0
  92. data/lib/inspec/resources/nginx_conf.rb +10 -6
  93. data/lib/inspec/resources/ntp_conf.rb +1 -0
  94. data/lib/inspec/resources/oneget.rb +1 -1
  95. data/lib/inspec/resources/oracledb_session.rb +4 -2
  96. data/lib/inspec/resources/os_env.rb +1 -0
  97. data/lib/inspec/resources/package.rb +10 -6
  98. data/lib/inspec/resources/packages.rb +7 -5
  99. data/lib/inspec/resources/passwd.rb +7 -7
  100. data/lib/inspec/resources/pip.rb +2 -0
  101. data/lib/inspec/resources/port.rb +22 -8
  102. data/lib/inspec/resources/postgres.rb +2 -1
  103. data/lib/inspec/resources/postgres_conf.rb +2 -0
  104. data/lib/inspec/resources/postgres_hba_conf.rb +6 -6
  105. data/lib/inspec/resources/postgres_ident_conf.rb +3 -3
  106. data/lib/inspec/resources/processes.rb +16 -15
  107. data/lib/inspec/resources/rabbitmq_config.rb +2 -0
  108. data/lib/inspec/resources/registry_key.rb +8 -3
  109. data/lib/inspec/resources/security_identifier.rb +3 -1
  110. data/lib/inspec/resources/security_policy.rb +2 -1
  111. data/lib/inspec/resources/service.rb +13 -1
  112. data/lib/inspec/resources/shadow.rb +1 -0
  113. data/lib/inspec/resources/ssh_config.rb +2 -0
  114. data/lib/inspec/resources/ssl.rb +12 -11
  115. data/lib/inspec/resources/users.rb +29 -19
  116. data/lib/inspec/resources/virtualization.rb +10 -0
  117. data/lib/inspec/resources/windows_feature.rb +1 -1
  118. data/lib/inspec/resources/windows_hotfix.rb +2 -0
  119. data/lib/inspec/resources/windows_task.rb +4 -0
  120. data/lib/inspec/resources/wmi.rb +2 -1
  121. data/lib/inspec/resources/x509_certificate.rb +8 -0
  122. data/lib/inspec/resources/xinetd_conf.rb +10 -9
  123. data/lib/inspec/resources/yum.rb +15 -11
  124. data/lib/inspec/resources/zfs_dataset.rb +4 -2
  125. data/lib/inspec/resources/zfs_pool.rb +2 -1
  126. data/lib/inspec/rule.rb +11 -1
  127. data/lib/inspec/runner.rb +9 -6
  128. data/lib/inspec/runner_rspec.rb +10 -8
  129. data/lib/inspec/schema.rb +1 -0
  130. data/lib/inspec/secrets.rb +1 -0
  131. data/lib/inspec/secrets/yaml.rb +1 -0
  132. data/lib/inspec/shell.rb +20 -19
  133. data/lib/inspec/shell_detector.rb +1 -1
  134. data/lib/inspec/source_reader.rb +2 -0
  135. data/lib/inspec/ui.rb +1 -0
  136. data/lib/inspec/utils/deprecation/config_file.rb +8 -4
  137. data/lib/inspec/utils/erlang_parser.rb +2 -0
  138. data/lib/inspec/utils/file_reader.rb +1 -1
  139. data/lib/inspec/utils/filter.rb +16 -3
  140. data/lib/inspec/utils/find_files.rb +2 -2
  141. data/lib/inspec/utils/object_traversal.rb +1 -0
  142. data/lib/inspec/utils/parser.rb +2 -0
  143. data/lib/inspec/utils/simpleconfig.rb +4 -1
  144. data/lib/inspec/utils/telemetry/global_methods.rb +1 -0
  145. data/lib/inspec/version.rb +1 -1
  146. data/lib/matchers/matchers.rb +4 -1
  147. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +12 -11
  148. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +15 -11
  149. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +4 -2
  150. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +13 -12
  151. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +3 -0
  152. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +1 -1
  153. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +2 -2
  154. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +1 -0
  155. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +6 -5
  156. data/lib/plugins/shared/core_plugin_test_helper.rb +1 -0
  157. data/lib/source_readers/flat.rb +1 -0
  158. data/lib/source_readers/inspec.rb +1 -0
  159. metadata +2 -2
@@ -69,6 +69,7 @@ module Inspec::Resources
69
69
 
70
70
  def filter(query = {})
71
71
  return self if query.nil? || query.empty?
72
+
72
73
  res = set_params
73
74
  filters = ""
74
75
  query.each do |attr, condition|
@@ -48,6 +48,7 @@ module Inspec::Resources
48
48
  return nil if param.nil?
49
49
  # extract first value if we have only one value in array
50
50
  return param[0] if param.length == 1
51
+
51
52
  param
52
53
  end
53
54
 
@@ -66,6 +67,7 @@ module Inspec::Resources
66
67
  def read_params
67
68
  return @params if defined?(@params)
68
69
  return @params = {} if read_content.nil?
70
+
69
71
  conf = SimpleConfig.new(
70
72
  read_content,
71
73
  assignment_regex: /^\s*(\S+?)\s+(.*?)\s*$/,
@@ -59,20 +59,21 @@ class SSL < Inspec.resource(1)
59
59
  filter = FilterTable.create
60
60
  filter.register_custom_matcher(:enabled?) do |x|
61
61
  raise "Cannot determine host for SSL test. Please specify it or use a different target." if x.resource.host.nil?
62
+
62
63
  x.handshake.values.any? { |i| i["success"] }
63
64
  end
64
65
  filter.register_column(:ciphers, field: "cipher")
65
- .register_column(:protocols, field: "protocol")
66
- .register_custom_property(:handshake) do |x|
67
- groups = x.entries.group_by(&:protocol)
68
- res = Parallel.map(groups, in_threads: 8) do |proto, e|
69
- [proto, SSLShake.hello(x.resource.host, port: x.resource.port,
70
- protocol: proto, ciphers: e.map(&:cipher),
71
- timeout: x.resource.timeout, retries: x.resource.retries, servername: x.resource.host)]
72
- end
73
- Hash[res]
74
- end
75
- .install_filter_methods_on_resource(self, :scan_config)
66
+ .register_column(:protocols, field: "protocol")
67
+ .register_custom_property(:handshake) do |x|
68
+ groups = x.entries.group_by(&:protocol)
69
+ res = Parallel.map(groups, in_threads: 8) do |proto, e|
70
+ [proto, SSLShake.hello(x.resource.host, port: x.resource.port,
71
+ protocol: proto, ciphers: e.map(&:cipher),
72
+ timeout: x.resource.timeout, retries: x.resource.retries, servername: x.resource.host)]
73
+ end
74
+ Hash[res]
75
+ end
76
+ .install_filter_methods_on_resource(self, :scan_config)
76
77
 
77
78
  def to_s
78
79
  "SSL/TLS on #{@host}:#{@port}"
@@ -72,18 +72,18 @@ module Inspec::Resources
72
72
  filter = FilterTable.create
73
73
  filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
74
74
  filter.register_column(:usernames, field: :username)
75
- .register_column(:uids, field: :uid)
76
- .register_column(:gids, field: :gid)
77
- .register_column(:groupnames, field: :groupname)
78
- .register_column(:groups, field: :groups)
79
- .register_column(:homes, field: :home)
80
- .register_column(:shells, field: :shell)
81
- .register_column(:mindays, field: :mindays)
82
- .register_column(:maxdays, field: :maxdays)
83
- .register_column(:warndays, field: :warndays)
84
- .register_column(:disabled, field: :disabled)
85
- .register_custom_matcher(:disabled?) { |x| x.where { disabled == false }.entries.empty? }
86
- .register_custom_matcher(:enabled?) { |x| x.where { disabled == true }.entries.empty? }
75
+ .register_column(:uids, field: :uid)
76
+ .register_column(:gids, field: :gid)
77
+ .register_column(:groupnames, field: :groupname)
78
+ .register_column(:groups, field: :groups)
79
+ .register_column(:homes, field: :home)
80
+ .register_column(:shells, field: :shell)
81
+ .register_column(:mindays, field: :mindays)
82
+ .register_column(:maxdays, field: :maxdays)
83
+ .register_column(:warndays, field: :warndays)
84
+ .register_column(:disabled, field: :disabled)
85
+ .register_custom_matcher(:disabled?) { |x| x.where { disabled == false }.entries.empty? }
86
+ .register_custom_matcher(:enabled?) { |x| x.where { disabled == true }.entries.empty? }
87
87
  filter.install_filter_methods_on_resource(self, :collect_user_details)
88
88
 
89
89
  def to_s
@@ -254,17 +254,20 @@ module Inspec::Resources
254
254
  # returns the iden
255
255
  def identity
256
256
  return @id_cache if defined?(@id_cache)
257
- @id_cache = @user_provider.identity(@username) if !@user_provider.nil?
257
+
258
+ @id_cache = @user_provider.identity(@username) unless @user_provider.nil?
258
259
  end
259
260
 
260
261
  def meta_info
261
262
  return @meta_cache if defined?(@meta_cache)
262
- @meta_cache = @user_provider.meta_info(@username) if !@user_provider.nil?
263
+
264
+ @meta_cache = @user_provider.meta_info(@username) unless @user_provider.nil?
263
265
  end
264
266
 
265
267
  def credentials
266
268
  return @cred_cache if defined?(@cred_cache)
267
- @cred_cache = @user_provider.credentials(@username) if !@user_provider.nil?
269
+
270
+ @cred_cache = @user_provider.credentials(@username) unless @user_provider.nil?
268
271
  end
269
272
  end
270
273
 
@@ -346,6 +349,7 @@ module Inspec::Resources
346
349
  def list_users
347
350
  cmd = inspec.command(list_users_cmd)
348
351
  return [] if cmd.exit_status != 0
352
+
349
353
  cmd.stdout.chomp.lines
350
354
  end
351
355
 
@@ -389,7 +393,7 @@ module Inspec::Resources
389
393
  data.push(raw[0, index + 1]) # inclue closing )
390
394
  raw = raw[index + 2, raw.length - index - 2]
391
395
  end
392
- data.push(raw) if !raw.nil?
396
+ data.push(raw) unless raw.nil?
393
397
  data.join("\n")
394
398
  end
395
399
  end
@@ -401,6 +405,7 @@ module Inspec::Resources
401
405
  def meta_info(username)
402
406
  cmd = inspec.command("getent passwd #{username}")
403
407
  return nil if cmd.exit_status != 0
408
+
404
409
  # returns: root:x:0:0:root:/root:/bin/bash
405
410
  passwd = parse_passwd_line(cmd.stdout.chomp)
406
411
  {
@@ -440,6 +445,7 @@ module Inspec::Resources
440
445
  def identity(username)
441
446
  id = super(username)
442
447
  return nil if id.nil?
448
+
443
449
  # AIX 'id' command doesn't include the primary group in the supplementary
444
450
  # yet it can be somewhere in the supplementary list if someone added root
445
451
  # to a groups list in /etc/group
@@ -483,6 +489,7 @@ module Inspec::Resources
483
489
  def meta_info(username)
484
490
  hpuxuser = inspec.command("logins -x -l #{username}")
485
491
  return nil if hpuxuser.exit_status != 0
492
+
486
493
  user = hpuxuser.stdout.chomp.split(" ")
487
494
  {
488
495
  home: user[4],
@@ -534,6 +541,7 @@ module Inspec::Resources
534
541
  def meta_info(username)
535
542
  cmd = inspec.command("pw usershow #{username} -7")
536
543
  return nil if cmd.exit_status != 0
544
+
537
545
  # returns: root:*:0:0:Charlie &:/root:/bin/csh
538
546
  passwd = parse_passwd_line(cmd.stdout.chomp)
539
547
  {
@@ -552,7 +560,7 @@ module Inspec::Resources
552
560
  def parse_windows_account(username)
553
561
  account = username.split('\\')
554
562
  name = account.pop
555
- domain = account.pop if !account.empty?
563
+ domain = account.pop unless account.empty?
556
564
  [name, domain]
557
565
  end
558
566
 
@@ -560,8 +568,9 @@ module Inspec::Resources
560
568
  # TODO: we look for local users only at this point
561
569
  name, _domain = parse_windows_account(username)
562
570
  return if collect_user_details.nil?
571
+
563
572
  res = collect_user_details.select { |user| user[:username] == name }
564
- res[0] if !res.empty?
573
+ res[0] unless res.empty?
565
574
  end
566
575
 
567
576
  def list_users
@@ -571,6 +580,7 @@ module Inspec::Resources
571
580
  # https://msdn.microsoft.com/en-us/library/aa746340(v=vs.85).aspx
572
581
  def collect_user_details # rubocop:disable Metrics/MethodLength
573
582
  return @users_cache if defined?(@users_cache)
583
+
574
584
  script = <<~EOH
575
585
  Function ConvertTo-SID { Param([byte[]]$BinarySID)
576
586
  (New-Object System.Security.Principal.SecurityIdentifier($BinarySID,0)).Value
@@ -640,7 +650,7 @@ module Inspec::Resources
640
650
  end
641
651
 
642
652
  # ensure we have an array of groups
643
- users = [users] if !users.is_a?(Array)
653
+ users = [users] unless users.is_a?(Array)
644
654
  # convert keys to symbols
645
655
  @users_cache = users.map { |user| user.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } }
646
656
  end
@@ -67,6 +67,7 @@ module Inspec::Resources
67
67
  def detect_xen
68
68
  # This file should exist on most Xen systems, normally empty for guests
69
69
  return false unless inspec.file("/proc/xen/capabilities").exist?
70
+
70
71
  @virtualization_data[:system] = "xen"
71
72
  if inspec.file("/proc/xen/capabilities").content =~ /control_d/i
72
73
  @virtualization_data[:role] = "host"
@@ -80,6 +81,7 @@ module Inspec::Resources
80
81
  # Detect Virtualbox from kernel module
81
82
  def detect_virtualbox
82
83
  return false unless inspec.file("/proc/modules").exist?
84
+
83
85
  modules = inspec.file("/proc/modules").content
84
86
  if modules =~ /^vboxdrv/
85
87
  Inspec::Log.debug("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host")
@@ -98,6 +100,7 @@ module Inspec::Resources
98
100
  # if nova binary is present we're on an openstack host
99
101
  def detect_openstack
100
102
  return false unless nova_exists?
103
+
101
104
  @virtualization_data[:system] = "openstack"
102
105
  @virtualization_data[:role] = "host"
103
106
  true
@@ -106,6 +109,7 @@ module Inspec::Resources
106
109
  # Detect paravirt KVM/QEMU from cpuinfo, report as KVM
107
110
  def detect_kvm_from_cpuinfo
108
111
  return false unless inspec.file("/proc/cpuinfo").content =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
112
+
109
113
  @virtualization_data[:system] = "kvm"
110
114
  @virtualization_data[:role] = "guest"
111
115
  true
@@ -115,6 +119,7 @@ module Inspec::Resources
115
119
  # guests will have the hypervisor cpu feature that hosts don't have
116
120
  def detect_kvm_from_sys
117
121
  return false unless inspec.file("/sys/devices/virtual/misc/kvm").exist?
122
+
118
123
  @virtualization_data[:system] = "kvm"
119
124
  if inspec.file("/proc/cpuinfo").content =~ /hypervisor/
120
125
  @virtualization_data[:role] = "guest"
@@ -142,6 +147,7 @@ module Inspec::Resources
142
147
  # Detect Parallels virtual machine from pci devices
143
148
  def detect_parallels
144
149
  return false unless inspec.file("/proc/bus/pci/devices").content =~ /1ab84000/
150
+
145
151
  @virtualization_data[:system] = "parallels"
146
152
  @virtualization_data[:role] = "guest"
147
153
  true
@@ -150,9 +156,11 @@ module Inspec::Resources
150
156
  # Detect Linux-VServer
151
157
  def detect_linux_vserver
152
158
  return false unless inspec.file("/proc/self/status").exist?
159
+
153
160
  proc_self_status = inspec.file("/proc/self/status").content
154
161
  vxid = proc_self_status.match(/^(s_context|VxID):\s*(\d+)$/)
155
162
  return false unless vxid && vxid[2]
163
+
156
164
  @virtualization_data[:system] = "linux-vserver"
157
165
  if vxid[2] == "0"
158
166
  @virtualization_data[:role] = "host"
@@ -182,6 +190,7 @@ module Inspec::Resources
182
190
  # Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
183
191
  def detect_lxc_docker
184
192
  return false unless inspec.file("/proc/self/cgroup").exist?
193
+
185
194
  cgroup_content = inspec.file("/proc/self/cgroup").content
186
195
  if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} ||
187
196
  cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-.+$} # rubocop:disable Layout/MultilineOperationIndentation
@@ -203,6 +212,7 @@ module Inspec::Resources
203
212
 
204
213
  def detect_docker
205
214
  return false unless inspec.file("/.dockerenv").exist? || inspec.file("/.dockerinit").exist?
215
+
206
216
  @virtualization_data[:system] = "docker"
207
217
  @virtualization_data[:role] = "guest"
208
218
  true
@@ -38,7 +38,7 @@ module Inspec::Resources
38
38
 
39
39
  # returns the package description
40
40
  def info
41
- return @cache if !@cache.nil?
41
+ return @cache unless @cache.nil?
42
42
 
43
43
  case @method
44
44
  when :powershell
@@ -18,6 +18,7 @@ module Inspec::Resources
18
18
  @content = nil
19
19
  os = inspec.os
20
20
  return skip_resource "The `windows_hotfix` resource is not a feature of your OS." unless os.windows?
21
+
21
22
  query = "get-hotfix -id #{@id}"
22
23
  cmd = inspec.powershell(query)
23
24
  @content = cmd.stdout
@@ -29,6 +30,7 @@ module Inspec::Resources
29
30
 
30
31
  def installed?
31
32
  return false if @content.nil?
33
+
32
34
  @content.include?(@id)
33
35
  end
34
36
  end
@@ -33,17 +33,20 @@ module Inspec::Resources
33
33
 
34
34
  def exists?
35
35
  return true unless info.nil? || info[:uri].nil?
36
+
36
37
  false
37
38
  end
38
39
 
39
40
  # rubocop:disable Style/WordArray
40
41
  def enabled?
41
42
  return false if info.nil? || info[:state].nil?
43
+
42
44
  ["Ready", "Running"].include?(info[:state])
43
45
  end
44
46
 
45
47
  def disabled?
46
48
  return false if info.nil? || info[:state].nil?
49
+
47
50
  info[:scheduled_task_state] == "Disabled" || info[:state] == "Disabled"
48
51
  end
49
52
 
@@ -69,6 +72,7 @@ module Inspec::Resources
69
72
 
70
73
  def info
71
74
  return @cache unless @cache.nil?
75
+
72
76
  # PowerShell v5 has Get-ScheduledTask cmdlet,
73
77
  # _using something with backward support to v3_
74
78
  # script = "Get-ScheduledTask | ? { $_.URI -eq '#{@taskuri}' } | Select-Object URI,@{N='State';E={$_.State.ToString()}} | ConvertTo-Json"
@@ -51,13 +51,14 @@ module Inspec::Resources
51
51
 
52
52
  def params
53
53
  return @content if defined?(@content)
54
+
54
55
  @content = {}
55
56
 
56
57
  # abort if no options are available
57
58
  return @content unless defined?(@options)
58
59
 
59
60
  # filter for supported options
60
- args = @options.select { |key, _value| [:class, :namespace, :query, :filter].include?(key) }
61
+ args = @options.select { |key, _value| %i{class namespace query filter}.include?(key) }
61
62
 
62
63
  # convert to Get-WmiObject arguments
63
64
  params = ""
@@ -56,16 +56,19 @@ module Inspec::Resources
56
56
 
57
57
  def fingerprint
58
58
  return if @cert.nil?
59
+
59
60
  OpenSSL::Digest::SHA1.new(@cert.to_der).to_s
60
61
  end
61
62
 
62
63
  def serial
63
64
  return if @cert.nil?
65
+
64
66
  @cert.serial.to_i
65
67
  end
66
68
 
67
69
  def subject_dn
68
70
  return if @cert.nil?
71
+
69
72
  @cert.subject.to_s
70
73
  end
71
74
 
@@ -73,12 +76,14 @@ module Inspec::Resources
73
76
  return if @cert.nil?
74
77
  # Return cached subject if we have already parsed it
75
78
  return @parsed_subject if @parsed_subject
79
+
76
80
  # Use a Mash to make it easier to access hash elements in "its('subject') {should ...}"
77
81
  @parsed_subject = Hashie::Mash.new(Hash[@cert.subject.to_a.map { |k, v, _| [k, v] }])
78
82
  end
79
83
 
80
84
  def issuer_dn
81
85
  return if @cert.nil?
86
+
82
87
  @cert.issuer.to_s
83
88
  end
84
89
 
@@ -86,12 +91,14 @@ module Inspec::Resources
86
91
  return if @cert.nil?
87
92
  # Return cached subject if we have already parsed it
88
93
  return @parsed_issuer if @parsed_issuer
94
+
89
95
  # Use a Mash to make it easier to access hash elements in "its('issuer') {should ...}"
90
96
  @parsed_issuer = Hashie::Mash.new(Hash[@cert.issuer.to_a.map { |k, v, _| [k, v] }])
91
97
  end
92
98
 
93
99
  def key_length
94
100
  return if @cert.nil?
101
+
95
102
  @cert.public_key.n.num_bytes * 8
96
103
  end
97
104
 
@@ -109,6 +116,7 @@ module Inspec::Resources
109
116
  return @extensions if @extensions
110
117
  # Return the exception class if we failed to instantiate a Cert from file
111
118
  return @cert unless @cert.respond_to? :extensions
119
+
112
120
  # Use a Mash to make it easier to access hash elements in "its('entensions') {should ...}"
113
121
  @extensions = Hashie::Mash.new({})
114
122
  # Make sure standard extensions exist so we don't get nil for nil:NilClass
@@ -35,15 +35,15 @@ module Inspec::Resources
35
35
  end
36
36
 
37
37
  filter = FilterTable.create
38
- filter.register_column(:services, field: "service")
39
- .register_column(:ids, field: "id")
40
- .register_column(:socket_types, field: "socket_type")
41
- .register_column(:types, field: "type")
42
- .register_column(:protocols, field: "protocol")
43
- .register_column(:wait, field: "wait")
44
- .register_custom_matcher(:disabled?) { |x| x.where("disable" => "no").services.empty? }
45
- .register_custom_matcher(:enabled?) { |x| x.where("disable" => "yes").services.empty? }
46
- .install_filter_methods_on_resource(self, :service_lines)
38
+ filter.register_column(:services, field: "service")
39
+ .register_column(:ids, field: "id")
40
+ .register_column(:socket_types, field: "socket_type")
41
+ .register_column(:types, field: "type")
42
+ .register_column(:protocols, field: "protocol")
43
+ .register_column(:wait, field: "wait")
44
+ .register_custom_matcher(:disabled?) { |x| x.where("disable" => "no").services.empty? }
45
+ .register_custom_matcher(:enabled?) { |x| x.where("disable" => "yes").services.empty? }
46
+ .install_filter_methods_on_resource(self, :service_lines)
47
47
 
48
48
  private
49
49
 
@@ -55,6 +55,7 @@ module Inspec::Resources
55
55
 
56
56
  def read_params
57
57
  return {} if read_content.nil?
58
+
58
59
  flat_params = parse_xinetd(read_content)
59
60
  # we need to map service data in order to use it with filtertable
60
61
  params = { "services" => {} }
@@ -47,6 +47,7 @@ module Inspec::Resources
47
47
  # until \n
48
48
  def repositories
49
49
  return @cache if defined?(@cache)
50
+
50
51
  # parse the repository data from yum
51
52
  # we cannot use -C, because this is not reliable and may lead to errors
52
53
  @command_result = inspec.command("yum -v repolist all")
@@ -82,7 +83,7 @@ module Inspec::Resources
82
83
 
83
84
  # alias for yum.repo('reponame')
84
85
  def method_missing(name)
85
- repo(name.to_s) if !name.nil?
86
+ repo(name.to_s) unless name.nil?
86
87
  end
87
88
 
88
89
  def to_s
@@ -99,6 +100,7 @@ module Inspec::Resources
99
100
  # Optimize the key value
100
101
  def repo_key(key)
101
102
  return key if key.nil?
103
+
102
104
  key.gsub("Repo-", "").downcase
103
105
  end
104
106
  end
@@ -118,6 +120,7 @@ module Inspec::Resources
118
120
 
119
121
  def info
120
122
  return @cache if defined?(@cache)
123
+
121
124
  selection = @yum.repositories.select { |e| e["id"] == @reponame || shortname(e["id"]) == @reponame }
122
125
  @cache = selection.empty? ? {} : selection.first
123
126
  @cache
@@ -129,20 +132,21 @@ module Inspec::Resources
129
132
 
130
133
  def enabled?
131
134
  return false unless exist?
135
+
132
136
  info["status"] == "enabled"
133
137
  end
134
138
 
135
139
  # provide a method for each of the repo metadata items we know about
136
- [
137
- :baseurl,
138
- :expire,
139
- :filename,
140
- :mirrors,
141
- :pkgs,
142
- :size,
143
- :status,
144
- :updated,
145
- ].each do |key|
140
+ %i{
141
+ baseurl
142
+ expire
143
+ filename
144
+ mirrors
145
+ pkgs
146
+ size
147
+ status
148
+ updated
149
+ }.each do |key|
146
150
  define_method key do
147
151
  info[key.to_s]
148
152
  end