foreman_openscap 0.7.13 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/compliance/arf_reports_controller.rb +4 -14
  3. data/app/controllers/api/v2/compliance/policies_controller.rb +4 -8
  4. data/app/controllers/api/v2/compliance/scap_contents_controller.rb +2 -2
  5. data/app/controllers/arf_reports_controller.rb +1 -1
  6. data/app/helpers/arf_reports_helper.rb +0 -13
  7. data/app/lib/proxy_api/openscap.rb +2 -3
  8. data/app/models/concerns/foreman_openscap/data_stream_content.rb +6 -13
  9. data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +5 -1
  10. data/app/models/foreman_openscap/arf_report.rb +13 -19
  11. data/app/models/foreman_openscap/asset.rb +1 -1
  12. data/app/models/foreman_openscap/asset_policy.rb +1 -1
  13. data/app/models/foreman_openscap/policy.rb +8 -21
  14. data/app/models/foreman_openscap/policy_arf_report.rb +1 -1
  15. data/app/models/foreman_openscap/policy_revision.rb +1 -1
  16. data/app/models/foreman_openscap/scap_content.rb +1 -3
  17. data/app/models/foreman_openscap/scap_content_profile.rb +1 -1
  18. data/app/models/foreman_openscap/tailoring_file.rb +1 -2
  19. data/app/overrides/hostgroups/form/select_openscap_proxy.rb +4 -0
  20. data/app/overrides/hosts/form/select_openscap_proxy.rb +4 -0
  21. data/app/views/api/v2/compliance/arf_reports/main.json.rabl +3 -11
  22. data/app/views/api/v2/compliance/common/_loc.json.rabl +1 -1
  23. data/app/views/api/v2/compliance/common/_org.json.rabl +1 -1
  24. data/app/views/api/v2/compliance/policies/show.json.rabl +0 -4
  25. data/app/views/arf_reports/_list.html.erb +2 -6
  26. data/app/views/arf_reports/delete_multiple.html.erb +1 -1
  27. data/app/views/arf_reports/show.html.erb +1 -2
  28. data/app/views/compliance_hosts/_openscap_proxy.html.erb +3 -0
  29. data/app/views/policies/_list.html.erb +1 -1
  30. data/db/migrate/20160830113437_remove_deleted_policy.rb +1 -1
  31. data/db/seeds.d/openscap_policy_notification.rb +2 -2
  32. data/lib/foreman_openscap/engine.rb +1 -13
  33. data/lib/foreman_openscap/version.rb +1 -1
  34. data/lib/tasks/foreman_openscap_tasks.rake +0 -9
  35. data/test/factories/policy_factory.rb +2 -2
  36. data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +6 -26
  37. data/test/functional/api/v2/compliance/policies_controller_test.rb +0 -8
  38. data/test/unit/policy_test.rb +7 -33
  39. data/test/unit/scap_content_test.rb +0 -15
  40. metadata +6 -8
  41. data/app/views/api/v2/compliance/scap_contents/create.json.rabl +0 -3
  42. data/app/views/api/v2/compliance/scap_contents/update.json.rabl +0 -3
  43. data/db/migrate/20170821081205_rename_mail_notification.foreman_openscap.rb +0 -15
  44. data/db/migrate/20170830221751_add_index_to_logs_result.rb +0 -9
  45. data/db/migrate/20171011134112_remove_arf_reports_without_policy.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8df18dc74e5bedec4c537aebb669668d5c30d56
4
- data.tar.gz: 5a3cc516ba8be0e717a71c16ec756194feacddcc
3
+ metadata.gz: 9486399cc59110965957e2a3f91d1fe521653e92
4
+ data.tar.gz: dc00dfd095d17a5eb6edd5bddc1d8e5a315a9a77
5
5
  SHA512:
6
- metadata.gz: 37774693e9f4c13cb758f1d27e813a93c3d8c176e4c82d853eea8bbb2c035d25f47ae80f8bacd0bdb110b81c4ce63e52eac0148d823b4293b423deb0c97e1302
7
- data.tar.gz: 50383b9cad954065a7851fcce0d751e287681ce5461ce287ce40d502e8aa5ed769e275486824a44969638ff4ebb99875e816d9ccd129237e690e30a56f830b40
6
+ metadata.gz: 04e9191662e177076cc0d740aeda0d51a418412a06e178af8922e0794010919b62ccabcef433462aab564bfe5180d4376f7e5e1dbaeadecbee43d7469f5e196c
7
+ data.tar.gz: 0c2e5932fba6d3c5be4b8c44b3891c21c4dad1d44cbc15dd5e6e814c6f4884cb18410f4ac4d3093de80a8920c20b46ce3cd79ef05d18284ffee7b1c429dab5c2
@@ -26,7 +26,7 @@ module Api
26
26
  param_group :search_and_pagination, ::Api::V2::BaseController
27
27
 
28
28
  def index
29
- @arf_reports = resource_scope_for_index(:permission => :view_arf_reports).includes(:openscap_proxy, :policy, :host)
29
+ @arf_reports = resource_scope_for_index(:permission => :edit_compliance).includes(:asset)
30
30
  end
31
31
 
32
32
  api :GET, '/compliance/arf_reports/:id', N_('Show an ARF report')
@@ -49,13 +49,9 @@ module Api
49
49
 
50
50
  def create
51
51
  asset = ForemanOpenscap::Helper::get_asset(params[:cname], params[:policy_id])
52
- if asset.host.openscap_proxy
53
- arf_report = ForemanOpenscap::ArfReport.create_arf(asset, params)
54
- asset.host.refresh_statuses
55
- render :json => { :result => :OK, :id => arf_report.id.to_s }
56
- else
57
- no_proxy_for_host asset
58
- end
52
+ arf_report = ForemanOpenscap::ArfReport.create_arf(asset, params)
53
+ asset.host.refresh_statuses if asset.host
54
+ render :json => { :result => :OK, :id => arf_report.id.to_s }
59
55
  end
60
56
 
61
57
  api :GET, "/compliance/arf_reports/:id/download/", N_("Download bzipped ARF report")
@@ -89,12 +85,6 @@ module Api
89
85
  render_error 'standard_error', :status => :internal_error, :locals => { :exception => error }
90
86
  end
91
87
 
92
- def no_proxy_for_host(asset)
93
- msg = _('Failed to upload Arf Report, no OpenSCAP proxy set for host %s') % asset.host.name
94
- logger.error msg
95
- render :json => { :result => msg }, :status => :unprocessable_entity
96
- end
97
-
98
88
  def action_permission
99
89
  case params[:action]
100
90
  when 'download', 'download_html'
@@ -26,7 +26,7 @@ module Api::V2
26
26
  param_group :search_and_pagination, ::Api::V2::BaseController
27
27
 
28
28
  def index
29
- @policies = resource_scope_for_index(:permission => :view_policies)
29
+ @policies = resource_scope_for_index(:permission => :edit_compliance)
30
30
  end
31
31
 
32
32
  api :GET, '/compliance/policies/:id', N_('Show a Policy')
@@ -90,13 +90,9 @@ module Api::V2
90
90
 
91
91
  def tailoring
92
92
  @tailoring_file = @policy.tailoring_file
93
- if @tailoring_file
94
- send_data @tailoring_file.scap_file,
95
- :type => 'application/xml',
96
- :filename => @tailoring_file.original_filename
97
- else
98
- render(:json => { :error => { :message => _("No Tailoring file assigned for policy with id %s") % @policy.id } }, :status => 404)
99
- end
93
+ send_data @tailoring_file.scap_file,
94
+ :type => 'application/xml',
95
+ :filename => @tailoring_file.original_filename
100
96
  end
101
97
 
102
98
  private
@@ -16,7 +16,7 @@ module Api::V2
16
16
  param_group :search_and_pagination, ::Api::V2::BaseController
17
17
 
18
18
  def index
19
- @scap_contents = resource_scope_for_index(:permission => :view_scap_contents)
19
+ @scap_contents = resource_scope_for_index(:permission => :edit_compliance)
20
20
  end
21
21
 
22
22
  api :GET, '/compliance/scap_contents/:id/xml', N_('Show an SCAP content as XML')
@@ -25,7 +25,7 @@ module Api::V2
25
25
  def xml
26
26
  send_data @scap_content.scap_file,
27
27
  :type => 'application/xml',
28
- :filename => @scap_content.original_filename || "#{@scap_content.title}.xml"
28
+ :filename => @scap_content.original_filename
29
29
  end
30
30
 
31
31
  api :GET, '/compliance/scap_contents/:id', N_('Show an SCAP content')
@@ -10,7 +10,7 @@ class ArfReportsController < ApplicationController
10
10
  end
11
11
 
12
12
  def index
13
- @arf_reports = resource_base.includes(:policy, :openscap_proxy, :host => %i[policies last_report_object host_statuses])
13
+ @arf_reports = resource_base.includes(:host => %i[policies last_report_object host_statuses])
14
14
  .search_for(params[:search], :order => params[:order])
15
15
  .paginate(:page => params[:page], :per_page => params[:per_page])
16
16
  end
@@ -52,17 +52,4 @@ module ArfReportsHelper
52
52
  :'data-dialog-title' => _("%s - The following compliance reports are about to be changed") % action[0])
53
53
  end.flatten)
54
54
  end
55
-
56
- def openscap_proxy_link(arf_report)
57
- return _("No proxy found!") unless arf_report.openscap_proxy
58
- display_link_if_authorized(arf_report.openscap_proxy.name, hash_for_smart_proxy_path(:id => arf_report.openscap_proxy_id))
59
- end
60
-
61
- def reported_info(arf_report)
62
- msg = _("Reported at %s") % arf_report.reported_at
63
- msg << _(" for policy %s") % display_link_if_authorized(arf_report.policy.name, hash_for_edit_policy_path(:id => arf_report.policy.id)) if arf_report.policy
64
- return msg.html_safe unless arf_report.openscap_proxy
65
- msg += _(" through %s") % openscap_proxy_link(arf_report)
66
- msg.html_safe
67
- end
68
55
  end
@@ -51,9 +51,8 @@ module ::ProxyAPI
51
51
  begin
52
52
  parse(delete("arf/#{report.id}/#{cname}/#{report.reported_at.to_i}/#{report.policy_arf_report.digest}"))
53
53
  rescue => e
54
- msg = "Failed to destroy arf report with id #{report.id} on Smart Proxy, cause: #{e.message}"
55
- logger.error msg
56
- report.errors.add(:base, msg)
54
+ logger.error "Failed to destroy arf report with id #{report.id} on Smart Proxy"
55
+ logger.debug e.backtrace.join("\n\t")
57
56
  false
58
57
  end
59
58
  end
@@ -28,23 +28,16 @@ module ForemanOpenscap
28
28
  self[:digest] ||= Digest::SHA256.hexdigest(scap_file.to_s)
29
29
  end
30
30
 
31
- def create_profiles
32
- fetch_profiles.each do |key, title|
33
- create_or_update_profile key, title
34
- end
35
- end
36
-
37
- def create_or_update_profile(profile_id, title)
38
- profile = ScapContentProfile.find_by(:profile_id => profile_id, "#{self.class.to_s.demodulize.underscore}_id".to_sym => id)
39
- return ScapContentProfile.create(:profile_id => profile_id, :title => title, "#{self.class.to_s.demodulize.underscore}_id".to_sym => id) unless profile
40
- profile.update(:title => title) unless profile.title == title
41
- profile
42
- end
43
-
44
31
  private
45
32
 
46
33
  def redigest
47
34
  self[:digest] = Digest::SHA256.hexdigest(scap_file.to_s)
48
35
  end
36
+
37
+ def create_profiles
38
+ fetch_profiles.each do |key, title|
39
+ ScapContentProfile.where(:profile_id => key, :title => title, "#{self.class.to_s.demodulize.underscore}_id".to_sym => id).first_or_create
40
+ end
41
+ end
49
42
  end
50
43
  end
@@ -2,10 +2,14 @@ module ForemanOpenscap
2
2
  module OpenscapProxyExtensions
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ included do
6
+ belongs_to :openscap_proxy, :class_name => "SmartProxy"
7
+ end
8
+
5
9
  def openscap_proxy_api
6
10
  return @openscap_api if @openscap_api
7
11
  proxy_url = openscap_proxy.url if openscap_proxy
8
- raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with id %{id}"), { :class => self.class, :id => id }) unless proxy_url
12
+ raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with %{id}"), { :class => self.class, :id => id }) unless proxy_url
9
13
  @openscap_api = ::ProxyAPI::Openscap.new(:url => proxy_url)
10
14
  end
11
15
  end
@@ -12,14 +12,11 @@ module ForemanOpenscap
12
12
 
13
13
  scoped_search :on => :status, :offset => 0, :word_size => 4*BIT_NUM, :complete_value => {:true => true, :false => false}, :rename => :eventful
14
14
 
15
- has_one :policy_arf_report
16
- has_one :policy, :through => :policy_arf_report, :dependent => :destroy
15
+ has_one :policy_arf_report, :dependent => :destroy
16
+ has_one :policy, :through => :policy_arf_report
17
17
  has_one :asset, :through => :host, :class_name => 'ForemanOpenscap::Asset', :as => :assetable
18
- has_one :log, :foreign_key => :report_id
19
- belongs_to :openscap_proxy, :class_name => "SmartProxy"
20
-
21
18
  after_save :assign_locations_organizations
22
- before_destroy :destroy_from_proxy
19
+ has_one :log, :foreign_key => :report_id
23
20
 
24
21
  delegate :asset=, :to => :host
25
22
 
@@ -176,21 +173,18 @@ module ForemanOpenscap
176
173
  policy.id == other.policy.id
177
174
  end
178
175
 
179
- def destroy_from_proxy
180
- if !host
181
- destroy_from_proxy_warning "host"
182
- elsif !policy
183
- destroy_from_proxy_warning "policy"
184
- elsif !openscap_proxy
185
- destroy_from_proxy_warning "OpenSCAP proxy"
176
+ def destroy
177
+ if host
178
+ begin
179
+ openscap_proxy_api.destroy_report(self, ForemanOpenscap::Helper::find_name_or_uuid_by_host(host))
180
+ rescue Foreman::Exception => e
181
+ logger.error "Failed to delete report with id #{id} from proxy, cause: #{e.message}"
182
+ logger.debug e.backtrace.join("\n\t")
183
+ end
186
184
  else
187
- openscap_proxy_api.destroy_report(self, ForemanOpenscap::Helper::find_name_or_uuid_by_host(host))
185
+ logger.error "Failed to delete report with id #{id} from proxy, no host associated with report"
188
186
  end
189
- end
190
-
191
- def destroy_from_proxy_warning(associated)
192
- logger.warn "Skipping deletion of report with id #{id} from proxy, no #{associated} associated with report"
193
- true
187
+ super
194
188
  end
195
189
 
196
190
  def self.newline_to_space(string)
@@ -1,5 +1,5 @@
1
1
  module ForemanOpenscap
2
- class Asset < ActiveRecord::Base
2
+ class Asset < ApplicationRecord
3
3
  has_many :asset_policies
4
4
  has_many :policies, :through => :asset_policies
5
5
  belongs_to :assetable, :polymorphic => true
@@ -1,5 +1,5 @@
1
1
  module ForemanOpenscap
2
- class AssetPolicy < ActiveRecord::Base
2
+ class AssetPolicy < ApplicationRecord
3
3
  belongs_to :policy
4
4
  belongs_to :asset
5
5
  end
@@ -1,10 +1,8 @@
1
- require 'rack/utils'
2
1
  module ForemanOpenscap
3
- class Policy < ActiveRecord::Base
2
+ class Policy < ApplicationRecord
4
3
  include Authorizable
5
4
  include Taxonomix
6
5
  attr_writer :current_step, :wizard_initiated
7
- audited
8
6
 
9
7
  belongs_to :scap_content
10
8
  belongs_to :scap_content_profile
@@ -30,9 +28,10 @@ module ForemanOpenscap
30
28
  :if => Proc.new { |policy| policy.should_validate?('Schedule') }
31
29
 
32
30
  validates :scap_content_id, presence: true, if: Proc.new { |policy| policy.should_validate?('SCAP Content') }
33
- validate :matching_content_profile, if: Proc.new { |policy| policy.should_validate?('SCAP Content') }
31
+ validates :scap_content_profile_id, presence: true, if: Proc.new { |policy| policy.should_validate?('SCAP Content') }
34
32
 
35
33
  validate :valid_cron_line, :valid_weekday, :valid_day_of_month, :valid_tailoring, :valid_tailoring_profile
34
+
36
35
  after_save :assign_policy_to_hostgroups
37
36
  # before_destroy - ensure that the policy has no hostgroups, or classes
38
37
 
@@ -47,17 +46,18 @@ module ForemanOpenscap
47
46
  end
48
47
 
49
48
  def to_html
50
- if scap_content.nil?
51
- return html_error_message(_('Cannot generate HTML guide, scap content is missing.'))
49
+ if scap_content.nil? || scap_content_profile.nil?
50
+ return ("<h2>%s</h2>" % (_('Cannot generate HTML guide for %{scap_content}/%{profile}') %
51
+ { :scap_content => h(self.scap_content), :profile => h(self.scap_content_profile) })).html_safe
52
52
  end
53
53
 
54
54
  if (proxy = scap_content.proxy_url)
55
55
  api = ProxyAPI::Openscap.new(:url => proxy)
56
56
  else
57
- return html_error_message(_('Cannot generate HTML guide, no valid OpenSCAP proxy server found.'))
57
+ return ("<h2>%s</h2>" % _('No valid OpenSCAP proxy server found.')).html_safe
58
58
  end
59
59
 
60
- api.policy_html_guide(scap_content.scap_file, scap_content_profile.try(:profile_id))
60
+ api.policy_html_guide(scap_content.scap_file, scap_content_profile.profile_id)
61
61
  end
62
62
 
63
63
  def hostgroup_ids
@@ -209,13 +209,6 @@ module ForemanOpenscap
209
209
 
210
210
  private
211
211
 
212
- def html_error_message(message)
213
- error_message = '<div class="alert alert-danger"><span class="pficon pficon-error-circle-o"></span><strong>' <<
214
- message <<
215
- '</strong></div>'
216
- error_message.html_safe
217
- end
218
-
219
212
  def erase_period_attrs(attrs)
220
213
  attrs.each { |attr| self.public_send("#{attr}=", nil) }
221
214
  end
@@ -301,12 +294,6 @@ module ForemanOpenscap
301
294
  end
302
295
  end
303
296
 
304
- def matching_content_profile
305
- if scap_content_id && scap_content_profile_id && !ScapContent.find(scap_content_id).scap_content_profile_ids.include?(scap_content_profile_id)
306
- errors.add(:scap_content_id, _("does not have the selected SCAP content profile"))
307
- end
308
- end
309
-
310
297
  def assign_policy_to_hostgroups
311
298
  if hostgroups.any?
312
299
  puppetclass = find_scap_puppetclass
@@ -1,6 +1,6 @@
1
1
  module ForemanOpenscap
2
2
  class PolicyArfReport < ::ActiveRecord::Base
3
- belongs_to :arf_report, :dependent => :destroy
3
+ belongs_to :arf_report
4
4
  belongs_to :policy
5
5
 
6
6
  scope :of_policy, lambda { |policy_id| joins(:policy).where(:policy_id => policy_id) }
@@ -1,5 +1,5 @@
1
1
  module ForemanOpenscap
2
- class PolicyRevision < ActiveRecord::Base
2
+ class PolicyRevision < ApplicationRecord
3
3
  belongs_to :policy
4
4
  belongs_to :scap_content
5
5
  end
@@ -1,15 +1,13 @@
1
1
  module ForemanOpenscap
2
- class ScapContent < ActiveRecord::Base
2
+ class ScapContent < ApplicationRecord
3
3
  include Authorizable
4
4
  include Taxonomix
5
5
  include DataStreamContent
6
- audited :except => [ :scap_file ]
7
6
 
8
7
  has_many :scap_content_profiles, :dependent => :destroy
9
8
  has_many :policies
10
9
 
11
10
  validates :title, :presence => true, :length => { :maximum => 255 }
12
- validates :original_filename, :length => { :maximum => 255 }
13
11
 
14
12
  scoped_search :on => :title, :complete_value => true
15
13
  scoped_search :on => :original_filename, :complete_value => true, :rename => :filename
@@ -1,5 +1,5 @@
1
1
  module ForemanOpenscap
2
- class ScapContentProfile < ActiveRecord::Base
2
+ class ScapContentProfile < ApplicationRecord
3
3
  belongs_to :scap_content
4
4
  has_many :policies
5
5
  belongs_to :tailoring_file
@@ -1,9 +1,8 @@
1
1
  module ForemanOpenscap
2
- class TailoringFile < ActiveRecord::Base
2
+ class TailoringFile < ApplicationRecord
3
3
  include Authorizable
4
4
  include Taxonomix
5
5
  include DataStreamContent
6
- audited :except => [ :scap_file ]
7
6
 
8
7
  has_many :policies
9
8
  has_many :scap_content_profiles, :dependent => :destroy
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "hostgroups/_form",
2
+ :name => "choose_openscap_proxy",
3
+ :insert_bottom => "#primary",
4
+ :partial => "compliance_hosts/openscap_proxy")
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "hosts/_form",
2
+ :name => "openscap_proxy",
3
+ :insert_bottom => "#primary",
4
+ :partial => "compliance_hosts/openscap_proxy")
@@ -2,16 +2,8 @@ object @arf_report
2
2
 
3
3
  extends "api/v2/compliance/arf_reports/base"
4
4
 
5
- attributes :created_at, :updated_at, :reported_at
5
+ attributes :created_at, :updated_at, :host_id, :openscap_proxy_id, :reported_at
6
6
 
7
- child :openscap_proxy => :openscap_proxy do
8
- attributes :id, :name
9
- end
10
-
11
- child :host do
12
- attributes :id, :name
13
- end
14
-
15
- child :policy do
16
- attributes :id, :name
7
+ node :openscap_proxy_name do |arf|
8
+ arf.openscap_proxy.name
17
9
  end
@@ -1,3 +1,3 @@
1
1
  child :locations => :locations do |loc|
2
- attributes :id, :name, :title
2
+ attributes :id, :name
3
3
  end
@@ -1,3 +1,3 @@
1
1
  child :organizations => :organizations do |org|
2
- attributes :id, :name, :title
2
+ attributes :id, :name
3
3
  end
@@ -1,7 +1,3 @@
1
1
  object @policy
2
2
 
3
- child :hostgroups => :hostgroups do |hostgroup|
4
- attributes :id, :name, :title
5
- end
6
-
7
3
  extends "api/v2/compliance/policies/main"
@@ -1,12 +1,10 @@
1
1
  <%= javascript "host_checkbox", "foreman_openscap/arf_reports" %>
2
2
 
3
- <table class="table table-bordered table-striped">
3
+ <table class="table table-bordered table-striped ellipsis">
4
4
  <tr>
5
5
  <th class="ca" width="40px"><%= check_box_tag "check_all", "", false, { :onclick => "toggleCheck()", :'check-title' => _("Select all items in this page"), :'uncheck-title'=> _("items selected. Uncheck to Clear") } %></th>
6
6
  <th><%= sort :host %></th>
7
7
  <th><%= sort :reported, :as => _("Reported At") %></th>
8
- <th><%= sort :policy, :as => _("Policy") %></th>
9
- <th><%= sort :openscap_proxy, :as => _("Openscap Proxy") %></th>
10
8
  <th><%= sort :compliance_passed, :as => _("Passed") %></th>
11
9
  <th><%= sort :compliance_failed, :as => _("Failed") %></th>
12
10
  <th><%= sort :compliance_othered, :as => _("Other") %></th>
@@ -23,10 +21,8 @@
23
21
  :class => 'host_select_boxes',
24
22
  :onclick => 'hostChecked(this)' %>
25
23
  </td>
26
- <td class="elipsis"><%= name_column(arf_report.host) %></td>
24
+ <td><%= name_column(arf_report.host) %></td>
27
25
  <td><%= display_link_if_authorized(_("%s ago") % time_ago_in_words(arf_report.reported_at), hash_for_arf_report_path(:id => arf_report.id)) %></td>
28
- <td class="ellipsis"><%= arf_report.policy.present? ? display_link_if_authorized(arf_report.policy.name, hash_for_edit_policy_path(:id => arf_report.policy.id)) : _('Deleted policy') %></th>
29
- <td class="ellipsis"><%= openscap_proxy_link arf_report %></th>
30
26
  <td><%= report_arf_column(arf_report.passed, "label-info") %></th>
31
27
  <td><%= report_arf_column(arf_report.failed, "label-danger") %></th>
32
28
  <td><%= report_arf_column(arf_report.othered, "label-warning") %></th>
@@ -25,5 +25,5 @@
25
25
 
26
26
  <%= form_tag submit_delete_multiple_arf_reports_path({:arf_report_ids => params[:arf_report_ids]}) do %>
27
27
  <span class="label label-danger"><%= _('Delete') %></span>
28
- <%= _('these Compliance reports') %>
28
+ <%= _('these Complianace reports') %>
29
29
  <% end %>
@@ -3,8 +3,7 @@
3
3
  <% stylesheet 'foreman_openscap/reports' %>
4
4
 
5
5
  <% title "#{@arf_report.host}" %>
6
-
7
- <p class='ra'><%= reported_info @arf_report %></p>
6
+ <p class='ra'> <%= _("Reported at %s") % @arf_report.reported_at %> </p>
8
7
 
9
8
  <% content_for(:search_bar) {show_logs} %>
10
9
 
@@ -0,0 +1,3 @@
1
+ <%= select_f f, :openscap_proxy_id, SmartProxy.with_features("Openscap"), :id, :name,
2
+ { :include_blank => blank_or_inherit_f(f, :openscap_proxy) },
3
+ { :label => _('Openscap Proxy') } %>
@@ -36,7 +36,7 @@
36
36
  display_link_if_authorized(_("Show Guide"), hash_for_policy_path(:id => policy.id)),
37
37
  display_link_if_authorized(_("Edit"), hash_for_edit_policy_path(:id => policy.id)),
38
38
  display_delete_if_authorized(hash_for_policy_path(:id => policy.id),
39
- :confirm => _("Delete compliance policy %s with all of its reports?") % policy.name)
39
+ :confirm => _("Delete compliance policy %s with all the reports?") % policy.name)
40
40
  ) %>
41
41
  </td>
42
42
  </tr>
@@ -1,7 +1,7 @@
1
1
  class RemoveDeletedPolicy < ActiveRecord::Migration
2
2
  def up
3
3
  ForemanOpenscap::AssetPolicy.all.collect(&:policy_id).uniq.each do |policy_id|
4
- execute("DELETE FROM foreman_openscap_asset_policies WHERE policy_id = '#{policy_id}';") if ForemanOpenscap::Policy.unscoped.find_by(id: policy_id).nil?
4
+ execute("DELETE FROM foreman_openscap_asset_policies WHERE policy_id = '#{policy_id}';") if ForemanOpenscap::Policy.find_by(id: policy_id).nil?
5
5
  end
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
- N_('Compliance policy summary')
1
+ N_('Openscap policy summary')
2
2
 
3
3
  policy_notification = {
4
- :name => :compliance_policy_summary,
4
+ :name => :openscap_policy_summary,
5
5
  :description => N_('A summary of reports for OpenSCAP policies'),
6
6
  :mailer => 'ForemanOpenscap::PolicyMailer',
7
7
  :method => 'policy_summary',
@@ -42,7 +42,7 @@ module ForemanOpenscap
42
42
 
43
43
  initializer 'foreman_openscap.register_plugin', :before => :finisher_hook do |app|
44
44
  Foreman::Plugin.register :foreman_openscap do
45
- requires_foreman '>= 1.15'
45
+ requires_foreman '>= 1.16'
46
46
 
47
47
  apipie_documented_controllers ["#{ForemanOpenscap::Engine.root}/app/controllers/api/v2/compliance/*.rb"]
48
48
 
@@ -156,18 +156,6 @@ view_openscap_proxies]
156
156
  parameter_filter Hostgroup, :openscap_proxy_id, :openscap_proxy
157
157
  parameter_filter Log, :result
158
158
 
159
- smart_proxy_for Hostgroup, :openscap_proxy,
160
- :feature => 'Openscap',
161
- :label => N_('OpenSCAP Proxy'),
162
- :description => N_('OpenSCAP Proxy to use for fetching SCAP content and uploading ARF reports'),
163
- :api_description => N_('ID of OpenSCAP Proxy')
164
- smart_proxy_for Host::Managed, :openscap_proxy,
165
- :feature => 'Openscap',
166
- :label => N_('OpenSCAP Proxy'),
167
- :description => N_('OpenSCAP Proxy to use for fetching SCAP content and uploading ARF reports'),
168
- :api_description => N_('ID of OpenSCAP Proxy')
169
-
170
-
171
159
  if ForemanOpenscap.with_remote_execution?
172
160
  options = {
173
161
  :description => N_("Run OpenSCAP scan"),
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "0.7.13".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  end
@@ -56,15 +56,6 @@ namespace :foreman_openscap do
56
56
  ForemanOpenscap::MessageCleaner.new.clean
57
57
  puts 'Done'
58
58
  end
59
-
60
- desc "Delete ArfReports without OpenSCAP proxy"
61
- task :clean_reports_without_proxy => :environment do
62
- User.as_anonymous_admin do
63
- report_ids_without_proxy = ForemanOpenscap::ArfReport.unscoped.where(:openscap_proxy => nil).pluck(:id)
64
- total = ForemanOpenscap::ArfReport.delete report_ids_without_proxy
65
- puts "Done cleaning #{total} reports"
66
- end
67
- end
68
59
  end
69
60
 
70
61
  # Tests
@@ -3,8 +3,8 @@ FactoryGirl.define do
3
3
  sequence(:name) { |n| "policy#{n}" }
4
4
  period 'weekly'
5
5
  weekday 'monday'
6
- scap_content { FactoryGirl.create(:scap_content) }
7
- scap_content_profile { FactoryGirl.create(:scap_content_profile, :scap_content => scap_content) }
6
+ scap_content
7
+ scap_content_profile
8
8
  tailoring_file nil
9
9
  tailoring_file_profile nil
10
10
  day_of_month nil
@@ -6,15 +6,17 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
6
6
  # override validation of policy (puppetclass, lookup_key overrides)
7
7
  ForemanOpenscap::Policy.any_instance.stubs(:valid?).returns(true)
8
8
  @host = FactoryGirl.create(:compliance_host)
9
+ @report = FactoryGirl.create(:arf_report,
10
+ :host_id => @host.id,
11
+ :openscap_proxy => FactoryGirl.create(:smart_proxy, :url => "http://smart-proxy.org:8000"))
9
12
  @policy = FactoryGirl.create(:policy)
10
- @asset = FactoryBot.create(:asset, :assetable_id => @host.id)
13
+ @asset = FactoryGirl.create(:asset)
11
14
 
12
15
  @from_json = arf_from_json "#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.json"
13
16
  @cname = '9521a5c5-8f44-495f-b087-20e86b30bf67'
14
17
  end
15
18
 
16
19
  test "should get index" do
17
- create_arf_report
18
20
  get :index, {}, set_session_user
19
21
  response = ActiveSupport::JSON.decode(@response.body)
20
22
  assert_not response['results'].empty?
@@ -22,8 +24,7 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
22
24
  end
23
25
 
24
26
  test "should get show" do
25
- report = create_arf_report
26
- get :show, { :id => report.to_param }, set_session_user
27
+ get :show, { :id => @report.to_param }, set_session_user
27
28
  response = ActiveSupport::JSON.decode(@response.body)
28
29
  refute response['passed'].blank?
29
30
  refute response['failed'].blank?
@@ -32,10 +33,9 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
32
33
  end
33
34
 
34
35
  test "should download report" do
35
- report = create_arf_report
36
36
  bzipped_report = File.read "#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.bz2"
37
37
  ForemanOpenscap::ArfReport.any_instance.stubs(:to_bzip).returns(bzipped_report)
38
- get :download, { :id => report.to_param }, set_session_user
38
+ get :download, { :id => @report.to_param }, set_session_user
39
39
  t = Tempfile.new('tmp_report')
40
40
  t.write @response.body
41
41
  t.close
@@ -60,20 +60,6 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
60
60
  assert_equal msg_count, src_count
61
61
  end
62
62
 
63
- test "should not create report for host without proxy" do
64
- asset = FactoryBot.create(:asset)
65
- date = Time.new(1944, 6, 6)
66
- ForemanOpenscap::Helper.stubs(:get_asset).returns(asset)
67
- post :create,
68
- @from_json.merge(:cname => @cname,
69
- :policy_id => @policy.id,
70
- :date => date.to_i),
71
- set_session_user
72
- assert_response :unprocessable_entity
73
- res = JSON.parse(@response.body)
74
- assert_equal "Failed to upload Arf Report, no OpenSCAP proxy set for host #{asset.host.name}", res["result"]
75
- end
76
-
77
63
  test "should not duplicate messages" do
78
64
  dates = [Time.new(1984, 9, 15), Time.new(1932, 3, 27)]
79
65
  ForemanOpenscap::Helper.stubs(:get_asset).returns(@asset)
@@ -159,10 +145,4 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
159
145
  file_content = File.read path
160
146
  JSON.parse file_content
161
147
  end
162
-
163
- def create_arf_report
164
- FactoryBot.create(:arf_report,
165
- :host_id => @host.id,
166
- :openscap_proxy => FactoryBot.create(:smart_proxy, :url => "http://smart-proxy.org:8000"))
167
- end
168
148
  end
@@ -93,12 +93,4 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
93
93
  assert(@response.header['Content-Type'], 'application/xml')
94
94
  assert_response :success
95
95
  end
96
-
97
- test "should return meaningufull error when no tailioring file assigned" do
98
- policy = FactoryGirl.create(:policy)
99
- get :tailoring, { :id => policy.id }, set_session_user
100
- assert_response :not_found
101
- response = ActiveSupport::JSON.decode(@response.body)
102
- assert_equal "No Tailoring file assigned for policy with id #{policy.id}", response['error']['message']
103
- end
104
96
  end
@@ -6,7 +6,7 @@ class PolicyTest < ActiveSupport::TestCase
6
6
  ForemanOpenscap::DataStreamValidator.any_instance.stubs(:validate)
7
7
  ForemanOpenscap::ScapContent.any_instance.stubs(:fetch_profiles).returns({ 'test_profile_key' => 'test_profile_title' })
8
8
  @scap_content = FactoryGirl.create(:scap_content)
9
- @scap_profile = FactoryGirl.create(:scap_content_profile, :scap_content => @scap_content)
9
+ @scap_profile = FactoryGirl.create(:scap_content_profile)
10
10
  @tailoring_profile = FactoryGirl.create(:scap_content_profile, :profile_id => 'xccdf_org.test.tailoring_test_profile')
11
11
  end
12
12
 
@@ -16,7 +16,7 @@ class PolicyTest < ActiveSupport::TestCase
16
16
  hg1 = FactoryGirl.create(:hostgroup)
17
17
  hg2 = FactoryGirl.create(:hostgroup)
18
18
  asset = FactoryGirl.create(:asset, :assetable_id => hg1.id, :assetable_type => 'Hostgroup')
19
- policy = FactoryGirl.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
19
+ policy = FactoryGirl.create(:policy, :assets => [asset])
20
20
  policy.hostgroup_ids = [hg1, hg2].map(&:id)
21
21
  policy.save!
22
22
  assert_equal 2, policy.hostgroups.count
@@ -28,7 +28,7 @@ class PolicyTest < ActiveSupport::TestCase
28
28
  ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
29
29
  hg = FactoryGirl.create(:hostgroup)
30
30
  asset = FactoryGirl.create(:asset, :assetable_id => hg.id, :assetable_type => 'Hostgroup')
31
- policy = FactoryGirl.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
31
+ policy = FactoryGirl.create(:policy, :assets => [asset])
32
32
  policy.save!
33
33
  hg.hostgroup_classes.destroy_all
34
34
  hg.destroy
@@ -135,16 +135,17 @@ class PolicyTest < ActiveSupport::TestCase
135
135
  assert p.errors[:scap_content_id].include?("can't be blank")
136
136
  end
137
137
 
138
- test "should create a policy with default SCAP content profile (profile id is nil)" do
138
+ test "should not create policy without SCAP content profile" do
139
139
  p = ForemanOpenscap::Policy.new(:name => "custom_policy",
140
140
  :scap_content_id => @scap_content.id,
141
141
  :period => 'monthly',
142
142
  :day_of_month => '5')
143
- assert p.save
143
+ refute p.save
144
+ assert p.errors[:scap_content_profile_id].include?("can't be blank")
144
145
  end
145
146
 
146
147
  test "should have correct scap profile in enc" do
147
- p = FactoryGirl.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
148
+ p = FactoryGirl.create(:policy)
148
149
  profile_id = p.scap_content_profile.profile_id
149
150
  assert_equal profile_id, p.to_enc['profile_id']
150
151
  tailoring_profile = FactoryGirl.create(:scap_content_profile, :profile_id => 'xccdf_org.test.tailoring_test_profile')
@@ -189,31 +190,4 @@ class PolicyTest < ActiveSupport::TestCase
189
190
  assert_equal 6, p.to_enc['tailoring_download_path'].split('/').length
190
191
  assert_equal tailoring_file.digest, p.to_enc['tailoring_download_path'].split('/').last
191
192
  end
192
-
193
- test "should have assigned a content profile that belongs to assigned scap content" do
194
- scap_content_2 = FactoryGirl.create(:scap_content)
195
- p = ForemanOpenscap::Policy.create(:name => "valid_profile_policy",
196
- :scap_content_id => @scap_content.id,
197
- :scap_content_profile_id => @scap_profile.id,
198
- :period => 'monthly',
199
- :day_of_month => '5')
200
- assert p.valid?
201
- q = ForemanOpenscap::Policy.create(:name => "invalid_profile_policy",
202
- :scap_content_id => scap_content_2.id,
203
- :scap_content_profile_id => @scap_profile.id,
204
- :period => 'monthly',
205
- :day_of_month => '5')
206
- refute q.valid?
207
- assert_equal "does not have the selected SCAP content profile", q.errors.messages[:scap_content_id].first
208
- end
209
-
210
- test "should delete arf_report when deleting policy" do
211
- policy = FactoryGirl.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
212
- host = FactoryGirl.create(:compliance_host)
213
- arf_report = FactoryGirl.create(:arf_report, :host_id => host.id)
214
- policy_arf_report = FactoryGirl.create(:policy_arf_report, :policy_id => policy.id, :arf_report_id => arf_report.id)
215
- policy.destroy
216
- assert_empty ForemanOpenscap::PolicyArfReport.where(:id => policy_arf_report.id)
217
- assert_empty ForemanOpenscap::ArfReport.where(:id => arf_report.id)
218
- end
219
193
  end
@@ -32,19 +32,4 @@ class ScapContentTest < ActiveSupport::TestCase
32
32
  assert_equal(available_proxy.url, scap_content.proxy_url)
33
33
  end
34
34
  end
35
-
36
- test 'should update profile title when fetching profiles from proxy' do
37
- scap_content = FactoryGirl.create(:scap_content)
38
- scap_content.stubs(:fetch_profiles).returns({ "xccdf.test.profile" => "Changed title" })
39
- scap_profile = FactoryGirl.create(:scap_content_profile, :scap_content => scap_content, :profile_id => 'xccdf.test.profile', :title => "Original title")
40
- scap_content.create_profiles
41
- assert_equal scap_profile.reload.title, 'Changed title'
42
- end
43
-
44
- test 'should create profile when fetching profiles from proxy' do
45
- scap_content = FactoryGirl.create(:scap_content)
46
- scap_content.stubs(:fetch_profiles).returns({ "xccdf.test.profile" => "My title" })
47
- scap_content.create_profiles
48
- assert scap_content.reload.scap_content_profiles.where(:title => 'My title').first
49
- end
50
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.13
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-13 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -91,6 +91,8 @@ files:
91
91
  - app/models/foreman_openscap/scap_content.rb
92
92
  - app/models/foreman_openscap/scap_content_profile.rb
93
93
  - app/models/foreman_openscap/tailoring_file.rb
94
+ - app/overrides/hostgroups/form/select_openscap_proxy.rb
95
+ - app/overrides/hosts/form/select_openscap_proxy.rb
94
96
  - app/overrides/hosts/overview/host_compliance_status.rb
95
97
  - app/services/foreman_openscap/arf_report_status_calculator.rb
96
98
  - app/services/foreman_openscap/host_report_dashboard/data.rb
@@ -111,11 +113,9 @@ files:
111
113
  - app/views/api/v2/compliance/policies/main.json.rabl
112
114
  - app/views/api/v2/compliance/policies/show.json.rabl
113
115
  - app/views/api/v2/compliance/scap_contents/base.json.rabl
114
- - app/views/api/v2/compliance/scap_contents/create.json.rabl
115
116
  - app/views/api/v2/compliance/scap_contents/index.json.rabl
116
117
  - app/views/api/v2/compliance/scap_contents/main.json.rabl
117
118
  - app/views/api/v2/compliance/scap_contents/show.json.rabl
118
- - app/views/api/v2/compliance/scap_contents/update.json.rabl
119
119
  - app/views/api/v2/compliance/tailoring_files/base.json.rabl
120
120
  - app/views/api/v2/compliance/tailoring_files/index.json.rabl
121
121
  - app/views/api/v2/compliance/tailoring_files/main.json.rabl
@@ -129,6 +129,7 @@ files:
129
129
  - app/views/arf_reports/show.html.erb
130
130
  - app/views/arf_reports/show_html.html.erb
131
131
  - app/views/compliance_hosts/_compliance_status.erb
132
+ - app/views/compliance_hosts/_openscap_proxy.html.erb
132
133
  - app/views/compliance_hosts/show.html.erb
133
134
  - app/views/dashboard/_compliance_host_reports_widget.html.erb
134
135
  - app/views/dashboard/_compliance_reports_breakdown_widget.html.erb
@@ -215,9 +216,6 @@ files:
215
216
  - db/migrate/20160925213031_change_scap_widget_names.rb
216
217
  - db/migrate/20161109155255_create_tailoring_files.rb
217
218
  - db/migrate/20161223153249_add_permissions_to_arf_report.rb
218
- - db/migrate/20170821081205_rename_mail_notification.foreman_openscap.rb
219
- - db/migrate/20170830221751_add_index_to_logs_result.rb
220
- - db/migrate/20171011134112_remove_arf_reports_without_policy.rb
221
219
  - db/seeds.d/75-job_templates.rb
222
220
  - db/seeds.d/openscap_feature.rb
223
221
  - db/seeds.d/openscap_policy_notification.rb
@@ -315,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
313
  version: '0'
316
314
  requirements: []
317
315
  rubyforge_project:
318
- rubygems_version: 2.6.8
316
+ rubygems_version: 2.4.5
319
317
  signing_key:
320
318
  specification_version: 4
321
319
  summary: Foreman plug-in for displaying OpenSCAP audit reports
@@ -1,3 +0,0 @@
1
- object @scap_content
2
-
3
- extends "api/v2/compliance/scap_contents/main"
@@ -1,3 +0,0 @@
1
- object @scap_content
2
-
3
- extends "api/v2/compliance/scap_contents/main"
@@ -1,15 +0,0 @@
1
- class RenameMailNotification < ActiveRecord::Migration
2
- def up
3
- notification = MailNotification.where(:name => 'openscap_policy_summary').first
4
- if notification
5
- notification.update_attribute :name, 'compliance_policy_summary'
6
- end
7
- end
8
-
9
- def down
10
- notification = MailNotification.where(:name => 'compliance_policy_summary').first
11
- if notification
12
- notification.update_attribute :name, 'openscap_policy_summary'
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- class AddIndexToLogsResult < ActiveRecord::Migration
2
- def up
3
- add_index :logs, :result
4
- end
5
-
6
- def down
7
- remove_index :logs, :result
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- class RemoveArfReportsWithoutPolicy < ActiveRecord::Migration
2
- def up
3
- if User.unscoped.find_by(:login => User::ANONYMOUS_ADMIN)
4
- User.as_anonymous_admin do
5
- delete_reports
6
- end
7
- else
8
- delete_reports
9
- end
10
- end
11
-
12
- def delete_reports
13
- ids_to_keep = ForemanOpenscap::ArfReport.unscoped.all.joins(:policy_arf_report).pluck(:id)
14
- ForemanOpenscap::ArfReport.unscoped.where.not(:id => ids_to_keep).find_in_batches do |batch|
15
- batch.map(&:destroy!)
16
- end
17
- end
18
- end