foreman_openscap 0.5.0 → 0.5.1

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_openscap/arf_reports.js +16 -0
  3. data/app/assets/javascripts/foreman_openscap/openscap_proxy.js +52 -0
  4. data/app/assets/javascripts/foreman_openscap/reports.js +6 -0
  5. data/app/assets/stylesheets/foreman_openscap/policy.css +2 -1
  6. data/app/assets/stylesheets/foreman_openscap/reports.css +3 -0
  7. data/app/controllers/api/v2/compliance/arf_reports_controller.rb +2 -2
  8. data/app/controllers/api/v2/compliance/policies_controller.rb +6 -6
  9. data/app/controllers/api/v2/compliance/scap_contents_controller.rb +2 -2
  10. data/app/controllers/arf_reports_controller.rb +41 -5
  11. data/app/controllers/concerns/foreman_openscap/hostgroups_controller_extensions.rb +20 -0
  12. data/app/controllers/concerns/foreman_openscap/hosts_common_controller_extensions.rb +45 -0
  13. data/app/controllers/concerns/foreman_openscap/hosts_controller_extensions.rb +17 -0
  14. data/app/controllers/policies_controller.rb +4 -4
  15. data/app/helpers/arf_report_dashboard_helper.rb +5 -5
  16. data/app/helpers/arf_reports_helper.rb +28 -0
  17. data/app/helpers/compliance_hosts_helper.rb +5 -3
  18. data/app/helpers/policies_helper.rb +3 -3
  19. data/app/helpers/policy_dashboard_helper.rb +2 -2
  20. data/app/lib/proxy_api/available_proxy.rb +7 -7
  21. data/app/lib/proxy_api/openscap.rb +10 -0
  22. data/app/mailers/foreman_openscap/policy_mailer.rb +2 -2
  23. data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +5 -5
  24. data/app/models/concerns/foreman_openscap/host_extensions.rb +22 -14
  25. data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +12 -0
  26. data/app/models/concerns/foreman_openscap/log_extensions.rb +8 -0
  27. data/app/models/concerns/foreman_openscap/openscap_proxy_core_extensions.rb +55 -0
  28. data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +17 -0
  29. data/app/models/concerns/foreman_openscap/smart_proxy_extensions.rb +23 -0
  30. data/app/models/foreman_openscap/arf_report.rb +42 -21
  31. data/app/models/foreman_openscap/policy.rb +38 -38
  32. data/app/models/foreman_openscap/scap_content.rb +9 -9
  33. data/app/overrides/hostgroups/form/select_openscap_proxy.rb +4 -0
  34. data/app/overrides/hosts/form/select_openscap_proxy.rb +4 -0
  35. data/app/services/foreman_openscap/host_report_dashboard/data.rb +5 -5
  36. data/app/services/foreman_openscap/report_dashboard/data.rb +5 -5
  37. data/app/views/arf_reports/_detailed_message.html.erb +9 -0
  38. data/app/views/arf_reports/_list.html.erb +29 -9
  39. data/app/views/arf_reports/_output.html.erb +12 -8
  40. data/app/views/arf_reports/delete_multiple.html.erb +29 -0
  41. data/app/views/arf_reports/index.html.erb +1 -1
  42. data/app/views/arf_reports/show.html.erb +3 -1
  43. data/app/views/compliance_hosts/_openscap_proxy.html.erb +8 -0
  44. data/app/views/policies/_form.html.erb +1 -1
  45. data/app/views/policies/steps/_schedule_form.html.erb +1 -1
  46. data/config/routes.rb +17 -1
  47. data/db/migrate/20141013172051_create_scaptimony_policies.rb +1 -1
  48. data/db/migrate/20141014105333_create_scaptimony_assets.rb +2 -2
  49. data/db/migrate/20141015092642_create_scaptimony_arf_reports.rb +4 -4
  50. data/db/migrate/20141104164201_create_scaptimony_scap_contents.rb +1 -3
  51. data/db/migrate/20141104171545_create_scaptimony_policy_revisions.rb +2 -2
  52. data/db/migrate/20141105174834_add_columns_to_scaptimony_policies.rb +1 -1
  53. data/db/migrate/20141113221054_create_scaptimony_scap_content_profiles.rb +1 -1
  54. data/db/migrate/20141116171305_add_profile_to_scaptimony_policies.rb +1 -1
  55. data/db/migrate/20141119182606_create_scaptimony_xccdf_rule_results.rb +3 -3
  56. data/db/migrate/20150821100137_migrate_from_scaptimony.rb +2 -2
  57. data/db/migrate/20150929152345_move_arf_reports_to_reports_table.rb +1 -1
  58. data/db/migrate/20151023131950_link_arf_report_directly_to_host.rb +12 -8
  59. data/db/migrate/20151118165125_add_size_to_scap_content.rb +5 -0
  60. data/db/migrate/20151119155419_add_arf_fields_to_message.rb +8 -0
  61. data/db/migrate/20151120090851_add_openscap_proxy_to_host_and_hostgroup.rb +25 -0
  62. data/db/seeds.d/openscap_feature.rb +1 -1
  63. data/db/seeds.d/openscap_scap_default.rb +1 -1
  64. data/lib/foreman_openscap/bulk_upload.rb +11 -12
  65. data/lib/foreman_openscap/engine.rb +22 -11
  66. data/lib/foreman_openscap/helper.rb +1 -1
  67. data/lib/foreman_openscap/version.rb +1 -1
  68. data/lib/tasks/foreman_openscap_tasks.rake +3 -2
  69. data/test/factories/arf_report_factory.rb +2 -1
  70. data/test/factories/compliance_host_factory.rb +1 -0
  71. data/test/factories/scap_content_related.rb +1 -1
  72. data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +3 -3
  73. data/test/functional/api/v2/compliance/policies_controller_test.rb +1 -1
  74. data/test/functional/api/v2/compliance/scap_contents_controller_test.rb +2 -2
  75. data/test/functional/arf_reports_controller_test.rb +21 -0
  76. data/test/lib/foreman_openscap/bulk_upload_test.rb +2 -2
  77. data/test/test_plugin_helper.rb +2 -2
  78. data/test/unit/arf_report_test.rb +12 -1
  79. data/test/unit/compliance_status_test.rb +6 -5
  80. data/test/unit/openscap_host_test.rb +4 -0
  81. data/test/unit/policy_mailer_test.rb +1 -1
  82. data/test/unit/scap_content_test.rb +1 -1
  83. 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.seconds until arfs_by_reported(reported_at).empty?
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.all.each do |report|
4
- asset = ForemanOpenscap::Asset.where(:id => report.host_id).first
5
- report.host_id = asset.host.id
6
- report.save!
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.all.each do |report|
12
- asset = ForemanOpenscap::Asset.where(:assetable_id => report.host_id, :assetable_type => 'Host::Base').first
13
- report.host_id = asset.id
14
- report.save!
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,5 @@
1
+ class AddSizeToScapContent < ActiveRecord::Migration
2
+ def change
3
+ change_column :foreman_openscap_scap_contents, :scap_file, :binary, :limit => 16.megabyte
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ class AddArfFieldsToMessage < ActiveRecord::Migration
2
+ def change
3
+ add_column :messages, :description, :text
4
+ add_column :messages, :rationale, :text
5
+ add_column :messages, :scap_references, :text
6
+ add_column :messages, :severity, :string
7
+ end
8
+ 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
- raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
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
- unless 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}"
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 => :'policies', :action => :index},
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 => :'scap_contents', :action => :index},
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 => :'arf_reports', :action => :index},
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
- "DashboardIntegrationTest" => ["dashboard page", "dashboard link hosts that had performed modifications",
119
- "dashboard link hosts in error state", "dashboard link good host reports",
120
- "dashboard link hosts that had pending changes", "dashboard link out of sync hosts",
121
- "dashboard link hosts with no reports", "dashboard link hosts with alerts disabled",
122
- "widgets not in dashboard show up in list"]
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
- raise ActiveRecord::RecordNotFound
38
+ fail ActiveRecord::RecordNotFound
39
39
  end
40
40
  host
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  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:setup')
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 {}
@@ -3,6 +3,7 @@ FactoryGirl.define do
3
3
  sequence(:name) { |n| "host#{n}" }
4
4
  sequence(:hostname) { |n| "hostname#{n}" }
5
5
  root_pass 'xybxa6JUkz63w'
6
+ openscap_proxy FactoryGirl.build(:smart_proxy, :url => "http://test.org:8080")
6
7
  policies []
7
8
  asset nil
8
9
  end
@@ -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('../foreman_openscap/test/files/scap_contents/ssg-fedora-ds.xml', 'rb').read }
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
- @asset = FactoryGirl.create(:asset)
8
- @report = FactoryGirl.create(:arf_report, :asset => @asset)
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
@@ -62,4 +62,4 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
62
62
  assert(@response.header['Content-Type'], 'application/xml')
63
63
  assert_response :success
64
64
  end
65
- end
65
+ 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" do
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 = ['../foreman_openscap/test/files/scap_contents/ssg-fedora-ds.xml']
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
@@ -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(['puppet', 'openscap'])
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(['puppet', 'openscap'])
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], @status[:othered] = 0, 0
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
- @failed_report = FactoryGirl.create(:arf_report)
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
- s = status.to_status
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
@@ -10,7 +10,7 @@ class PolicyMailerTest < ActiveSupport::TestCase
10
10
  :mailer => 'ForemanOpenscap::PolicyMailer',
11
11
  :method => 'policy_summary',
12
12
  :subscription_type => 'report',
13
- )
13
+ )
14
14
 
15
15
  @user.mail_notifications << MailNotification[:openscap_policy_summary]
16
16