diff --git a/db/migrate/20201217161511_add_url_to_oval_content.rb b/db/migrate/20201217161511_add_url_to_oval_content.rb index 7ce6a0e2..642d3612 100644 --- a/db/migrate/20201217161511_add_url_to_oval_content.rb +++ b/db/migrate/20201217161511_add_url_to_oval_content.rb @@ -1,4 +1,4 @@ -class AddUrlToOvalContent < ActiveRecord::Migration[6.0] +class AddURLToOvalContent < ActiveRecord::Migration[6.0] def change add_column :foreman_openscap_oval_contents, :url, :string end diff --git a/lib/foreman_openscap/engine.rb b/lib/foreman_openscap/engine.rb index 1ef0a7ab..318f72d1 100644 --- a/lib/foreman_openscap/engine.rb +++ b/lib/foreman_openscap/engine.rb @@ -5,15 +5,6 @@ def self.with_katello? class Engine < ::Rails::Engine engine_name 'foreman_openscap' - config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"] - config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"] - config.autoload_paths += Dir["#{config.root}/app/models/concerns"] - config.autoload_paths += Dir["#{config.root}/app/models"] - config.autoload_paths += Dir["#{config.root}/app/graphql"] - config.autoload_paths += Dir["#{config.root}/app/lib"] - config.autoload_paths += Dir["#{config.root}/app/services"] - config.autoload_paths += Dir["#{config.root}/lib"] - config.autoload_paths += Dir["#{config.root}/test/"] # Add any db migrations initializer "foreman_openscap.load_app_instance_data" do |app| @@ -47,154 +38,156 @@ class Engine < ::Rails::Engine end initializer 'foreman_openscap.register_plugin', :before => :finisher_hook do |app| - Foreman::Plugin.register :foreman_openscap do - requires_foreman '>= 3.11' - register_gettext - - apipie_documented_controllers ["#{ForemanOpenscap::Engine.root}/app/controllers/api/v2/compliance/*.rb"] - - register_custom_status ForemanOpenscap::ComplianceStatus - - # Add permissions - security_block :foreman_openscap do - permission :view_arf_reports, { :arf_reports => %i[index show parse_html show_html show_log - parse_bzip auto_complete_search download_html], - 'api/v2/compliance/arf_reports' => %i[index show download download_html], - :compliance_hosts => [:show] }, - :resource_type => 'ForemanOpenscap::ArfReport' - permission :destroy_arf_reports, { :arf_reports => %i[destroy delete_multiple submit_delete_multiple], - 'api/v2/compliance/arf_reports' => [:destroy] }, - :resource_type => 'ForemanOpenscap::ArfReport' - permission :create_arf_reports, { 'api/v2/compliance/arf_reports' => [:create] }, - :resource_type => 'ForemanOpenscap::ArfReport' - - permission :view_policies, { :policies => %i[index show parse auto_complete_search], - :policy_dashboard => [:index], - :compliance_dashboard => [:index], - 'api/v2/compliance/policies' => %i[index show content] }, - :resource_type => 'ForemanOpenscap::Policy' - permission :edit_policies, { :policies => %i[edit update scap_content_selected], - 'api/v2/compliance/policies' => [:update] }, - :resource_type => 'ForemanOpenscap::Policy' - permission :create_policies, { :policies => %i[new create], - 'api/v2/compliance/policies' => [:create] }, - :resource_type => 'ForemanOpenscap::Policy' - permission :destroy_policies, { :policies => [:destroy], - 'api/v2/compliance/policies' => [:destroy] }, - :resource_type => 'ForemanOpenscap::Policy' - permission :assign_policies, { :policies => %i[select_multiple_hosts update_multiple_hosts - disassociate_multiple_hosts - remove_policy_from_multiple_hosts] }, - :resource_type => 'ForemanOpenscap::Policy' - permission :view_scap_contents, { :scap_contents => %i[index show auto_complete_search], - 'api/v2/compliance/scap_contents' => %i[index show xml], - 'api/v2/compliance/scap_content_profiles' => %i[index] }, - :resource_type => 'ForemanOpenscap::ScapContent' - permission :edit_scap_contents, { :scap_contents => %i[edit update], - 'api/v2/compliance/scap_contents' => [:update] }, - :resource_type => 'ForemanOpenscap::ScapContent' - permission :create_scap_contents, { :scap_contents => %i[new create], - 'api/v2/compliance/scap_contents' => %i[create bulk_upload] }, - :resource_type => 'ForemanOpenscap::ScapContent' - permission :destroy_scap_contents, { :scap_contents => [:destroy], - 'api/v2/compliance/scap_contents' => [:destroy] }, - :resource_type => 'ForemanOpenscap::ScapContent' - permission :edit_hosts, { :hosts => %i[openscap_proxy_changed - select_multiple_openscap_proxy - update_multiple_openscap_proxy] }, - :resource_type => "Host" - permission :view_hosts, { 'api/v2/hosts' => [:policies_enc] }, :resource_type => 'Host' - permission :edit_hostgroups, { :hostgroups => [:openscap_proxy_changed] }, :resource_type => "Hostgroup" - permission :create_tailoring_files, { :tailoring_files => %i[create new], - 'api/v2/compliance/tailoring_files' => [:create] }, - :resource_type => 'ForemanOpenscap::TailoringFile' - permission :view_tailoring_files, { :tailoring_files => %i[index auto_complete_search xml], - :policies => [:tailoring_file_selected], - 'api/v2/compliance/tailoring_files' => %i[show xml index], - 'api/v2/compliance/policies' => [:tailoring], + app.reloader.to_prepare do + Foreman::Plugin.register :foreman_openscap do + requires_foreman '>= 3.13' + register_gettext + + apipie_documented_controllers ["#{ForemanOpenscap::Engine.root}/app/controllers/api/v2/compliance/*.rb"] + + register_custom_status ForemanOpenscap::ComplianceStatus + + # Add permissions + security_block :foreman_openscap do + permission :view_arf_reports, { :arf_reports => %i[index show parse_html show_html show_log + parse_bzip auto_complete_search download_html], + 'api/v2/compliance/arf_reports' => %i[index show download download_html], + :compliance_hosts => [:show] }, + :resource_type => 'ForemanOpenscap::ArfReport' + permission :destroy_arf_reports, { :arf_reports => %i[destroy delete_multiple submit_delete_multiple], + 'api/v2/compliance/arf_reports' => [:destroy] }, + :resource_type => 'ForemanOpenscap::ArfReport' + permission :create_arf_reports, { 'api/v2/compliance/arf_reports' => [:create] }, + :resource_type => 'ForemanOpenscap::ArfReport' + + permission :view_policies, { :policies => %i[index show parse auto_complete_search], + :policy_dashboard => [:index], + :compliance_dashboard => [:index], + 'api/v2/compliance/policies' => %i[index show content] }, + :resource_type => 'ForemanOpenscap::Policy' + permission :edit_policies, { :policies => %i[edit update scap_content_selected], + 'api/v2/compliance/policies' => [:update] }, + :resource_type => 'ForemanOpenscap::Policy' + permission :create_policies, { :policies => %i[new create], + 'api/v2/compliance/policies' => [:create] }, + :resource_type => 'ForemanOpenscap::Policy' + permission :destroy_policies, { :policies => [:destroy], + 'api/v2/compliance/policies' => [:destroy] }, + :resource_type => 'ForemanOpenscap::Policy' + permission :assign_policies, { :policies => %i[select_multiple_hosts update_multiple_hosts + disassociate_multiple_hosts + remove_policy_from_multiple_hosts] }, + :resource_type => 'ForemanOpenscap::Policy' + permission :view_scap_contents, { :scap_contents => %i[index show auto_complete_search], + 'api/v2/compliance/scap_contents' => %i[index show xml], 'api/v2/compliance/scap_content_profiles' => %i[index] }, - :resource_type => 'ForemanOpenscap::TailoringFile' - permission :edit_tailoring_files, { :tailoring_files => %i[edit update], - 'api/v2/compliance/tailoring_files' => [:update] }, - :resource_type => 'ForemanOpenscap::TailoringFile' - permission :destroy_tailoring_files, { :tailoring_files => [:destroy], - 'api/v2/compliance/tailoring_files' => [:destroy] }, - :resource_type => 'ForemanOpenscap::TailoringFile' - permission :view_openscap_proxies, { :openscap_proxies => [:openscap_spool] }, - :resource_type => 'SmartProxy' - end - - role "Compliance viewer", %i[view_arf_reports view_policies view_scap_contents view_tailoring_files view_openscap_proxies], - "Role granting read permissions to policy configuration, scan results and downloading reports." - role "Compliance manager", %i[view_arf_reports view_policies view_scap_contents - destroy_arf_reports edit_policies edit_scap_contents assign_policies - create_policies create_scap_contents destroy_policies destroy_scap_contents - create_tailoring_files view_tailoring_files edit_tailoring_files destroy_tailoring_files - view_openscap_proxies], - "Role granting all permissions to compliance features to non-admin users." - role "Create ARF report", [:create_arf_reports] # special as only Proxy can create - - add_all_permissions_to_default_roles - - # add menu entries - divider :top_menu, :caption => N_('Compliance'), :parent => :hosts_menu - menu :top_menu, :compliance_policies, :caption => N_('Policies'), - :url_hash => { :controller => :policies, :action => :index }, + :resource_type => 'ForemanOpenscap::ScapContent' + permission :edit_scap_contents, { :scap_contents => %i[edit update], + 'api/v2/compliance/scap_contents' => [:update] }, + :resource_type => 'ForemanOpenscap::ScapContent' + permission :create_scap_contents, { :scap_contents => %i[new create], + 'api/v2/compliance/scap_contents' => %i[create bulk_upload] }, + :resource_type => 'ForemanOpenscap::ScapContent' + permission :destroy_scap_contents, { :scap_contents => [:destroy], + 'api/v2/compliance/scap_contents' => [:destroy] }, + :resource_type => 'ForemanOpenscap::ScapContent' + permission :edit_hosts, { :hosts => %i[openscap_proxy_changed + select_multiple_openscap_proxy + update_multiple_openscap_proxy] }, + :resource_type => "Host" + permission :view_hosts, { 'api/v2/hosts' => [:policies_enc] }, :resource_type => 'Host' + permission :edit_hostgroups, { :hostgroups => [:openscap_proxy_changed] }, :resource_type => "Hostgroup" + permission :create_tailoring_files, { :tailoring_files => %i[create new], + 'api/v2/compliance/tailoring_files' => [:create] }, + :resource_type => 'ForemanOpenscap::TailoringFile' + permission :view_tailoring_files, { :tailoring_files => %i[index auto_complete_search xml], + :policies => [:tailoring_file_selected], + 'api/v2/compliance/tailoring_files' => %i[show xml index], + 'api/v2/compliance/policies' => [:tailoring], + 'api/v2/compliance/scap_content_profiles' => %i[index] }, + :resource_type => 'ForemanOpenscap::TailoringFile' + permission :edit_tailoring_files, { :tailoring_files => %i[edit update], + 'api/v2/compliance/tailoring_files' => [:update] }, + :resource_type => 'ForemanOpenscap::TailoringFile' + permission :destroy_tailoring_files, { :tailoring_files => [:destroy], + 'api/v2/compliance/tailoring_files' => [:destroy] }, + :resource_type => 'ForemanOpenscap::TailoringFile' + permission :view_openscap_proxies, { :openscap_proxies => [:openscap_spool] }, + :resource_type => 'SmartProxy' + end + + role "Compliance viewer", %i[view_arf_reports view_policies view_scap_contents view_tailoring_files view_openscap_proxies], + "Role granting read permissions to policy configuration, scan results and downloading reports." + role "Compliance manager", %i[view_arf_reports view_policies view_scap_contents + destroy_arf_reports edit_policies edit_scap_contents assign_policies + create_policies create_scap_contents destroy_policies destroy_scap_contents + create_tailoring_files view_tailoring_files edit_tailoring_files destroy_tailoring_files + view_openscap_proxies], + "Role granting all permissions to compliance features to non-admin users." + role "Create ARF report", [:create_arf_reports] # special as only Proxy can create + + add_all_permissions_to_default_roles + + # add menu entries + divider :top_menu, :caption => N_('Compliance'), :parent => :hosts_menu + menu :top_menu, :compliance_policies, :caption => N_('Policies'), + :url_hash => { :controller => :policies, :action => :index }, + :parent => :hosts_menu + menu :top_menu, :compliance_contents, :caption => N_('SCAP contents'), + :url_hash => { :controller => :scap_contents, :action => :index }, + :parent => :hosts_menu + menu :top_menu, :compliance_reports, :caption => N_('Reports'), + :url_hash => { :controller => :arf_reports, :action => :index }, :parent => :hosts_menu - menu :top_menu, :compliance_contents, :caption => N_('SCAP contents'), - :url_hash => { :controller => :scap_contents, :action => :index }, - :parent => :hosts_menu - menu :top_menu, :compliance_reports, :caption => N_('Reports'), - :url_hash => { :controller => :arf_reports, :action => :index }, - :parent => :hosts_menu - menu :top_menu, :compliance_files, :caption => N_('Tailoring Files'), - :url_hash => { :controller => :tailoring_files, :action => :index }, - :parent => :hosts_menu - - # add dashboard widget - widget 'compliance_host_reports_widget', - :name => N_('Latest Compliance Reports'), :sizex => 6, :sizey => 1 - widget 'compliance_reports_breakdown_widget', - :name => N_('Compliance Reports Breakdown'), :sizex => 4, :sizey => 1 - - # As 'arf_report_breakdowns' is a view and does not appear in schema.rb, db:test:prepare will not create the view - # which will make the following tests fail. - tests_to_skip({ "DashboardIntegrationTest" => ["dashboard page", "dashboard link hosts that had performed modifications", - "dashboard link hosts in error state", "dashboard link good host reports", - "dashboard link hosts that had pending changes", "dashboard link out of sync hosts", - "dashboard link hosts with no reports", "dashboard link hosts with alerts disabled", - "widgets not in dashboard show up in list"] }) - # strong params - parameter_filter ::Host::Managed, :openscap_proxy_id, :openscap_proxy - parameter_filter ::Hostgroup, :openscap_proxy_id, :openscap_proxy - parameter_filter Log, :result - - proxy_description = N_('OpenSCAP Proxy to use for fetching SCAP content and uploading ARF reports. Leave blank and override appropriate parameters when using proxy load balancer.') - - smart_proxy_for ::Hostgroup, :openscap_proxy, - :feature => 'Openscap', - :label => N_('OpenSCAP Proxy'), - :description => proxy_description, - :api_description => N_('ID of OpenSCAP Proxy') - smart_proxy_for Host::Managed, :openscap_proxy, - :feature => 'Openscap', - :label => N_('OpenSCAP Proxy'), - :description => proxy_description, - :api_description => N_('ID of OpenSCAP Proxy') - - add_controller_action_scope('Api::V2::HostsController', :index) do |base_scope| - base_scope.preload(:policies) - end - - add_controller_action_scope('HostsController', :index) do |base_scope| - base_scope.preload(:policies) - end - - register_global_js_file 'global' - - describe_host do - multiple_actions_provider :compliance_host_multiple_actions - overview_buttons_provider :compliance_host_overview_button + menu :top_menu, :compliance_files, :caption => N_('Tailoring Files'), + :url_hash => { :controller => :tailoring_files, :action => :index }, + :parent => :hosts_menu + + # add dashboard widget + widget 'compliance_host_reports_widget', + :name => N_('Latest Compliance Reports'), :sizex => 6, :sizey => 1 + widget 'compliance_reports_breakdown_widget', + :name => N_('Compliance Reports Breakdown'), :sizex => 4, :sizey => 1 + + # As 'arf_report_breakdowns' is a view and does not appear in schema.rb, db:test:prepare will not create the view + # which will make the following tests fail. + tests_to_skip({ "DashboardIntegrationTest" => ["dashboard page", "dashboard link hosts that had performed modifications", + "dashboard link hosts in error state", "dashboard link good host reports", + "dashboard link hosts that had pending changes", "dashboard link out of sync hosts", + "dashboard link hosts with no reports", "dashboard link hosts with alerts disabled", + "widgets not in dashboard show up in list"] }) + # strong params + parameter_filter ::Host::Managed, :openscap_proxy_id, :openscap_proxy + parameter_filter ::Hostgroup, :openscap_proxy_id, :openscap_proxy + parameter_filter Log, :result + + proxy_description = N_('OpenSCAP Proxy to use for fetching SCAP content and uploading ARF reports. Leave blank and override appropriate parameters when using proxy load balancer.') + + smart_proxy_for ::Hostgroup, :openscap_proxy, + :feature => 'Openscap', + :label => N_('OpenSCAP Proxy'), + :description => proxy_description, + :api_description => N_('ID of OpenSCAP Proxy') + smart_proxy_for Host::Managed, :openscap_proxy, + :feature => 'Openscap', + :label => N_('OpenSCAP Proxy'), + :description => proxy_description, + :api_description => N_('ID of OpenSCAP Proxy') + + add_controller_action_scope('Api::V2::HostsController', :index) do |base_scope| + base_scope.preload(:policies) + end + + add_controller_action_scope('HostsController', :index) do |base_scope| + base_scope.preload(:policies) + end + + register_global_js_file 'global' + + describe_host do + multiple_actions_provider :compliance_host_multiple_actions + overview_buttons_provider :compliance_host_overview_button + end end end end diff --git a/test/unit/message_cleaner_test.rb b/test/unit/message_cleaner_test.rb index 6a0ecde8..297bd845 100644 --- a/test/unit/message_cleaner_test.rb +++ b/test/unit/message_cleaner_test.rb @@ -1,4 +1,5 @@ require 'test_plugin_helper' +require 'foreman_openscap/message_cleaner' class MessageCleanerTest < ActiveSupport::TestCase setup do