foreman_openscap 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/foreman_openscap/arf_reports.js +16 -0
- data/app/assets/javascripts/foreman_openscap/openscap_proxy.js +52 -0
- data/app/assets/javascripts/foreman_openscap/reports.js +6 -0
- data/app/assets/stylesheets/foreman_openscap/policy.css +2 -1
- data/app/assets/stylesheets/foreman_openscap/reports.css +3 -0
- data/app/controllers/api/v2/compliance/arf_reports_controller.rb +2 -2
- data/app/controllers/api/v2/compliance/policies_controller.rb +6 -6
- data/app/controllers/api/v2/compliance/scap_contents_controller.rb +2 -2
- data/app/controllers/arf_reports_controller.rb +41 -5
- data/app/controllers/concerns/foreman_openscap/hostgroups_controller_extensions.rb +20 -0
- data/app/controllers/concerns/foreman_openscap/hosts_common_controller_extensions.rb +45 -0
- data/app/controllers/concerns/foreman_openscap/hosts_controller_extensions.rb +17 -0
- data/app/controllers/policies_controller.rb +4 -4
- data/app/helpers/arf_report_dashboard_helper.rb +5 -5
- data/app/helpers/arf_reports_helper.rb +28 -0
- data/app/helpers/compliance_hosts_helper.rb +5 -3
- data/app/helpers/policies_helper.rb +3 -3
- data/app/helpers/policy_dashboard_helper.rb +2 -2
- data/app/lib/proxy_api/available_proxy.rb +7 -7
- data/app/lib/proxy_api/openscap.rb +10 -0
- data/app/mailers/foreman_openscap/policy_mailer.rb +2 -2
- data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +5 -5
- data/app/models/concerns/foreman_openscap/host_extensions.rb +22 -14
- data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +12 -0
- data/app/models/concerns/foreman_openscap/log_extensions.rb +8 -0
- data/app/models/concerns/foreman_openscap/openscap_proxy_core_extensions.rb +55 -0
- data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +17 -0
- data/app/models/concerns/foreman_openscap/smart_proxy_extensions.rb +23 -0
- data/app/models/foreman_openscap/arf_report.rb +42 -21
- data/app/models/foreman_openscap/policy.rb +38 -38
- data/app/models/foreman_openscap/scap_content.rb +9 -9
- data/app/overrides/hostgroups/form/select_openscap_proxy.rb +4 -0
- data/app/overrides/hosts/form/select_openscap_proxy.rb +4 -0
- data/app/services/foreman_openscap/host_report_dashboard/data.rb +5 -5
- data/app/services/foreman_openscap/report_dashboard/data.rb +5 -5
- data/app/views/arf_reports/_detailed_message.html.erb +9 -0
- data/app/views/arf_reports/_list.html.erb +29 -9
- data/app/views/arf_reports/_output.html.erb +12 -8
- data/app/views/arf_reports/delete_multiple.html.erb +29 -0
- data/app/views/arf_reports/index.html.erb +1 -1
- data/app/views/arf_reports/show.html.erb +3 -1
- data/app/views/compliance_hosts/_openscap_proxy.html.erb +8 -0
- data/app/views/policies/_form.html.erb +1 -1
- data/app/views/policies/steps/_schedule_form.html.erb +1 -1
- data/config/routes.rb +17 -1
- data/db/migrate/20141013172051_create_scaptimony_policies.rb +1 -1
- data/db/migrate/20141014105333_create_scaptimony_assets.rb +2 -2
- data/db/migrate/20141015092642_create_scaptimony_arf_reports.rb +4 -4
- data/db/migrate/20141104164201_create_scaptimony_scap_contents.rb +1 -3
- data/db/migrate/20141104171545_create_scaptimony_policy_revisions.rb +2 -2
- data/db/migrate/20141105174834_add_columns_to_scaptimony_policies.rb +1 -1
- data/db/migrate/20141113221054_create_scaptimony_scap_content_profiles.rb +1 -1
- data/db/migrate/20141116171305_add_profile_to_scaptimony_policies.rb +1 -1
- data/db/migrate/20141119182606_create_scaptimony_xccdf_rule_results.rb +3 -3
- data/db/migrate/20150821100137_migrate_from_scaptimony.rb +2 -2
- data/db/migrate/20150929152345_move_arf_reports_to_reports_table.rb +1 -1
- data/db/migrate/20151023131950_link_arf_report_directly_to_host.rb +12 -8
- data/db/migrate/20151118165125_add_size_to_scap_content.rb +5 -0
- data/db/migrate/20151119155419_add_arf_fields_to_message.rb +8 -0
- data/db/migrate/20151120090851_add_openscap_proxy_to_host_and_hostgroup.rb +25 -0
- data/db/seeds.d/openscap_feature.rb +1 -1
- data/db/seeds.d/openscap_scap_default.rb +1 -1
- data/lib/foreman_openscap/bulk_upload.rb +11 -12
- data/lib/foreman_openscap/engine.rb +22 -11
- data/lib/foreman_openscap/helper.rb +1 -1
- data/lib/foreman_openscap/version.rb +1 -1
- data/lib/tasks/foreman_openscap_tasks.rake +3 -2
- data/test/factories/arf_report_factory.rb +2 -1
- data/test/factories/compliance_host_factory.rb +1 -0
- data/test/factories/scap_content_related.rb +1 -1
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +3 -3
- data/test/functional/api/v2/compliance/policies_controller_test.rb +1 -1
- data/test/functional/api/v2/compliance/scap_contents_controller_test.rb +2 -2
- data/test/functional/arf_reports_controller_test.rb +21 -0
- data/test/lib/foreman_openscap/bulk_upload_test.rb +2 -2
- data/test/test_plugin_helper.rb +2 -2
- data/test/unit/arf_report_test.rb +12 -1
- data/test/unit/compliance_status_test.rb +6 -5
- data/test/unit/openscap_host_test.rb +4 -0
- data/test/unit/policy_mailer_test.rb +1 -1
- data/test/unit/scap_content_test.rb +1 -1
- metadata +29 -8
@@ -20,7 +20,7 @@ class MoveArfReportsToReportsTable < ActiveRecord::Migration
|
|
20
20
|
#reported_at attribute must be unique
|
21
21
|
reported_at = DateTime.strptime(item["created_at"], "%Y-%m-%d %H:%M:%S")
|
22
22
|
|
23
|
-
reported_at += 1.
|
23
|
+
reported_at += 1.second until arfs_by_reported(reported_at).empty?
|
24
24
|
|
25
25
|
arf = ForemanOpenscap::ArfReport.create!(:metrics => metrics,
|
26
26
|
:reported_at => reported_at,
|
@@ -1,17 +1,21 @@
|
|
1
1
|
class LinkArfReportDirectlyToHost < ActiveRecord::Migration
|
2
2
|
def up
|
3
|
-
ForemanOpenscap::ArfReport.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
ForemanOpenscap::ArfReport.find_in_batches do |batch|
|
4
|
+
batch.each do |report|
|
5
|
+
asset = ForemanOpenscap::Asset.find(:id => report.host_id)
|
6
|
+
report.host_id = asset.host.id
|
7
|
+
report.save!
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
12
|
def down
|
11
|
-
ForemanOpenscap::ArfReport.
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
ForemanOpenscap::ArfReport.find_in_batches do |batch|
|
14
|
+
batch.all.each do |report|
|
15
|
+
asset = ForemanOpenscap::Asset.find(:assetable_id => report.host_id, :assetable_type => 'Host::Base')
|
16
|
+
report.host_id = asset.id
|
17
|
+
report.save!
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class AddOpenscapProxyToHostAndHostgroup < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :hostgroups, :openscap_proxy_id, :integer
|
4
|
+
add_column :hosts, :openscap_proxy_id, :integer
|
5
|
+
add_column :reports, :openscap_proxy_id, :integer
|
6
|
+
|
7
|
+
#to ensure backward compatiblity
|
8
|
+
#this relies on the fact that only one scap proxy was registered
|
9
|
+
#because there has not been support for multiple scap proxies
|
10
|
+
reports = ForemanOpenscap::ArfReport.where(:openscap_proxy_id => nil)
|
11
|
+
scap_proxy = SmartProxy.with_features("Openscap").first
|
12
|
+
unless scap_proxy.nil?
|
13
|
+
reports.each do |report|
|
14
|
+
report.openscap_proxy = scap_proxy
|
15
|
+
report.save!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def down
|
21
|
+
remove_column :hostgroups, :openscap_proxy_id, :integer
|
22
|
+
remove_column :hosts, :openscap_proxy_id, :integer
|
23
|
+
remove_column :reports, :openscap_proxy_id
|
24
|
+
end
|
25
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
f = Feature.find_or_create_by_name('Openscap')
|
2
|
-
|
2
|
+
fail "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
|
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'foreman_openscap/bulk_upload'
|
2
|
-
ForemanOpenscap::BulkUpload.new(true).generate_scap_default_content
|
2
|
+
ForemanOpenscap::BulkUpload.new(true).generate_scap_default_content
|
@@ -2,7 +2,7 @@ require 'digest/sha2'
|
|
2
2
|
module ForemanOpenscap
|
3
3
|
class BulkUpload
|
4
4
|
attr_accessor :from_scap_security_guide
|
5
|
-
def initialize(from_scap_security_guide=false)
|
5
|
+
def initialize(from_scap_security_guide = false)
|
6
6
|
@from_scap_security_guide = from_scap_security_guide
|
7
7
|
end
|
8
8
|
|
@@ -25,17 +25,16 @@ module ForemanOpenscap
|
|
25
25
|
title = content_name(datastream)
|
26
26
|
filename = original_filename(datastream)
|
27
27
|
scap_content = ScapContent.where(:title => title, :digest => digest).first_or_initialize
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
28
|
+
next if scap_content.persisted?
|
29
|
+
scap_content.scap_file = file
|
30
|
+
scap_content.original_filename = filename
|
31
|
+
scap_content.location_ids = Location.all.map(&:id) if SETTINGS[:locations_enabled]
|
32
|
+
scap_content.organization_ids = Organization.all.map(&:id) if SETTINGS[:organizations_enabled]
|
33
|
+
next puts "## SCAP content is invalid: #{scap_content.errors.full_messages.uniq.join(',')} ##" unless scap_content.valid?
|
34
|
+
if scap_content.save
|
35
|
+
puts "Saved #{datastream} as #{scap_content.title}"
|
36
|
+
else
|
37
|
+
puts "Failed saving #{datastream}"
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
@@ -52,7 +52,7 @@ module ForemanOpenscap
|
|
52
52
|
:parse_bzip, :auto_complete_search],
|
53
53
|
'api/v2/compliance/arf_reports' => [:index, :show],
|
54
54
|
:compliance_hosts => [:show]}
|
55
|
-
permission :destroy_arf_reports, {:arf_reports => [:destroy],
|
55
|
+
permission :destroy_arf_reports, {:arf_reports => [:destroy, :delete_multiple, :submit_delete_multiple],
|
56
56
|
'api/v2/compliance/arf_reports' => [:destroy]}
|
57
57
|
permission :create_arf_reports, {'api/v2/compliance/arf_reports' => [:create]}
|
58
58
|
|
@@ -86,6 +86,8 @@ module ForemanOpenscap
|
|
86
86
|
permission :destroy_scap_contents, {:scap_contents => [:destroy],
|
87
87
|
'api/v2/compliance/scap_contents' => [:destroy]},
|
88
88
|
:resource_type => 'ForemanOpenscap::ScapContent'
|
89
|
+
permission :edit_hosts, { :hosts => [:openscap_proxy_changed] }, :resource_type => "Host"
|
90
|
+
permission :edit_hostgroups, { :hostgroups => [:openscap_proxy_changed] }, :resource_type => "Hostgroup"
|
89
91
|
end
|
90
92
|
|
91
93
|
role "Compliance viewer", [:view_arf_reports, :view_policies, :view_scap_contents]
|
@@ -97,13 +99,13 @@ module ForemanOpenscap
|
|
97
99
|
#add menu entries
|
98
100
|
divider :top_menu, :caption => N_('Compliance'), :parent => :hosts_menu
|
99
101
|
menu :top_menu, :compliance_policies, :caption => N_('Policies'),
|
100
|
-
:url_hash => {:controller => :
|
102
|
+
:url_hash => {:controller => :policies, :action => :index},
|
101
103
|
:parent => :hosts_menu
|
102
104
|
menu :top_menu, :compliance_contents, :caption => N_('SCAP contents'),
|
103
|
-
:url_hash => {:controller => :
|
105
|
+
:url_hash => {:controller => :scap_contents, :action => :index},
|
104
106
|
:parent => :hosts_menu
|
105
107
|
menu :top_menu, :compliance_reports, :caption => N_('Reports'),
|
106
|
-
:url_hash => {:controller => :
|
108
|
+
:url_hash => {:controller => :arf_reports, :action => :index},
|
107
109
|
:parent => :hosts_menu
|
108
110
|
|
109
111
|
# add dashboard widget
|
@@ -114,22 +116,31 @@ module ForemanOpenscap
|
|
114
116
|
|
115
117
|
# As 'arf_report_breakdowns' is a view and does not appear in schema.rb, db:test:prepare will not create the view
|
116
118
|
# which will make the following tests fail.
|
117
|
-
tests_to_skip
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
})
|
119
|
+
tests_to_skip({ "DashboardIntegrationTest" => ["dashboard page", "dashboard link hosts that had performed modifications",
|
120
|
+
"dashboard link hosts in error state", "dashboard link good host reports",
|
121
|
+
"dashboard link hosts that had pending changes", "dashboard link out of sync hosts",
|
122
|
+
"dashboard link hosts with no reports", "dashboard link hosts with alerts disabled",
|
123
|
+
"widgets not in dashboard show up in list"]
|
124
|
+
})
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
#Include concerns in this config.to_prepare block
|
128
129
|
config.to_prepare do
|
130
|
+
Host::Managed.send(:include, ForemanOpenscap::OpenscapProxyExtensions)
|
131
|
+
Host::Managed.send(:include, ForemanOpenscap::OpenscapProxyCoreExtensions)
|
129
132
|
Host::Managed.send(:include, ForemanOpenscap::HostExtensions)
|
130
133
|
HostsHelper.send(:include, ForemanOpenscap::HostsHelperExtensions)
|
131
134
|
Hostgroup.send(:include, ForemanOpenscap::HostgroupExtensions)
|
135
|
+
Hostgroup.send(:include, ForemanOpenscap::OpenscapProxyExtensions)
|
136
|
+
Hostgroup.send(:include, ForemanOpenscap::OpenscapProxyCoreExtensions)
|
132
137
|
Report.send(:include, ForemanOpenscap::ComplianceStatusScopedSearch)
|
138
|
+
SmartProxy.send(:include, ForemanOpenscap::SmartProxyExtensions)
|
139
|
+
HostsController.send(:include, ForemanOpenscap::HostsControllerExtensions)
|
140
|
+
HostsController.send(:include, ForemanOpenscap::HostsCommonControllerExtensions)
|
141
|
+
HostgroupsController.send(:include, ForemanOpenscap::HostgroupsControllerExtensions)
|
142
|
+
HostgroupsController.send(:include, ForemanOpenscap::HostsCommonControllerExtensions)
|
143
|
+
Log.send(:include, ForemanOpenscap::LogExtensions)
|
133
144
|
end
|
134
145
|
|
135
146
|
rake_tasks do
|
@@ -35,7 +35,7 @@ module ForemanOpenscap::Helper
|
|
35
35
|
unless host
|
36
36
|
Rails.logger.error "Could not find Host with name: #{cname}"
|
37
37
|
Rails.logger.error "Please check that Content host is linked to Foreman host" if defined?(Katello::System)
|
38
|
-
|
38
|
+
fail ActiveRecord::RecordNotFound
|
39
39
|
end
|
40
40
|
host
|
41
41
|
end
|
@@ -37,7 +37,7 @@ namespace :test do
|
|
37
37
|
desc "Test ForemanOpenscap"
|
38
38
|
Rake::TestTask.new(:foreman_openscap) do |t|
|
39
39
|
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
40
|
-
t.libs << ["test",test_dir]
|
40
|
+
t.libs << ["test", test_dir]
|
41
41
|
t.pattern = "#{test_dir}/**/*_test.rb"
|
42
42
|
t.verbose = true
|
43
43
|
end
|
@@ -48,8 +48,9 @@ Rake::Task[:test].enhance do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
load 'tasks/jenkins.rake'
|
51
|
-
if Rake::Task.task_defined?(:'jenkins:
|
51
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
52
52
|
Rake::Task["jenkins:unit"].enhance do
|
53
53
|
Rake::Task['test:foreman_openscap'].invoke
|
54
|
+
Rake::Task['foreman_openscap:rubocop'].invoke
|
54
55
|
end
|
55
56
|
end
|
@@ -3,7 +3,8 @@ FactoryGirl.define do
|
|
3
3
|
host_id 1
|
4
4
|
policy nil
|
5
5
|
policy_arf_report nil
|
6
|
-
sequence(:reported_at) { |n| Time.new(1490 + n, 01, 13, 15, 24, 00)}
|
6
|
+
sequence(:reported_at) { |n| Time.new(1490 + n, 01, 13, 15, 24, 00) }
|
7
|
+
sequence(:created_at) { |n| Time.new(1490 + n, 01, 13, 15, 24, 00) }
|
7
8
|
logs []
|
8
9
|
status 0
|
9
10
|
metrics {}
|
@@ -4,7 +4,7 @@ FactoryGirl.define do
|
|
4
4
|
factory :scap_content, :class => ::ForemanOpenscap::ScapContent do |f|
|
5
5
|
f.title 'fedora'
|
6
6
|
f.original_filename 'fedora ds'
|
7
|
-
f.scap_file { File.new(
|
7
|
+
f.scap_file { File.new("#{ForemanOpenscap::Engine.root}/test/files/scap_contents/ssg-fedora-ds.xml", 'rb').read }
|
8
8
|
end
|
9
9
|
|
10
10
|
factory :scap_content_profile, :class => ::ForemanOpenscap::ScapContentProfile do |f|
|
@@ -4,8 +4,8 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
4
4
|
setup do
|
5
5
|
# override validation of policy (puppetclass, lookup_key overrides)
|
6
6
|
ForemanOpenscap::Policy.any_instance.stubs(:valid?).returns(true)
|
7
|
-
@
|
8
|
-
@report = FactoryGirl.create(:arf_report, :
|
7
|
+
@host = FactoryGirl.create(:compliance_host)
|
8
|
+
@report = FactoryGirl.create(:arf_report, :host_id => @host.id)
|
9
9
|
end
|
10
10
|
test "should get index" do
|
11
11
|
get :index, {}, set_session_user
|
@@ -22,4 +22,4 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
22
22
|
refute response['othered'].blank?
|
23
23
|
assert_response :success
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
@@ -33,7 +33,7 @@ class Api::V2::Compliance::ScapContentsControllerTest < ActionController::TestCa
|
|
33
33
|
assert scap_content.title, 'RHEL7 SCAP'
|
34
34
|
end
|
35
35
|
|
36
|
-
test "should not update invalid scap content"
|
36
|
+
test "should not update invalid scap content" do
|
37
37
|
skip("Solve 'ActiveRecord::RecordInvalid' error")
|
38
38
|
ProxyAPI::Openscap.any_instance.stubs(:validate_scap_content).returns({'errors' => ['Invalid file']})
|
39
39
|
scap_content = FactoryGirl.create(:scap_content)
|
@@ -47,4 +47,4 @@ class Api::V2::Compliance::ScapContentsControllerTest < ActionController::TestCa
|
|
47
47
|
assert_response :ok
|
48
48
|
refute ForemanOpenscap::ScapContent.exists?(scap_content.id)
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class ArfReportsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "should delete selected reports" do
|
6
|
+
host = FactoryGirl.create(:compliance_host)
|
7
|
+
ForemanOpenscap::Helper.stubs(:find_name_or_uuid_by_host)
|
8
|
+
::ProxyAPI::Openscap.any_instance.stubs(:destroy_report).returns(true)
|
9
|
+
ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy).returns(host.openscap_proxy)
|
10
|
+
arf_reports = []
|
11
|
+
3.times do
|
12
|
+
arf_reports << FactoryGirl.create(:arf_report, :host_id => host.id)
|
13
|
+
end
|
14
|
+
last_arf = arf_reports[-1]
|
15
|
+
assert_difference("ForemanOpenscap::ArfReport.count", -2) do
|
16
|
+
post :submit_delete_multiple, { :arf_report_ids => arf_reports[0..-2].map(&:id) }, set_session_user
|
17
|
+
end
|
18
|
+
assert_redirected_to arf_reports_path
|
19
|
+
assert_equal last_arf, ForemanOpenscap::ArfReport.first
|
20
|
+
end
|
21
|
+
end
|
@@ -6,11 +6,11 @@ class BulkUploadTest < ActiveSupport::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'upload_from_files should create only one scap content' do
|
9
|
-
scap_files = [
|
9
|
+
scap_files = ["#{ForemanOpenscap::Engine.root}/test/files/scap_contents/ssg-fedora-ds.xml"]
|
10
10
|
assert_difference('ForemanOpenscap::ScapContent.count', 1) do
|
11
11
|
2.times do
|
12
12
|
ForemanOpenscap::BulkUpload.new.upload_from_files(scap_files)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -13,7 +13,7 @@ Spork.each_run do
|
|
13
13
|
|
14
14
|
def add_smart_proxy
|
15
15
|
FactoryGirl.create(:smart_proxy, :url => 'http://localhost:8443', :features => [FactoryGirl.create(:feature, :name => 'Openscap')])
|
16
|
-
::ProxyAPI::Features.any_instance.stubs(:features).returns(
|
16
|
+
::ProxyAPI::Features.any_instance.stubs(:features).returns(%w(puppet openscap))
|
17
17
|
ProxyAPI::Openscap.any_instance.stubs(:validate_scap_content).returns({'errors' => []})
|
18
18
|
ProxyAPI::Openscap.any_instance.stubs(:fetch_policies_for_scap_content)
|
19
19
|
.returns({'xccdf_org.ssgproject.content_profile_common' => 'Common Profile for General-Purpose Fedora Systems'})
|
@@ -27,7 +27,7 @@ Spork.each_run do
|
|
27
27
|
|
28
28
|
def add_smart_proxy
|
29
29
|
FactoryGirl.create(:smart_proxy, :url => 'http://localhost:8443', :features => [FactoryGirl.create(:feature, :name => 'Openscap')])
|
30
|
-
::ProxyAPI::Features.any_instance.stubs(:features).returns(
|
30
|
+
::ProxyAPI::Features.any_instance.stubs(:features).returns(%w(puppet openscap))
|
31
31
|
ProxyAPI::Openscap.any_instance.stubs(:validate_scap_content).returns({'errors' => []})
|
32
32
|
ProxyAPI::Openscap.any_instance.stubs(:fetch_policies_for_scap_content)
|
33
33
|
.returns({'xccdf_org.ssgproject.content_profile_common' => 'Common Profile for General-Purpose Fedora Systems'})
|
@@ -71,7 +71,8 @@ module ForemanOpenscap
|
|
71
71
|
end
|
72
72
|
|
73
73
|
test 'should recognize report that passed' do
|
74
|
-
@status[:failed]
|
74
|
+
@status[:failed] = 0
|
75
|
+
@status[:othered] = 0
|
75
76
|
report = FactoryGirl.create(:arf_report, :host_id => @host.id, :status => @status)
|
76
77
|
assert report.passed?
|
77
78
|
end
|
@@ -144,5 +145,15 @@ module ForemanOpenscap
|
|
144
145
|
@passed_reports.each { |pass| assert ForemanOpenscap::ArfReport.passed.include?(pass) }
|
145
146
|
end
|
146
147
|
end
|
148
|
+
|
149
|
+
test 'should destroy report' do
|
150
|
+
openscap_proxy_api = ::ProxyAPI::Openscap.new(:url => 'https://test-proxy.com:9090')
|
151
|
+
openscap_proxy_api.stubs(:destroy_report).returns(true)
|
152
|
+
ForemanOpenscap::Helper.stubs(:find_name_or_uuid_by_host).returns("abcde")
|
153
|
+
ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy_api).returns(openscap_proxy_api)
|
154
|
+
report = FactoryGirl.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
|
155
|
+
report.destroy
|
156
|
+
refute ForemanOpenscap::ArfReport.all.include? report
|
157
|
+
end
|
147
158
|
end
|
148
159
|
end
|
@@ -7,12 +7,13 @@ class ComplianceStatusTest < ActiveSupport::TestCase
|
|
7
7
|
ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
|
8
8
|
@policy_a = FactoryGirl.create(:policy)
|
9
9
|
@policy_b = FactoryGirl.create(:policy)
|
10
|
-
@
|
10
|
+
@host = FactoryGirl.create(:compliance_host)
|
11
|
+
@failed_report = FactoryGirl.create(:arf_report, :host_id => @host.id)
|
11
12
|
@failed_report.stubs(:failed?).returns(true)
|
12
|
-
@passed_report = FactoryGirl.create(:arf_report)
|
13
|
+
@passed_report = FactoryGirl.create(:arf_report, :host_id => @host.id)
|
13
14
|
@passed_report.stubs(:failed?).returns(false)
|
14
15
|
@passed_report.stubs(:othered?).returns(false)
|
15
|
-
@othered_report = FactoryGirl.create(:arf_report)
|
16
|
+
@othered_report = FactoryGirl.create(:arf_report, :host_id => @host.id)
|
16
17
|
@othered_report.stubs(:failed?).returns(false)
|
17
18
|
@othered_report.stubs(:othered?).returns(true)
|
18
19
|
end
|
@@ -22,7 +23,7 @@ class ComplianceStatusTest < ActiveSupport::TestCase
|
|
22
23
|
host = FactoryGirl.create(:compliance_host, :policies => [@policy_a])
|
23
24
|
status.host = host
|
24
25
|
host.stubs(:last_report_for_policy).returns(@failed_report)
|
25
|
-
|
26
|
+
status.to_status
|
26
27
|
assert_equal 2, status.to_status
|
27
28
|
end
|
28
29
|
|
@@ -61,7 +62,7 @@ class ComplianceStatusTest < ActiveSupport::TestCase
|
|
61
62
|
test 'status should be compliant for multiple policies' do
|
62
63
|
status = ForemanOpenscap::ComplianceStatus.new
|
63
64
|
host = FactoryGirl.create(:compliance_host, :policies => [@policy_a, @policy_b])
|
64
|
-
passed_report = FactoryGirl.create(:arf_report)
|
65
|
+
passed_report = FactoryGirl.create(:arf_report, :host_id => @host.id)
|
65
66
|
passed_report.stubs(:othered?).returns(false)
|
66
67
|
passed_report.stubs(:failed?).returns(false)
|
67
68
|
host.stubs(:last_report_for_policy).returns(passed_report, @passed_report)
|
@@ -51,6 +51,10 @@ class OpenscapHostTest < ActiveSupport::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
test 'scap_status_changed should not detect status change when there are reports < 2' do
|
54
|
+
openscap_proxy_api = ::ProxyAPI::Openscap.new(:url => 'https://test-proxy.com:9090')
|
55
|
+
openscap_proxy_api.stubs(:destroy_report).returns(true)
|
56
|
+
ForemanOpenscap::Helper.stubs(:find_name_or_uuid_by_host).returns("abcde")
|
57
|
+
ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy_api).returns(openscap_proxy_api)
|
54
58
|
@report_2.destroy
|
55
59
|
refute @host.scap_status_changed?(@policy)
|
56
60
|
end
|