foreman_openscap 11.1.0 → 12.0.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 +4 -4
- data/app/controllers/arf_reports_controller.rb +1 -2
- data/app/models/foreman_openscap/arf_report.rb +3 -0
- data/lib/foreman_openscap/engine.rb +1 -1
- data/lib/foreman_openscap/version.rb +1 -1
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +24 -0
- data/test/functional/arf_reports_controller_test.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96e4d934fc2d51a5bbe4bc72af3571327447e6b6216e23841978440fea078f25
|
4
|
+
data.tar.gz: 7b652d18b0d2a663ab6808dcb13a76eeed2fcc9d55d8cfc5b5cde46becdf4a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 579169b33271da9334e095c53bc57d2b09b0eed9638c45b26562d77e22d902a1d313be9880b2276e24fae45b372417823d119a34e158e183505160f84e84066d
|
7
|
+
data.tar.gz: 5f05c3cdd6e9ab5030ddf719d79f6ab9dce2462791e0219b865abdf339d61364ab4dd2f1aa7fbe021c7d8c11d2768fe336cd386c135294630c17c55de96479f4
|
@@ -13,8 +13,7 @@ class ArfReportsController < ApplicationController
|
|
13
13
|
# Avoid using includes() with nested associations and "order by" together. Otherwise,
|
14
14
|
# includes() will use join tables instead and Rails somehow create many objects and
|
15
15
|
# high memory consumption.
|
16
|
-
@arf_reports_pg =
|
17
|
-
.paginate(:page => params[:page], :per_page => params[:per_page])
|
16
|
+
@arf_reports_pg = resource_base_search_and_page.load
|
18
17
|
arf_report_ids = @arf_reports_pg.pluck(:id)
|
19
18
|
@arf_reports = resource_base.includes(:policy, :openscap_proxy, :host => %i[policies last_report_object host_statuses])
|
20
19
|
.where(id: arf_report_ids)
|
@@ -53,11 +53,14 @@ module ForemanOpenscap
|
|
53
53
|
|
54
54
|
scope :failed, lambda { where("(#{report_status_column} >> #{bit_mask 'failed'}) > 0") }
|
55
55
|
scope :not_failed, lambda { where("(#{report_status_column} >> #{bit_mask 'failed'}) = 0") }
|
56
|
+
virtual_column_scope :select_compliance_failed, lambda { select("reports.*, (#{report_status_column} >> #{bit_mask 'failed'}) as compliance_failed") }
|
56
57
|
|
57
58
|
scope :othered, lambda { where("(#{report_status_column} >> #{bit_mask 'othered'}) > 0").merge(not_failed) }
|
58
59
|
scope :not_othered, lambda { where("(#{report_status_column} >> #{bit_mask 'othered'}) = 0") }
|
60
|
+
virtual_column_scope :select_compliance_othered, lambda { select("reports.*, (#{report_status_column} >> #{bit_mask 'othered'}) as compliance_othered") }
|
59
61
|
|
60
62
|
scope :passed, lambda { where("(#{report_status_column} >> #{bit_mask 'passed'}) > 0").merge(not_failed).merge(not_othered) }
|
63
|
+
virtual_column_scope :select_compliance_passed, lambda { select("reports.*, (#{report_status_column} >> #{bit_mask 'passed'}) as compliance_passed") }
|
61
64
|
|
62
65
|
scope :by_rule_result, lambda { |rule_name, rule_result| joins(:sources).where(:sources => { :value => rule_name }, :logs => { :result => rule_result }) }
|
63
66
|
|
@@ -40,7 +40,7 @@ module ForemanOpenscap
|
|
40
40
|
initializer 'foreman_openscap.register_plugin', :before => :finisher_hook do |app|
|
41
41
|
app.reloader.to_prepare do
|
42
42
|
Foreman::Plugin.register :foreman_openscap do
|
43
|
-
requires_foreman '>= 3.
|
43
|
+
requires_foreman '>= 3.17'
|
44
44
|
register_gettext
|
45
45
|
|
46
46
|
apipie_documented_controllers ["#{ForemanOpenscap::Engine.root}/app/controllers/api/v2/compliance/*.rb"]
|
@@ -436,6 +436,30 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
436
436
|
assert_equal report.id, response['results'].first["id"].to_i
|
437
437
|
end
|
438
438
|
|
439
|
+
test "should order by compliance_[failed|passed|othered]" do
|
440
|
+
reports_cleanup
|
441
|
+
policy = FactoryBot.create(:policy)
|
442
|
+
create_arf_report_for_search({ "passed" => 4, "othered" => 0, "failed" => 1 }, policy)
|
443
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, policy)
|
444
|
+
create_arf_report_for_search({ "passed" => 15, "othered" => 9, "failed" => 0 }, policy)
|
445
|
+
create_arf_report_for_search({ "passed" => 2, "othered" => 3, "failed" => 7 }, policy)
|
446
|
+
|
447
|
+
get :index, :params => { :order => "compliance_failed DESC" }, :session => set_session_user
|
448
|
+
assert_response :success
|
449
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
450
|
+
assert_equal 7, response['results'].first['failed']
|
451
|
+
|
452
|
+
get :index, :params => { :order => "compliance_passed DESC" }, :session => set_session_user
|
453
|
+
assert_response :success
|
454
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
455
|
+
assert_equal 15, response['results'].first['passed']
|
456
|
+
|
457
|
+
get :index, :params => { :order => "compliance_othered DESC" }, :session => set_session_user
|
458
|
+
assert_response :success
|
459
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
460
|
+
assert_equal 9, response['results'].first['othered']
|
461
|
+
end
|
462
|
+
|
439
463
|
private
|
440
464
|
|
441
465
|
def reports_cleanup
|
@@ -37,4 +37,13 @@ class ArfReportsControllerTest < ActionController::TestCase
|
|
37
37
|
get :download_html, :params => { :id => arf_report.id }, :session => set_session_user
|
38
38
|
assert_equal report_html, @response.body
|
39
39
|
end
|
40
|
+
|
41
|
+
test "should order arf reports by compliance_[failed|passed|othered]" do
|
42
|
+
get :index, params: { order: "compliance_failed DESC" }, :session => set_session_user
|
43
|
+
assert_response :success
|
44
|
+
get :index, params: { order: "compliance_passed DESC" }, :session => set_session_user
|
45
|
+
assert_response :success
|
46
|
+
get :index, params: { order: "compliance_othered DESC" }, :session => set_session_user
|
47
|
+
assert_response :success
|
48
|
+
end
|
40
49
|
end
|