foreman_openscap 13.1.1 → 13.1.3

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_openscap/locale/cs_CZ/foreman_openscap.js +67 -17
  3. data/app/assets/javascripts/foreman_openscap/locale/de/foreman_openscap.js +67 -17
  4. data/app/assets/javascripts/foreman_openscap/locale/en/foreman_openscap.js +68 -18
  5. data/app/assets/javascripts/foreman_openscap/locale/en_GB/foreman_openscap.js +67 -17
  6. data/app/assets/javascripts/foreman_openscap/locale/es/foreman_openscap.js +67 -17
  7. data/app/assets/javascripts/foreman_openscap/locale/fr/foreman_openscap.js +70 -18
  8. data/app/assets/javascripts/foreman_openscap/locale/gl/foreman_openscap.js +67 -17
  9. data/app/assets/javascripts/foreman_openscap/locale/it/foreman_openscap.js +67 -17
  10. data/app/assets/javascripts/foreman_openscap/locale/ja/foreman_openscap.js +70 -22
  11. data/app/assets/javascripts/foreman_openscap/locale/ka/foreman_openscap.js +88 -38
  12. data/app/assets/javascripts/foreman_openscap/locale/ko/foreman_openscap.js +70 -22
  13. data/app/assets/javascripts/foreman_openscap/locale/pt_BR/foreman_openscap.js +67 -17
  14. data/app/assets/javascripts/foreman_openscap/locale/ru/foreman_openscap.js +67 -17
  15. data/app/assets/javascripts/foreman_openscap/locale/sv_SE/foreman_openscap.js +67 -17
  16. data/app/assets/javascripts/foreman_openscap/locale/zh_CN/foreman_openscap.js +66 -18
  17. data/app/assets/javascripts/foreman_openscap/locale/zh_TW/foreman_openscap.js +67 -17
  18. data/app/models/concerns/foreman_openscap/host_extensions.rb +10 -4
  19. data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +7 -0
  20. data/app/models/foreman_openscap/asset.rb +21 -1
  21. data/app/models/foreman_openscap/compliance_status.rb +19 -7
  22. data/app/models/foreman_openscap/policy.rb +43 -3
  23. data/app/services/foreman_openscap/compliance_status_resetter.rb +26 -0
  24. data/lib/foreman_openscap/version.rb +1 -1
  25. data/locale/cs_CZ/LC_MESSAGES/foreman_openscap.mo +0 -0
  26. data/locale/cs_CZ/foreman_openscap.po +69 -17
  27. data/locale/de/LC_MESSAGES/foreman_openscap.mo +0 -0
  28. data/locale/de/foreman_openscap.po +69 -17
  29. data/locale/en/LC_MESSAGES/foreman_openscap.mo +0 -0
  30. data/locale/en/foreman_openscap.po +70 -18
  31. data/locale/en_GB/LC_MESSAGES/foreman_openscap.mo +0 -0
  32. data/locale/en_GB/foreman_openscap.po +69 -17
  33. data/locale/es/LC_MESSAGES/foreman_openscap.mo +0 -0
  34. data/locale/es/foreman_openscap.po +69 -17
  35. data/locale/foreman_openscap.pot +154 -70
  36. data/locale/fr/LC_MESSAGES/foreman_openscap.mo +0 -0
  37. data/locale/fr/foreman_openscap.po +72 -18
  38. data/locale/gl/LC_MESSAGES/foreman_openscap.mo +0 -0
  39. data/locale/gl/foreman_openscap.po +69 -17
  40. data/locale/it/LC_MESSAGES/foreman_openscap.mo +0 -0
  41. data/locale/it/foreman_openscap.po +69 -17
  42. data/locale/ja/LC_MESSAGES/foreman_openscap.mo +0 -0
  43. data/locale/ja/foreman_openscap.po +72 -22
  44. data/locale/ka/LC_MESSAGES/foreman_openscap.mo +0 -0
  45. data/locale/ka/foreman_openscap.po +90 -38
  46. data/locale/ko/LC_MESSAGES/foreman_openscap.mo +0 -0
  47. data/locale/ko/foreman_openscap.po +72 -22
  48. data/locale/pt_BR/LC_MESSAGES/foreman_openscap.mo +0 -0
  49. data/locale/pt_BR/foreman_openscap.po +69 -17
  50. data/locale/ru/LC_MESSAGES/foreman_openscap.mo +0 -0
  51. data/locale/ru/foreman_openscap.po +69 -17
  52. data/locale/sv_SE/LC_MESSAGES/foreman_openscap.mo +0 -0
  53. data/locale/sv_SE/foreman_openscap.po +69 -17
  54. data/locale/zh_CN/LC_MESSAGES/foreman_openscap.mo +0 -0
  55. data/locale/zh_CN/foreman_openscap.po +68 -18
  56. data/locale/zh_TW/LC_MESSAGES/foreman_openscap.mo +0 -0
  57. data/locale/zh_TW/foreman_openscap.po +69 -17
  58. data/test/test_plugin_helper.rb +7 -0
  59. data/test/unit/compliance_status_resetter_test.rb +48 -0
  60. data/test/unit/compliance_status_test.rb +53 -4
  61. data/test/unit/concerns/host_extensions_test.rb +55 -0
  62. data/test/unit/concerns/hostgroup_extensions_test.rb +64 -0
  63. data/test/unit/policy_test.rb +90 -0
  64. metadata +4 -1
@@ -6,7 +6,7 @@
6
6
  # FIRST AUTHOR <EMAIL@ADDRESS>, 2016
7
7
  msgid ""
8
8
  msgstr ""
9
- "Project-Id-Version: foreman_openscap 12.0.1\n"
9
+ "Project-Id-Version: foreman_openscap 13.1.1\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
11
  "PO-Revision-Date: 2016-04-14 07:48+0000\n"
12
12
  "Last-Translator: FIRST AUTHOR <EMAIL@ADDRESS>, 2016\n"
@@ -47,6 +47,9 @@ msgstr "%s 最新報告"
47
47
  msgid "%s reports over time"
48
48
  msgstr "%s 一直以來的報告"
49
49
 
50
+ msgid "%s selected hosts."
51
+ msgstr ""
52
+
50
53
  msgid "%s spool errors detected, inspect the appropriate file directly on proxy"
51
54
  msgstr ""
52
55
 
@@ -65,6 +68,9 @@ msgstr ""
65
68
  msgid "A summary of reports for OpenSCAP policies"
66
69
  msgstr ""
67
70
 
71
+ msgid "ALL selected hosts."
72
+ msgstr ""
73
+
68
74
  msgid "Actions"
69
75
  msgstr "動作"
70
76
 
@@ -83,12 +89,21 @@ msgstr ""
83
89
  msgid "Apply policy to hosts"
84
90
  msgstr ""
85
91
 
86
- msgid "Are you sure you want to delete %s?"
92
+ msgid "Assign"
87
93
  msgstr ""
88
94
 
89
95
  msgid "Assign Compliance Policy"
90
96
  msgstr "指定合規政策"
91
97
 
98
+ msgid "Assign OpenSCAP Proxy"
99
+ msgstr ""
100
+
101
+ msgid "Assign OpenSCAP Proxy for "
102
+ msgstr ""
103
+
104
+ msgid "Assign OpenSCAP Proxy to multiple hosts"
105
+ msgstr ""
106
+
92
107
  msgid "Back"
93
108
  msgstr "上一頁"
94
109
 
@@ -164,9 +179,6 @@ msgstr "合規主機"
164
179
  msgid "Compliant with the policy"
165
180
  msgstr "合於政策"
166
181
 
167
- msgid "Confirm"
168
- msgstr ""
169
-
170
182
  msgid "Content"
171
183
  msgstr ""
172
184
 
@@ -308,6 +320,11 @@ msgstr "只有失敗"
308
320
  msgid "Failed saving %s:"
309
321
  msgstr ""
310
322
 
323
+ msgid "Failed to assign OpenSCAP Proxy to %{failed} of %{total} host."
324
+ msgid_plural "Failed to assign OpenSCAP Proxy to %{failed} of %{total} hosts."
325
+ msgstr[0] ""
326
+ msgstr[1] ""
327
+
311
328
  msgid "Failed to delete %s compliance reports"
312
329
  msgstr "刪除 %s 合規報告失敗"
313
330
 
@@ -396,12 +413,21 @@ msgstr ""
396
413
  msgid "Hosts passing this rule"
397
414
  msgstr ""
398
415
 
416
+ msgid "Hosts to explicitly exclude in the action. All other hosts will be included in the action, unless an included parameter is passed as well."
417
+ msgstr ""
418
+
419
+ msgid "Hosts to include in the action"
420
+ msgstr ""
421
+
399
422
  msgid "How the policy should be deployed"
400
423
  msgstr ""
401
424
 
402
425
  msgid "ID of OpenSCAP Proxy"
403
426
  msgstr ""
404
427
 
428
+ msgid "ID of the OpenSCAP Proxy to assign to the hosts"
429
+ msgstr ""
430
+
405
431
  msgid "In Foreman, a compliance policy checklist is defined via %s."
406
432
  msgstr ""
407
433
 
@@ -439,6 +465,9 @@ msgstr ""
439
465
  msgid "Latest reports for policy: %s"
440
466
  msgstr "最新的政策報告:%s"
441
467
 
468
+ msgid "Line chart"
469
+ msgstr ""
470
+
442
471
  msgid "List ARF reports"
443
472
  msgstr ""
444
473
 
@@ -454,6 +483,15 @@ msgstr "列出 SCAP 內容"
454
483
  msgid "List Tailoring files"
455
484
  msgstr ""
456
485
 
486
+ msgid "List of host ids to exclude and not perform the action on"
487
+ msgstr ""
488
+
489
+ msgid "List of host ids to perform the action on"
490
+ msgstr ""
491
+
492
+ msgid "Loading"
493
+ msgstr "載入中"
494
+
457
495
  msgid "Loading..."
458
496
  msgstr "載入中…"
459
497
 
@@ -499,6 +537,9 @@ msgstr "否"
499
537
  msgid "No ARF reports for this policy"
500
538
  msgstr "此政策沒有 ARF 報告"
501
539
 
540
+ msgid "No OpenSCAP Proxies available. Please configure a Smart Proxy with the OpenSCAP feature."
541
+ msgstr ""
542
+
502
543
  msgid "No OpenSCAP Proxy selected."
503
544
  msgstr ""
504
545
 
@@ -520,6 +561,9 @@ msgstr ""
520
561
  msgid "No compliance reports were found."
521
562
  msgstr ""
522
563
 
564
+ msgid "No data available"
565
+ msgstr ""
566
+
523
567
  msgid "No hosts selected"
524
568
  msgstr "未選擇主機"
525
569
 
@@ -583,9 +627,15 @@ msgstr ""
583
627
  msgid "OpenSCAP Proxy"
584
628
  msgstr ""
585
629
 
630
+ msgid "OpenSCAP Proxy is set to %s"
631
+ msgstr ""
632
+
586
633
  msgid "OpenSCAP Proxy to use for fetching SCAP content and uploading ARF reports. Leave blank and override appropriate parameters when using proxy load balancer."
587
634
  msgstr ""
588
635
 
636
+ msgid "OpenSCAP Proxy with id %s not found"
637
+ msgstr ""
638
+
589
639
  msgid "Openscap Proxy"
590
640
  msgstr ""
591
641
 
@@ -615,9 +665,6 @@ msgstr "已通過"
615
665
  msgid "Passed|P"
616
666
  msgstr "Passed|P"
617
667
 
618
- msgid "Permission denied"
619
- msgstr "使用權限被拒"
620
-
621
668
  msgid "Please Confirm"
622
669
  msgstr "請確認"
623
670
 
@@ -723,9 +770,6 @@ msgstr ""
723
770
  msgid "Reports"
724
771
  msgstr "報告"
725
772
 
726
- msgid "Request the following permissions from administrator: %s."
727
- msgstr ""
728
-
729
773
  msgid "Request timed out. Please try increasing Settings -> proxy_request_timeout"
730
774
  msgstr ""
731
775
 
@@ -795,6 +839,9 @@ msgstr ""
795
839
  msgid "Schedule"
796
840
  msgstr "排程"
797
841
 
842
+ msgid "Search string describing which hosts to perform the action on"
843
+ msgstr ""
844
+
798
845
  msgid "Select Action"
799
846
  msgstr "選擇動作"
800
847
 
@@ -876,6 +923,11 @@ msgstr "刪除 %s 合規報告成功"
876
923
  msgid "Successfully deleted ARF report."
877
924
  msgstr ""
878
925
 
926
+ msgid "Successfully updated %{success} host."
927
+ msgid_plural "Successfully updated %{success} hosts."
928
+ msgstr[0] ""
929
+ msgstr[1] ""
930
+
879
931
  msgid "Summary from %{time} ago to now"
880
932
  msgstr "%{time} 之前到現在的摘要"
881
933
 
@@ -920,13 +972,13 @@ msgstr ""
920
972
  msgid "The job has started on selected host(s), you can check the status on the job details page."
921
973
  msgstr ""
922
974
 
923
- msgid "There are significant differences in deployment options."
975
+ msgid "The selected OpenSCAP Proxy does not have the OpenSCAP feature enabled."
924
976
  msgstr ""
925
977
 
926
- msgid "There is no job to remediate with. Please remediate manually."
978
+ msgid "There are significant differences in deployment options."
927
979
  msgstr ""
928
980
 
929
- msgid "There was a following error when deleting %(name)s: %(error)s"
981
+ msgid "There is no job to remediate with. Please remediate manually."
930
982
  msgstr ""
931
983
 
932
984
  msgid "There's no available report for this host"
@@ -938,6 +990,9 @@ msgstr ""
938
990
  msgid "This profile will be used to override the one from scap content"
939
991
  msgstr ""
940
992
 
993
+ msgid "This will change previous proxy assignments on the selected hosts."
994
+ msgstr ""
995
+
941
996
  msgid "Title"
942
997
  msgstr "標題"
943
998
 
@@ -1033,9 +1088,6 @@ msgstr ""
1033
1088
  msgid "Yes"
1034
1089
  msgstr "是"
1035
1090
 
1036
- msgid "You are not authorized to view the page. "
1037
- msgstr ""
1038
-
1039
1091
  msgid "You can remediate by running a remote job or you can display a snippet for manual remediation."
1040
1092
  msgstr ""
1041
1093
 
@@ -59,6 +59,13 @@ end
59
59
  module ScapTestCommon
60
60
  private
61
61
 
62
+ def set_compliance_status(host, status)
63
+ compliance_status = host.get_status(ForemanOpenscap::ComplianceStatus)
64
+ compliance_status.status = status
65
+ compliance_status.reported_at = Time.current
66
+ compliance_status.save!
67
+ end
68
+
62
69
  def create_report_with_rules(host, rule_names, rule_results)
63
70
  raise "rule_names and rule_results should have the same length!" if rule_names.size != rule_results.size
64
71
  metrics = {
@@ -0,0 +1,48 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ComplianceStatusResetterTest < ActiveSupport::TestCase
4
+ setup do
5
+ ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
6
+ @policy = FactoryBot.create(:policy)
7
+ end
8
+
9
+ test 'creates inconclusive status for host without existing status' do
10
+ host = FactoryBot.create(:compliance_host, :policies => [@policy])
11
+
12
+ ForemanOpenscap::ComplianceStatusResetter.to_inconclusive([host.id])
13
+
14
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
15
+ end
16
+
17
+ test 'resets existing compliant status to inconclusive' do
18
+ host = FactoryBot.create(:compliance_host, :policies => [@policy])
19
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
20
+
21
+ ForemanOpenscap::ComplianceStatusResetter.to_inconclusive([host.id])
22
+
23
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
24
+ end
25
+
26
+ test 'ignores blank and duplicate host ids without error' do
27
+ host = FactoryBot.create(:compliance_host, :policies => [@policy])
28
+
29
+ ForemanOpenscap::ComplianceStatusResetter.to_inconclusive([host.id, host.id, nil])
30
+
31
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
32
+ end
33
+
34
+ test 'does nothing for an empty list of host ids' do
35
+ assert_nil ForemanOpenscap::ComplianceStatusResetter.to_inconclusive([])
36
+ end
37
+
38
+ test 'refreshes host global_status so it reflects the new inconclusive compliance status' do
39
+ host = FactoryBot.create(:compliance_host, :policies => [@policy])
40
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
41
+ host.refresh_global_status!
42
+ assert_equal ::HostStatus::Global::OK, host.reload.global_status
43
+
44
+ ForemanOpenscap::ComplianceStatusResetter.to_inconclusive([host.id])
45
+
46
+ assert_equal ::HostStatus::Global::WARN, host.reload.global_status
47
+ end
48
+ end
@@ -74,12 +74,48 @@ class ComplianceStatusTest < ActiveSupport::TestCase
74
74
  status = ForemanOpenscap::ComplianceStatus.new
75
75
  host = FactoryBot.create(:compliance_host, :policies => [@policy_a])
76
76
 
77
+ host.expects(:combined_policies).never
77
78
  status.host = host
78
79
 
79
80
  assert status.relevant?
80
81
  end
81
82
 
82
- test 'relevant? should be true for hostgroup policies and to_status should use them' do
83
+ test 'relevant? should be false for host without policies' do
84
+ status = ForemanOpenscap::ComplianceStatus.new
85
+ host = FactoryBot.create(:host)
86
+
87
+ status.host = host
88
+
89
+ refute status.relevant?
90
+ end
91
+
92
+ test 'relevant? should be false for host with hostgroup but no policies' do
93
+ status = ForemanOpenscap::ComplianceStatus.new
94
+ host = FactoryBot.create(:host, :with_hostgroup)
95
+
96
+ status.host = host
97
+
98
+ refute status.relevant?
99
+ end
100
+
101
+ test 'relevant? should be true for hostgroup policies without loading combined_policies' do
102
+ status = ForemanOpenscap::ComplianceStatus.new
103
+ host = FactoryBot.create(:host, :with_hostgroup)
104
+
105
+ assert_empty host.policies
106
+ @policy_a.hostgroup_ids = [host.hostgroup.id]
107
+ assert @policy_a.save
108
+
109
+ host.reload
110
+ assert_includes host.combined_policies, @policy_a
111
+
112
+ status.host = host
113
+ host.expects(:combined_policies).never
114
+
115
+ assert status.relevant?
116
+ end
117
+
118
+ test 'to_status should use hostgroup policies' do
83
119
  status = ForemanOpenscap::ComplianceStatus.new
84
120
  host = FactoryBot.create(:host, :with_hostgroup)
85
121
  othered_status = { :passed => 0, :failed => 0, :othered => 1 }.with_indifferent_access
@@ -95,12 +131,10 @@ class ComplianceStatusTest < ActiveSupport::TestCase
95
131
  FactoryBot.create(:policy_arf_report, :policy_id => @policy_a.id, :arf_report_id => report.id)
96
132
 
97
133
  status.host = host
98
-
99
- assert status.relevant?
100
134
  assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, status.to_status
101
135
  end
102
136
 
103
- test 'relevant? should be true for inherited parent hostgroup policies' do
137
+ test 'relevant? should be true for inherited parent hostgroup policies without loading combined_policies' do
104
138
  status = ForemanOpenscap::ComplianceStatus.new
105
139
  host = FactoryBot.create(:host, :with_hostgroup)
106
140
  hostgroup = host.hostgroup
@@ -116,7 +150,22 @@ class ComplianceStatusTest < ActiveSupport::TestCase
116
150
  assert_includes host.combined_policies, @policy_a
117
151
 
118
152
  status.host = host
153
+ host.expects(:combined_policies).never
119
154
 
120
155
  assert status.relevant?
121
156
  end
157
+
158
+ test 'to_label returns label based on stored status' do
159
+ status = ForemanOpenscap::ComplianceStatus.new
160
+ status.status = ForemanOpenscap::ComplianceStatus::COMPLIANT
161
+ status.expects(:to_status).never
162
+ assert_equal 'Compliant', status.to_label
163
+ end
164
+
165
+ test 'to_global returns global status based on stored status' do
166
+ status = ForemanOpenscap::ComplianceStatus.new
167
+ status.status = ForemanOpenscap::ComplianceStatus::COMPLIANT
168
+ status.expects(:to_status).never
169
+ assert_equal ::HostStatus::Global::OK, status.to_global
170
+ end
122
171
  end
@@ -162,6 +162,61 @@ class HostExtensionsTest < ActiveSupport::TestCase
162
162
  assert_empty ForemanOpenscap::Asset.where(:assetable_id => host.id, :assetable_type => 'Host::Base')
163
163
  end
164
164
 
165
+ test 'should reset compliance status when assigning policy through host policies' do
166
+ host = FactoryBot.create(:compliance_host)
167
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
168
+
169
+ host.policies = [@policy]
170
+
171
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
172
+ end
173
+
174
+ test 'should reset compliance status when removing policy through host policies' do
175
+ host = FactoryBot.create(:compliance_host, :policies => [@policy])
176
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
177
+
178
+ host.policies = []
179
+
180
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
181
+ end
182
+
183
+ test 'should reset compliance status when host is moved to a different hostgroup' do
184
+ old_hostgroup = FactoryBot.create(:hostgroup)
185
+ new_hostgroup = FactoryBot.create(:hostgroup)
186
+ host = FactoryBot.create(:compliance_host, :hostgroup_id => old_hostgroup.id)
187
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
188
+
189
+ host.update!(:hostgroup_id => new_hostgroup.id)
190
+
191
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, host.reload.compliance_status
192
+ end
193
+
194
+ test 'should not reset compliance status when host is saved without hostgroup change' do
195
+ hostgroup = FactoryBot.create(:hostgroup)
196
+ host = FactoryBot.create(:compliance_host, :hostgroup_id => hostgroup.id)
197
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
198
+
199
+ host.update!(:comment => 'unrelated change')
200
+
201
+ assert_equal ForemanOpenscap::ComplianceStatus::COMPLIANT, host.reload.compliance_status
202
+ end
203
+
204
+ test 'compliance_status returns stored persisted status without recalculation' do
205
+ set_compliance_status(@host, ForemanOpenscap::ComplianceStatus::INCONCLUSIVE)
206
+ status = @host.reload.get_status(ForemanOpenscap::ComplianceStatus)
207
+ status.expects(:to_status).never
208
+
209
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, @host.compliance_status
210
+ end
211
+
212
+ test 'compliance_status_label returns label from stored persisted status without recalculation' do
213
+ set_compliance_status(@host, ForemanOpenscap::ComplianceStatus::INCOMPLIANT)
214
+ status = @host.reload.get_status(ForemanOpenscap::ComplianceStatus)
215
+ status.expects(:to_status).never
216
+
217
+ assert_equal 'Incompliant', @host.compliance_status_label
218
+ end
219
+
165
220
  private
166
221
 
167
222
  def setup_hosts_with_policy
@@ -7,4 +7,68 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
7
7
  asset_scope = ::ForemanOpenscap::Asset.where(:assetable_id => hostgroup.id, :assetable_type => 'Hostgroup')
8
8
  assert_difference("asset_scope.count", -3) { hostgroup.destroy }
9
9
  end
10
+
11
+ test "should reset compliance status for subtree when assigning policy through hostgroup asset policies" do
12
+ parent = FactoryBot.create(:hostgroup)
13
+ child = FactoryBot.create(:hostgroup, :ancestry => parent.id.to_s)
14
+ parent_host = FactoryBot.create(:compliance_host, :hostgroup_id => parent.id)
15
+ child_host = FactoryBot.create(:compliance_host, :hostgroup_id => child.id)
16
+ policy = FactoryBot.create(:policy)
17
+ asset = FactoryBot.create(:asset, :assetable_id => parent.id, :assetable_type => 'Hostgroup')
18
+
19
+ set_compliance_status(parent_host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
20
+ set_compliance_status(child_host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
21
+
22
+ asset.policies = [policy]
23
+
24
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, parent_host.reload.compliance_status
25
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, child_host.reload.compliance_status
26
+ end
27
+
28
+ test "should reset compliance status for subtree when removing policy through hostgroup asset policies" do
29
+ parent = FactoryBot.create(:hostgroup)
30
+ child = FactoryBot.create(:hostgroup, :ancestry => parent.id.to_s)
31
+ parent_host = FactoryBot.create(:compliance_host, :hostgroup_id => parent.id)
32
+ child_host = FactoryBot.create(:compliance_host, :hostgroup_id => child.id)
33
+ policy = FactoryBot.create(:policy)
34
+ asset = FactoryBot.create(:asset, :assetable_id => parent.id, :assetable_type => 'Hostgroup')
35
+ asset.policies = [policy]
36
+
37
+ set_compliance_status(parent_host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
38
+ set_compliance_status(child_host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
39
+
40
+ asset.policies = []
41
+
42
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, parent_host.reload.compliance_status
43
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, child_host.reload.compliance_status
44
+ end
45
+
46
+ test "should reset compliance status for subtree when hostgroup is reparented" do
47
+ old_parent = FactoryBot.create(:hostgroup)
48
+ new_parent = FactoryBot.create(:hostgroup)
49
+ moved = FactoryBot.create(:hostgroup, :ancestry => old_parent.id.to_s)
50
+ child = FactoryBot.create(:hostgroup, :ancestry => "#{old_parent.id}/#{moved.id}")
51
+ moved_host = FactoryBot.create(:compliance_host, :hostgroup_id => moved.id)
52
+ child_host = FactoryBot.create(:compliance_host, :hostgroup_id => child.id)
53
+ unrelated_host = FactoryBot.create(:compliance_host, :hostgroup_id => old_parent.id)
54
+ [moved_host, child_host, unrelated_host].each do |host|
55
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
56
+ end
57
+
58
+ moved.update!(:parent_id => new_parent.id)
59
+
60
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, moved_host.reload.compliance_status
61
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, child_host.reload.compliance_status
62
+ assert_equal ForemanOpenscap::ComplianceStatus::COMPLIANT, unrelated_host.reload.compliance_status
63
+ end
64
+
65
+ test "should not reset compliance status for hostgroup save without ancestry change" do
66
+ hostgroup = FactoryBot.create(:hostgroup)
67
+ host = FactoryBot.create(:compliance_host, :hostgroup_id => hostgroup.id)
68
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
69
+
70
+ hostgroup.update!(:name => 'renamed')
71
+
72
+ assert_equal ForemanOpenscap::ComplianceStatus::COMPLIANT, host.reload.compliance_status
73
+ end
10
74
  end
@@ -46,6 +46,90 @@ class PolicyTest < ActiveSupport::TestCase
46
46
  assert_equal 1, policy.hosts.count
47
47
  end
48
48
 
49
+ test "should reset compliance status when assigning policy to host" do
50
+ host = FactoryBot.create(:compliance_host)
51
+ unrelated_host = FactoryBot.create(:compliance_host)
52
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
53
+ set_compliance_status(unrelated_host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
54
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
55
+
56
+ policy.host_ids = [host.id]
57
+ policy.save!
58
+
59
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(host)
60
+ assert_equal ForemanOpenscap::ComplianceStatus::COMPLIANT, compliance_status_for(unrelated_host)
61
+ end
62
+
63
+ test "should create inconclusive compliance status when assigning policy to host without status" do
64
+ host = FactoryBot.create(:compliance_host)
65
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
66
+
67
+ policy.host_ids = [host.id]
68
+ policy.save!
69
+
70
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(host)
71
+ end
72
+
73
+ test "should reset compliance status when removing policy from host assignment" do
74
+ host = FactoryBot.create(:compliance_host)
75
+ asset = FactoryBot.create(:asset, :assetable_id => host.id, :assetable_type => 'Host::Base')
76
+ policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
77
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
78
+
79
+ policy.host_ids = []
80
+ policy.save!
81
+
82
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(host)
83
+ end
84
+
85
+ test "should reset compliance status when unassigning host from policy" do
86
+ host = FactoryBot.create(:compliance_host)
87
+ asset = FactoryBot.create(:asset, :assetable_id => host.id, :assetable_type => 'Host::Base')
88
+ policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
89
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
90
+
91
+ policy.unassign_hosts([host])
92
+
93
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(host)
94
+ end
95
+
96
+ test "should reset compliance status for hostgroup subtree when assigning policy to hostgroup" do
97
+ parent = FactoryBot.create(:hostgroup)
98
+ child = FactoryBot.create(:hostgroup, :ancestry => parent.id.to_s)
99
+ parent_host = FactoryBot.create(:compliance_host, :hostgroup_id => parent.id)
100
+ child_host = FactoryBot.create(:compliance_host, :hostgroup_id => child.id)
101
+ unrelated_host = FactoryBot.create(:compliance_host)
102
+ [parent_host, child_host, unrelated_host].each do |host|
103
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
104
+ end
105
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_profile)
106
+
107
+ policy.hostgroup_ids = [parent.id]
108
+ policy.save!
109
+
110
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(parent_host)
111
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(child_host)
112
+ assert_equal ForemanOpenscap::ComplianceStatus::COMPLIANT, compliance_status_for(unrelated_host)
113
+ end
114
+
115
+ test "should reset compliance status for hostgroup subtree when removing policy from hostgroup" do
116
+ parent = FactoryBot.create(:hostgroup)
117
+ child = FactoryBot.create(:hostgroup, :ancestry => parent.id.to_s)
118
+ parent_host = FactoryBot.create(:compliance_host, :hostgroup_id => parent.id)
119
+ child_host = FactoryBot.create(:compliance_host, :hostgroup_id => child.id)
120
+ asset = FactoryBot.create(:asset, :assetable_id => parent.id, :assetable_type => 'Hostgroup')
121
+ policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
122
+ [parent_host, child_host].each do |host|
123
+ set_compliance_status(host, ForemanOpenscap::ComplianceStatus::COMPLIANT)
124
+ end
125
+
126
+ policy.hostgroup_ids = []
127
+ policy.save!
128
+
129
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(parent_host)
130
+ assert_equal ForemanOpenscap::ComplianceStatus::INCONCLUSIVE, compliance_status_for(child_host)
131
+ end
132
+
49
133
  test "should delete assets when unassigning hosts" do
50
134
  host1 = FactoryBot.create(:compliance_host)
51
135
  host2 = FactoryBot.create(:compliance_host)
@@ -331,4 +415,10 @@ class PolicyTest < ActiveSupport::TestCase
331
415
  assert_equal policy.deploy_by, 'manual'
332
416
  assert_equal policy.name, name
333
417
  end
418
+
419
+ private
420
+
421
+ def compliance_status_for(host)
422
+ ForemanOpenscap::ComplianceStatus.find_by(:host_id => host.id).try(:status)
423
+ end
334
424
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.1.1
4
+ version: 13.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
@@ -106,6 +106,7 @@ files:
106
106
  - app/services/foreman_openscap/client_config/base.rb
107
107
  - app/services/foreman_openscap/client_config/manual.rb
108
108
  - app/services/foreman_openscap/client_config/puppet.rb
109
+ - app/services/foreman_openscap/compliance_status_resetter.rb
109
110
  - app/services/foreman_openscap/config_name_service.rb
110
111
  - app/services/foreman_openscap/host_report_dashboard/data.rb
111
112
  - app/services/foreman_openscap/hostgroup_overrider.rb
@@ -349,6 +350,7 @@ files:
349
350
  - test/test_plugin_helper.rb
350
351
  - test/unit/arf_report_status_calculator_test.rb
351
352
  - test/unit/arf_report_test.rb
353
+ - test/unit/compliance_status_resetter_test.rb
352
354
  - test/unit/compliance_status_test.rb
353
355
  - test/unit/concerns/bookmark_controller_validator_extensions_test.rb
354
356
  - test/unit/concerns/host_extensions_test.rb
@@ -457,6 +459,7 @@ test_files:
457
459
  - test/test_plugin_helper.rb
458
460
  - test/unit/arf_report_status_calculator_test.rb
459
461
  - test/unit/arf_report_test.rb
462
+ - test/unit/compliance_status_resetter_test.rb
460
463
  - test/unit/compliance_status_test.rb
461
464
  - test/unit/concerns/bookmark_controller_validator_extensions_test.rb
462
465
  - test/unit/concerns/host_extensions_test.rb