foreman_openscap 8.0.2 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/app/services/foreman_openscap/client_config/ansible.rb +1 -10
  4. data/config/initializers/inflections.rb +0 -2
  5. data/config/routes.rb +0 -15
  6. data/db/migrate/20240313111822_drop_oval.rb +17 -0
  7. data/lib/foreman_openscap/engine.rb +2 -56
  8. data/lib/foreman_openscap/version.rb +1 -1
  9. data/test/factories/compliance_host_factory.rb +0 -12
  10. data/test/test_plugin_helper.rb +0 -2
  11. data/webpack/global_index.js +0 -4
  12. metadata +7 -168
  13. data/app/controllers/api/v2/compliance/oval_contents_controller.rb +0 -72
  14. data/app/controllers/api/v2/compliance/oval_policies_controller.rb +0 -111
  15. data/app/controllers/api/v2/compliance/oval_reports_controller.rb +0 -47
  16. data/app/controllers/concerns/foreman/controller/parameters/oval_content.rb +0 -22
  17. data/app/controllers/concerns/foreman/controller/parameters/oval_policy.rb +0 -22
  18. data/app/graphql/mutations/oval_contents/delete.rb +0 -9
  19. data/app/graphql/mutations/oval_policies/create.rb +0 -33
  20. data/app/graphql/mutations/oval_policies/delete.rb +0 -9
  21. data/app/graphql/mutations/oval_policies/update.rb +0 -15
  22. data/app/graphql/types/cve.rb +0 -17
  23. data/app/graphql/types/oval_check.rb +0 -11
  24. data/app/graphql/types/oval_content.rb +0 -19
  25. data/app/graphql/types/oval_policy.rb +0 -24
  26. data/app/models/concerns/foreman_openscap/oval_facet_host_extensions.rb +0 -38
  27. data/app/models/concerns/foreman_openscap/oval_facet_hostgroup_extensions.rb +0 -31
  28. data/app/models/foreman_openscap/cve.rb +0 -23
  29. data/app/models/foreman_openscap/host/oval_facet.rb +0 -14
  30. data/app/models/foreman_openscap/host_cve.rb +0 -7
  31. data/app/models/foreman_openscap/hostgroup/oval_facet.rb +0 -14
  32. data/app/models/foreman_openscap/hostgroup_oval_facet_oval_policy.rb +0 -6
  33. data/app/models/foreman_openscap/oval_content.rb +0 -28
  34. data/app/models/foreman_openscap/oval_facet_oval_policy.rb +0 -6
  35. data/app/models/foreman_openscap/oval_policy.rb +0 -54
  36. data/app/models/foreman_openscap/oval_status.rb +0 -45
  37. data/app/services/foreman_openscap/oval/check_collection.rb +0 -45
  38. data/app/services/foreman_openscap/oval/configure.rb +0 -83
  39. data/app/services/foreman_openscap/oval/cves.rb +0 -41
  40. data/app/services/foreman_openscap/oval/setup.rb +0 -93
  41. data/app/services/foreman_openscap/oval/setup_check.rb +0 -58
  42. data/app/services/foreman_openscap/oval/sync_oval_contents.rb +0 -42
  43. data/app/views/api/v2/compliance/oval_contents/base.json.rabl +0 -6
  44. data/app/views/api/v2/compliance/oval_contents/create.json.rabl +0 -3
  45. data/app/views/api/v2/compliance/oval_contents/destroy.json.rabl +0 -3
  46. data/app/views/api/v2/compliance/oval_contents/index.json.rabl +0 -3
  47. data/app/views/api/v2/compliance/oval_contents/show.json.rabl +0 -3
  48. data/app/views/api/v2/compliance/oval_contents/sync.json.rabl +0 -3
  49. data/app/views/api/v2/compliance/oval_contents/sync_result.json.rabl +0 -11
  50. data/app/views/api/v2/compliance/oval_contents/update.json.rabl +0 -3
  51. data/app/views/api/v2/compliance/oval_policies/create.json.rabl +0 -3
  52. data/app/views/api/v2/compliance/oval_policies/index.json.rabl +0 -3
  53. data/app/views/api/v2/compliance/oval_policies/main.json.rabl +0 -15
  54. data/app/views/api/v2/compliance/oval_policies/show.json.rabl +0 -3
  55. data/app/views/job_templates/run_oval_scans.erb +0 -24
  56. data/locale/cs_CZ/foreman_openscap.edit.po +0 -1863
  57. data/locale/cs_CZ/foreman_openscap.po.time_stamp +0 -0
  58. data/locale/de/foreman_openscap.edit.po +0 -1873
  59. data/locale/de/foreman_openscap.po.time_stamp +0 -0
  60. data/locale/en/foreman_openscap.edit.po +0 -1863
  61. data/locale/en/foreman_openscap.po.time_stamp +0 -0
  62. data/locale/en_GB/foreman_openscap.edit.po +0 -1863
  63. data/locale/en_GB/foreman_openscap.po.time_stamp +0 -0
  64. data/locale/es/foreman_openscap.edit.po +0 -1868
  65. data/locale/es/foreman_openscap.po.time_stamp +0 -0
  66. data/locale/fr/foreman_openscap.edit.po +0 -1874
  67. data/locale/fr/foreman_openscap.po.time_stamp +0 -0
  68. data/locale/gl/foreman_openscap.edit.po +0 -1863
  69. data/locale/gl/foreman_openscap.po.time_stamp +0 -0
  70. data/locale/it/foreman_openscap.edit.po +0 -1865
  71. data/locale/it/foreman_openscap.po.time_stamp +0 -0
  72. data/locale/ja/foreman_openscap.edit.po +0 -1869
  73. data/locale/ja/foreman_openscap.po.time_stamp +0 -0
  74. data/locale/ka/foreman_openscap.edit.po +0 -1863
  75. data/locale/ka/foreman_openscap.po.time_stamp +0 -0
  76. data/locale/ko/foreman_openscap.edit.po +0 -1863
  77. data/locale/ko/foreman_openscap.po.time_stamp +0 -0
  78. data/locale/pt_BR/foreman_openscap.edit.po +0 -1873
  79. data/locale/pt_BR/foreman_openscap.po.time_stamp +0 -0
  80. data/locale/ru/foreman_openscap.edit.po +0 -1867
  81. data/locale/ru/foreman_openscap.po.time_stamp +0 -0
  82. data/locale/sv_SE/foreman_openscap.edit.po +0 -1863
  83. data/locale/sv_SE/foreman_openscap.po.time_stamp +0 -0
  84. data/locale/zh_CN/foreman_openscap.edit.po +0 -1868
  85. data/locale/zh_CN/foreman_openscap.po.time_stamp +0 -0
  86. data/locale/zh_TW/foreman_openscap.edit.po +0 -1864
  87. data/locale/zh_TW/foreman_openscap.po.time_stamp +0 -0
  88. data/test/factories/oval_content_factory.rb +0 -7
  89. data/test/factories/oval_policy_factory.rb +0 -9
  90. data/test/fixtures/cve_fixtures.rb +0 -104
  91. data/test/functional/api/v2/compliance/oval_contents_controller_test.rb +0 -39
  92. data/test/functional/api/v2/compliance/oval_policies_controller_test.rb +0 -141
  93. data/test/functional/api/v2/compliance/oval_reports_controller_test.rb +0 -32
  94. data/test/graphql/mutations/oval_policies/delete_mutation_test.rb +0 -63
  95. data/test/graphql/queries/oval_content_query_test.rb +0 -29
  96. data/test/graphql/queries/oval_contents_query_test.rb +0 -35
  97. data/test/graphql/queries/oval_policies_query_test.rb +0 -35
  98. data/test/unit/oval_host_test.rb +0 -45
  99. data/test/unit/oval_policy_test.rb +0 -133
  100. data/test/unit/oval_status_test.rb +0 -47
  101. data/test/unit/services/oval/cves_test.rb +0 -81
  102. data/test/unit/services/oval/setup_check_test.rb +0 -37
  103. data/test/unit/services/oval/setup_test.rb +0 -87
  104. data/webpack/graphql/mutations/createOvalPolicy.gql +0 -22
  105. data/webpack/graphql/mutations/deleteOvalContent.gql +0 -9
  106. data/webpack/graphql/mutations/deleteOvalPolicy.gql +0 -9
  107. data/webpack/graphql/mutations/updateOvalPolicy.gql +0 -14
  108. data/webpack/graphql/queries/currentUserAttributes.gql +0 -11
  109. data/webpack/graphql/queries/cves.gql +0 -23
  110. data/webpack/graphql/queries/hostgroups.gql +0 -14
  111. data/webpack/graphql/queries/ovalContent.gql +0 -8
  112. data/webpack/graphql/queries/ovalContents.gql +0 -19
  113. data/webpack/graphql/queries/ovalPolicies.gql +0 -20
  114. data/webpack/graphql/queries/ovalPolicy.gql +0 -29
  115. data/webpack/helpers/pathsHelper.js +0 -29
  116. data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsIndex.js +0 -71
  117. data/webpack/routes/OvalContents/OvalContentsIndex/OvalContentsTable.js +0 -83
  118. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsDestroy.fixtures.js +0 -105
  119. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsDestroy.test.js +0 -124
  120. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.fixtures.js +0 -127
  121. data/webpack/routes/OvalContents/OvalContentsIndex/__tests__/OvalContentsIndex.test.js +0 -89
  122. data/webpack/routes/OvalContents/OvalContentsIndex/index.js +0 -13
  123. data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNew.js +0 -138
  124. data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNew.scss +0 -3
  125. data/webpack/routes/OvalContents/OvalContentsNew/OvalContentsNewHelper.js +0 -73
  126. data/webpack/routes/OvalContents/OvalContentsNew/__tests__/OvalContentsNew.test.js +0 -104
  127. data/webpack/routes/OvalContents/OvalContentsNew/index.js +0 -13
  128. data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShow.js +0 -62
  129. data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShow.test.js +0 -45
  130. data/webpack/routes/OvalContents/OvalContentsShow/OvalContentsShowHelper.js +0 -0
  131. data/webpack/routes/OvalContents/OvalContentsShow/index.js +0 -35
  132. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesIndex.js +0 -62
  133. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/OvalPoliciesTable.js +0 -74
  134. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesDestroy.fixtures.js +0 -101
  135. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesDestroy.test.js +0 -117
  136. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.fixtures.js +0 -111
  137. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/__tests__/OvalPoliciesIndex.test.js +0 -81
  138. data/webpack/routes/OvalPolicies/OvalPoliciesIndex/index.js +0 -13
  139. data/webpack/routes/OvalPolicies/OvalPoliciesNew/HostgroupSelect.js +0 -135
  140. data/webpack/routes/OvalPolicies/OvalPoliciesNew/NewOvalPolicyForm.js +0 -119
  141. data/webpack/routes/OvalPolicies/OvalPoliciesNew/NewOvalPolicyFormHelpers.js +0 -107
  142. data/webpack/routes/OvalPolicies/OvalPoliciesNew/OvalPoliciesNew.js +0 -32
  143. data/webpack/routes/OvalPolicies/OvalPoliciesNew/__tests__/OvalPoliciesNew.fixtures.js +0 -147
  144. data/webpack/routes/OvalPolicies/OvalPoliciesNew/__tests__/OvalPoliciesNew.test.js +0 -172
  145. data/webpack/routes/OvalPolicies/OvalPoliciesNew/index.js +0 -11
  146. data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTab.js +0 -49
  147. data/webpack/routes/OvalPolicies/OvalPoliciesShow/CvesTable.js +0 -63
  148. data/webpack/routes/OvalPolicies/OvalPoliciesShow/DetailsTab.js +0 -87
  149. data/webpack/routes/OvalPolicies/OvalPoliciesShow/HostgroupsTab.js +0 -49
  150. data/webpack/routes/OvalPolicies/OvalPoliciesShow/HostgroupsTable.js +0 -38
  151. data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShow.js +0 -82
  152. data/webpack/routes/OvalPolicies/OvalPoliciesShow/OvalPoliciesShowHelper.js +0 -117
  153. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesEdit.fixtures.js +0 -48
  154. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesEdit.test.js +0 -202
  155. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.fixtures.js +0 -124
  156. data/webpack/routes/OvalPolicies/OvalPoliciesShow/__tests__/OvalPoliciesShow.test.js +0 -172
  157. data/webpack/routes/OvalPolicies/OvalPoliciesShow/index.js +0 -39
  158. data/webpack/routes/routes.js +0 -49
File without changes
@@ -1,7 +0,0 @@
1
- FactoryBot.define do
2
- factory :oval_content, :class => ::ForemanOpenscap::OvalContent do |f|
3
- f.sequence(:name) { |n| "oval_content_#{n}" }
4
- f.original_filename { 'test-oval.xml' }
5
- f.scap_file { '<xml>foo</xml>' }
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- FactoryBot.define do
2
- factory :oval_policy, :class => ::ForemanOpenscap::OvalPolicy do
3
- sequence(:name) { |n| "policy#{n}" }
4
- period { 'weekly' }
5
- weekday { 'monday' }
6
- day_of_month { nil }
7
- cron_line { nil }
8
- end
9
- end
@@ -1,104 +0,0 @@
1
- module ForemanOpenscap
2
- class CveFixtures
3
- def res_one(result_state = 'true')
4
- init_result(
5
- { "references" => [
6
- { "ref_id" => "RHSA-2020:0215", "ref_url" => "https://access.redhat.com/errata/RHSA-2020:0215" },
7
- { "ref_id" => "CVE-2019-16541", "ref_url" => "https://access.redhat.com/security/cve/CVE-2019-16541" },
8
- { "ref_id" => "CVE-2020-14040", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-14040" },
9
- { "ref_id" => "CVE-2020-14370", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-14370" },
10
- { "ref_id" => "CVE-2020-15586", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-15586" },
11
- { "ref_id" => "CVE-2020-16845", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-16845" },
12
- { "ref_id" => "CVE-2020-2252", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2252" },
13
- { "ref_id" => "CVE-2020-2254", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2254" },
14
- { "ref_id" => "CVE-2020-2255", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2255" },
15
- { "ref_id" => "CVE-2020-8564", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-8564" }
16
- ] },
17
- result_state,
18
- "oval:com.redhat.rhsa:def:20201545"
19
- )
20
- end
21
-
22
- def res_two(result_state = 'true')
23
- init_result(
24
- { "references" => [
25
- { "ref_id" => "RHSA-2020:3601", "ref_url" => "https://access.redhat.com/errata/RHSA-2020:3601" },
26
- { "ref_id" => "CVE-2020-2181", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2181" },
27
- { "ref_id" => "CVE-2020-2182", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2182" },
28
- { "ref_id" => "CVE-2020-2224", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2224" },
29
- { "ref_id" => "CVE-2020-2225", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2225" },
30
- { "ref_id" => "CVE-2020-2226", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2226" }
31
- ] },
32
- result_state,
33
- "oval:com.redhat.rhsa:def:20201544"
34
- )
35
- end
36
-
37
- def res_three(result_state = 'true')
38
- init_result(
39
- { "references" => [
40
- { "ref_id" => "CVE-2019-17638", "ref_url" => "https://access.redhat.com/security/cve/CVE-2019-17638" },
41
- { "ref_id" => "CVE-2020-2229", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2229" },
42
- { "ref_id" => "CVE-2020-2230", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2230" },
43
- { "ref_id" => "CVE-2020-2231", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2231" }
44
- ] },
45
- result_state,
46
- "oval:com.redhat.rhsa:def:20201543"
47
- )
48
- end
49
-
50
- def res_four(result_state = 'true')
51
- init_result(
52
- { "references" => [
53
- { "ref_id" => "RHSA-2020:3601", "ref_url" => "https://access.redhat.com/errata/RHSA-2020:3601" },
54
- { "ref_id" => "CVE-2019-17638", "ref_url" => "https://access.redhat.com/security/cve/CVE-2019-17638" },
55
- { "ref_id" => "CVE-2020-2220", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2220" },
56
- { "ref_id" => "CVE-2020-2221", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2221" },
57
- { "ref_id" => "CVE-2020-2222", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2222" },
58
- { "ref_id" => "CVE-2020-2223", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2223" },
59
- { "ref_id" => "CVE-2020-2229", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2229" },
60
- { "ref_id" => "CVE-2020-2230", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2230" },
61
- { "ref_id" => "CVE-2020-2231", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2231" },
62
- { "ref_id" => "CVE-2020-8557", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-8557" }
63
- ] },
64
- result_state,
65
- "oval:com.redhat.rhsa:def:20201542"
66
- )
67
- end
68
-
69
- def res_five(result_state = 'true')
70
- init_result(
71
- { "references" => [
72
- { "ref_id" => "CVE-2020-2181", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2181" },
73
- { "ref_id" => "CVE-2020-2182", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2182" },
74
- { "ref_id" => "CVE-2020-2190", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2190" },
75
- { "ref_id" => "CVE-2020-2224", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2224" },
76
- { "ref_id" => "CVE-2020-2225", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2225" },
77
- { "ref_id" => "CVE-2020-2226", "ref_url" => "https://access.redhat.com/security/cve/CVE-2020-2226" }
78
- ] },
79
- result_state,
80
- "oval:com.redhat.rhsa:def:20201541"
81
- )
82
- end
83
-
84
- def one
85
- [res_one, res_two, res_three, res_four, res_five]
86
- end
87
-
88
- def two
89
- [res_one('false'), res_two, res_three('false')]
90
- end
91
-
92
- def ids_from(fixture)
93
- fixture['references'].pluck('ref_id')
94
- end
95
-
96
- private
97
-
98
- def init_result(data, result_state, definition_id)
99
- data['result'] = result_state
100
- data['definition_id'] = definition_id
101
- data
102
- end
103
- end
104
- end
@@ -1,39 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'tempfile'
3
-
4
- class Api::V2::Compliance::OvalContentsControllerTest < ActionController::TestCase
5
- test "should get index" do
6
- FactoryBot.create(:oval_content)
7
- get :index, :session => set_session_user
8
- response = ActiveSupport::JSON.decode(@response.body)
9
- assert response['results'].any?
10
- assert_response :success
11
- end
12
-
13
- test "should create OVAL content" do
14
- post :create, :params => { :oval_content => { :name => 'OVAL test', :scap_file => content_file } }, :session => set_session_user
15
- assert_response :success
16
- end
17
-
18
- test "should update OVAL content" do
19
- new_name = 'RHEL7 OVAL'
20
- oval_content = FactoryBot.create(:oval_content)
21
- put :update, :params => { :id => oval_content.id, :oval_content => { :name => new_name } }, :session => set_session_user
22
- assert_response :success
23
- assert oval_content.name, new_name
24
- end
25
-
26
- test "should destory OVAL content" do
27
- oval_content = FactoryBot.create(:oval_content)
28
- delete :destroy, :params => { :id => oval_content.id }, :session => set_session_user
29
- assert_response :ok
30
- refute ForemanOpenscap::OvalContent.exists?(oval_content.id)
31
- end
32
-
33
- def content_file
34
- file = Tempfile.new('test')
35
- file.write('<xml>test</xml>')
36
- file.rewind
37
- Rack::Test::UploadedFile.new(file, '')
38
- end
39
- end
@@ -1,141 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'base64'
3
-
4
- class Api::V2::Compliance::OvalPoliciesControllerTest < ActionController::TestCase
5
- setup do
6
- @file = Base64.encode64(read_oval_content('ansible-2.9.oval.xml.bz2'))
7
- oval_content = FactoryBot.create(:oval_content, :scap_file => @file)
8
- @attributes = { :oval_policy => { :name => 'my_policy', :period => 'weekly', :weekday => 'friday', :oval_content_id => oval_content.id } }
9
- @config = ForemanOpenscap::ClientConfig::Ansible.new(::ForemanOpenscap::OvalPolicy)
10
- @policy = FactoryBot.create(:oval_policy, :oval_content => oval_content)
11
- end
12
-
13
- test "should get index of OVAL policies" do
14
- get :index, :session => set_session_user
15
- response = ActiveSupport::JSON.decode(@response.body)
16
- assert !response['results'].empty?
17
- assert_response :success
18
- end
19
-
20
- test "should show OVAL policy" do
21
- get :show, :params => { :id => @policy.to_param }, :session => set_session_user
22
- response = ActiveSupport::JSON.decode(@response.body)
23
- assert response['name'], @policy.name
24
- assert_response :success
25
- end
26
-
27
- test "should update OVAL policy" do
28
- put :update, :params => { :id => @policy.id, :oval_policy => { :period => 'monthly', :day_of_month => 15 } }
29
- updated_policy = ActiveSupport::JSON.decode(@response.body)
30
- assert(updated_policy['period'], 'monthly')
31
- assert_response :ok
32
- end
33
-
34
- test "should not update invalid OVAL policy" do
35
- put :update, :params => { :id => @policy.id, :oval_policy => { :name => '' } }
36
- assert_response :unprocessable_entity
37
- end
38
-
39
- test "should create OVAL policy" do
40
- post :create, :params => @attributes, :session => set_session_user
41
- assert_response :created
42
- end
43
-
44
- test "should not create invalid OVAL policy" do
45
- post :create, :session => set_session_user
46
- assert_response :unprocessable_entity
47
- end
48
-
49
- test "should destroy OVAL policy" do
50
- delete :destroy, :params => { :id => @policy.id }, :session => set_session_user
51
- assert_response :ok
52
- refute ForemanOpenscap::OvalPolicy.exists?(@policy.id)
53
- end
54
-
55
- test "should return error when OVAL policy not found" do
56
- get :show, :params => { :id => @policy.id + 1 }, :session => set_session_user
57
- response = ActiveSupport::JSON.decode(@response.body)
58
- assert response['error']
59
- assert_response :missing
60
- end
61
-
62
- test "should assign policy to multiple hosts correctly" do
63
- proxy = FactoryBot.create(:openscap_proxy)
64
- host1 = FactoryBot.create(:compliance_host, :openscap_proxy => proxy)
65
- host2 = FactoryBot.create(:compliance_host, :openscap_proxy => proxy)
66
- setup_ansible
67
-
68
- assert_empty host1.oval_policies
69
- assert_empty host2.oval_policies
70
-
71
- post :assign_hosts, :params => { :id => @policy.id, :host_ids => [host1, host2].pluck(:id) }, :session => set_session_user
72
- assert_equal "OVAL policy successfully configured with hosts.", ActiveSupport::JSON.decode(@response.body)['message']
73
-
74
- assert_equal 2, host1.lookup_values.count
75
- server_value = @server_key.lookup_values.find_by :match => "fqdn=#{host1.name}"
76
- port_value = @port_key.lookup_values.find_by :match => "fqdn=#{host1.name}"
77
- assert_equal proxy.hostname, server_value.value
78
- assert_equal proxy.port, port_value.value
79
- end
80
-
81
- test "should assign policy to multiple hostgroups correctly" do
82
- proxy = FactoryBot.create(:openscap_proxy)
83
- hg1 = FactoryBot.create(:hostgroup, :openscap_proxy => proxy)
84
- hg2 = FactoryBot.create(:hostgroup, :openscap_proxy => proxy)
85
- setup_ansible
86
-
87
- assert_empty hg1.oval_policies
88
- assert_empty hg2.oval_policies
89
-
90
- post :assign_hostgroups, :params => { :id => @policy.id, :hostgroup_ids => [hg1, hg2].pluck(:id) }, :session => set_session_user
91
- assert_equal "OVAL policy successfully configured with hostgroups.", ActiveSupport::JSON.decode(@response.body)['message']
92
-
93
- assert_equal 2, hg1.lookup_values.count
94
- server_value = @server_key.lookup_values.find_by :match => "hostgroup=#{hg1.name}"
95
- port_value = @port_key.lookup_values.find_by :match => "hostgroup=#{hg1.name}"
96
- assert_equal proxy.hostname, server_value.value
97
- assert_equal proxy.port, port_value.value
98
- end
99
-
100
- test "should not assign policy to hostgroup without openscap proxy" do
101
- hg = FactoryBot.create(:hostgroup)
102
- setup_ansible
103
-
104
- assert_empty hg.oval_policies
105
-
106
- post :assign_hostgroups, :params => { :id => @policy.id, :hostgroup_ids => hg.id }, :session => set_session_user
107
- res = ActiveSupport::JSON.decode(@response.body)['results'].first
108
- assert_equal "Was Hostgroup configured successfully?", res['title']
109
- assert_equal "fail", res['result']
110
- assert_equal "Assign openscap_proxy to #{hg.name} before proceeding.", res['fail_message']
111
- hg.reload
112
- assert_empty hg.oval_policies
113
- end
114
-
115
- test "should not assign policy to hostgroup when ansible role not present" do
116
- hg = FactoryBot.create(:hostgroup)
117
- assert_empty hg.oval_policies
118
-
119
- post :assign_hostgroups, :params => { :id => @policy.id, :hostgroup_ids => hg.id }, :session => set_session_user
120
- res = ActiveSupport::JSON.decode(@response.body)['results'].first
121
- assert_equal 'theforeman.foreman_scap_client Ansible Role not found, please import it before running this action again.', res['fail_message']
122
- hg.reload
123
- assert_empty hg.oval_policies
124
- end
125
-
126
- test "should show oval content" do
127
- get :oval_content, :params => { :id => @policy.id }
128
- assert response.body, @file
129
- end
130
-
131
- def setup_ansible
132
- @ansible_role = FactoryBot.create(:ansible_role, :name => @config.ansible_role_name)
133
- @port_key = FactoryBot.create(:ansible_variable, :key => @config.port_param, :ansible_role => @ansible_role)
134
- @server_key = FactoryBot.create(:ansible_variable, :key => @config.server_param, :ansible_role => @ansible_role)
135
- FactoryBot.create(:ansible_variable, :key => @config.policies_param, :ansible_role => @ansible_role)
136
- end
137
-
138
- def read_oval_content(file_name)
139
- File.read "#{ForemanOpenscap::Engine.root}/test/files/oval_contents/#{file_name}"
140
- end
141
- end
@@ -1,32 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class Api::V2::Compliance::OvalReportsControllerTest < ActionController::TestCase
4
- setup do
5
- @params = {
6
- :oval_results => ForemanOpenscap::CveFixtures.new.one,
7
- :oval_policy_id => 5,
8
- :date => Time.now.to_i
9
- }
10
- end
11
-
12
- test 'should accept new CVEs for host' do
13
- host = FactoryBot.create(:host)
14
- post :create, :params => @params.merge(:cname => host.name), :session => set_session_user
15
-
16
- response = ActiveSupport::JSON.decode(@response.body)
17
- assert_equal 'ok', response['result']
18
- assert_response :success
19
- end
20
-
21
- test 'should show host errors on CVEs upload' do
22
- proxy = FactoryBot.create(:smart_proxy)
23
- host = FactoryBot.create(:host, :puppet_proxy => proxy)
24
- SmartProxy.any_instance.stubs(:smart_proxy_features).returns([])
25
- post :create, :params => @params.merge(:cname => host.name), :session => set_session_user
26
-
27
- response = ActiveSupport::JSON.decode(@response.body)
28
- assert_equal 'fail', response['result']
29
- refute response['errors'].empty?
30
- assert_response :unprocessable_entity
31
- end
32
- end
@@ -1,63 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Mutations
4
- module OvalPolicies
5
- class DeleteMutationTest < ActiveSupport::TestCase
6
- let(:policy) { FactoryBot.create(:oval_policy, :oval_content => FactoryBot.create(:oval_content)) }
7
- let(:policy_id) { Foreman::GlobalId.for(policy) }
8
- let(:variables) do
9
- {
10
- id: policy_id,
11
- }
12
- end
13
- let(:query) do
14
- <<-GRAPHQL
15
- mutation DeleteOvalPolicyMutation($id:ID!){
16
- deleteOvalPolicy(input:{id:$id}) {
17
- id
18
- errors {
19
- message
20
- path
21
- }
22
- }
23
- }
24
- GRAPHQL
25
- end
26
-
27
- context 'with admin user' do
28
- let(:user) { FactoryBot.create(:user, :admin) }
29
-
30
- test 'should delete oval policy' do
31
- context = { current_user: user }
32
-
33
- policy
34
-
35
- assert_difference('::ForemanOpenscap::OvalPolicy.count', -1) do
36
- result = ForemanGraphqlSchema.execute(query, variables: variables, context: context)
37
- assert_empty result['errors']
38
- assert_empty result['data']['deleteOvalPolicy']['errors']
39
- assert_equal policy_id, result['data']['deleteOvalPolicy']['id']
40
- end
41
- assert_equal user.id, Audit.last.user_id
42
- end
43
- end
44
-
45
- context 'with user with view permissions' do
46
- setup do
47
- policy
48
- @user = setup_user 'view', 'oval_policies'
49
- end
50
-
51
- test 'should not delete oval policy' do
52
- context = { current_user: @user }
53
-
54
- assert_difference('ForemanOpenscap::OvalPolicy.count', 0) do
55
- result = ForemanGraphqlSchema.execute(query, variables: variables, context: context)
56
- assert_not_empty result['errors']
57
- assert_includes result['errors'].map { |error| error['message'] }.to_sentence, 'Unauthorized.'
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,29 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Queries
4
- class OvalContentQueryTest < GraphQLQueryTestCase
5
- let(:query) do
6
- <<-GRAPHQL
7
- query($id:String!) {
8
- ovalContent(id: $id) {
9
- id
10
- name
11
- originalFilename
12
- url
13
- }
14
- }
15
- GRAPHQL
16
- end
17
-
18
- let(:oval_content) { FactoryBot.create(:oval_content) }
19
-
20
- let(:global_id) { Foreman::GlobalId.for(oval_content) }
21
- let(:variables) { { id: global_id } }
22
- let(:data) { result['data']['ovalContent'] }
23
-
24
- test 'should return OVAL Content' do
25
- assert_equal global_id, data['id']
26
- assert_equal oval_content.name, data['name']
27
- end
28
- end
29
- end
@@ -1,35 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Queries
4
- class OvalContentsQueryTest < GraphQLQueryTestCase
5
- let(:query) do
6
- <<-GRAPHQL
7
- query {
8
- ovalContents {
9
- totalCount
10
- nodes {
11
- id
12
- name
13
- }
14
- }
15
- }
16
- GRAPHQL
17
- end
18
-
19
- let(:data) { result['data']['ovalContents'] }
20
-
21
- setup do
22
- FactoryBot.create_list(:oval_content, 2)
23
- end
24
-
25
- test 'should fetch oval contentes' do
26
- assert_empty result['errors']
27
-
28
- expected_count = ForemanOpenscap::OvalContent.count
29
-
30
- assert_not_equal 0, expected_count
31
- assert_equal expected_count, data['totalCount']
32
- assert_equal expected_count, data['nodes'].count
33
- end
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Queries
4
- class OvalPoliciesQueryTest < GraphQLQueryTestCase
5
- let(:query) do
6
- <<-GRAPHQL
7
- query {
8
- ovalPolicies {
9
- totalCount
10
- nodes {
11
- id
12
- name
13
- }
14
- }
15
- }
16
- GRAPHQL
17
- end
18
-
19
- let(:data) { result['data']['ovalPolicies'] }
20
-
21
- setup do
22
- FactoryBot.create_list(:oval_policy, 2, :oval_content => FactoryBot.create(:oval_content))
23
- end
24
-
25
- test 'should fetch oval policies' do
26
- assert_empty result['errors']
27
-
28
- expected_count = ForemanOpenscap::OvalPolicy.count
29
-
30
- assert_not_equal 0, expected_count
31
- assert_equal expected_count, data['totalCount']
32
- assert_equal expected_count, data['nodes'].count
33
- end
34
- end
35
- end
@@ -1,45 +0,0 @@
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