inspec-core 4.22.0 → 4.23.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/inspec-core.gemspec +4 -6
  4. data/lib/bundles/inspec-supermarket/cli.rb +1 -1
  5. data/lib/inspec/base_cli.rb +5 -1
  6. data/lib/inspec/config.rb +19 -1
  7. data/lib/inspec/input.rb +4 -3
  8. data/lib/inspec/input_registry.rb +7 -1
  9. data/lib/inspec/plugin/v2/plugin_types/reporter.rb +4 -25
  10. data/lib/inspec/reporters.rb +0 -3
  11. data/lib/inspec/reporters/automate.rb +3 -3
  12. data/lib/inspec/reporters/base.rb +7 -23
  13. data/lib/inspec/resources/apt.rb +5 -5
  14. data/lib/inspec/resources/bridge.rb +1 -1
  15. data/lib/inspec/resources/host.rb +1 -1
  16. data/lib/inspec/resources/mount.rb +1 -1
  17. data/lib/inspec/resources/mysql_session.rb +31 -8
  18. data/lib/inspec/resources/postgres.rb +1 -1
  19. data/lib/inspec/resources/postgres_session.rb +6 -4
  20. data/lib/inspec/resources/processes.rb +1 -1
  21. data/lib/inspec/resources/service.rb +1 -1
  22. data/lib/inspec/resources/users.rb +1 -1
  23. data/lib/inspec/resources/windows_firewall.rb +110 -0
  24. data/lib/inspec/resources/windows_firewall_rule.rb +137 -0
  25. data/lib/inspec/run_data/profile.rb +3 -2
  26. data/lib/inspec/schema/exec_json.rb +1 -1
  27. data/lib/inspec/shell.rb +3 -3
  28. data/lib/inspec/utils/parser.rb +1 -1
  29. data/lib/inspec/utils/run_data_filters.rb +104 -0
  30. data/lib/inspec/version.rb +1 -1
  31. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +4 -4
  32. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +1 -1
  33. data/lib/plugins/inspec-init/templates/profiles/aws/README.md +1 -1
  34. data/lib/plugins/inspec-reporter-html2/README.md +1 -1
  35. data/lib/plugins/inspec-reporter-junit/README.md +17 -0
  36. data/lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit.rb +21 -0
  37. data/lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb +155 -0
  38. data/lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/version.rb +5 -0
  39. data/lib/plugins/shared/core_plugin_test_helper.rb +0 -16
  40. metadata +25 -36
  41. data/README.md +0 -474
  42. data/lib/inspec/reporters/junit.rb +0 -77
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.22.0".freeze
2
+ VERSION = "4.23.10".freeze
3
3
  end
@@ -22,7 +22,7 @@ module InspecPlugins
22
22
  # return all compliance profiles available for the user
23
23
  # the user is either specified in the options hash or by default
24
24
  # the username of the account is used that is logged in
25
- def self.profiles(config, profile_filter = nil) # rubocop:disable PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
25
+ def self.profiles(config, profile_filter = nil) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
26
26
  owner = config["owner"] || config["user"]
27
27
 
28
28
  # Chef Compliance
@@ -81,13 +81,13 @@ module InspecPlugins
81
81
  mapped_profiles.select! do |p|
82
82
  (!ver || p["version"] == ver) && (!id || p["name"] == id)
83
83
  end
84
- return msg, mapped_profiles
84
+ [msg, mapped_profiles]
85
85
  when "401"
86
86
  msg = "401 Unauthorized. Please check your token."
87
- return msg, []
87
+ [msg, []]
88
88
  else
89
89
  msg = "An unexpected error occurred (HTTP #{response_code}): #{response.message}"
90
- return msg, []
90
+ [msg, []]
91
91
  end
92
92
  end
93
93
 
@@ -126,7 +126,7 @@ module InspecPlugins
126
126
  desc: "Overwrite existing profile on Server."
127
127
  option :owner, type: :string, required: false,
128
128
  desc: "Owner that should own the profile"
129
- def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, PerceivedComplexity, Metrics/CyclomaticComplexity
129
+ def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
130
130
  config = InspecPlugins::Compliance::Configuration.new
131
131
  return unless loggedin(config)
132
132
 
@@ -26,7 +26,7 @@ Creating new profile at /Users/spaterson/my-profile
26
26
  aws_vpc_id: 'custom-vpc-id'
27
27
  ```
28
28
 
29
- The related control will simply be skipped if this is not provided. See the [InSpec DSL documentation](https://www.inspec.io/docs/reference/dsl_inspec/) for more details on conditional execution using `only_if`.
29
+ The related control will simply be skipped if this is not provided. See the [InSpec DSL documentation](https://docs.chef.io/inspec/dsl_inspec/) for more details on conditional execution using `only_if`.
30
30
 
31
31
  ## Run the tests
32
32
 
@@ -24,7 +24,7 @@ Note the `2` in the reporter name. If you omit it and run `--reporter html` inst
24
24
 
25
25
  ## Configuring the Plugin
26
26
 
27
- The `html2` reporter requires no configuration to function. However, two options--`alternate_css_file` and `alternate_js_file`--are available for customization. The options are set in the JSON-formatted configuration file that Chef InSpec consumes. For details, see [our configuration file documentation](https://www.inspec.io/docs/reference/config/).
27
+ The `html2` reporter requires no configuration to function. However, two options--`alternate_css_file` and `alternate_js_file`--are available for customization. The options are set in the JSON-formatted configuration file that Chef InSpec consumes. For details, see [our configuration file documentation](https://docs.chef.io/inspec/config/).
28
28
 
29
29
  For example:
30
30
 
@@ -0,0 +1,17 @@
1
+ # junit and junit2 reporters
2
+
3
+ This is the implementation of the junit and junit2 XML reporters.
4
+
5
+ ## Installation
6
+
7
+ This plugin ships with Chef InSpec and requires no additional installation.
8
+
9
+ ## What These Plugins Do
10
+
11
+ `junit` is the legacy Chef InSpec JUnit reporter, which is retained for backwards compatibility. It generates an XML report in Apache Ant JUnit format. The output format is considered nonstandard in several ways. New users are advised to use `junit2`.
12
+
13
+ `junit2` is an updated reporter that provides JUnit output according to the schema published by [Windy Road](https://github.com/windyroad/JUnit-Schema).
14
+
15
+ ## Implementation Note
16
+
17
+ This reporter uses the REXML XML generator at runtime, but uses Nokogiri, a more heavyweight XML library, for testing. This design keeps packaging requirements lightweight and free of compiled dependencies.
@@ -0,0 +1,21 @@
1
+ require_relative "inspec-reporter-junit/version"
2
+ module InspecPlugins
3
+ module JUnitReporter
4
+ class Plugin < ::Inspec.plugin(2)
5
+ plugin_name :'inspec-reporter-junit'
6
+
7
+ # Legacy JUnit reporter, which generates subtly incorrect XML.
8
+ reporter :junit do
9
+ require_relative "inspec-reporter-junit/reporter"
10
+ InspecPlugins::JUnitReporter::ReporterV1
11
+ end
12
+
13
+ # v2 reporter, which generates valid JUnit XML.
14
+ reporter :junit2 do
15
+ require_relative "inspec-reporter-junit/reporter"
16
+ InspecPlugins::JUnitReporter::ReporterV2
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,155 @@
1
+ module InspecPlugins::JUnitReporter
2
+ class Reporter < Inspec.plugin(2, :reporter)
3
+ def self.run_data_schema_constraints
4
+ "~> 0.0"
5
+ end
6
+
7
+ def render
8
+ require "rexml/document"
9
+ xml_output = REXML::Document.new
10
+ xml_output.add(REXML::XMLDecl.new)
11
+
12
+ testsuites = REXML::Element.new("testsuites")
13
+ xml_output.add(testsuites)
14
+
15
+ run_data.profiles.each_with_index do |profile, idx|
16
+ testsuites.add(build_profile_xml(profile, idx))
17
+ end
18
+
19
+ formatter = REXML::Formatters::Pretty.new
20
+ formatter.compact = true
21
+ output(formatter.write(xml_output.xml_decl, ""))
22
+ output(formatter.write(xml_output.root, ""))
23
+ end
24
+
25
+ def count_profile_tests(profile)
26
+ profile.controls.reduce(0) do |acc, elem|
27
+ acc + elem.results.count
28
+ end
29
+ end
30
+
31
+ def count_profile_failed_tests(profile)
32
+ profile.controls.reduce(0) do |acc, elem|
33
+ acc + elem.results.reduce(0) do |fail_test_total, test_case|
34
+ test_case.status == "failed" ? fail_test_total + 1 : fail_test_total
35
+ end
36
+ end
37
+ end
38
+
39
+ def count_profile_skipped_tests(profile)
40
+ profile.controls.reduce(0) do |acc, elem|
41
+ acc + elem.results.reduce(0) do |skip_test_total, test_case|
42
+ test_case.status == "skipped" ? skip_test_total + 1 : skip_test_total
43
+ end
44
+ end
45
+ end
46
+
47
+ def count_profile_errored_tests(profile)
48
+ profile.controls.reduce(0) do |acc, elem|
49
+ acc + elem.results.reduce(0) do |err_test_total, test_case|
50
+ test_case.backtrace.nil? ? err_test_total : err_test_total + 1
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ # This is the "Legacy" JUnit reporter. It produces XML which is not
57
+ # correct according to the JUnit standard. It is retained for backwards
58
+ # compatibility.
59
+ class ReporterV1 < Reporter
60
+ def build_profile_xml(profile, _idx)
61
+ profile_xml = REXML::Element.new("testsuite")
62
+ profile_xml.add_attribute("name", profile.name)
63
+ profile_xml.add_attribute("tests", count_profile_tests(profile))
64
+ profile_xml.add_attribute("failed", count_profile_failed_tests(profile))
65
+ profile_xml.add_attribute("failures", count_profile_failed_tests(profile))
66
+
67
+ profile.controls.each do |control|
68
+ control.results.each do |result|
69
+ profile_xml.add(build_result_xml(profile.name, control, result))
70
+ end
71
+ end
72
+
73
+ profile_xml
74
+ end
75
+
76
+ def build_result_xml(profile_name, control, result)
77
+ result_xml = REXML::Element.new("testcase")
78
+ result_xml.add_attribute("name", result.code_desc)
79
+ result_xml.add_attribute("classname", control.title.nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control.id}")
80
+ result_xml.add_attribute("target", run_data.platform.target.nil? ? "" : run_data.platform.target.to_s)
81
+ result_xml.add_attribute("time", result.run_time)
82
+
83
+ if result.status == "failed"
84
+ failure_element = REXML::Element.new("failure")
85
+ failure_element.add_attribute("message", result[:message])
86
+ result_xml.add(failure_element)
87
+ elsif result.status == "skipped"
88
+ result_xml.add_element("skipped")
89
+ end
90
+
91
+ result_xml
92
+ end
93
+ end
94
+
95
+ # This is the "Corrected" JUnit reporter. It produces XML which is intended
96
+ # to be valid. It should be used whenever possible.
97
+ class ReporterV2 < Reporter
98
+ def build_profile_xml(profile, idx)
99
+ profile_xml = REXML::Element.new("testsuite")
100
+ profile_xml.add_attribute("name", profile.name)
101
+ profile_xml.add_attribute("tests", count_profile_tests(profile))
102
+ profile_xml.add_attribute("id", idx + 1)
103
+
104
+ # junit2 counts failures and errors separately
105
+ errors = count_profile_errored_tests(profile)
106
+ profile_xml.add_attribute("errors", errors)
107
+ profile_xml.add_attribute("failures", count_profile_failed_tests(profile) - errors)
108
+ profile_xml.add_attribute("skipped", count_profile_skipped_tests(profile))
109
+
110
+ profile_xml.add_attribute("hostname", run_data.platform.target.nil? ? "" : run_data.platform.target.to_s)
111
+ # Author of the schema specified 8601, then went on to add
112
+ # a regex that requires no TZ
113
+ profile_xml.add_attribute("timestamp", Time.now.iso8601.slice(0, 19))
114
+
115
+ # These are empty but are just here to satisfy the schema
116
+ profile_xml.add_attribute("package", "")
117
+ profile_xml.add(REXML::Element.new("properties"))
118
+
119
+ profile_time = 0.0
120
+ profile.controls.each do |control|
121
+ control.results.each do |result|
122
+ profile_time += result.run_time
123
+ profile_xml.add(build_result_xml(profile.name, control, result))
124
+ end
125
+ end
126
+ profile_xml.add_attribute("time", "%.6f" % profile_time)
127
+
128
+ profile_xml.add(REXML::Element.new("system-out"))
129
+ profile_xml.add(REXML::Element.new("system-err"))
130
+
131
+ profile_xml
132
+ end
133
+
134
+ def build_result_xml(profile_name, control, result)
135
+ result_xml = REXML::Element.new("testcase")
136
+ result_xml.add_attribute("name", result.code_desc)
137
+ result_xml.add_attribute("classname", control.title.nil? ? "#{profile_name}.Anonymous" : "#{profile_name}.#{control.id}")
138
+
139
+ # <Nokogiri::XML::SyntaxError: 20:0: ERROR: Element 'testcase', attribute 'time': '4.9e-05' is not a valid value of the atomic type 'xs:decimal'.
140
+ # So, we format it.
141
+ result_xml.add_attribute("time", "%.6f" % result.run_time)
142
+
143
+ if result.status == "failed"
144
+ failure_element = REXML::Element.new("failure")
145
+ failure_element.add_attribute("message", result.message)
146
+ failure_element.add_attribute("type", result.resource_title&.to_s || "")
147
+ result_xml.add(failure_element)
148
+ elsif result.status == "skipped"
149
+ result_xml.add_element("skipped")
150
+ end
151
+
152
+ result_xml
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,5 @@
1
+ module InspecPlugins
2
+ module JUnitReporter
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -50,22 +50,6 @@ module CorePluginFunctionalHelper
50
50
  include CorePluginBaseHelper
51
51
  include FunctionalHelper
52
52
 
53
- # TODO: so much duplication! Remove everything we can!
54
- require "train"
55
- TRAIN_CONNECTION = Train.create("local", command_runner: :generic).connection
56
-
57
- # TODO: remove me! it's in test/functional/helper.rb
58
- def run_inspec_process(command_line, opts = {})
59
- prefix = ""
60
- if opts.key?(:prefix)
61
- prefix = opts[:prefix]
62
- elsif opts.key?(:env)
63
- prefix = assemble_env_prefix opts[:env]
64
- end
65
-
66
- TRAIN_CONNECTION.run_command("#{prefix} #{exec_inspec} #{command_line}")
67
- end
68
-
69
53
  # This helper does some fancy footwork to make InSpec think a plugin
70
54
  # under development is temporarily installed.
71
55
  # @param String command_line Invocation, without the word 'inspec'
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.22.0
4
+ version: 4.23.10
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-07-15 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 0.2.13
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '2.0'
36
+ version: '3.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.2.13
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.0'
46
+ version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: thor
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -68,16 +68,22 @@ dependencies:
68
68
  name: json_schemer
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - "~>"
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: 0.2.1
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.2.12
74
77
  type: :runtime
75
78
  prerelease: false
76
79
  version_requirements: !ruby/object:Gem::Requirement
77
80
  requirements:
78
- - - "~>"
81
+ - - ">="
79
82
  - !ruby/object:Gem::Version
80
83
  version: 0.2.1
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: 0.2.12
81
87
  - !ruby/object:Gem::Dependency
82
88
  name: method_source
83
89
  requirement: !ruby/object:Gem::Requirement
@@ -223,6 +229,9 @@ dependencies:
223
229
  - - ">="
224
230
  - !ruby/object:Gem::Version
225
231
  version: 0.9.0
232
+ - - "<"
233
+ - !ruby/object:Gem::Version
234
+ version: '1.1'
226
235
  type: :runtime
227
236
  prerelease: false
228
237
  version_requirements: !ruby/object:Gem::Requirement
@@ -230,6 +239,9 @@ dependencies:
230
239
  - - ">="
231
240
  - !ruby/object:Gem::Version
232
241
  version: 0.9.0
242
+ - - "<"
243
+ - !ruby/object:Gem::Version
244
+ version: '1.1'
233
245
  - !ruby/object:Gem::Dependency
234
246
  name: tty-table
235
247
  requirement: !ruby/object:Gem::Requirement
@@ -314,20 +326,6 @@ dependencies:
314
326
  - - "~>"
315
327
  - !ruby/object:Gem::Version
316
328
  version: '3.0'
317
- - !ruby/object:Gem::Dependency
318
- name: htmlentities
319
- requirement: !ruby/object:Gem::Requirement
320
- requirements:
321
- - - "~>"
322
- - !ruby/object:Gem::Version
323
- version: '4.3'
324
- type: :runtime
325
- prerelease: false
326
- version_requirements: !ruby/object:Gem::Requirement
327
- requirements:
328
- - - "~>"
329
- - !ruby/object:Gem::Version
330
- version: '4.3'
331
329
  - !ruby/object:Gem::Dependency
332
330
  name: multipart-post
333
331
  requirement: !ruby/object:Gem::Requirement
@@ -342,20 +340,6 @@ dependencies:
342
340
  - - "~>"
343
341
  - !ruby/object:Gem::Version
344
342
  version: '2.0'
345
- - !ruby/object:Gem::Dependency
346
- name: term-ansicolor
347
- requirement: !ruby/object:Gem::Requirement
348
- requirements:
349
- - - "~>"
350
- - !ruby/object:Gem::Version
351
- version: '1.7'
352
- type: :runtime
353
- prerelease: false
354
- version_requirements: !ruby/object:Gem::Requirement
355
- requirements:
356
- - - "~>"
357
- - !ruby/object:Gem::Version
358
- version: '1.7'
359
343
  - !ruby/object:Gem::Dependency
360
344
  name: train-core
361
345
  requirement: !ruby/object:Gem::Requirement
@@ -383,7 +367,6 @@ extra_rdoc_files: []
383
367
  files:
384
368
  - Gemfile
385
369
  - LICENSE
386
- - README.md
387
370
  - etc/deprecations.json
388
371
  - etc/plugin_filters.json
389
372
  - inspec-core.gemspec
@@ -483,7 +466,6 @@ files:
483
466
  - lib/inspec/reporters/cli.rb
484
467
  - lib/inspec/reporters/json.rb
485
468
  - lib/inspec/reporters/json_automate.rb
486
- - lib/inspec/reporters/junit.rb
487
469
  - lib/inspec/reporters/yaml.rb
488
470
  - lib/inspec/require_loader.rb
489
471
  - lib/inspec/resource.rb
@@ -601,6 +583,8 @@ files:
601
583
  - lib/inspec/resources/vbscript.rb
602
584
  - lib/inspec/resources/virtualization.rb
603
585
  - lib/inspec/resources/windows_feature.rb
586
+ - lib/inspec/resources/windows_firewall.rb
587
+ - lib/inspec/resources/windows_firewall_rule.rb
604
588
  - lib/inspec/resources/windows_hotfix.rb
605
589
  - lib/inspec/resources/windows_registry_key.rb
606
590
  - lib/inspec/resources/windows_task.rb
@@ -660,6 +644,7 @@ files:
660
644
  - lib/inspec/utils/object_traversal.rb
661
645
  - lib/inspec/utils/parser.rb
662
646
  - lib/inspec/utils/pkey_reader.rb
647
+ - lib/inspec/utils/run_data_filters.rb
663
648
  - lib/inspec/utils/simpleconfig.rb
664
649
  - lib/inspec/utils/spdx.rb
665
650
  - lib/inspec/utils/spdx.txt
@@ -740,6 +725,10 @@ files:
740
725
  - lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min.rb
741
726
  - lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/reporter.rb
742
727
  - lib/plugins/inspec-reporter-json-min/lib/inspec-reporter-json-min/version.rb
728
+ - lib/plugins/inspec-reporter-junit/README.md
729
+ - lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit.rb
730
+ - lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/reporter.rb
731
+ - lib/plugins/inspec-reporter-junit/lib/inspec-reporter-junit/version.rb
743
732
  - lib/plugins/shared/core_plugin_test_helper.rb
744
733
  - lib/plugins/things-for-train-integration.rb
745
734
  - lib/source_readers/flat.rb