scelint 0.7.0 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1e8f8d8e3eb96d5aa6bc36fb178f2b3cb283240ff04c37f469f4563693e94ee
4
- data.tar.gz: d89de6916fd66be7a7572240e8d04606ce33201b964f58b455da8423e850d474
3
+ metadata.gz: 0fa4c86efdc5b8b53f3be73a0065a4c13bc0c7759e1886556c62fbb5a8a5d9eb
4
+ data.tar.gz: 8b3cdf888b0f474c91d53e2999e1b258d55c6269f6a20093cbf3840aaf14510a
5
5
  SHA512:
6
- metadata.gz: 29896aa3398ae2a5503f304ec68968bf4e2944084dbbee5eee3056eba57cb843d3cc9e39eb1660bb6d679485548fed575e5a027a38ce9c3f2ef0cf2d34bc0900
7
- data.tar.gz: f34b1e846bd6a188af09b9b5e5fc4fed0510c068ed05c09488ed845ba8e83f0ab46738551a005daa5a34cc4d6aef587bc8ca0a75b6a2833cc3482da452cd9243
6
+ metadata.gz: e0af13652e213967a70272e1f34bee0664fc6a7b6aaf0bcc00271daedc8ca70d66035d1b2e22681605444db721de214932a0c83b500a9dbade4a07b766caebf6
7
+ data.tar.gz: '07856efc5a6e5d7fd71c48fcc294c98963b6595f2e8e8efe9a89923cd331f1040a61b19ff15b0fb89c22db58ef823c3830c5a03d88a301ed8485cdb725b64b1b'
@@ -17,7 +17,7 @@ jobs:
17
17
  - name: "Install Ruby"
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
20
- ruby-version: 4.0.9
20
+ ruby-version: 4.0.10
21
21
  bundler-cache: true
22
22
  - run: bundle exec rake rubocop
23
23
 
@@ -92,7 +92,7 @@ jobs:
92
92
  echo "release_command=$GEM_RELEASE_COMMAND" | tee -a "$GITHUB_OUTPUT"
93
93
  - uses: ruby/setup-ruby@v1
94
94
  with:
95
- ruby-version: 4.0.9
95
+ ruby-version: 4.0.10
96
96
  bundler-cache: true
97
97
  - name: Test build the package
98
98
  run: "${{ steps.commands.outputs.build_command }}"
@@ -187,7 +187,7 @@ jobs:
187
187
  clean: true
188
188
  - uses: ruby/setup-ruby@v1
189
189
  with:
190
- ruby-version: 4.0.9
190
+ ruby-version: 4.0.10
191
191
  bundler-cache: true
192
192
  - name: Build RubyGem
193
193
  run: |
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.8.0 / 2026-11-24
2
+ * **BREAKING:** Report an error when a check's `value` is `null`. A `null`
3
+ overrides lower Hiera layers with the parameter's default. Remove the
4
+ check to leave the parameter alone, or use the module's removal value.
5
+ * Report a warning when a check's `value` contains a nested `null`
6
+ * Add `--allow-revision-drift PATTERN` (repeatable). Two files whose basenames
7
+ both match the same glob may name different revisions of the same DISA rule,
8
+ as when a manual and a SCAP benchmark for one release disagree on rule
9
+ revisions. A file from another release is still reported, as are different
10
+ rules. A pattern that matches no file is reported as a warning.
11
+ * Parse `.scelint` lines as a shell would, so quoted arguments work there
12
+
1
13
  ### 0.7.0 / 2026-11-02
2
14
  * **BREAKING:** Report an error when files give a CE `oval-ids` for different
3
15
  rules, as happens when two revisions of a benchmark ship together. Remove
data/Gemfile CHANGED
@@ -7,10 +7,10 @@ gem 'rake', '~> 13.4.0'
7
7
 
8
8
  group :tests do
9
9
  gem 'rspec', '~> 3.13.1'
10
- gem 'rubocop', '~> 1.92.0'
10
+ gem 'rubocop', '~> 1.93.0'
11
11
  gem 'rubocop-performance', '~> 1.27.0'
12
12
  gem 'rubocop-rake', '~> 0.7.1'
13
- gem 'rubocop-rspec', '~> 3.10.0'
13
+ gem 'rubocop-rspec', '~> 3.11.0'
14
14
  end
15
15
 
16
16
  group :development do
data/lib/scelint/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'scelint'
4
4
  require 'thor'
5
5
  require 'logger'
6
+ require 'shellwords'
6
7
 
7
8
  # SCELint CLI
8
9
  class Scelint::CLI < Thor
@@ -13,12 +14,13 @@ class Scelint::CLI < Thor
13
14
  DEFAULTS_FILE = '.scelint'
14
15
 
15
16
  # Load default arguments from .scelint in the current directory.
16
- # Each non-blank, non-comment line may contain one or more arguments.
17
+ # Each non-blank, non-comment line may contain one or more arguments,
18
+ # split as a shell would, so quoted arguments work as on the command line.
17
19
  def self.load_defaults
18
20
  return [] unless File.exist?(DEFAULTS_FILE)
19
21
  File.readlines(DEFAULTS_FILE, chomp: true)
20
22
  .reject { |line| line.strip.empty? || line.strip.start_with?('#') }
21
- .flat_map(&:split)
23
+ .flat_map { |line| Shellwords.split(line) }
22
24
  end
23
25
 
24
26
  # When the first argument is not a known subcommand or an option flag,
@@ -38,9 +40,12 @@ class Scelint::CLI < Thor
38
40
  desc 'lint PATH', 'Lint all files in PATH'
39
41
  option :strict, type: :boolean, aliases: '-s', default: false
40
42
  option :allow_reserved_words, type: :boolean, default: false
43
+ option :allow_revision_drift, type: :string, repeatable: true, banner: 'PATTERN',
44
+ desc: 'Let two files whose names both match PATTERN name different revisions of the same DISA rule (repeatable)'
41
45
  def lint(*paths)
42
46
  paths = ['.'] if paths.nil? || paths.empty?
43
- lint = Scelint::Lint.new(paths, logger: logger, allow_reserved_words: options[:allow_reserved_words])
47
+ lint = Scelint::Lint.new(paths, logger: logger, allow_reserved_words: options[:allow_reserved_words],
48
+ allow_revision_drift: options[:allow_revision_drift] || [])
44
49
 
45
50
  count = lint.files.count
46
51
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scelint
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/scelint.rb CHANGED
@@ -134,9 +134,13 @@ module Scelint
134
134
  #
135
135
  # @param paths [Array<String>] Paths to look for SCE data in. Defaults to ['.']
136
136
  # @param logger [Logger] A logger to send messages to. Defaults to an instance of Logger with the log level set to INFO.
137
- def initialize(paths = ['.'], logger: Logger.new(STDOUT, level: Logger::INFO), allow_reserved_words: false)
137
+ # @param allow_revision_drift [Array<String>] File name patterns (File.fnmatch globs,
138
+ # matched against each file's basename). Two files that both match the same pattern
139
+ # may name different revisions of the same rule. Defaults to none.
140
+ def initialize(paths = ['.'], logger: Logger.new(STDOUT, level: Logger::INFO), allow_reserved_words: false, allow_revision_drift: [])
138
141
  @log = logger
139
142
  @allow_reserved_words = allow_reserved_words
143
+ @allow_revision_drift = Array(allow_revision_drift)
140
144
  @errors = []
141
145
  @warnings = []
142
146
  @notes = []
@@ -527,13 +531,19 @@ module Scelint
527
531
 
528
532
  # Check a value
529
533
  #
530
- # @param _file [String] The path to the file being checked (currently unused)
531
- # @param _check [String] The name of the check (currently unused)
532
- # @param _value [Object] The value to be validated (currently unused)
533
- # @return [Boolean] Always returns true (currently)
534
- def check_value(_file, _check, _value) # rubocop:disable Naming/PredicateMethod
535
- # value could be anything
536
- true
534
+ # @param file [String] The path to the file being checked
535
+ # @param check [String] The name of the check
536
+ # @param value [Object] The value to be validated
537
+ def check_value(file, check, value)
538
+ if value.nil?
539
+ errors << "#{file} (check '#{check}'): value is null, which overrides lower Hiera layers with the " \
540
+ "parameter's default; remove the check to leave the parameter alone, or use the module's removal value"
541
+ return
542
+ end
543
+
544
+ return unless nested_nil?(value)
545
+
546
+ warnings << "#{file} (check '#{check}'): value contains a nested null"
537
547
  end
538
548
 
539
549
  # Check settings
@@ -822,15 +832,37 @@ module Scelint
822
832
  end
823
833
 
824
834
  by_file.to_a.combination(2) do |(file_a, ids_a), (file_b, ids_b)|
825
- next if same_rules?(ids_a, ids_b)
835
+ next if same_rules?(ids_a, ids_b, ignore_revision: drift_allowed?(file_a, file_b))
826
836
 
827
837
  errors << "CE '#{ce}': conflicting oval-ids (#{ids_a.inspect} in #{file_a}, #{ids_b.inspect} in #{file_b})"
828
838
  end
829
839
  end
840
+
841
+ @allow_revision_drift.each do |pattern|
842
+ next if files.any? { |file| File.fnmatch(pattern, File.basename(file)) }
843
+
844
+ warnings << "--allow-revision-drift pattern '#{pattern}' matches no file"
845
+ end
830
846
  end
831
847
 
832
848
  private
833
849
 
850
+ # Return true if two files may name different revisions of the same rule
851
+ #
852
+ # That is the case when one --allow-revision-drift pattern matches both
853
+ # files' basenames, as with a manual and a SCAP benchmark for the same
854
+ # release. A file from another release does not match the pair's pattern,
855
+ # so a superseded file left beside its replacement is still reported.
856
+ #
857
+ # @param file_a [String] Path to a file
858
+ # @param file_b [String] Path to another file
859
+ # @return [Boolean]
860
+ def drift_allowed?(file_a, file_b)
861
+ names = [File.basename(file_a), File.basename(file_b)]
862
+
863
+ @allow_revision_drift.any? { |pattern| names.all? { |name| File.fnmatch(pattern, name) } }
864
+ end
865
+
834
866
  # Return true if two sets of oval-ids name the same rules
835
867
  #
836
868
  # The same rule is routinely written two ways in one data set: a manual
@@ -842,15 +874,37 @@ module Scelint
842
874
  # written with '.' or ':', as in 'xccdf_org.ssgproject.content_rule_foo'
843
875
  # and 'xccdf_org:ssgproject:content_rule_foo'.
844
876
  #
877
+ # With ignore_revision, the revision in a DISA rule id is ignored as well,
878
+ # so 'SV-230221r1017040_rule' and 'SV-230221r1017041_rule' name the same
879
+ # rule. DISA can publish a manual and a SCAP benchmark for one release
880
+ # whose rule revisions differ.
881
+ #
845
882
  # @param ids_a [Array<String>] A set of oval-ids
846
883
  # @param ids_b [Array<String>] A set of oval-ids
884
+ # @param ignore_revision [Boolean] Ignore DISA rule revisions
847
885
  # @return [Boolean]
848
- def same_rules?(ids_a, ids_b)
849
- rule_names = ->(ids) { ids.map { |id| id.sub(%r{\Axccdf_[^_]+_rule_}, '') }.uniq.sort }
886
+ def same_rules?(ids_a, ids_b, ignore_revision: false)
887
+ rule_name = ->(id) {
888
+ name = id.sub(%r{\Axccdf_[^_]+_rule_}, '')
889
+ ignore_revision ? name.sub(%r{\A(SV-\d+)r\d+(_rule)\z}, '\1\2') : name
890
+ }
891
+ rule_names = ->(ids) { ids.map(&rule_name).uniq.sort }
850
892
 
851
893
  rule_names.call(ids_a) == rule_names.call(ids_b)
852
894
  end
853
895
 
896
+ # Whether a Hash or Array contains nil at any depth
897
+ #
898
+ # @param value [Object] The value to search
899
+ # @return [Boolean]
900
+ def nested_nil?(value)
901
+ case value
902
+ when Hash then value.values.any? { |v| v.nil? || nested_nil?(v) }
903
+ when Array then value.any? { |v| v.nil? || nested_nil?(v) }
904
+ else false
905
+ end
906
+ end
907
+
854
908
  # Merge a ComplianceEngine::Collection object into a Hash
855
909
  #
856
910
  # Components that cannot be merged (usually because a fragment is
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scelint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Pritchard