inspec-core 4.23.15 → 4.24.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8d456ded6249283aa4db22d7dc054afeb37996472a16d9d8d007bd492f7a6c8
4
- data.tar.gz: f355c608691df7895a0440a7f70a0ffb0f8cd0d7167da490dfcefeec45bba2bc
3
+ metadata.gz: 40b226d810bf523c7b914a00d3e3e0556d23eb78b944f12fe7af7fac35a279f4
4
+ data.tar.gz: ff6cafe82a9e7234814575a3723098ccb1238fb88754cb4891288547e9c3a47b
5
5
  SHA512:
6
- metadata.gz: f9c878fa83d12844ea6d0b1a58da70d6e39650a41e5ad7b7041bfc11faee21c8ce67adee8c5eae29ef04a4734b7c916415d285dab888c0c776a80717037c049b
7
- data.tar.gz: f072fbccdb85a007f3a33ba9294024b403eda80b184ee806a08226a47728681aaed1692ac61cbefde5fe7e965ea0db5e6306405e6c808f15d4011a44a6215542
6
+ metadata.gz: c663121d4e9dba5764ba321d391b4779f3b9236b827fc7dca58aa2a6a3b9d76a5749205635c38ca6a28f614364f19fef1c7c790321067fef2ae1e1eb9a1dbd74
7
+ data.tar.gz: da255c1b0637e48aa1f83ea42607829767450bd03fd5f970e527afa81898ba215b7ac4ec66c508d23ef2de74ebb9e3dc26893427c76ab4176e67ffaf5df42c54
data/Gemfile CHANGED
@@ -11,6 +11,11 @@ gem "inspec-bin", path: "./inspec-bin"
11
11
 
12
12
  gem "ffi", ">= 1.9.14", "!= 1.13.0"
13
13
 
14
+ if Gem.ruby_version.to_s.start_with?("2.5")
15
+ # 16.7.23 required ruby 2.6+
16
+ gem "chef-utils", "< 16.7.23" # TODO: remove when we drop ruby 2.5
17
+ end
18
+
14
19
  group :omnibus do
15
20
  gem "rb-readline"
16
21
  gem "appbundler"
@@ -20,45 +25,31 @@ end
20
25
 
21
26
  group :test do
22
27
  gem "chefstyle", "~> 1.2.1"
23
- gem "minitest", "~> 5.5"
24
- gem "minitest-sprint", "~> 1.0"
25
- gem "rake", ">= 10"
26
- gem "simplecov", ["~> 0.10", "<=0.18.2"]
27
28
  gem "concurrent-ruby", "~> 1.0"
28
- gem "nokogiri", "~> 1.9"
29
+ gem "html-proofer", platforms: :ruby # do not attempt to run proofer on windows
30
+ gem "json_schemer", ">= 0.2.1", "< 0.2.12"
31
+ gem "m"
32
+ gem "minitest-sprint", "~> 1.0"
33
+ gem "minitest", "~> 5.5"
29
34
  gem "mocha", "~> 1.1"
35
+ gem "nokogiri", "~> 1.9"
36
+ gem "pry-byebug"
37
+ gem "pry", "~> 0.10"
38
+ gem "rake", ">= 10"
30
39
  gem "ruby-progressbar", "~> 1.8"
40
+ gem "simplecov", ["~> 0.10", "<=0.18.2"]
31
41
  gem "webmock", "~> 3.0"
32
- gem "m"
33
- gem "pry", "~> 0.10"
34
- gem "pry-byebug"
35
- gem "html-proofer", platforms: :ruby # do not attempt to run proofer on windows
36
42
  end
37
43
 
38
44
  group :integration do
39
45
  gem "berkshelf"
40
- gem "test-kitchen"
41
- gem "kitchen-vagrant"
42
- gem "chef", "< 15"
43
- gem "chef-zero", "< 15"
44
- gem "kitchen-inspec"
45
- gem "kitchen-ec2"
46
- gem "kitchen-dokken"
46
+ gem "test-kitchen", ">= 2.8"
47
+ gem "kitchen-vagrant", ">= 1.7"
48
+ gem "kitchen-inspec", ">= 2.0"
49
+ gem "kitchen-dokken", ">= 2.11"
47
50
  gem "git"
48
51
  end
49
52
 
50
- # gems for Maintainers.md generation
51
- group :maintenance do
52
- gem "tomlrb"
53
-
54
- # To sync maintainers with github
55
- gem "octokit"
56
- gem "netrc"
57
- end
58
-
59
53
  group :deploy do
60
54
  gem "inquirer"
61
- end
62
-
63
- # add these additional dependencies into Gemfile.local
64
- eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local")
55
+ end
@@ -26,10 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "chef-telemetry", "~> 1.0"
27
27
  spec.add_dependency "license-acceptance", ">= 0.2.13", "< 3.0"
28
28
  spec.add_dependency "thor", ">= 0.20", "< 2.0"
29
- spec.add_dependency "json_schemer", ">= 0.2.1", "< 0.2.12"
30
29
  spec.add_dependency "method_source", ">= 0.8", "< 2.0"
31
30
  spec.add_dependency "rubyzip", "~> 1.2", ">= 1.2.2"
32
- spec.add_dependency "rspec", "~> 3.9"
31
+ spec.add_dependency "rspec", "~> 3.9.0"
33
32
  spec.add_dependency "rspec-its", "~> 1.2"
34
33
  spec.add_dependency "pry", "~> 0.13"
35
34
  spec.add_dependency "hashie", "~> 3.4"
@@ -159,6 +159,14 @@ module Inspec::Formatters
159
159
  resource_title: example.metadata[:described_class] || example.metadata[:example_group][:description],
160
160
  expectation_message: format_expectation_message(example),
161
161
  waiver_data: example.metadata[:waiver_data],
162
+ # This enforces the resource name as expected based off of the class
163
+ # name. However, if we wanted the `name` attribute against the class
164
+ # to be canonical for this case (consider edge cases!) we would use
165
+ # example.metadata[:described_class].instance_variable_get(:@__resource_name__)&.to_s
166
+ resource_class: example.metadata[:described_class].class.superclass.name,
167
+ # This is a raw grep of the text passed to the resource in any format,
168
+ # and is used to enforce near-uniqueness against the resource.
169
+ resource_params: find_resource_params(example.metadata[:described_class]),
162
170
  }
163
171
 
164
172
  unless (pid = example.metadata[:profile_id]).nil?
@@ -174,6 +182,14 @@ module Inspec::Formatters
174
182
  res
175
183
  end
176
184
 
185
+ def find_resource_params(example)
186
+ if example.class.ancestors.include?(Inspec::Resource)
187
+ example.instance_variable_get(:@resource_params)
188
+ else
189
+ []
190
+ end
191
+ end
192
+
177
193
  def format_expectation_message(example)
178
194
  if (example.metadata[:example_group][:description_args].first == example.metadata[:example_group][:described_class]) ||
179
195
  example.metadata[:example_group][:described_class].nil?
@@ -1,15 +1,21 @@
1
1
  require_relative "utils/install_context"
2
2
 
3
3
  module Inspec
4
-
5
4
  extend Inspec::InstallContextHelpers
6
5
 
7
6
  def self.config_dir
8
- ENV["INSPEC_CONFIG_DIR"] ? ENV["INSPEC_CONFIG_DIR"] : File.join(Dir.home, ".inspec")
7
+ ENV["INSPEC_CONFIG_DIR"] || File.join(home_path, ".inspec")
9
8
  end
10
9
 
11
10
  def self.src_root
12
11
  @src_root ||= File.expand_path(File.join(__FILE__, "../../.."))
13
12
  end
14
13
 
14
+ def self.home_path
15
+ Dir.home
16
+ rescue ArgumentError, NoMethodError
17
+ # If ENV['HOME'] is not set, Dir.home will fail due to expanding the ~. Fallback to Etc.
18
+ require "etc" unless defined?(Etc)
19
+ Etc.getpwuid.dir
20
+ end
15
21
  end
@@ -50,6 +50,11 @@ module Inspec::Plugin::V2
50
50
  # we want to allow "sidecar loading", in which case a plugin may add an entry to the registry.
51
51
  registry.plugin_names.dup.each do |plugin_name|
52
52
  plugin_details = registry[plugin_name]
53
+
54
+ # Under some conditions (kitchen-inspec with multiple test suites, for example), this may be
55
+ # called multple times. Don't reload anything.
56
+ next if plugin_details.loaded
57
+
53
58
  # We want to capture literally any possible exception here, since we are storing them.
54
59
  # rubocop: disable Lint/RescueException
55
60
  begin
@@ -40,6 +40,8 @@ module Inspec::Reporters
40
40
  message: r[:message],
41
41
  exception: r[:exception],
42
42
  backtrace: r[:backtrace],
43
+ resource_class: r[:resource_class],
44
+ resource_params: r[:resource_params].to_s,
43
45
  }.reject { |_k, v| v.nil? }
44
46
  }
45
47
  end
@@ -108,6 +108,7 @@ module Inspec
108
108
  # Infrastructure / Bookkeeping
109
109
 
110
110
  def self.__register(name, resource_klass)
111
+ # This has bitten us and should be a great candidate to remove in InSpec5
111
112
  cl = Class.new(resource_klass) do # TODO: remove
112
113
  # As best I can figure out, this anonymous class only exists
113
114
  # because we're trying to avoid having resources with
@@ -116,6 +117,7 @@ module Inspec
116
117
  # documentation.
117
118
  def initialize(backend, name, *args)
118
119
  supersuper_initialize(backend, name) do
120
+ @resource_params = args
119
121
  super(*args)
120
122
  end
121
123
  end
@@ -29,7 +29,7 @@ module Inspec::Resources
29
29
  @content = read_file(@conf_path)
30
30
  @kernel = kernel || "default"
31
31
  rescue UnknownGrubConfig
32
- skip_resource "The `grub_config` resource is not supported on your OS yet."
32
+ skip_resource "The `grub_conf` resource is not yet supported on the target OS #{inspec.os[:name]}."
33
33
  end
34
34
 
35
35
  def config_for_platform(path)
@@ -77,6 +77,7 @@ module Inspec::Resources
77
77
 
78
78
  def grub2_parse_kernel_lines(content, conf)
79
79
  menu_entries = extract_menu_entries(content)
80
+ return {} if menu_entries.empty?
80
81
 
81
82
  if @kernel == "default"
82
83
  default_menu_entry(menu_entries, conf["GRUB_DEFAULT"])
@@ -314,7 +314,7 @@ module Inspec::Resources
314
314
  # Find the package
315
315
  cmd = inspec.command <<-EOF.gsub(/^\s*/, "")
316
316
  Get-ItemProperty (@("#{search_paths.join('", "')}") | Where-Object { Test-Path $_ }) |
317
- Where-Object { $_.DisplayName -match "^\s*#{package_name.shellescape}\.*" -or $_.PSChildName -match "^\s*#{package_name.shellescape}\.*" } |
317
+ Where-Object { $_.DisplayName -like "#{package_name}" -or $_.PSChildName -like "#{package_name}" } |
318
318
  Select-Object -Property DisplayName,DisplayVersion | ConvertTo-Json
319
319
  EOF
320
320
 
@@ -81,7 +81,7 @@ module Inspec::Resources
81
81
  when :os, :platform then
82
82
  platform?(v)
83
83
  when :os_name, :platform_name then
84
- name == v
84
+ check_name(v)
85
85
  when :release then
86
86
  check_release(v)
87
87
  end
@@ -99,6 +99,16 @@ module Inspec::Resources
99
99
 
100
100
  private
101
101
 
102
+ def check_name(value)
103
+ # allow wild card matching
104
+ if value.include?("*")
105
+ cleaned = Regexp.escape(value).gsub('\*', ".*?")
106
+ name =~ /#{cleaned}/
107
+ else
108
+ name == value
109
+ end
110
+ end
111
+
102
112
  def check_release(value)
103
113
  # allow wild card matching
104
114
  if value.include?("*")
@@ -16,7 +16,10 @@ module Inspec::Resources
16
16
  namespace: 'root\\rsop\\computer',
17
17
  filter: 'KeyName = \'MinimumPasswordAge\' And precedence=1'
18
18
  }) do
19
- its('Setting') { should eq true }
19
+ its('Setting') { should cmp true }
20
+ end
21
+ describe wmi({namespace: "root\\cimv2", query: "SELECT installstate FROM win32_optionalfeature"}) do
22
+ its("installstate") { should include 2 }
20
23
  end
21
24
  EXAMPLE
22
25
 
@@ -66,13 +69,18 @@ module Inspec::Resources
66
69
 
67
70
  # run wmi command and filter empty wmi
68
71
  script = <<-EOH
69
- Filter Aggregate
70
- {
71
- $arr = @{}
72
- $_.properties | % {
73
- $arr.Add($_.name, $_.value)
72
+ Function Aggregate {
73
+ $propsHash = @{}
74
+ ForEach ($wmiObj in $Input) {
75
+ ForEach ($wmiProp in $wmiObj.properties) {
76
+ If($propsHash.ContainsKey($wmiProp.name)) {
77
+ $propsHash[$wmiProp.name].add($wmiProp.value) | Out-Null
78
+ } Else {
79
+ $propsHash[$wmiProp.name] = [System.Collections.ArrayList]@($wmiProp.value)
80
+ }
74
81
  }
75
- $arr
82
+ }
83
+ $propsHash
76
84
  }
77
85
  Get-WmiObject #{params} | Aggregate | ConvertTo-Json
78
86
  EOH
@@ -47,7 +47,7 @@ module Inspec
47
47
  # core reporters have been migrated to plugins. It is probable that new data elements
48
48
  # and new Hash compatibility behavior will be added during the core reporter plugin
49
49
  # conversion process.
50
- SCHEMA_VERSION = "0.2.0".freeze
50
+ SCHEMA_VERSION = "0.3.0".freeze
51
51
 
52
52
  def self.compatible_schema?(constraints)
53
53
  reqs = Gem::Requirement.create(constraints)
@@ -8,6 +8,7 @@ module Inspec
8
8
  :run_time, # Float seconds execution time
9
9
  :skip_message, # String
10
10
  :start_time, # DateTime
11
+ :resource_params, # What is passed to the resource as a raw grep
11
12
  :status, # String
12
13
  :resource_title, # Ugly internals
13
14
  # :waiver_data, # Undocumented tramp data / not exposed in this API
@@ -34,6 +35,7 @@ module Inspec
34
35
  end
35
36
 
36
37
  self.resource_name = raw_res_data[:resource_title].instance_variable_get(:@__resource_name__)&.to_s
38
+ self.resource_params = raw_res_data[:resource_title].instance_variable_get(:@grep)&.to_s
37
39
  end
38
40
  end
39
41
  end
@@ -56,6 +56,7 @@ module Inspec
56
56
  "code_desc" => { "type" => "string" },
57
57
  "run_time" => { "type" => "number" },
58
58
  "start_time" => { "type" => "string" },
59
+ "resource_class" => { "type" => "string", "optional" => true },
59
60
  "skip_message" => { "type" => "string", "optional" => true },
60
61
  "resource" => { "type" => "string", "optional" => true },
61
62
  "message" => { "type" => "string", "optional" => true },
@@ -194,6 +195,7 @@ module Inspec
194
195
  "profile_sha256" => { "type" => "string" },
195
196
  "status" => { "type" => "string" },
196
197
  "code_desc" => { "type" => "string" },
198
+ "resource_class" => { "type" => "string", "optional" => true },
197
199
  "skip_message" => { "type" => "string", "optional" => true },
198
200
  "resource" => { "type" => "string", "optional" => true },
199
201
  "message" => { "type" => "string", "optional" => true },
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.23.15".freeze
2
+ VERSION = "4.24.8".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.23.15
4
+ version: 4.24.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-22 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry
@@ -64,26 +64,6 @@ dependencies:
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '2.0'
67
- - !ruby/object:Gem::Dependency
68
- name: json_schemer
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: 0.2.1
74
- - - "<"
75
- - !ruby/object:Gem::Version
76
- version: 0.2.12
77
- type: :runtime
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: 0.2.1
84
- - - "<"
85
- - !ruby/object:Gem::Version
86
- version: 0.2.12
87
67
  - !ruby/object:Gem::Dependency
88
68
  name: method_source
89
69
  requirement: !ruby/object:Gem::Requirement
@@ -130,14 +110,14 @@ dependencies:
130
110
  requirements:
131
111
  - - "~>"
132
112
  - !ruby/object:Gem::Version
133
- version: '3.9'
113
+ version: 3.9.0
134
114
  type: :runtime
135
115
  prerelease: false
136
116
  version_requirements: !ruby/object:Gem::Requirement
137
117
  requirements:
138
118
  - - "~>"
139
119
  - !ruby/object:Gem::Version
140
- version: '3.9'
120
+ version: 3.9.0
141
121
  - !ruby/object:Gem::Dependency
142
122
  name: rspec-its
143
123
  requirement: !ruby/object:Gem::Requirement