foreman_openscap 8.0.2 → 9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/app/services/foreman_openscap/client_config/ansible.rb +1 -10
- data/config/initializers/inflections.rb +0 -2
- data/config/routes.rb +0 -15
- data/db/migrate/20240313111822_drop_oval.rb +17 -0
- data/db/migrate/20240617105409_remove_oval_permissions.rb +24 -0
- data/lib/foreman_openscap/engine.rb +2 -56
- data/lib/foreman_openscap/version.rb +1 -1
- data/test/factories/compliance_host_factory.rb +0 -12
- data/test/test_plugin_helper.rb +0 -2
- data/webpack/global_index.js +0 -4
- metadata +8 -168
- data/app/controllers/api/v2/compliance/oval_contents_controller.rb +0 -72
- data/app/controllers/api/v2/compliance/oval_policies_controller.rb +0 -111
- data/app/controllers/api/v2/compliance/oval_reports_controller.rb +0 -47
- data/app/controllers/concerns/foreman/controller/parameters/oval_content.rb +0 -22
- data/app/controllers/concerns/foreman/controller/parameters/oval_policy.rb +0 -22
- data/app/graphql/mutations/oval_contents/delete.rb +0 -9
- data/app/graphql/mutations/oval_policies/create.rb +0 -33
- data/app/graphql/mutations/oval_policies/delete.rb +0 -9
- data/app/graphql/mutations/oval_policies/update.rb +0 -15
- data/app/graphql/types/cve.rb +0 -17
- data/app/graphql/types/oval_check.rb +0 -11
- data/app/graphql/types/oval_content.rb +0 -19
- data/app/graphql/types/oval_policy.rb +0 -24
- data/app/models/concerns/foreman_openscap/oval_facet_host_extensions.rb +0 -38
- data/app/models/concerns/foreman_openscap/oval_facet_hostgroup_extensions.rb +0 -31
- data/app/models/foreman_openscap/cve.rb +0 -23
- data/app/models/foreman_openscap/host/oval_facet.rb +0 -14
- data/app/models/foreman_openscap/host_cve.rb +0 -7
- data/app/models/foreman_openscap/hostgroup/oval_facet.rb +0 -14
- data/app/models/foreman_openscap/hostgroup_oval_facet_oval_policy.rb +0 -6
- data/app/models/foreman_openscap/oval_content.rb +0 -28
- data/app/models/foreman_openscap/oval_facet_oval_policy.rb +0 -6
- data/app/models/foreman_openscap/oval_policy.rb +0 -54
- data/app/models/foreman_openscap/oval_status.rb +0 -45
- data/app/services/foreman_openscap/oval/check_collection.rb +0 -45
- data/app/services/foreman_openscap/oval/configure.rb +0 -83
- data/app/services/foreman_openscap/oval/cves.rb +0 -41
- data/app/services/foreman_openscap/oval/setup.rb +0 -93
- data/app/services/foreman_openscap/oval/setup_check.rb +0 -58
- data/app/services/foreman_openscap/oval/sync_oval_contents.rb +0 -42
- data/app/views/api/v2/compliance/oval_contents/base.json.rabl +0 -6
- data/app/views/api/v2/compliance/oval_contents/create.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_contents/destroy.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_contents/index.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_contents/show.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_contents/sync.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_contents/sync_result.json.rabl +0 -11
- data/app/views/api/v2/compliance/oval_contents/update.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_policies/create.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_policies/index.json.rabl +0 -3
- data/app/views/api/v2/compliance/oval_policies/main.json.rabl +0 -15
- data/app/views/api/v2/compliance/oval_policies/show.json.rabl +0 -3
- data/app/views/job_templates/run_oval_scans.erb +0 -24
- data/locale/cs_CZ/foreman_openscap.edit.po +0 -1863
- data/locale/cs_CZ/foreman_openscap.po.time_stamp +0 -0
- data/locale/de/foreman_openscap.edit.po +0 -1873
- data/locale/de/foreman_openscap.po.time_stamp +0 -0
- data/locale/en/foreman_openscap.edit.po +0 -1863
- data/locale/en/foreman_openscap.po.time_stamp +0 -0
- data/locale/en_GB/foreman_openscap.edit.po +0 -1863
- data/locale/en_GB/foreman_openscap.po.time_stamp +0 -0
- data/locale/es/foreman_openscap.edit.po +0 -1868
- data/locale/es/foreman_openscap.po.time_stamp +0 -0
- data/locale/fr/foreman_openscap.edit.po +0 -1874
- data/locale/fr/foreman_openscap.po.time_stamp +0 -0
- data/locale/gl/foreman_openscap.edit.po +0 -1863
- data/locale/gl/foreman_openscap.po.time_stamp +0 -0
- data/locale/it/foreman_openscap.edit.po +0 -1865
- data/locale/it/foreman_openscap.po.time_stamp +0 -0
- data/locale/ja/foreman_openscap.edit.po +0 -1869
- data/locale/ja/foreman_openscap.po.time_stamp +0 -0
- data/locale/ka/foreman_openscap.edit.po +0 -1863
- data/locale/ka/foreman_openscap.po.time_stamp +0 -0
- data/locale/ko/foreman_openscap.edit.po +0 -1863
- data/locale/ko/foreman_openscap.po.time_stamp +0 -0
- data/locale/pt_BR/foreman_openscap.edit.po +0 -1873
- data/locale/pt_BR/foreman_openscap.po.time_stamp +0 -0
- data/locale/ru/foreman_openscap.edit.po +0 -1867
- data/locale/ru/foreman_openscap.po.time_stamp +0 -0
- data/locale/sv_SE/foreman_openscap.edit.po +0 -1863
- data/locale/sv_SE/foreman_openscap.po.time_stamp +0 -0
- data/locale/zh_CN/foreman_openscap.edit.po +0 -1868
- data/locale/zh_CN/foreman_openscap.po.time_stamp +0 -0
- data/locale/zh_TW/foreman_openscap.edit.po +0 -1864
- data/locale/zh_TW/foreman_openscap.po.time_stamp +0 -0
- data/test/factories/oval_content_factory.rb +0 -7
- data/test/factories/oval_policy_factory.rb +0 -9
- data/test/fixtures/cve_fixtures.rb +0 -104
- data/test/functional/api/v2/compliance/oval_contents_controller_test.rb +0 -39
- data/test/functional/api/v2/compliance/oval_policies_controller_test.rb +0 -141
- data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +0 -32
- data/test/graphql/mutations/oval_policies/delete_mutation_test.rb +0 -63
- data/test/graphql/queries/oval_content_query_test.rb +0 -29
- data/test/graphql/queries/oval_contents_query_test.rb +0 -35
- data/test/graphql/queries/oval_policies_query_test.rb +0 -35
- data/test/unit/oval_host_test.rb +0 -45
- data/test/unit/oval_policy_test.rb +0 -133
- data/test/unit/oval_status_test.rb +0 -47
- data/test/unit/services/oval/cves_test.rb +0 -81
- data/test/unit/services/oval/setup_check_test.rb +0 -37
- data/test/unit/services/oval/setup_test.rb +0 -87
- data/webpack/graphql/mutations/createOvalPolicy.gql +0 -22
- data/webpack/graphql/mutations/deleteOvalContent.gql +0 -9
- data/webpack/graphql/mutations/deleteOvalPolicy.gql +0 -9
- data/webpack/graphql/mutations/updateOvalPolicy.gql +0 -14
- data/webpack/graphql/queries/currentUserAttributes.gql +0 -11
- data/webpack/graphql/queries/cves.gql +0 -23
- data/webpack/graphql/queries/hostgroups.gql +0 -14
- data/webpack/graphql/queries/ovalContent.gql +0 -8
- data/webpack/graphql/queries/ovalContents.gql +0 -19
- data/webpack/graphql/queries/ovalPolicies.gql +0 -20
- data/webpack/graphql/queries/ovalPolicy.gql +0 -29
- data/webpack/helpers/pathsHelper.js +0 -29
- data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsIndex.js +0 -71
- data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsTable.js +0 -83
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsDestroy.fixtures.js +0 -105
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsDestroy.test.js +0 -124
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.fixtures.js +0 -127
- data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.test.js +0 -89
- data/webpack/routes/OvalContents/OvalContentsIndex/index.js +0 -13
- data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNew.js +0 -138
- data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNew.scss +0 -3
- data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNewHelper.js +0 -73
- data/webpack/routes/OvalContents/OvalContentsNew/__tests__/OvalContentsNew.test.js +0 -104
- data/webpack/routes/OvalContents/OvalContentsNew/index.js +0 -13
- data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShow.js +0 -62
- data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShow.test.js +0 -45
- data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShowHelper.js +0 -0
- data/webpack/routes/OvalContents/OvalContentsShow/index.js +0 -35
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesIndex.js +0 -62
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesTable.js +0 -74
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesDestroy.fixtures.js +0 -101
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesDestroy.test.js +0 -117
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.fixtures.js +0 -111
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.test.js +0 -81
- data/webpack/routes/OvalPolicies/OvalPoliciesIndex/index.js +0 -13
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/HostgroupSelect.js +0 -135
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/NewOvalPolicyForm.js +0 -119
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/NewOvalPolicyFormHelpers.js +0 -107
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/OvalPoliciesNew.js +0 -32
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/__tests__/OvalPoliciesNew.fixtures.js +0 -147
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/__tests__/OvalPoliciesNew.test.js +0 -172
- data/webpack/routes/OvalPolicies/OvalPoliciesNew/index.js +0 -11
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTab.js +0 -49
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTable.js +0 -63
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/DetailsTab.js +0 -87
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/HostgroupsTab.js +0 -49
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/HostgroupsTable.js +0 -38
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShow.js +0 -82
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShowHelper.js +0 -117
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesEdit.fixtures.js +0 -48
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesEdit.test.js +0 -202
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.fixtures.js +0 -124
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.test.js +0 -172
- data/webpack/routes/OvalPolicies/OvalPoliciesShow/index.js +0 -39
- data/webpack/routes/routes.js +0 -49
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'test_plugin_helper'
|
2
|
-
|
3
|
-
class OvalPolicyTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@oval_content = FactoryBot.create(:oval_content)
|
6
|
-
end
|
7
|
-
|
8
|
-
test "should not create OVAL policy with custom period" do
|
9
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
10
|
-
:period => 'custom',
|
11
|
-
:cron_line => 'aaa',
|
12
|
-
:oval_content => @oval_content)
|
13
|
-
refute policy.save
|
14
|
-
assert policy.errors[:cron_line].include?("does not consist of 5 parts separated by space")
|
15
|
-
end
|
16
|
-
|
17
|
-
test "should create OVAL policy with weekly period" do
|
18
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
19
|
-
:period => 'weekly',
|
20
|
-
:weekday => 'monday',
|
21
|
-
:oval_content => @oval_content)
|
22
|
-
assert policy.save
|
23
|
-
end
|
24
|
-
|
25
|
-
test "should not create OVAL policy with weekly period" do
|
26
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
27
|
-
:period => 'weekly',
|
28
|
-
:weekday => 'someday',
|
29
|
-
:oval_content => @oval_content)
|
30
|
-
refute policy.save
|
31
|
-
assert policy.errors[:weekday].include?("is not a valid value")
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should create OVAL policy with monthly period" do
|
35
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
36
|
-
:period => 'monthly',
|
37
|
-
:day_of_month => '1',
|
38
|
-
:oval_content => @oval_content)
|
39
|
-
assert policy.save
|
40
|
-
end
|
41
|
-
|
42
|
-
test "should not create OVAL policy with monthly period" do
|
43
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
44
|
-
:period => 'monthly',
|
45
|
-
:day_of_month => '0',
|
46
|
-
:oval_content => @oval_content)
|
47
|
-
refute policy.save
|
48
|
-
assert policy.errors[:day_of_month].include?("must be between 1 and 31")
|
49
|
-
end
|
50
|
-
|
51
|
-
test "should not create OVAL policy when attributes do not correspond to selected period in new record" do
|
52
|
-
policy_0 = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
53
|
-
:period => 'monthly',
|
54
|
-
:weekday => 'tuesday',
|
55
|
-
:cron_line => "0 0 0 0 0",
|
56
|
-
:oval_content => @oval_content)
|
57
|
-
policy_1 = ForemanOpenscap::OvalPolicy.new(:name => "test policy",
|
58
|
-
:period => 'custom',
|
59
|
-
:weekday => 'tuesday',
|
60
|
-
:day_of_month => "15",
|
61
|
-
:oval_content => @oval_content)
|
62
|
-
refute policy_0.save
|
63
|
-
refute policy_1.save
|
64
|
-
end
|
65
|
-
|
66
|
-
test "should update OVAL policy period" do
|
67
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
68
|
-
:period => 'monthly',
|
69
|
-
:day_of_month => '5',
|
70
|
-
:oval_content => @oval_content)
|
71
|
-
assert policy.save
|
72
|
-
policy.period = 'weekly'
|
73
|
-
policy.weekday = 'monday'
|
74
|
-
policy.day_of_month = nil
|
75
|
-
assert policy.save
|
76
|
-
end
|
77
|
-
|
78
|
-
test "should add and remove hosts for OVAL policy" do
|
79
|
-
host = FactoryBot.create(:oval_host)
|
80
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
81
|
-
:period => 'monthly',
|
82
|
-
:day_of_month => '5',
|
83
|
-
:host_ids => [host.id],
|
84
|
-
:oval_content => @oval_content)
|
85
|
-
|
86
|
-
assert policy.save
|
87
|
-
assert policy.reload.hosts.include?(host)
|
88
|
-
|
89
|
-
policy.host_ids = []
|
90
|
-
assert policy.save
|
91
|
-
refute policy.reload.hosts.include?(host)
|
92
|
-
end
|
93
|
-
|
94
|
-
test "should add and remove hostgroups for OVAL policy" do
|
95
|
-
hostgroup = FactoryBot.create(:hostgroup)
|
96
|
-
policy = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
97
|
-
:period => 'monthly',
|
98
|
-
:day_of_month => '5',
|
99
|
-
:hostgroup_ids => [hostgroup.id],
|
100
|
-
:oval_content => @oval_content)
|
101
|
-
assert policy.save
|
102
|
-
assert policy.reload.hostgroups.include?(hostgroup)
|
103
|
-
|
104
|
-
policy.hostgroup_ids = []
|
105
|
-
assert policy.save
|
106
|
-
refute policy.reload.hostgroups.include?(hostgroup)
|
107
|
-
end
|
108
|
-
|
109
|
-
test "should add and remove inherited OVAL policy" do
|
110
|
-
hostgroup = FactoryBot.create(:hostgroup)
|
111
|
-
host = FactoryBot.create(:oval_host, :hostgroup => hostgroup)
|
112
|
-
policy_1 = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy",
|
113
|
-
:period => 'monthly',
|
114
|
-
:day_of_month => '5',
|
115
|
-
:hostgroup_ids => [hostgroup.id],
|
116
|
-
:oval_content => @oval_content)
|
117
|
-
policy_2 = ForemanOpenscap::OvalPolicy.new(:name => "custom_policy_again",
|
118
|
-
:period => 'monthly',
|
119
|
-
:day_of_month => '6',
|
120
|
-
:host_ids => [host.id],
|
121
|
-
:oval_content => @oval_content)
|
122
|
-
assert policy_1.save
|
123
|
-
assert policy_2.save
|
124
|
-
|
125
|
-
assert host.reload.combined_oval_policies.include?(policy_1)
|
126
|
-
assert host.combined_oval_policies.include?(policy_2)
|
127
|
-
|
128
|
-
policy_1.hostgroup_ids = []
|
129
|
-
assert policy_1.save
|
130
|
-
refute host.reload.combined_oval_policies.include?(policy_1)
|
131
|
-
assert host.combined_oval_policies.include?(policy_2)
|
132
|
-
end
|
133
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test_plugin_helper'
|
2
|
-
|
3
|
-
class OvalStatusTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@policy = FactoryBot.create(:oval_policy, :oval_content => FactoryBot.create(:oval_content))
|
6
|
-
end
|
7
|
-
|
8
|
-
test 'should have no vulnerabilities' do
|
9
|
-
host = FactoryBot.create(:oval_host)
|
10
|
-
FactoryBot.create(:oval_facet, :host => host, :oval_policies => [@policy])
|
11
|
-
|
12
|
-
status = ForemanOpenscap::OvalStatus.new
|
13
|
-
status.host = host
|
14
|
-
assert_equal 0, status.to_status
|
15
|
-
assert_equal ::HostStatus::Global::OK, status.to_global
|
16
|
-
assert status.relevant?
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'should have vulnerabilities with available patch' do
|
20
|
-
host = FactoryBot.create(:oval_host, :cves => [FactoryBot.create(:cve, :has_errata => false), FactoryBot.create(:cve, :has_errata => true)])
|
21
|
-
FactoryBot.create(:oval_facet, :host => host, :oval_policies => [@policy])
|
22
|
-
|
23
|
-
status = ForemanOpenscap::OvalStatus.new
|
24
|
-
status.host = host
|
25
|
-
assert_equal 2, status.to_status
|
26
|
-
assert_equal ::HostStatus::Global::ERROR, status.to_global
|
27
|
-
assert status.relevant?
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'should have vulnerabilities without available patch' do
|
31
|
-
host = FactoryBot.create(:oval_host, :cves => [FactoryBot.create(:cve, :has_errata => false), FactoryBot.create(:cve, :has_errata => false)])
|
32
|
-
FactoryBot.create(:oval_facet, :host => host, :oval_policies => [@policy])
|
33
|
-
|
34
|
-
status = ForemanOpenscap::OvalStatus.new
|
35
|
-
status.host = host
|
36
|
-
assert_equal 1, status.to_status
|
37
|
-
assert_equal ::HostStatus::Global::WARN, status.to_global
|
38
|
-
assert status.relevant?
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'should not be relevant without oval policy' do
|
42
|
-
host = FactoryBot.create(:oval_host, :cves => [FactoryBot.create(:cve)])
|
43
|
-
status = ForemanOpenscap::OvalStatus.new
|
44
|
-
status.host = host
|
45
|
-
refute status.relevant?
|
46
|
-
end
|
47
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'test_plugin_helper'
|
2
|
-
|
3
|
-
class ForemanOpenscap::Oval::CvesTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@fxs = ForemanOpenscap::CveFixtures.new
|
6
|
-
@instance = ForemanOpenscap::Oval::Cves.new
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should add CVEs to host" do
|
10
|
-
oval_data = create_cve_data @fxs.one
|
11
|
-
host = FactoryBot.create(:host)
|
12
|
-
assert_empty host.cves
|
13
|
-
@instance.create host, oval_data
|
14
|
-
refute_empty host.cves
|
15
|
-
|
16
|
-
assert_equal host.cves, host.cves.distinct
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should filter out CVEs that do not affect the host" do
|
20
|
-
oval_data = create_cve_data @fxs.two
|
21
|
-
host = FactoryBot.create(:host)
|
22
|
-
assert_empty host.cves
|
23
|
-
@instance.create host, oval_data
|
24
|
-
refute_empty host.cves
|
25
|
-
|
26
|
-
assert_equal host.cves, ForemanOpenscap::Cve.where(:ref_id => @fxs.ids_from(@fxs.res_two))
|
27
|
-
end
|
28
|
-
|
29
|
-
test "should update host with a new set of CVEs" do
|
30
|
-
oval_data = create_cve_data @fxs.one
|
31
|
-
host = FactoryBot.create(:host)
|
32
|
-
assert_empty host.cves
|
33
|
-
@instance.create host, oval_data
|
34
|
-
refute_empty host.cves
|
35
|
-
|
36
|
-
cve_ids_before = host.reload.cve_ids
|
37
|
-
new_oval_data = create_cve_data @fxs.two
|
38
|
-
@instance.create host, new_oval_data
|
39
|
-
|
40
|
-
refute_equal host.reload.cve_ids, cve_ids_before
|
41
|
-
assert_equal host.cves, ForemanOpenscap::Cve.where(:ref_id => @fxs.ids_from(@fxs.res_two))
|
42
|
-
|
43
|
-
@fxs.ids_from(@fxs.res_three).map do |ref_id|
|
44
|
-
refute ForemanOpenscap::Cve.find_by :ref_id => ref_id
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
test "should not delete CVEs associated to another host" do
|
49
|
-
oval_data = create_cve_data @fxs.one
|
50
|
-
host = FactoryBot.create(:host)
|
51
|
-
@instance.create host, oval_data
|
52
|
-
refute_empty host.cves
|
53
|
-
|
54
|
-
cves_before = host.reload.cves
|
55
|
-
|
56
|
-
oval_data_2 = create_cve_data @fxs.two
|
57
|
-
host_2 = FactoryBot.create(:host)
|
58
|
-
@instance.create host_2, oval_data_2
|
59
|
-
|
60
|
-
assert_equal host.reload.cves, cves_before
|
61
|
-
end
|
62
|
-
|
63
|
-
test "should not delete CVEs associated to another policy" do
|
64
|
-
oval_data = create_cve_data [@fxs.res_three]
|
65
|
-
host = FactoryBot.create(:host)
|
66
|
-
assert_empty host.cves
|
67
|
-
@instance.create host, oval_data
|
68
|
-
refute_empty host.cves
|
69
|
-
|
70
|
-
cve_ids_before = host.reload.cve_ids
|
71
|
-
new_oval_data = create_cve_data [@fxs.res_four], 2
|
72
|
-
@instance.create host, new_oval_data
|
73
|
-
|
74
|
-
refute_equal host.reload.cve_ids, cve_ids_before
|
75
|
-
assert_equal host.cves, ForemanOpenscap::Cve.where(:ref_id => @fxs.ids_from(@fxs.res_three).concat(@fxs.ids_from(@fxs.res_four)))
|
76
|
-
end
|
77
|
-
|
78
|
-
def create_cve_data(fixture, policy_id = 1)
|
79
|
-
{ 'oval_results' => fixture, 'oval_policy_id' => policy_id }
|
80
|
-
end
|
81
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_plugin_helper'
|
2
|
-
|
3
|
-
class ForemanOpenscap::Oval::SetupCheckTest < ActiveSupport::TestCase
|
4
|
-
test 'should show error message with filled in data' do
|
5
|
-
check = ::ForemanOpenscap::Oval::SetupCheck.new(
|
6
|
-
:id => :test_check,
|
7
|
-
:title => _("Will it pass?"),
|
8
|
-
:fail_msg => ->(hash) { "There was an error in #{hash[:name]}, you need to #{hash[:action]}" }
|
9
|
-
)
|
10
|
-
|
11
|
-
check.fail_with!(:name => 'your engine', :action => 'run')
|
12
|
-
assert_equal 'There was an error in your engine, you need to run', check.fail_msg
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'should show error message when it is a string' do
|
16
|
-
msg = "Do not panic"
|
17
|
-
check = ::ForemanOpenscap::Oval::SetupCheck.new(
|
18
|
-
:id => :test_check,
|
19
|
-
:title => _("Will it pass?"),
|
20
|
-
:fail_msg => msg
|
21
|
-
)
|
22
|
-
check.fail!
|
23
|
-
assert_equal msg, check.fail_msg
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'should not show error message when check not failed' do
|
27
|
-
check = ::ForemanOpenscap::Oval::SetupCheck.new(
|
28
|
-
:id => :test_check,
|
29
|
-
:title => _("Will it pass?"),
|
30
|
-
:fail_msg => 'foo'
|
31
|
-
)
|
32
|
-
|
33
|
-
assert_nil check.fail_msg
|
34
|
-
check.fail!
|
35
|
-
assert_not_nil check.fail_msg
|
36
|
-
end
|
37
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'test_plugin_helper'
|
2
|
-
|
3
|
-
class ForemanOpenscap::Oval::SetupTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@config = ForemanOpenscap::ClientConfig::Ansible.new(::ForemanOpenscap::OvalPolicy)
|
6
|
-
end
|
7
|
-
|
8
|
-
test "should fail check when Ansible not available" do
|
9
|
-
ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(false)
|
10
|
-
|
11
|
-
check_collection = ForemanOpenscap::Oval::Setup.new.run
|
12
|
-
assert check_collection.find_check(:foreman_ansible_present).failed?
|
13
|
-
assert check_collection.checks.reject { |res| res.id == :foreman_ansible_present }.all?(&:skipped?)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should fail check when Ansible role for client not imported" do
|
17
|
-
ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:find_config_item).returns(nil)
|
18
|
-
|
19
|
-
check_collection = ForemanOpenscap::Oval::Setup.new.run
|
20
|
-
assert check_collection.find_check(:foreman_ansible_present).passed?
|
21
|
-
assert check_collection.find_check(:foreman_scap_client_role_present).failed?
|
22
|
-
|
23
|
-
assert check_collection.checks
|
24
|
-
.select { |res| res.id != :foreman_ansible_present && res.id != :foreman_scap_client_role_present }
|
25
|
-
.all?(&:skipped?)
|
26
|
-
end
|
27
|
-
|
28
|
-
test "should fail check when required Ansible variables are not imported" do
|
29
|
-
FactoryBot.create(:ansible_role, :name => @config.ansible_role_name)
|
30
|
-
check_collection = ForemanOpenscap::Oval::Setup.new.run
|
31
|
-
assert check_collection.find_check(:foreman_ansible_present).passed?
|
32
|
-
assert check_collection.find_check(:foreman_scap_client_role_present).passed?
|
33
|
-
|
34
|
-
res = check_collection.find_check(:foreman_scap_client_vars_present)
|
35
|
-
assert res.failed?
|
36
|
-
msg = "The following Ansible Variables were not found: foreman_scap_client_oval_policies, foreman_scap_client_port, foreman_scap_client_server, please import them before running this action again."
|
37
|
-
assert res.fail_msg, msg
|
38
|
-
assert override_results(check_collection.checks).all?(&:skipped?)
|
39
|
-
end
|
40
|
-
|
41
|
-
test "should fail check when fails to override a variable" do
|
42
|
-
role = FactoryBot.create(:ansible_role, :name => @config.ansible_role_name)
|
43
|
-
FactoryBot.create(:ansible_variable, :key => @config.port_param, :ansible_role => role)
|
44
|
-
FactoryBot.create(:ansible_variable, :key => @config.server_param, :ansible_role => role)
|
45
|
-
FactoryBot.create(:ansible_variable, :key => @config.policies_param, :ansible_role => role)
|
46
|
-
AnsibleVariable.any_instance.stubs(:save).returns(false)
|
47
|
-
AnsibleVariable.any_instance.stubs(:changed?).returns(true)
|
48
|
-
check_collection = ForemanOpenscap::Oval::Setup.new.run
|
49
|
-
assert check_collection.find_check(:foreman_ansible_present).passed?
|
50
|
-
assert check_collection.find_check(:foreman_scap_client_role_present).passed?
|
51
|
-
assert check_collection.find_check(:foreman_scap_client_vars_present).passed?
|
52
|
-
assert override_results(check_collection.checks).all?(&:failed?)
|
53
|
-
end
|
54
|
-
|
55
|
-
test "should pass all checks" do
|
56
|
-
role = FactoryBot.create(:ansible_role, :name => @config.ansible_role_name)
|
57
|
-
port_param = FactoryBot.create(:ansible_variable, :key => @config.port_param, :ansible_role => role)
|
58
|
-
server_param = FactoryBot.create(:ansible_variable, :key => @config.server_param, :ansible_role => role)
|
59
|
-
policies_param = FactoryBot.create(:ansible_variable, :key => @config.policies_param, :ansible_role => role)
|
60
|
-
check_collection = ForemanOpenscap::Oval::Setup.new.run
|
61
|
-
|
62
|
-
[policies_param, port_param, server_param].map(&:reload)
|
63
|
-
|
64
|
-
assert check_collection.all_passed?
|
65
|
-
|
66
|
-
assert @config.policies_param_default_value, policies_param.default_value
|
67
|
-
assert_equal 'array', policies_param.key_type
|
68
|
-
refute policies_param.hidden_value?
|
69
|
-
assert policies_param.override
|
70
|
-
|
71
|
-
refute port_param.value
|
72
|
-
assert_equal 'integer', port_param.key_type
|
73
|
-
assert port_param.override
|
74
|
-
|
75
|
-
refute server_param.hidden_value?
|
76
|
-
assert_equal 'string', server_param.key_type
|
77
|
-
assert server_param.override
|
78
|
-
end
|
79
|
-
|
80
|
-
def override_results(checks)
|
81
|
-
checks.select do |res|
|
82
|
-
res.id == :foreman_scap_client_server_overriden ||
|
83
|
-
res.id == :foreman_scap_client_port_overriden ||
|
84
|
-
res.id == :foreman_scap_client_policies_overriden
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
mutation CreateOvalPolicy($name: String!, $period: String!, $cronLine: String, $ovalContentId: Int!, $hostgroupIds: [Int!]) {
|
2
|
-
createOvalPolicy(input: {name: $name, period: $period, cronLine: $cronLine, ovalContentId: $ovalContentId, hostgroupIds: $hostgroupIds}) {
|
3
|
-
ovalPolicy {
|
4
|
-
name
|
5
|
-
id
|
6
|
-
period
|
7
|
-
cronLine
|
8
|
-
hostgroups {
|
9
|
-
nodes {
|
10
|
-
name
|
11
|
-
id
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
checkCollection {
|
16
|
-
id
|
17
|
-
errors
|
18
|
-
failMsg
|
19
|
-
result
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
mutation UpdateOvalPolicy($id: ID!, $name: String, $description: String, $cronLine: String) {
|
2
|
-
updateOvalPolicy(input:{ id:$id, name:$name, description: $description, cronLine: $cronLine }) {
|
3
|
-
ovalPolicy {
|
4
|
-
id
|
5
|
-
name
|
6
|
-
description
|
7
|
-
cronLine
|
8
|
-
}
|
9
|
-
errors {
|
10
|
-
path
|
11
|
-
message
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
#import "./currentUserAttributes.gql"
|
2
|
-
|
3
|
-
query($search: String, $first: Int, $last: Int) {
|
4
|
-
cves(search: $search, first: $first, last: $last) {
|
5
|
-
totalCount
|
6
|
-
nodes {
|
7
|
-
id
|
8
|
-
refId
|
9
|
-
refUrl
|
10
|
-
hasErrata
|
11
|
-
definitionId
|
12
|
-
hosts {
|
13
|
-
nodes {
|
14
|
-
id
|
15
|
-
name
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
20
|
-
currentUser {
|
21
|
-
...CurrentUserAttributes
|
22
|
-
}
|
23
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#import "./currentUserAttributes.gql"
|
2
|
-
|
3
|
-
query($first: Int, $last: Int) {
|
4
|
-
ovalContents(first: $first, last: $last) {
|
5
|
-
totalCount
|
6
|
-
nodes {
|
7
|
-
id
|
8
|
-
name
|
9
|
-
url
|
10
|
-
originalFilename
|
11
|
-
meta {
|
12
|
-
canDestroy
|
13
|
-
}
|
14
|
-
}
|
15
|
-
}
|
16
|
-
currentUser {
|
17
|
-
...CurrentUserAttributes
|
18
|
-
}
|
19
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
#import "./currentUserAttributes.gql"
|
2
|
-
|
3
|
-
query($first: Int, $last: Int) {
|
4
|
-
ovalPolicies(first: $first, last: $last) {
|
5
|
-
totalCount
|
6
|
-
nodes {
|
7
|
-
id
|
8
|
-
name
|
9
|
-
meta {
|
10
|
-
canDestroy
|
11
|
-
}
|
12
|
-
ovalContent {
|
13
|
-
name
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
17
|
-
currentUser {
|
18
|
-
...CurrentUserAttributes
|
19
|
-
}
|
20
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
#import "./currentUserAttributes.gql"
|
2
|
-
|
3
|
-
query($id: String!) {
|
4
|
-
ovalPolicy(id: $id) {
|
5
|
-
id
|
6
|
-
name
|
7
|
-
period
|
8
|
-
cronLine
|
9
|
-
weekday
|
10
|
-
dayOfMonth
|
11
|
-
description
|
12
|
-
meta {
|
13
|
-
canEdit
|
14
|
-
}
|
15
|
-
hostgroups {
|
16
|
-
nodes {
|
17
|
-
id
|
18
|
-
descendants {
|
19
|
-
nodes {
|
20
|
-
id
|
21
|
-
}
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
currentUser {
|
27
|
-
...CurrentUserAttributes
|
28
|
-
}
|
29
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { decodeModelId } from './globalIdHelper';
|
2
|
-
|
3
|
-
const experimental = path => `/experimental${path}`;
|
4
|
-
|
5
|
-
const showPath = path => `${path}/:id`;
|
6
|
-
const newPath = path => `${path}/new`;
|
7
|
-
|
8
|
-
export const modelPath = (basePath, model) =>
|
9
|
-
`${basePath}/${decodeModelId(model)}`;
|
10
|
-
|
11
|
-
// react-router uses path-to-regexp, should we use it as well in a future?
|
12
|
-
// https://github.com/pillarjs/path-to-regexp/tree/v1.7.0#compile-reverse-path-to-regexp
|
13
|
-
export const resolvePath = (path, params) =>
|
14
|
-
Object.entries(params).reduce(
|
15
|
-
(memo, [key, value]) => memo.replace(key, value),
|
16
|
-
path
|
17
|
-
);
|
18
|
-
|
19
|
-
export const ovalContentsApiPath = '/api/v2/compliance/oval_contents';
|
20
|
-
|
21
|
-
export const ovalContentsPath = experimental('/compliance/oval_contents');
|
22
|
-
export const ovalContentsShowPath = showPath(ovalContentsPath);
|
23
|
-
export const ovalContentsNewPath = newPath(ovalContentsPath);
|
24
|
-
export const ovalPoliciesPath = experimental('/compliance/oval_policies');
|
25
|
-
export const ovalPoliciesShowPath = `${showPath(ovalPoliciesPath)}/:tab?`;
|
26
|
-
export const ovalPoliciesNewPath = newPath(ovalPoliciesPath);
|
27
|
-
export const hostsPath = '/hosts';
|
28
|
-
export const newJobPath = newPath('/job_invocations');
|
29
|
-
export const hostsShowPath = showPath(hostsPath);
|
@@ -1,71 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import PropTypes from 'prop-types';
|
3
|
-
import { useQuery } from '@apollo/client';
|
4
|
-
import { translate as __ } from 'foremanReact/common/I18n';
|
5
|
-
|
6
|
-
import IndexLayout from '../../../components/IndexLayout';
|
7
|
-
import LinkButton from '../../../components/LinkButton';
|
8
|
-
import OvalContentsTable from './OvalContentsTable';
|
9
|
-
import { ovalContentsNewPath } from '../../../helpers/pathsHelper';
|
10
|
-
import {
|
11
|
-
useParamsToVars,
|
12
|
-
useCurrentPagination,
|
13
|
-
} from '../../../helpers/pageParamsHelper';
|
14
|
-
|
15
|
-
import { submitDelete, prepareMutation } from '../../../helpers/mutationHelper';
|
16
|
-
import ovalContentsQuery from '../../../graphql/queries/ovalContents.gql';
|
17
|
-
import deleteOvalContentMutation from '../../../graphql/mutations/deleteOvalContent.gql';
|
18
|
-
|
19
|
-
const OvalContentsIndex = props => {
|
20
|
-
const useFetchFn = componentProps =>
|
21
|
-
useQuery(ovalContentsQuery, {
|
22
|
-
variables: useParamsToVars(componentProps.history),
|
23
|
-
});
|
24
|
-
|
25
|
-
const renameData = data => ({
|
26
|
-
ovalContents: data.ovalContents.nodes,
|
27
|
-
totalCount: data.ovalContents.totalCount,
|
28
|
-
});
|
29
|
-
|
30
|
-
const pagination = useCurrentPagination(props.history);
|
31
|
-
|
32
|
-
return (
|
33
|
-
<IndexLayout pageTitle={__('OVAL Contents')}>
|
34
|
-
<OvalContentsTable
|
35
|
-
{...props}
|
36
|
-
fetchFn={useFetchFn}
|
37
|
-
renameData={renameData}
|
38
|
-
resultPath="ovalContents.nodes"
|
39
|
-
pagination={pagination}
|
40
|
-
emptyStateTitle={__('No OVAL Contents found.')}
|
41
|
-
permissions={['view_oval_contents']}
|
42
|
-
confirmDeleteTitle={__('Delete OVAL Content')}
|
43
|
-
submitDelete={submitDelete}
|
44
|
-
prepareMutation={prepareMutation(
|
45
|
-
props.history,
|
46
|
-
props.showToast,
|
47
|
-
ovalContentsQuery,
|
48
|
-
'deleteOvalContent',
|
49
|
-
__('OVAL Content successfully deleted.'),
|
50
|
-
deleteOvalContentMutation,
|
51
|
-
__('OVAL Content')
|
52
|
-
)}
|
53
|
-
primaryButton={
|
54
|
-
<LinkButton
|
55
|
-
path={ovalContentsNewPath}
|
56
|
-
btnText={__('Create OVAL Content')}
|
57
|
-
/>
|
58
|
-
}
|
59
|
-
shouldRefetch={props.location?.state?.refreshOvalContents}
|
60
|
-
/>
|
61
|
-
</IndexLayout>
|
62
|
-
);
|
63
|
-
};
|
64
|
-
|
65
|
-
OvalContentsIndex.propTypes = {
|
66
|
-
history: PropTypes.object.isRequired,
|
67
|
-
showToast: PropTypes.func.isRequired,
|
68
|
-
location: PropTypes.object.isRequired,
|
69
|
-
};
|
70
|
-
|
71
|
-
export default OvalContentsIndex;
|