foreman_openscap 4.3.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/compliance/arf_reports_controller.rb +0 -6
  3. data/app/controllers/api/v2/compliance/oval_policies_controller.rb +1 -1
  4. data/app/helpers/arf_report_dashboard_helper.rb +2 -4
  5. data/app/helpers/compliance_hosts_helper.rb +1 -1
  6. data/app/helpers/policies_helper.rb +1 -1
  7. data/app/services/foreman_openscap/client_config/base.rb +1 -0
  8. data/app/services/foreman_openscap/client_config/puppet.rb +6 -2
  9. data/app/views/api/v2/compliance/oval_contents/destroy.json.rabl +3 -0
  10. data/app/views/arf_reports/_metrics.html.erb +4 -4
  11. data/app/views/compliance_hosts/show.html.erb +4 -6
  12. data/app/views/dashboard/_compliance_reports_breakdown_widget.html.erb +4 -3
  13. data/app/views/policy_dashboard/_policy_chart_widget.html.erb +3 -2
  14. data/db/migrate/20200117135424_migrate_port_overrides_to_int.rb +2 -1
  15. data/db/migrate/20201202110213_update_puppet_port_param_type.rb +2 -1
  16. data/lib/foreman_openscap/engine.rb +0 -7
  17. data/lib/foreman_openscap/version.rb +1 -1
  18. data/package.json +48 -0
  19. data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +1 -1
  20. data/test/functional/api/v2/compliance/policies_controller_test.rb +2 -0
  21. data/test/helpers/arf_report_dashboard_helper_test.rb +9 -10
  22. data/test/helpers/policy_dashboard_helper_test.rb +1 -1
  23. data/test/test_plugin_helper.rb +9 -4
  24. data/test/unit/policy_test.rb +1 -1
  25. data/test/unit/services/config_name_service_test.rb +1 -0
  26. data/test/unit/services/hostgroup_overrider_test.rb +2 -1
  27. data/test/unit/services/lookup_key_overrider_test.rb +4 -1
  28. data/webpack/components/EmptyState.js +73 -0
  29. data/webpack/components/IndexLayout.js +35 -0
  30. data/webpack/components/IndexLayout.scss +3 -0
  31. data/webpack/components/IndexTable/IndexTableHelper.js +9 -0
  32. data/webpack/components/IndexTable/index.js +65 -0
  33. data/webpack/components/RuleSeverity/RuleSeverity.scss +3 -0
  34. data/webpack/components/RuleSeverity/RuleSeverity.test.js +13 -0
  35. data/webpack/components/RuleSeverity/__snapshots__/RuleSeverity.test.js.snap +41 -0
  36. data/webpack/components/RuleSeverity/i_severity-critical.svg +61 -0
  37. data/webpack/components/RuleSeverity/i_severity-high.svg +61 -0
  38. data/webpack/components/RuleSeverity/i_severity-low.svg +62 -0
  39. data/webpack/components/RuleSeverity/i_severity-med.svg +62 -0
  40. data/webpack/components/RuleSeverity/i_unknown.svg +33 -0
  41. data/webpack/components/RuleSeverity/index.js +33 -0
  42. data/webpack/components/withLoading.js +87 -0
  43. data/webpack/global_index.js +5 -0
  44. data/webpack/graphql/queries/currentUserAttributes.gql +11 -0
  45. data/webpack/graphql/queries/cves.gql +23 -0
  46. data/webpack/graphql/queries/ovalContents.gql +16 -0
  47. data/webpack/graphql/queries/ovalPolicies.gql +17 -0
  48. data/webpack/graphql/queries/ovalPolicy.gql +26 -0
  49. data/webpack/helpers/commonHelper.js +1 -0
  50. data/webpack/helpers/globalIdHelper.js +13 -0
  51. data/webpack/helpers/pageParamsHelper.js +31 -0
  52. data/webpack/helpers/pathsHelper.js +22 -0
  53. data/webpack/helpers/permissionsHelper.js +42 -0
  54. data/webpack/helpers/tableHelper.js +9 -0
  55. data/webpack/index.js +8 -0
  56. data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsIndex.js +46 -0
  57. data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsTable.js +46 -0
  58. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.fixtures.js +120 -0
  59. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.test.js +101 -0
  60. data/webpack/routes/OvalContents/OvalContentsIndex/index.js +7 -0
  61. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesIndex.js +47 -0
  62. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesTable.js +44 -0
  63. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.fixtures.js +95 -0
  64. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.test.js +98 -0
  65. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/index.js +7 -0
  66. data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTab.js +49 -0
  67. data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTable.js +63 -0
  68. data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShow.js +78 -0
  69. data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShowHelper.js +39 -0
  70. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.fixtures.js +87 -0
  71. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.test.js +129 -0
  72. data/webpack/routes/OvalPolicies/OvalPoliciesShow/index.js +36 -0
  73. data/webpack/routes/routes.js +28 -0
  74. data/webpack/testHelper.js +96 -0
  75. metadata +56 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bc31c3bac07804311899dc01dd5dbe0c0500cc8981eefa1ec867316d0465fb8
4
- data.tar.gz: 4b00712959d937f44fa2da29de505704e153277043bf319c84fa0d4a44f8d5ac
3
+ metadata.gz: 534b669988c89b1335565f67c02b63443b0cfd36636749397b50617c4797316b
4
+ data.tar.gz: 4ee455ef101cc0bb6b034f1b081e2d604848620e7438e3ae887493ee77d13015
5
5
  SHA512:
6
- metadata.gz: 90f233717d65a7bf4d1793251a27d6f7268e81a93e4dd06b86258e8f6f5b108d0a886fe8ebe455766eccfe10a55076d9b61bd211165620f5d899cd94147d203c
7
- data.tar.gz: b77f05c002ef0fb3fdcc4050974bc5b4390d2af5322aac601ef912172391e0bfb3f391e4166ad94b7e701156e9b84f640dcda03d434323d5e2921e50974f6109
6
+ metadata.gz: b2ddaa5f34a78a9f085f5564f7e12f28071baf8b1679e645c327bb6d229986f0b399ae9a3bf50078e7d4c536014b43df974125851277ff1584130918b93382a2
7
+ data.tar.gz: 6a115b58c74b88f4c9e4f81ab5c31a0db2195a285d2c2eb4612251aead4131a426b34aab2593b7e8b6e2b656fee92cae0adc1b3d5bd19787466514e35312fd70
@@ -140,12 +140,6 @@ module Api
140
140
  super
141
141
  end
142
142
  end
143
-
144
- protected
145
-
146
- def assign_lone_taxonomies
147
- # do not assign lone taxonomies to arf report
148
- end
149
143
  end
150
144
  end
151
145
  end
@@ -75,7 +75,7 @@ module Api::V2
75
75
  assign _('hosts'), params["host_ids"], ::Host::Managed
76
76
  end
77
77
 
78
- api :GET, '/compliance/oval_policies/:id/oval_content', N_("Show a policy's SCAP content")
78
+ api :GET, '/compliance/oval_policies/:id/oval_content', N_("Show a policy's OVAL content")
79
79
  param :id, :identifier, :required => true
80
80
 
81
81
  def oval_content
@@ -6,11 +6,9 @@ module ArfReportDashboardHelper
6
6
  }.freeze
7
7
 
8
8
  def breakdown_chart_data(categories, report, colors = COLORS)
9
- data = categories.reduce([]) do |memo, (key, value)|
9
+ categories.reduce([]) do |memo, (key, value)|
10
10
  memo << [value, report[key], colors[key]]
11
11
  end
12
-
13
- data.to_json
14
12
  end
15
13
 
16
14
  def donut_breakdown_chart_data(report)
@@ -27,6 +25,6 @@ module ArfReportDashboardHelper
27
25
  :data => status.to_a,
28
26
  :yAxisLabel => _("Number of Events"),
29
27
  :xAxisLabel => _("Rule Results"),
30
- }.to_json
28
+ }
31
29
  end
32
30
  end
@@ -16,7 +16,7 @@ module ComplianceHostsHelper
16
16
  [_("Othered"), othered, ArfReportDashboardHelper::COLORS[:othered]],
17
17
  ['dates', date, nil]
18
18
  ]
19
- { :data => data, :xAxisDataLabel => 'dates', :config => 'timeseries' }.to_json
19
+ { :data => data, :xAxisDataLabel => 'dates', :config => 'timeseries' }
20
20
  end
21
21
 
22
22
  def compliance_host_multiple_actions
@@ -41,7 +41,7 @@ module PoliciesHelper
41
41
  end
42
42
 
43
43
  def deploy_by_radio_checked(policy, tool)
44
- type = policy.deploy_by ? policy.deploy_by.to_sym : :puppet
44
+ type = policy.deploy_by ? policy.deploy_by.to_sym : :manual
45
45
  tool.type == type
46
46
  end
47
47
 
@@ -38,6 +38,7 @@ module ForemanOpenscap
38
38
  end
39
39
 
40
40
  def find_config_item(scope = config_item_class_name.constantize)
41
+ return unless scope
41
42
  return scope.find_by :name => config_item_name if scope.respond_to?(:find_by)
42
43
  # all_puppetclasses, all_ansible_roles methods return Array, not ActiveRecord::Relation
43
44
  scope.find { |item| item.name == config_item_name }
@@ -10,7 +10,7 @@ module ForemanOpenscap
10
10
  end
11
11
 
12
12
  def available?
13
- defined?(Puppetclass)
13
+ defined?(ForemanPuppet)
14
14
  end
15
15
 
16
16
  def inline_help
@@ -21,13 +21,17 @@ module ForemanOpenscap
21
21
  }
22
22
  end
23
23
 
24
+ def collection_method
25
+ :puppetclasses
26
+ end
27
+
24
28
  def constants
25
29
  OpenStruct.new(
26
30
  :server_param => 'server',
27
31
  :port_param => 'port',
28
32
  :policies_param => 'policies',
29
33
  :puppetclass_name => 'foreman_scap_client',
30
- :config_item_class_name => 'Puppetclass',
34
+ :config_item_class_name => 'ForemanPuppet::Puppetclass',
31
35
  :override_method_name => 'class_params',
32
36
  :msg_name => _('Puppet class'),
33
37
  :lookup_key_plural_name => _('Smart Class Parameters'),
@@ -0,0 +1,3 @@
1
+ object @oval_content
2
+
3
+ extends "api/v2/compliance/oval_contents/base"
@@ -4,15 +4,15 @@
4
4
  <div class="col-md-5 scap-breakdown-chart-col">
5
5
  <div class="stats-well">
6
6
  <h4 class="ca" ><%= _('Report Metrics') %></h4>
7
- <div id="arf-report-breakdown-chart" class="scap-breakdown-chart"></div>
8
- <%= mount_react_component('DonutChart', "#arf-report-breakdown-chart", donut_breakdown_chart_data(metrics)) %>
7
+ <div class="scap-breakdown-chart">
8
+ <%= react_component('DonutChart', :data => donut_breakdown_chart_data(metrics)) %>
9
+ </div>
9
10
  </div>
10
11
  </div>
11
12
  <div class="col-md-5 arf-report-rule-chart-col">
12
13
  <div class="stats-well">
13
14
  <h4 class="ca" ><%= _('Report Status') %></h4>
14
- <div id="arf-report-rule-chart"></div>
15
- <%= mount_react_component('BarChart', "#arf-report-rule-chart", arf_report_status_chart_data(status), :flatten_data => true) %>
15
+ <%= react_component('BarChart', arf_report_status_chart_data(status)) %>
16
16
  </div>
17
17
  </div>
18
18
  <div class="col-md-2">
@@ -17,18 +17,16 @@
17
17
  hash_for_arf_report_path(:id => data.latest_report.id)
18
18
  .merge(:auth_object => data.latest_report)) %></h4>
19
19
  <% report = data.report %>
20
- <% id = "host-policy-breakdown-chart-#{policy.id}" %>
21
- <div id="<%= id %>" class="scap-breakdown-chart"></div>
22
- <%= mount_react_component('DonutChart', "##{id}", donut_breakdown_chart_data(report)) %>
20
+ <div class="scap-breakdown-chart">
21
+ <%= react_component('DonutChart', :data => donut_breakdown_chart_data(report)) %>
22
+ </div>
23
23
  </div>
24
24
  </div>
25
25
 
26
26
  <div class="col-md-8">
27
27
  <div class="stats-well">
28
28
  <h4 class="ca"><%= _("%s reports over time") % policy %></h4>
29
- <% reports_graph_id = "arf-reports-over-time-#{policy.id}" %>
30
- <div id="<%= reports_graph_id %>"></div>
31
- <%= mount_react_component('LineChart', "##{reports_graph_id}", host_arf_reports_chart_data(policy.id), :flatten_data => true) %>
29
+ <%= react_component('LineChart', host_arf_reports_chart_data(policy.id)) %>
32
30
  </div>
33
31
  </div>
34
32
  <% else %>
@@ -1,4 +1,5 @@
1
1
  <h4 class="header ca"><%= _('Compliance Reports Breakdown') %></h4>
2
- <div id="compliance-reports-breakdown" class="host-configuration-chart"/>
3
- <% report = ForemanOpenscap::ReportDashboard::Data.new().report %>
4
- <%= mount_react_component('DonutChart', "#compliance-reports-breakdown", donut_breakdown_chart_data(report)) %>
2
+ <div class="host-configuration-chart">
3
+ <% report = ForemanOpenscap::ReportDashboard::Data.new().report %>
4
+ <%= react_component('DonutChart', :data => donut_breakdown_chart_data(report)) %>
5
+ </div>
@@ -2,6 +2,7 @@
2
2
 
3
3
  <div id='status-chart'>
4
4
  <h4 class="header ca"><%= _('Host Breakdown Chart') %></h4>
5
- <div id="policy-breakdown-chart" class="scap-breakdown-chart"></div>
6
- <%= mount_react_component('DonutChart', "#policy-breakdown-chart", policy_breakdown_chart_data(@report)) %>
5
+ <div class="scap-breakdown-chart">
6
+ <%= react_component('DonutChart', :data => policy_breakdown_chart_data(@report)) %>
7
+ </div>
7
8
  </div>
@@ -10,7 +10,8 @@ class MigratePortOverridesToInt < ActiveRecord::Migration[5.2]
10
10
  private
11
11
 
12
12
  def transform_lookup_values(method)
13
- puppet_class = Puppetclass.find_by :name => 'foreman_scap_client'
13
+ return unless defined?(ForemanPuppet)
14
+ puppet_class = ::ForemanPuppet::Puppetclass.find_by :name => 'foreman_scap_client'
14
15
  return unless puppet_class
15
16
  port_key = puppet_class.class_params.find_by :key => 'port'
16
17
  return unless port_key
@@ -10,7 +10,8 @@ class UpdatePuppetPortParamType < ActiveRecord::Migration[6.0]
10
10
  private
11
11
 
12
12
  def update_port_type(method)
13
- puppet_class = Puppetclass.find_by :name => 'foreman_scap_client'
13
+ return unless defined?(ForemanPuppet)
14
+ puppet_class = ::ForemanPuppet::Puppetclass.find_by :name => 'foreman_scap_client'
14
15
  return unless puppet_class
15
16
  port_key = puppet_class.class_params.find_by :key => 'port'
16
17
  return unless port_key
@@ -223,13 +223,6 @@ module ForemanOpenscap
223
223
  register_graphql_query_field :oval_policy, '::Types::OvalPolicy', :record_field
224
224
  register_graphql_query_field :cves, '::Types::Cve', :collection_field
225
225
 
226
- # move to core
227
- extend_graphql_type type: ::Types::Hostgroup do
228
- field :descendants, Types::Hostgroup.connection_type, null: true, resolve: (proc do |object|
229
- RecordLoader.for(model_class).load_many(object.descendant_ids)
230
- end)
231
- end
232
-
233
226
  register_facet ForemanOpenscap::Host::OvalFacet, :oval_facet do
234
227
  configure_host do
235
228
  extend_model ForemanOpenscap::OvalFacetHostExtensions
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "4.3.0".freeze
2
+ VERSION = "5.0.0".freeze
3
3
  end
data/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "foreman_openscap",
3
+ "version": "0.1.0",
4
+ "description": "Foreman plug-in for managing security compliance reports",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "test": "tfm-test --plugin --config jest.config.js",
9
+ "test:watch": "tfm-test --plugin --watchAll --config jest.config.js",
10
+ "test:current": "tfm-test --plugin --watch --config jest.config.js",
11
+ "publish-coverage": "tfm-publish-coverage",
12
+ "stories": "tfm-stories --plugin",
13
+ "stories:build": "tfm-build-stories --plugin",
14
+ "create-react-component": "yo react-domain"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/theforeman/foreman_openscap.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://projects.theforeman.org/projects/foreman_openscap/issues"
22
+ },
23
+ "peerDependencies": {
24
+ "@theforeman/vendor": ">= 4.13.2"
25
+ },
26
+ "devDependencies": {
27
+ "@apollo/react-testing": "^4.0.0",
28
+ "@babel/core": "^7.7.0",
29
+ "@testing-library/dom": "^7.30.4",
30
+ "@testing-library/jest-dom": "^5.11.9",
31
+ "@testing-library/react": "^11.2.5",
32
+ "@testing-library/user-event": "^13.1.2",
33
+ "@theforeman/builder": "^8.4.1",
34
+ "@theforeman/eslint-plugin-foreman": "8.4.1",
35
+ "@theforeman/find-foreman": "^8.4.1",
36
+ "@theforeman/stories": "^8.4.1",
37
+ "@theforeman/test": "^8.4.1",
38
+ "@theforeman/vendor-dev": "^8.4.1",
39
+ "babel-eslint": "^10.0.3",
40
+ "eslint": "^6.7.2",
41
+ "jed": "^1.1.1",
42
+ "jest-svg-transformer": "^1.0.0",
43
+ "jest-transform-graphql": "^2.1.0",
44
+ "prettier": "^1.13.5",
45
+ "stylelint": "^9.3.0",
46
+ "stylelint-config-standard": "^18.0.0"
47
+ }
48
+ }
@@ -20,7 +20,7 @@ class Api::V2::Compliance::OvalReportsControllerTest < ActionController::TestCas
20
20
 
21
21
  test 'should show host errors on CVEs upload' do
22
22
  proxy = FactoryBot.create(:smart_proxy)
23
- host = FactoryBot.create(:host, :puppet_proxy => proxy, :environment => FactoryBot.create(:environment))
23
+ host = FactoryBot.create(:host, :puppet_proxy => proxy)
24
24
  SmartProxy.any_instance.stubs(:smart_proxy_features).returns([])
25
25
  post :create, :params => @params.merge(:cname => host.name), :session => set_session_user
26
26
 
@@ -40,6 +40,7 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
40
40
  end
41
41
 
42
42
  test "should get index and show hostgroups" do
43
+ skip unless puppet_available?
43
44
  ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
44
45
  ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
45
46
  hostgroup = FactoryBot.create(:hostgroup)
@@ -61,6 +62,7 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
61
62
  end
62
63
 
63
64
  test "should show a policy hosts and hostgroups" do
65
+ skip unless puppet_available?
64
66
  ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
65
67
  ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
66
68
  hostgroup = FactoryBot.create(:hostgroup)
@@ -7,14 +7,13 @@ class ArfReportDashboardHelperTest < ActionView::TestCase
7
7
  categories = { :passed => 'passed', :failed => 'failed' }
8
8
  report = { :passed => 23, :failed => 24 }
9
9
  colors = { :passed => '#FFF', :failed => '#000' }
10
- res = JSON.parse(breakdown_chart_data(categories, report, colors))
10
+ res = breakdown_chart_data(categories, report, colors)
11
11
  assert_equal ["passed", 23, "#FFF"], res.first
12
12
  assert_equal ["failed", 24, "#000"], res.last
13
13
  end
14
14
 
15
15
  test 'should return breakdown chart data for donut as json' do
16
- report = { :passed => 4, :failed => 7, :othered => 5 }
17
- res = JSON.parse(donut_breakdown_chart_data(report))
16
+ res = donut_breakdown_chart_data(:passed => 4, :failed => 7, :othered => 5)
18
17
  assert_equal 3, res.size
19
18
  assert_include res, ["Passed", 4, ArfReportDashboardHelper::COLORS[:passed]]
20
19
  assert_include res, ["Failed", 7, ArfReportDashboardHelper::COLORS[:failed]]
@@ -22,12 +21,12 @@ class ArfReportDashboardHelperTest < ActionView::TestCase
22
21
  end
23
22
 
24
23
  test 'should return data for report status chart' do
25
- res = JSON.parse(arf_report_status_chart_data(:passed => 6, :failed => 7, :othered => 8))
26
- assert_equal "Number of Events", res['yAxisLabel']
27
- assert_equal "Rule Results", res['xAxisLabel']
28
- assert_equal 3, res['data'].size
29
- assert_include res['data'], ["passed", 6]
30
- assert_include res['data'], ["failed", 7]
31
- assert_include res['data'], ["othered", 8]
24
+ res = arf_report_status_chart_data(:passed => 6, :failed => 7, :othered => 8)
25
+ assert_equal "Number of Events", res[:yAxisLabel]
26
+ assert_equal "Rule Results", res[:xAxisLabel]
27
+ assert_equal 3, res[:data].size
28
+ assert_include res[:data], [:passed, 6]
29
+ assert_include res[:data], [:failed, 7]
30
+ assert_include res[:data], [:othered, 8]
32
31
  end
33
32
  end
@@ -11,7 +11,7 @@ class PolicyDashboardHelperTest < ActionView::TestCase
11
11
  :inconclusive_hosts => 7,
12
12
  :report_missing => 8
13
13
  }
14
- res = JSON.parse(policy_breakdown_chart_data(report))
14
+ res = policy_breakdown_chart_data(report)
15
15
  assert_equal 4, res.size
16
16
  assert_include res, ['Compliant hosts', 5, PolicyDashboardHelper::COLORS[:compliant_hosts]]
17
17
  assert_include res, ['Incompliant hosts', 6, PolicyDashboardHelper::COLORS[:incompliant_hosts]]
@@ -5,19 +5,24 @@ require 'test_helper'
5
5
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
6
  # Add factories from foreman_ansible
7
7
  FactoryBot.definition_file_paths << File.join(ForemanAnsible::Engine.root, '/test/factories')
8
+ FactoryBot.definition_file_paths << File.join(ForemanPuppet::Engine.root, '/test/factories') if defined?(ForemanPuppet)
8
9
  FactoryBot.reload
9
10
 
10
11
  require "#{ForemanOpenscap::Engine.root}/test/fixtures/cve_fixtures"
11
12
 
12
13
  module ScapClientPuppetclass
14
+ def puppet_available?
15
+ defined?(ForemanPuppet)
16
+ end
17
+
13
18
  def setup_puppet_class
14
19
  puppet_config = ::ForemanOpenscap::ClientConfig::Puppet.new
15
- Puppetclass.find_by(:name => puppet_config.puppetclass_name)&.destroy
20
+ ForemanPuppet::Puppetclass.find_by(:name => puppet_config.puppetclass_name)&.destroy
16
21
 
17
22
  puppet_class = FactoryBot.create(:puppetclass, :name => puppet_config.puppetclass_name)
18
- server_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.server_param, :default_value => nil)
19
- port_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.port_param, :default_value => nil)
20
- policies_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.policies_param, :default_value => nil)
23
+ server_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.server_param, :default_value => nil, :override => false)
24
+ port_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.port_param, :default_value => nil, :override => false)
25
+ policies_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.policies_param, :default_value => nil, :override => false)
21
26
 
22
27
  env = FactoryBot.create :environment
23
28
 
@@ -75,7 +75,6 @@ class PolicyTest < ActiveSupport::TestCase
75
75
  asset = FactoryBot.create(:asset, :assetable_id => hg.id, :assetable_type => 'Hostgroup')
76
76
  policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
77
77
  policy.save!
78
- hg.hostgroup_classes.destroy_all
79
78
  hg.destroy
80
79
  assert_equal 0, policy.hostgroups.count
81
80
  end
@@ -314,6 +313,7 @@ class PolicyTest < ActiveSupport::TestCase
314
313
  end
315
314
 
316
315
  test "should change deploy type" do
316
+ skip unless puppet_available?
317
317
  policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
318
318
  setup_puppet_class
319
319
  policy.change_deploy_type({ :deploy_by => 'puppet' })
@@ -24,6 +24,7 @@ class ConfigNameServiceTest < ActiveSupport::TestCase
24
24
  end
25
25
 
26
26
  test 'should find all available except Manual' do
27
+ skip unless puppet_available?
27
28
  ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(false)
28
29
  configs = @name_service.all_available_except(:manual)
29
30
  assert_equal 1, configs.size
@@ -9,11 +9,12 @@ class HostgroupOverriderTest < ActiveSupport::TestCase
9
9
  end
10
10
 
11
11
  test 'should populate puppet overrides' do
12
+ skip unless puppet_available?
12
13
  puppet_class, env, port_param, server_param = setup_puppet_class.values_at :puppet_class, :env, :port_param, :server_param
13
14
 
14
15
  proxy = FactoryBot.create(:openscap_proxy, :url => 'https://override-keys.example.com:8998')
15
16
 
16
- hostgroup = FactoryBot.create(:hostgroup, :environment_id => env.id, :openscap_proxy_id => proxy.id)
17
+ hostgroup = FactoryBot.create(:hostgroup, :environment_id => env.id, :openscap_proxy_id => proxy.id, :puppet => FactoryBot.create(:hostgroup_puppet_facet))
17
18
  refute hostgroup.puppetclasses.include? puppet_class
18
19
  assert LookupValue.where(:match => "hostgroup=#{hostgroup.to_label}",
19
20
  :lookup_key_id => port_param.id,
@@ -8,6 +8,7 @@ class LookupKeyOverriderTest < ActiveSupport::TestCase
8
8
  end
9
9
 
10
10
  test 'should override puppet class parameters' do
11
+ skip unless puppet_available?
11
12
  server_param, port_param, policies_param = setup_puppet_class.values_at :server_param, :port_param, :policies_param
12
13
  refute server_param.override
13
14
  refute port_param.override
@@ -21,7 +22,8 @@ class LookupKeyOverriderTest < ActiveSupport::TestCase
21
22
  end
22
23
 
23
24
  test 'should add error when no puppet class found' do
24
- puppet_class = Puppetclass.find_by :name => ForemanOpenscap::ClientConfig::Puppet.new.puppetclass_name
25
+ skip unless puppet_available?
26
+ puppet_class = ::ForemanPuppet::Puppetclass.find_by :name => ForemanOpenscap::ClientConfig::Puppet.new.puppetclass_name
25
27
  puppet_class.destroy if puppet_class
26
28
  policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_content_profile, :deploy_by => :puppet)
27
29
  ForemanOpenscap::LookupKeyOverrider.new(policy).override
@@ -41,6 +43,7 @@ class LookupKeyOverriderTest < ActiveSupport::TestCase
41
43
  end
42
44
 
43
45
  test 'should add error when lookup keys not present' do
46
+ skip unless puppet_available?
44
47
  server_param, port_param, policies_param = setup_puppet_class.values_at :server_param, :port_param, :policies_param
45
48
  server_param.destroy
46
49
  port_param.destroy