simp-beaker-helpers 1.16.2 → 1.17.0

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: fb4493d282ad548aeb475ef2918f65d1b331cd03bf9a463d2b928b58eb39b02b
4
- data.tar.gz: 6fc59e935a58ed366560a2b0adc270af741ca0d41e2ccc4538c3261320388dea
3
+ metadata.gz: 2d2df234c2357c8763e82b9cabaf6b9da39736ca7fcedc4a16dd344a993c2c2d
4
+ data.tar.gz: eda59ab6e07fadc67fb31b0d5d5462b89a2f4290129f46d32fda963999b5bc99
5
5
  SHA512:
6
- metadata.gz: a0551449fe17b14f27af4428ba49385e355f4ae28e5e7bab592215df56d6c91bdcb6e7b6222da0ec002ceb7f3ae373038ae2d26fef5b23fbba93f510ce2ef8d4
7
- data.tar.gz: e610f52d3bafec88e05ed6af1a3197441c76308287df3854324d94740d360c510c835db0a9f812e202a31270d7f03dd48d502b40e89dd74af7164061546f820b
6
+ metadata.gz: bbcabe0f22e139595747cde2afd378e8f7d4f35e1d4ce387fc2c09da3bc57d2099e8abfc0beb407cfff0a53aad13c4be032840d54a78f86a7c4f5f47a504628a
7
+ data.tar.gz: 84235e55f67ee2fefc02dce2221763e817876a22fb1bf6cfee7adfcbfd261913022a39bba804ad66643f0cc884c164f41e0ac3b239a8b339e1809c8b7e55b063
@@ -1,3 +1,7 @@
1
+ ### 1.17.0 / 2019-10-22
2
+ * Allow users to perform exclusion filters on SSG results
3
+ * Allow users to pass Arrays of items to match for SSG results
4
+
1
5
  ### 1.16.2 / 2019-10-10
2
6
  * Pull latest inspec package now that the upstream bug is fixed
3
7
 
@@ -156,23 +156,45 @@ module Simp::BeakerHelpers
156
156
  end
157
157
  end
158
158
 
159
- # Retrieve a subset of test results based on a match to
160
- # filter
159
+ # Retrieve a subset of test results based on a match to filter
160
+ #
161
+ # @param filter [String, Array[String]]
162
+ # A 'short name' filter that will be matched against the rule ID name
163
+ #
164
+ # @param exclusions [String, Array[String]]
165
+ # A 'short name' filter of items that will be removed from the `filter`
166
+ # matches
167
+ #
168
+ # @return [Hash] A Hash of statistics and a formatted report
161
169
  #
162
170
  # FIXME:
163
171
  # - This is a hack! Should be searching for rules based on a set
164
172
  # set of STIG ids, but don't see those ids in the oscap results xml.
165
173
  # Further mapping is required...
166
174
  # - Create the same report structure as inspec
167
- def process_ssg_results(filter=nil)
168
- self.class.process_ssg_results(File.join(@output_dir, @result_file) + '.xml', filter)
175
+ def process_ssg_results(filter=nil, exclusions=nil)
176
+ self.class.process_ssg_results(
177
+ File.join(@output_dir, @result_file) + '.xml',
178
+ filter,
179
+ exclusions
180
+ )
169
181
  end
170
182
 
171
183
  # Process the results of an SSG run
172
184
  #
185
+ # @param result_file [String]
186
+ # The oscap result XML file to process
187
+ #
188
+ # @param filter [String, Array[String]]
189
+ # A 'short name' filter that will be matched against the rule ID name
190
+ #
191
+ # @param exclusions [String, Array[String]]
192
+ # A 'short name' filter of items that will be removed from the `filter`
193
+ # matches
194
+ #
173
195
  # @return [Hash] A Hash of statistics and a formatted report
174
196
  #
175
- def self.process_ssg_results(result_file, filter=nil)
197
+ def self.process_ssg_results(result_file, filter=nil, exclusions=nil)
176
198
  require 'highline'
177
199
  require 'nokogiri'
178
200
 
@@ -187,10 +209,39 @@ module Simp::BeakerHelpers
187
209
  doc.remove_namespaces!
188
210
 
189
211
  if filter
212
+ filter = Array(filter)
213
+
214
+ xpath_query = [
215
+ '//rule-result[(',
216
+ ]
217
+
218
+ xpath_query << filter.map do |flt|
219
+ "contains(@idref,'#{flt}')"
220
+ end.join(' or ')
221
+
222
+ xpath_query << ')' if filter.size > 1
223
+
224
+ if exclusions
225
+ exclusions = Array(exclusions)
226
+
227
+ xpath_query << 'and not('
228
+
229
+ xpath_query << exclusions.map do |exl|
230
+ "contains(@idref,'#{exl}')"
231
+ end.join(' or ')
232
+
233
+ xpath_query << ')' if exclusions.size > 1
234
+ end
235
+
236
+ xpath_query << ')]'
237
+
238
+ xpath_query = xpath_query.join(' ')
239
+
190
240
  # XPATH to get the pertinent test results:
191
241
  # Any node named 'rule-result' for which the attribute 'idref'
192
- # contains filter
193
- result_nodes = doc.xpath("//rule-result[contains(@idref,'#{filter}')]")
242
+ # contains any of the `filter` Strings and does not contain any of the
243
+ # `exclusions` Strings
244
+ result_nodes = doc.xpath(xpath_query)
194
245
  else
195
246
  result_nodes = doc.xpath('//rule-result')
196
247
  end
@@ -1,5 +1,5 @@
1
1
  module Simp; end
2
2
 
3
3
  module Simp::BeakerHelpers
4
- VERSION = '1.16.2'
4
+ VERSION = '1.17.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-beaker-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.2
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-14 00:00:00.000000000 Z
12
+ date: 2019-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beaker