foreman_openscap 4.1.0 → 4.3.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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/foreman_openscap/policy.css +5 -0
  3. data/app/controllers/api/v2/compliance/oval_contents_controller.rb +72 -0
  4. data/app/controllers/api/v2/compliance/oval_policies_controller.rb +111 -0
  5. data/app/controllers/api/v2/compliance/oval_reports_controller.rb +47 -0
  6. data/app/controllers/api/v2/compliance/scap_contents_controller.rb +2 -0
  7. data/app/controllers/concerns/foreman/controller/parameters/oval_content.rb +22 -0
  8. data/app/controllers/concerns/foreman/controller/parameters/oval_policy.rb +22 -0
  9. data/app/controllers/concerns/foreman_openscap/hosts_controller_extensions.rb +1 -1
  10. data/app/graphql/types/cve.rb +17 -0
  11. data/app/graphql/types/oval_content.rb +17 -0
  12. data/app/graphql/types/oval_policy.rb +21 -0
  13. data/app/helpers/arf_reports_helper.rb +7 -24
  14. data/app/helpers/policies_helper.rb +4 -17
  15. data/app/mailers/foreman_openscap/policy_mailer.rb +2 -2
  16. data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +1 -1
  17. data/app/models/concerns/foreman_openscap/data_stream_content.rb +0 -17
  18. data/app/models/concerns/foreman_openscap/host_extensions.rb +11 -11
  19. data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +3 -5
  20. data/app/models/concerns/foreman_openscap/inherited_policies.rb +11 -0
  21. data/app/models/concerns/foreman_openscap/oval_facet_host_extensions.rb +38 -0
  22. data/app/models/concerns/foreman_openscap/oval_facet_hostgroup_extensions.rb +15 -0
  23. data/app/models/concerns/foreman_openscap/policy_common.rb +75 -0
  24. data/app/models/concerns/foreman_openscap/scap_file_content.rb +24 -0
  25. data/app/models/foreman_openscap/arf_report.rb +2 -2
  26. data/app/models/foreman_openscap/cve.rb +23 -0
  27. data/app/models/foreman_openscap/host/oval_facet.rb +14 -0
  28. data/app/models/foreman_openscap/host_cve.rb +7 -0
  29. data/app/models/foreman_openscap/hostgroup/oval_facet.rb +14 -0
  30. data/app/models/foreman_openscap/hostgroup_oval_facet_oval_policy.rb +6 -0
  31. data/app/models/foreman_openscap/oval_content.rb +26 -0
  32. data/app/models/foreman_openscap/oval_facet_oval_policy.rb +6 -0
  33. data/app/models/foreman_openscap/oval_policy.rb +54 -0
  34. data/app/models/foreman_openscap/oval_status.rb +45 -0
  35. data/app/models/foreman_openscap/policy.rb +10 -73
  36. data/app/models/foreman_openscap/scap_content.rb +1 -0
  37. data/app/models/foreman_openscap/tailoring_file.rb +1 -0
  38. data/app/services/foreman_openscap/client_config/ansible.rb +39 -6
  39. data/app/services/foreman_openscap/client_config/base.rb +5 -1
  40. data/app/services/foreman_openscap/client_config/puppet.rb +2 -1
  41. data/app/services/foreman_openscap/config_name_service.rb +1 -1
  42. data/app/services/foreman_openscap/hostgroup_overrider.rb +2 -24
  43. data/app/services/foreman_openscap/hostgroup_overrider_common.rb +28 -0
  44. data/app/services/foreman_openscap/lookup_key_overrider.rb +30 -62
  45. data/app/services/foreman_openscap/lookup_key_overrides_common.rb +63 -0
  46. data/app/services/foreman_openscap/oval/check_collection.rb +45 -0
  47. data/app/services/foreman_openscap/oval/configure.rb +80 -0
  48. data/app/services/foreman_openscap/oval/cves.rb +41 -0
  49. data/app/services/foreman_openscap/oval/setup.rb +93 -0
  50. data/app/services/foreman_openscap/oval/setup_check.rb +55 -0
  51. data/app/services/foreman_openscap/oval/sync_oval_contents.rb +42 -0
  52. data/app/views/api/v2/compliance/oval_contents/base.json.rabl +6 -0
  53. data/app/views/api/v2/compliance/oval_contents/create.json.rabl +3 -0
  54. data/app/views/api/v2/compliance/oval_contents/index.json.rabl +3 -0
  55. data/app/views/api/v2/compliance/oval_contents/show.json.rabl +3 -0
  56. data/app/views/api/v2/compliance/oval_contents/sync.json.rabl +3 -0
  57. data/app/views/api/v2/compliance/oval_contents/sync_result.json.rabl +11 -0
  58. data/app/views/api/v2/compliance/oval_contents/update.json.rabl +3 -0
  59. data/app/views/api/v2/compliance/oval_policies/create.json.rabl +3 -0
  60. data/app/views/api/v2/compliance/oval_policies/index.json.rabl +3 -0
  61. data/app/views/api/v2/compliance/oval_policies/main.json.rabl +15 -0
  62. data/app/views/api/v2/compliance/oval_policies/show.json.rabl +3 -0
  63. data/app/views/api/v2/compliance/policies/base.json.rabl +2 -2
  64. data/app/views/api/v2/compliance/policies_common/_attrs.json.rabl +2 -0
  65. data/app/views/arf_reports/_output.html.erb +9 -1
  66. data/app/views/arf_reports/show.html.erb +1 -1
  67. data/app/views/arf_reports/show_html.html.erb +1 -0
  68. data/app/views/compliance_hosts/show.html.erb +1 -8
  69. data/app/views/job_templates/run_oval_scans.erb +24 -0
  70. data/app/views/policies/edit.html.erb +3 -2
  71. data/app/views/policies/show.html.erb +3 -1
  72. data/app/views/policies/steps/_deployment_options_form.html.erb +2 -2
  73. data/app/views/scap_contents/edit.html.erb +2 -12
  74. data/app/views/tailoring_files/edit.html.erb +2 -10
  75. data/config/initializers/inflections.rb +12 -0
  76. data/config/routes.rb +19 -0
  77. data/db/migrate/20201019074925_create_oval_policy.rb +13 -0
  78. data/db/migrate/20201020113801_create_oval_facet.rb +14 -0
  79. data/db/migrate/20201021084109_create_hostgroup_oval_facet.rb +14 -0
  80. data/db/migrate/20201106080924_create_oval_content.rb +12 -0
  81. data/db/migrate/20201116110256_add_oval_content_to_oval_policy.rb +5 -0
  82. data/db/migrate/20201120080329_create_cves.rb +13 -0
  83. data/db/migrate/20201202110213_update_puppet_port_param_type.rb +24 -0
  84. data/db/migrate/20201217130800_add_has_errata_to_cve.rb +8 -0
  85. data/db/migrate/20201217161511_add_url_to_oval_content.rb +5 -0
  86. data/db/migrate/20210409095625_add_oval_policy_reference_to_cve.rb +7 -0
  87. data/db/seeds.d/75-job_templates.rb +3 -2
  88. data/lib/foreman_openscap/bulk_upload.rb +2 -2
  89. data/lib/foreman_openscap/engine.rb +80 -22
  90. data/lib/foreman_openscap/version.rb +1 -1
  91. data/lib/tasks/foreman_openscap_tasks.rake +14 -9
  92. data/locale/de/LC_MESSAGES/foreman_openscap.mo +0 -0
  93. data/locale/de/foreman_openscap.edit.po +0 -0
  94. data/locale/de/foreman_openscap.po +215 -17
  95. data/locale/en_GB/LC_MESSAGES/foreman_openscap.mo +0 -0
  96. data/locale/en_GB/foreman_openscap.edit.po +0 -0
  97. data/locale/en_GB/foreman_openscap.po +213 -15
  98. data/locale/es/LC_MESSAGES/foreman_openscap.mo +0 -0
  99. data/locale/es/foreman_openscap.edit.po +0 -0
  100. data/locale/es/foreman_openscap.po +239 -41
  101. data/locale/foreman_openscap.pot +395 -112
  102. data/locale/fr/LC_MESSAGES/foreman_openscap.mo +0 -0
  103. data/locale/fr/foreman_openscap.edit.po +0 -0
  104. data/locale/fr/foreman_openscap.po +243 -45
  105. data/locale/gl/LC_MESSAGES/foreman_openscap.mo +0 -0
  106. data/locale/gl/foreman_openscap.edit.po +0 -0
  107. data/locale/gl/foreman_openscap.po +213 -15
  108. data/locale/it/LC_MESSAGES/foreman_openscap.mo +0 -0
  109. data/locale/it/foreman_openscap.edit.po +0 -0
  110. data/locale/it/foreman_openscap.po +213 -15
  111. data/locale/ja/LC_MESSAGES/foreman_openscap.mo +0 -0
  112. data/locale/ja/foreman_openscap.edit.po +0 -0
  113. data/locale/ja/foreman_openscap.po +262 -66
  114. data/locale/ko/LC_MESSAGES/foreman_openscap.mo +0 -0
  115. data/locale/ko/foreman_openscap.edit.po +0 -0
  116. data/locale/ko/foreman_openscap.po +214 -16
  117. data/locale/pt_BR/LC_MESSAGES/foreman_openscap.mo +0 -0
  118. data/locale/pt_BR/foreman_openscap.edit.po +0 -0
  119. data/locale/pt_BR/foreman_openscap.po +252 -54
  120. data/locale/ru/LC_MESSAGES/foreman_openscap.mo +0 -0
  121. data/locale/ru/foreman_openscap.edit.po +0 -0
  122. data/locale/ru/foreman_openscap.po +214 -16
  123. data/locale/sv_SE/LC_MESSAGES/foreman_openscap.mo +0 -0
  124. data/locale/sv_SE/foreman_openscap.edit.po +0 -0
  125. data/locale/sv_SE/foreman_openscap.po +213 -15
  126. data/locale/zh_CN/LC_MESSAGES/foreman_openscap.mo +0 -0
  127. data/locale/zh_CN/foreman_openscap.edit.po +0 -0
  128. data/locale/zh_CN/foreman_openscap.po +369 -169
  129. data/locale/zh_TW/LC_MESSAGES/foreman_openscap.mo +0 -0
  130. data/locale/zh_TW/foreman_openscap.edit.po +0 -0
  131. data/locale/zh_TW/foreman_openscap.po +214 -16
  132. data/test/factories/compliance_host_factory.rb +12 -0
  133. data/test/factories/oval_content_factory.rb +7 -0
  134. data/test/factories/oval_policy_factory.rb +9 -0
  135. data/test/files/oval_contents/ansible-2.9.oval.xml.bz2 +0 -0
  136. data/test/fixtures/cve_fixtures.rb +104 -0
  137. data/test/functional/api/v2/compliance/oval_contents_controller_test.rb +39 -0
  138. data/test/functional/api/v2/compliance/oval_policies_controller_test.rb +141 -0
  139. data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +32 -0
  140. data/test/graphql/queries/oval_contents_query_test.rb +35 -0
  141. data/test/graphql/queries/oval_policies_query_test.rb +35 -0
  142. data/test/test_plugin_helper.rb +4 -0
  143. data/test/unit/oval_host_test.rb +45 -0
  144. data/test/unit/oval_policy_test.rb +133 -0
  145. data/test/unit/oval_status_test.rb +47 -0
  146. data/test/unit/services/oval/cves_test.rb +81 -0
  147. data/test/unit/services/oval/setup_test.rb +87 -0
  148. metadata +98 -3
@@ -0,0 +1,45 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class OvalHostTest < ActiveSupport::TestCase
4
+ test 'should show oval policies in enc' do
5
+ setup_ansible
6
+
7
+ content = FactoryBot.create(:oval_content)
8
+ policy = FactoryBot.create(:oval_policy, :oval_content => content)
9
+ proxy = FactoryBot.create(:openscap_proxy)
10
+ host = FactoryBot.create(:oval_host, :ansible_roles => [@ansible_role], :openscap_proxy => proxy)
11
+ facet = FactoryBot.create(:oval_facet, :host => host, :oval_policies => [policy])
12
+
13
+ host_params = host.info["parameters"]
14
+ policies = JSON.parse(host_params[@config.policies_param])
15
+ assert_equal 1, policies.length
16
+ assert_equal policies.first["id"], policy.id
17
+
18
+ assert_equal host_params[@config.port_param], proxy.port.to_s
19
+ assert_equal host_params[@config.server_param], proxy.hostname
20
+ end
21
+
22
+ def setup_ansible
23
+ @config = ForemanOpenscap::ClientConfig::Ansible.new(::ForemanOpenscap::OvalPolicy)
24
+ @ansible_role = FactoryBot.create(:ansible_role, :name => @config.ansible_role_name)
25
+ @port_key = FactoryBot.create(
26
+ :ansible_variable,
27
+ :key => @config.port_param,
28
+ :ansible_role => @ansible_role,
29
+ :override => true
30
+ )
31
+ @server_key = FactoryBot.create(
32
+ :ansible_variable,
33
+ :key => @config.server_param,
34
+ :ansible_role => @ansible_role,
35
+ :override => true
36
+ )
37
+ @policies_param = FactoryBot.create(
38
+ :ansible_variable,
39
+ :key => @config.policies_param,
40
+ :ansible_role => @ansible_role,
41
+ :override => true,
42
+ :default_value => @config.policies_param_default_value
43
+ )
44
+ end
45
+ end
@@ -0,0 +1,133 @@
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
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,81 @@
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
@@ -0,0 +1,87 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -45,6 +45,9 @@ files:
45
45
  - app/assets/stylesheets/foreman_openscap/reports.css
46
46
  - app/assets/stylesheets/foreman_openscap/scap_breakdown_chart.css
47
47
  - app/controllers/api/v2/compliance/arf_reports_controller.rb
48
+ - app/controllers/api/v2/compliance/oval_contents_controller.rb
49
+ - app/controllers/api/v2/compliance/oval_policies_controller.rb
50
+ - app/controllers/api/v2/compliance/oval_reports_controller.rb
48
51
  - app/controllers/api/v2/compliance/policies_controller.rb
49
52
  - app/controllers/api/v2/compliance/scap_content_profiles_controller.rb
50
53
  - app/controllers/api/v2/compliance/scap_contents_controller.rb
@@ -52,6 +55,8 @@ files:
52
55
  - app/controllers/arf_reports_controller.rb
53
56
  - app/controllers/compliance_dashboard_controller.rb
54
57
  - app/controllers/compliance_hosts_controller.rb
58
+ - app/controllers/concerns/foreman/controller/parameters/oval_content.rb
59
+ - app/controllers/concerns/foreman/controller/parameters/oval_policy.rb
55
60
  - app/controllers/concerns/foreman/controller/parameters/policy.rb
56
61
  - app/controllers/concerns/foreman/controller/parameters/policy_api.rb
57
62
  - app/controllers/concerns/foreman/controller/parameters/scap_content.rb
@@ -67,6 +72,9 @@ files:
67
72
  - app/controllers/policy_dashboard_controller.rb
68
73
  - app/controllers/scap_contents_controller.rb
69
74
  - app/controllers/tailoring_files_controller.rb
75
+ - app/graphql/types/cve.rb
76
+ - app/graphql/types/oval_content.rb
77
+ - app/graphql/types/oval_policy.rb
70
78
  - app/helpers/arf_report_dashboard_helper.rb
71
79
  - app/helpers/arf_reports_helper.rb
72
80
  - app/helpers/compliance_dashboard_helper.rb
@@ -84,14 +92,28 @@ files:
84
92
  - app/models/concerns/foreman_openscap/data_stream_content.rb
85
93
  - app/models/concerns/foreman_openscap/host_extensions.rb
86
94
  - app/models/concerns/foreman_openscap/hostgroup_extensions.rb
95
+ - app/models/concerns/foreman_openscap/inherited_policies.rb
87
96
  - app/models/concerns/foreman_openscap/log_extensions.rb
88
97
  - app/models/concerns/foreman_openscap/openscap_proxy_core_extensions.rb
89
98
  - app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb
99
+ - app/models/concerns/foreman_openscap/oval_facet_host_extensions.rb
100
+ - app/models/concerns/foreman_openscap/oval_facet_hostgroup_extensions.rb
101
+ - app/models/concerns/foreman_openscap/policy_common.rb
102
+ - app/models/concerns/foreman_openscap/scap_file_content.rb
90
103
  - app/models/concerns/foreman_openscap/smart_proxy_extensions.rb
91
104
  - app/models/foreman_openscap/arf_report.rb
92
105
  - app/models/foreman_openscap/asset.rb
93
106
  - app/models/foreman_openscap/asset_policy.rb
94
107
  - app/models/foreman_openscap/compliance_status.rb
108
+ - app/models/foreman_openscap/cve.rb
109
+ - app/models/foreman_openscap/host/oval_facet.rb
110
+ - app/models/foreman_openscap/host_cve.rb
111
+ - app/models/foreman_openscap/hostgroup/oval_facet.rb
112
+ - app/models/foreman_openscap/hostgroup_oval_facet_oval_policy.rb
113
+ - app/models/foreman_openscap/oval_content.rb
114
+ - app/models/foreman_openscap/oval_facet_oval_policy.rb
115
+ - app/models/foreman_openscap/oval_policy.rb
116
+ - app/models/foreman_openscap/oval_status.rb
95
117
  - app/models/foreman_openscap/policy.rb
96
118
  - app/models/foreman_openscap/policy_arf_report.rb
97
119
  - app/models/foreman_openscap/policy_revision.rb
@@ -106,9 +128,17 @@ files:
106
128
  - app/services/foreman_openscap/config_name_service.rb
107
129
  - app/services/foreman_openscap/host_report_dashboard/data.rb
108
130
  - app/services/foreman_openscap/hostgroup_overrider.rb
131
+ - app/services/foreman_openscap/hostgroup_overrider_common.rb
109
132
  - app/services/foreman_openscap/lookup_key_overrider.rb
133
+ - app/services/foreman_openscap/lookup_key_overrides_common.rb
110
134
  - app/services/foreman_openscap/openscap_proxy_assigned_version_check.rb
111
135
  - app/services/foreman_openscap/openscap_proxy_version_check.rb
136
+ - app/services/foreman_openscap/oval/check_collection.rb
137
+ - app/services/foreman_openscap/oval/configure.rb
138
+ - app/services/foreman_openscap/oval/cves.rb
139
+ - app/services/foreman_openscap/oval/setup.rb
140
+ - app/services/foreman_openscap/oval/setup_check.rb
141
+ - app/services/foreman_openscap/oval/sync_oval_contents.rb
112
142
  - app/services/foreman_openscap/policy_dashboard/data.rb
113
143
  - app/services/foreman_openscap/report_dashboard/data.rb
114
144
  - app/services/proxy_status/openscap_spool.rb
@@ -120,12 +150,24 @@ files:
120
150
  - app/views/api/v2/compliance/arf_reports/show.json.rabl
121
151
  - app/views/api/v2/compliance/common/_loc.json.rabl
122
152
  - app/views/api/v2/compliance/common/_org.json.rabl
153
+ - app/views/api/v2/compliance/oval_contents/base.json.rabl
154
+ - app/views/api/v2/compliance/oval_contents/create.json.rabl
155
+ - app/views/api/v2/compliance/oval_contents/index.json.rabl
156
+ - app/views/api/v2/compliance/oval_contents/show.json.rabl
157
+ - app/views/api/v2/compliance/oval_contents/sync.json.rabl
158
+ - app/views/api/v2/compliance/oval_contents/sync_result.json.rabl
159
+ - app/views/api/v2/compliance/oval_contents/update.json.rabl
160
+ - app/views/api/v2/compliance/oval_policies/create.json.rabl
161
+ - app/views/api/v2/compliance/oval_policies/index.json.rabl
162
+ - app/views/api/v2/compliance/oval_policies/main.json.rabl
163
+ - app/views/api/v2/compliance/oval_policies/show.json.rabl
123
164
  - app/views/api/v2/compliance/policies/base.json.rabl
124
165
  - app/views/api/v2/compliance/policies/children.json.rabl
125
166
  - app/views/api/v2/compliance/policies/create.json.rabl
126
167
  - app/views/api/v2/compliance/policies/index.json.rabl
127
168
  - app/views/api/v2/compliance/policies/main.json.rabl
128
169
  - app/views/api/v2/compliance/policies/show.json.rabl
170
+ - app/views/api/v2/compliance/policies_common/_attrs.json.rabl
129
171
  - app/views/api/v2/compliance/scap_content_profiles/base.json.rabl
130
172
  - app/views/api/v2/compliance/scap_content_profiles/index.json.rabl
131
173
  - app/views/api/v2/compliance/scap_content_profiles/main.json.rabl
@@ -161,6 +203,7 @@ files:
161
203
  - app/views/foreman_openscap/policy_mailer/policy_summary.erb
162
204
  - app/views/hosts/select_multiple_openscap_proxy.html.erb
163
205
  - app/views/job_templates/run_openscap_scans.erb
206
+ - app/views/job_templates/run_oval_scans.erb
164
207
  - app/views/policies/_form.html.erb
165
208
  - app/views/policies/_list.html.erb
166
209
  - app/views/policies/_scap_content_results.html.erb
@@ -199,6 +242,7 @@ files:
199
242
  - app/views/tailoring_files/index.html.erb
200
243
  - app/views/tailoring_files/new.html.erb
201
244
  - app/views/tailoring_files/welcome.html.erb
245
+ - config/initializers/inflections.rb
202
246
  - config/routes.rb
203
247
  - db/migrate/20141013172051_create_scaptimony_policies.rb
204
248
  - db/migrate/20141014105333_create_scaptimony_assets.rb
@@ -246,6 +290,16 @@ files:
246
290
  - db/migrate/20190103093409_add_deployment_option_to_policy.foreman_openscap.rb
247
291
  - db/migrate/20200117135424_migrate_port_overrides_to_int.rb
248
292
  - db/migrate/20200803065041_migrate_port_overrides_for_ansible.rb
293
+ - db/migrate/20201019074925_create_oval_policy.rb
294
+ - db/migrate/20201020113801_create_oval_facet.rb
295
+ - db/migrate/20201021084109_create_hostgroup_oval_facet.rb
296
+ - db/migrate/20201106080924_create_oval_content.rb
297
+ - db/migrate/20201116110256_add_oval_content_to_oval_policy.rb
298
+ - db/migrate/20201120080329_create_cves.rb
299
+ - db/migrate/20201202110213_update_puppet_port_param_type.rb
300
+ - db/migrate/20201217130800_add_has_errata_to_cve.rb
301
+ - db/migrate/20201217161511_add_url_to_oval_content.rb
302
+ - db/migrate/20210409095625_add_oval_policy_reference_to_cve.rb
249
303
  - db/seeds.d/75-job_templates.rb
250
304
  - db/seeds.d/openscap_feature.rb
251
305
  - db/seeds.d/openscap_policy_notification.rb
@@ -260,37 +314,52 @@ files:
260
314
  - locale/Makefile
261
315
  - locale/action_names.rb
262
316
  - locale/de/LC_MESSAGES/foreman_openscap.mo
317
+ - locale/de/foreman_openscap.edit.po
263
318
  - locale/de/foreman_openscap.po
264
319
  - locale/en_GB/LC_MESSAGES/foreman_openscap.mo
320
+ - locale/en_GB/foreman_openscap.edit.po
265
321
  - locale/en_GB/foreman_openscap.po
266
322
  - locale/es/LC_MESSAGES/foreman_openscap.mo
323
+ - locale/es/foreman_openscap.edit.po
267
324
  - locale/es/foreman_openscap.po
268
325
  - locale/foreman_openscap.pot
269
326
  - locale/fr/LC_MESSAGES/foreman_openscap.mo
327
+ - locale/fr/foreman_openscap.edit.po
270
328
  - locale/fr/foreman_openscap.po
271
329
  - locale/gl/LC_MESSAGES/foreman_openscap.mo
330
+ - locale/gl/foreman_openscap.edit.po
272
331
  - locale/gl/foreman_openscap.po
273
332
  - locale/it/LC_MESSAGES/foreman_openscap.mo
333
+ - locale/it/foreman_openscap.edit.po
274
334
  - locale/it/foreman_openscap.po
275
335
  - locale/ja/LC_MESSAGES/foreman_openscap.mo
336
+ - locale/ja/foreman_openscap.edit.po
276
337
  - locale/ja/foreman_openscap.po
277
338
  - locale/ko/LC_MESSAGES/foreman_openscap.mo
339
+ - locale/ko/foreman_openscap.edit.po
278
340
  - locale/ko/foreman_openscap.po
279
341
  - locale/pt_BR/LC_MESSAGES/foreman_openscap.mo
342
+ - locale/pt_BR/foreman_openscap.edit.po
280
343
  - locale/pt_BR/foreman_openscap.po
281
344
  - locale/ru/LC_MESSAGES/foreman_openscap.mo
345
+ - locale/ru/foreman_openscap.edit.po
282
346
  - locale/ru/foreman_openscap.po
283
347
  - locale/sv_SE/LC_MESSAGES/foreman_openscap.mo
348
+ - locale/sv_SE/foreman_openscap.edit.po
284
349
  - locale/sv_SE/foreman_openscap.po
285
350
  - locale/zanata.xml
286
351
  - locale/zh_CN/LC_MESSAGES/foreman_openscap.mo
352
+ - locale/zh_CN/foreman_openscap.edit.po
287
353
  - locale/zh_CN/foreman_openscap.po
288
354
  - locale/zh_TW/LC_MESSAGES/foreman_openscap.mo
355
+ - locale/zh_TW/foreman_openscap.edit.po
289
356
  - locale/zh_TW/foreman_openscap.po
290
357
  - test/factories/arf_report_factory.rb
291
358
  - test/factories/asset_factory.rb
292
359
  - test/factories/compliance_host_factory.rb
293
360
  - test/factories/compliance_log_factory.rb
361
+ - test/factories/oval_content_factory.rb
362
+ - test/factories/oval_policy_factory.rb
294
363
  - test/factories/policy_arf_report_factory.rb
295
364
  - test/factories/policy_factory.rb
296
365
  - test/factories/scap_content_related.rb
@@ -299,10 +368,15 @@ files:
299
368
  - test/files/arf_report/arf_report.json
300
369
  - test/files/arf_report/arf_report_msg_desc_changed.json
301
370
  - test/files/arf_report/arf_report_msg_value_changed.json
371
+ - test/files/oval_contents/ansible-2.9.oval.xml.bz2
302
372
  - test/files/scap_contents/ssg-fedora-ds.xml
303
373
  - test/files/tailoring_files/ssg-firefox-ds-tailoring-2.xml
304
374
  - test/files/tailoring_files/ssg-firefox-ds-tailoring.xml
375
+ - test/fixtures/cve_fixtures.rb
305
376
  - test/functional/api/v2/compliance/arf_reports_controller_test.rb
377
+ - test/functional/api/v2/compliance/oval_contents_controller_test.rb
378
+ - test/functional/api/v2/compliance/oval_policies_controller_test.rb
379
+ - test/functional/api/v2/compliance/oval_reports_controller_test.rb
306
380
  - test/functional/api/v2/compliance/policies_controller_test.rb
307
381
  - test/functional/api/v2/compliance/scap_content_profiles_controller_test.rb
308
382
  - test/functional/api/v2/compliance/scap_contents_controller_test.rb
@@ -311,6 +385,8 @@ files:
311
385
  - test/functional/arf_reports_controller_test.rb
312
386
  - test/functional/openscap_proxies_controller_test.rb
313
387
  - test/functional/tailoring_files_controller_test.rb
388
+ - test/graphql/queries/oval_contents_query_test.rb
389
+ - test/graphql/queries/oval_policies_query_test.rb
314
390
  - test/helpers/arf_report_dashboard_helper_test.rb
315
391
  - test/helpers/policy_dashboard_helper_test.rb
316
392
  - test/lib/foreman_openscap/bulk_upload_test.rb
@@ -322,12 +398,17 @@ files:
322
398
  - test/unit/concerns/openscap_proxy_extenstions_test.rb
323
399
  - test/unit/message_cleaner_test.rb
324
400
  - test/unit/openscap_host_test.rb
401
+ - test/unit/oval_host_test.rb
402
+ - test/unit/oval_policy_test.rb
403
+ - test/unit/oval_status_test.rb
325
404
  - test/unit/policy_mailer_test.rb
326
405
  - test/unit/policy_test.rb
327
406
  - test/unit/scap_content_test.rb
328
407
  - test/unit/services/config_name_service_test.rb
329
408
  - test/unit/services/hostgroup_overrider_test.rb
330
409
  - test/unit/services/lookup_key_overrider_test.rb
410
+ - test/unit/services/oval/cves_test.rb
411
+ - test/unit/services/oval/setup_test.rb
331
412
  - test/unit/services/report_dashboard/data_test.rb
332
413
  - test/unit/services/tailoring_files_proxy_check_test.rb
333
414
  - test/unit/tailoring_file_test.rb
@@ -357,11 +438,13 @@ summary: Foreman plug-in for displaying OpenSCAP audit reports
357
438
  test_files:
358
439
  - test/factories/arf_report_factory.rb
359
440
  - test/factories/asset_factory.rb
360
- - test/factories/compliance_host_factory.rb
361
441
  - test/factories/policy_arf_report_factory.rb
362
442
  - test/factories/policy_factory.rb
363
443
  - test/factories/scap_content_related.rb
364
444
  - test/factories/compliance_log_factory.rb
445
+ - test/factories/compliance_host_factory.rb
446
+ - test/factories/oval_content_factory.rb
447
+ - test/factories/oval_policy_factory.rb
365
448
  - test/files/arf_report/arf_report.bz2
366
449
  - test/files/arf_report/arf_report.html
367
450
  - test/files/arf_report/arf_report.json
@@ -370,11 +453,15 @@ test_files:
370
453
  - test/files/scap_contents/ssg-fedora-ds.xml
371
454
  - test/files/tailoring_files/ssg-firefox-ds-tailoring-2.xml
372
455
  - test/files/tailoring_files/ssg-firefox-ds-tailoring.xml
456
+ - test/files/oval_contents/ansible-2.9.oval.xml.bz2
373
457
  - test/functional/api/v2/compliance/policies_controller_test.rb
374
458
  - test/functional/api/v2/compliance/scap_content_profiles_controller_test.rb
375
459
  - test/functional/api/v2/compliance/scap_contents_controller_test.rb
376
460
  - test/functional/api/v2/compliance/tailoring_files_controller_test.rb
377
461
  - test/functional/api/v2/compliance/arf_reports_controller_test.rb
462
+ - test/functional/api/v2/compliance/oval_contents_controller_test.rb
463
+ - test/functional/api/v2/compliance/oval_policies_controller_test.rb
464
+ - test/functional/api/v2/compliance/oval_reports_controller_test.rb
378
465
  - test/functional/api/v2/hosts_controller_test.rb
379
466
  - test/functional/arf_reports_controller_test.rb
380
467
  - test/functional/openscap_proxies_controller_test.rb
@@ -396,6 +483,14 @@ test_files:
396
483
  - test/unit/services/lookup_key_overrider_test.rb
397
484
  - test/unit/services/report_dashboard/data_test.rb
398
485
  - test/unit/services/tailoring_files_proxy_check_test.rb
486
+ - test/unit/services/oval/cves_test.rb
487
+ - test/unit/services/oval/setup_test.rb
399
488
  - test/unit/tailoring_file_test.rb
400
489
  - test/unit/policy_test.rb
490
+ - test/unit/oval_host_test.rb
491
+ - test/unit/oval_policy_test.rb
492
+ - test/unit/oval_status_test.rb
493
+ - test/fixtures/cve_fixtures.rb
494
+ - test/graphql/queries/oval_contents_query_test.rb
495
+ - test/graphql/queries/oval_policies_query_test.rb
401
496
  - test/test_plugin_helper.rb