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.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/compliance/arf_reports_controller.rb +0 -6
- data/app/controllers/api/v2/compliance/oval_policies_controller.rb +1 -1
- data/app/helpers/arf_report_dashboard_helper.rb +2 -4
- data/app/helpers/compliance_hosts_helper.rb +1 -1
- data/app/helpers/policies_helper.rb +1 -1
- data/app/services/foreman_openscap/client_config/base.rb +1 -0
- data/app/services/foreman_openscap/client_config/puppet.rb +6 -2
- data/app/views/api/v2/compliance/oval_contents/destroy.json.rabl +3 -0
- data/app/views/arf_reports/_metrics.html.erb +4 -4
- data/app/views/compliance_hosts/show.html.erb +4 -6
- data/app/views/dashboard/_compliance_reports_breakdown_widget.html.erb +4 -3
- data/app/views/policy_dashboard/_policy_chart_widget.html.erb +3 -2
- data/db/migrate/20200117135424_migrate_port_overrides_to_int.rb +2 -1
- data/db/migrate/20201202110213_update_puppet_port_param_type.rb +2 -1
- data/lib/foreman_openscap/engine.rb +0 -7
- data/lib/foreman_openscap/version.rb +1 -1
- data/package.json +48 -0
- data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +1 -1
- data/test/functional/api/v2/compliance/policies_controller_test.rb +2 -0
- data/test/helpers/arf_report_dashboard_helper_test.rb +9 -10
- data/test/helpers/policy_dashboard_helper_test.rb +1 -1
- data/test/test_plugin_helper.rb +9 -4
- data/test/unit/policy_test.rb +1 -1
- data/test/unit/services/config_name_service_test.rb +1 -0
- data/test/unit/services/hostgroup_overrider_test.rb +2 -1
- data/test/unit/services/lookup_key_overrider_test.rb +4 -1
- data/webpack/components/EmptyState.js +73 -0
- data/webpack/components/IndexLayout.js +35 -0
- data/webpack/components/IndexLayout.scss +3 -0
- data/webpack/components/IndexTable/IndexTableHelper.js +9 -0
- data/webpack/components/IndexTable/index.js +65 -0
- data/webpack/components/RuleSeverity/RuleSeverity.scss +3 -0
- data/webpack/components/RuleSeverity/RuleSeverity.test.js +13 -0
- data/webpack/components/RuleSeverity/__snapshots__/RuleSeverity.test.js.snap +41 -0
- data/webpack/components/RuleSeverity/i_severity-critical.svg +61 -0
- data/webpack/components/RuleSeverity/i_severity-high.svg +61 -0
- data/webpack/components/RuleSeverity/i_severity-low.svg +62 -0
- data/webpack/components/RuleSeverity/i_severity-med.svg +62 -0
- data/webpack/components/RuleSeverity/i_unknown.svg +33 -0
- data/webpack/components/RuleSeverity/index.js +33 -0
- data/webpack/components/withLoading.js +87 -0
- data/webpack/global_index.js +5 -0
- data/webpack/graphql/queries/currentUserAttributes.gql +11 -0
- data/webpack/graphql/queries/cves.gql +23 -0
- data/webpack/graphql/queries/ovalContents.gql +16 -0
- data/webpack/graphql/queries/ovalPolicies.gql +17 -0
- data/webpack/graphql/queries/ovalPolicy.gql +26 -0
- data/webpack/helpers/commonHelper.js +1 -0
- data/webpack/helpers/globalIdHelper.js +13 -0
- data/webpack/helpers/pageParamsHelper.js +31 -0
- data/webpack/helpers/pathsHelper.js +22 -0
- data/webpack/helpers/permissionsHelper.js +42 -0
- data/webpack/helpers/tableHelper.js +9 -0
- data/webpack/index.js +8 -0
- data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsIndex.js +46 -0
- data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsTable.js +46 -0
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.fixtures.js +120 -0
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.test.js +101 -0
- data/webpack/routes/OvalContents/OvalContentsIndex/index.js +7 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesIndex.js +47 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesTable.js +44 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.fixtures.js +95 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.test.js +98 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/index.js +7 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTab.js +49 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTable.js +63 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShow.js +78 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShowHelper.js +39 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.fixtures.js +87 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.test.js +129 -0
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/index.js +36 -0
- data/webpack/routes/routes.js +28 -0
- data/webpack/testHelper.js +96 -0
- metadata +56 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 534b669988c89b1335565f67c02b63443b0cfd36636749397b50617c4797316b
|
|
4
|
+
data.tar.gz: 4ee455ef101cc0bb6b034f1b081e2d604848620e7438e3ae887493ee77d13015
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2ddaa5f34a78a9f085f5564f7e12f28071baf8b1679e645c327bb6d229986f0b399ae9a3bf50078e7d4c536014b43df974125851277ff1584130918b93382a2
|
|
7
|
+
data.tar.gz: 6a115b58c74b88f4c9e4f81ab5c31a0db2195a285d2c2eb4612251aead4131a426b34aab2593b7e8b6e2b656fee92cae0adc1b3d5bd19787466514e35312fd70
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
}
|
|
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' }
|
|
19
|
+
{ :data => data, :xAxisDataLabel => 'dates', :config => 'timeseries' }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def compliance_host_multiple_actions
|
|
@@ -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?(
|
|
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'),
|
|
@@ -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
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
3
|
-
<% report = ForemanOpenscap::ReportDashboard::Data.new().report %>
|
|
4
|
-
<%=
|
|
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
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
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
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
26
|
-
assert_equal "Number of Events", res[
|
|
27
|
-
assert_equal "Rule Results", res[
|
|
28
|
-
assert_equal 3, res[
|
|
29
|
-
assert_include res[
|
|
30
|
-
assert_include res[
|
|
31
|
-
assert_include res[
|
|
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 =
|
|
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]]
|
data/test/test_plugin_helper.rb
CHANGED
|
@@ -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
|
|
data/test/unit/policy_test.rb
CHANGED
|
@@ -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
|
-
|
|
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
|