foreman_openscap 0.11.5 → 0.12.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/compliance/arf_reports_controller.rb +3 -6
  3. data/app/controllers/api/v2/compliance/policies_controller.rb +3 -1
  4. data/app/controllers/concerns/foreman/controller/parameters/policy_api.rb +1 -1
  5. data/app/controllers/policies_controller.rb +2 -1
  6. data/app/helpers/foreman_openscap_helper.rb +14 -0
  7. data/app/helpers/policies_helper.rb +36 -0
  8. data/app/models/concerns/foreman_openscap/host_extensions.rb +5 -1
  9. data/app/models/concerns/foreman_openscap/openscap_proxy_core_extensions.rb +15 -19
  10. data/app/models/foreman_openscap/policy.rb +14 -80
  11. data/app/services/foreman_openscap/client_config/ansible.rb +38 -0
  12. data/app/services/foreman_openscap/client_config/base.rb +41 -0
  13. data/app/services/foreman_openscap/client_config/manual.rb +27 -0
  14. data/app/services/foreman_openscap/client_config/puppet.rb +38 -0
  15. data/app/services/foreman_openscap/config_name_service.rb +29 -0
  16. data/app/services/foreman_openscap/hostgroup_overrider.rb +71 -0
  17. data/app/services/foreman_openscap/lookup_key_overrider.rb +94 -0
  18. data/app/views/policies/_form.html.erb +6 -2
  19. data/app/views/policies/steps/_deployment_options_form.html.erb +11 -0
  20. data/app/views/policies/steps/{_create_policy_form.html.erb → _policy_attributes_form.html.erb} +0 -0
  21. data/db/migrate/20190103093409_add_deployment_option_to_policy.foreman_openscap.rb +15 -0
  22. data/lib/foreman_openscap/engine.rb +3 -3
  23. data/lib/foreman_openscap/version.rb +1 -1
  24. data/locale/de/foreman_openscap.edit.po +302 -106
  25. data/locale/en_GB/foreman_openscap.edit.po +302 -106
  26. data/locale/es/foreman_openscap.edit.po +302 -106
  27. data/locale/fr/foreman_openscap.edit.po +302 -106
  28. data/locale/gl/foreman_openscap.edit.po +302 -106
  29. data/locale/it/foreman_openscap.edit.po +302 -106
  30. data/locale/ja/foreman_openscap.edit.po +302 -106
  31. data/locale/ko/foreman_openscap.edit.po +302 -106
  32. data/locale/pt_BR/foreman_openscap.edit.po +302 -106
  33. data/locale/ru/foreman_openscap.edit.po +302 -106
  34. data/locale/sv_SE/foreman_openscap.edit.po +302 -106
  35. data/locale/zh_CN/foreman_openscap.edit.po +302 -106
  36. data/locale/zh_TW/foreman_openscap.edit.po +302 -106
  37. data/test/factories/policy_factory.rb +1 -0
  38. data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +2 -3
  39. data/test/functional/api/v2/compliance/policies_controller_test.rb +2 -2
  40. data/test/test_plugin_helper.rb +26 -7
  41. data/test/unit/openscap_host_test.rb +0 -2
  42. data/test/unit/policy_test.rb +32 -23
  43. data/test/unit/services/config_name_service_test.rb +39 -0
  44. data/test/unit/services/hostgroup_overrider_test.rb +78 -0
  45. data/test/unit/services/lookup_key_overrider_test.rb +52 -0
  46. metadata +19 -5
  47. data/test/unit/puppet_overrides_test.rb +0 -38
@@ -11,5 +11,6 @@ FactoryBot.define do
11
11
  cron_line nil
12
12
  hosts []
13
13
  assets []
14
+ deploy_by 'manual'
14
15
  end
15
16
  end
@@ -96,8 +96,7 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
96
96
  test "should not create report when host is missing" do
97
97
  reports_cleanup
98
98
  date = Time.new(1984, 9, 16)
99
- ForemanOpenscap::Helper.stubs(:find_host_by_name_or_uuid).returns(nil)
100
-
99
+ ForemanOpenscap::Helper.stubs(:get_asset).returns(nil)
101
100
  cname = '9521a5c5-8f44-495f-b087-20e86b30bffg'
102
101
  post :create,
103
102
  :params => @from_json.merge(:cname => cname,
@@ -114,7 +113,7 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
114
113
  test "should not create report when policy is missing" do
115
114
  reports_cleanup
116
115
  date = Time.new(1984, 9, 17)
117
- ForemanOpenscap::Helper.stubs(:find_host_by_name_or_uuid).returns(@host)
116
+ ForemanOpenscap::Helper.stubs(:get_asset).returns(@asset)
118
117
  policy_id = 0
119
118
  post :create,
120
119
  :params => @from_json.merge(:cname => @cname,
@@ -2,13 +2,13 @@ require 'test_plugin_helper'
2
2
 
3
3
  class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
4
4
  setup do
5
- ::ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
6
5
  @scap_content_profile = FactoryBot.create(:scap_content_profile)
7
6
  @attributes = { :policy => { :name => 'my_policy',
8
7
  :scap_content_profile_id => @scap_content_profile.id,
9
8
  :scap_content_id => @scap_content_profile.scap_content_id,
10
9
  :period => 'weekly',
11
- :weekday => 'friday' } }
10
+ :weekday => 'friday',
11
+ :deploy_by => 'manual' } }
12
12
  end
13
13
 
14
14
  test "should get index" do
@@ -6,10 +6,30 @@ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories
6
6
  FactoryBot.reload
7
7
 
8
8
  module ScapClientPuppetclass
9
- def skip_scap_callback
10
- Host::Managed.any_instance.stubs(:update_scap_client).returns(nil)
11
- Host::Managed.any_instance.stubs(:scap_client_class_present).returns(nil)
12
- Hostgroup.any_instance.stubs(:update_scap_client).returns(nil)
9
+ def setup_puppet_class
10
+ puppet_config = ::ForemanOpenscap::ClientConfig::Puppet.new
11
+ Puppetclass.find_by(:name => puppet_config.puppetclass_name)&.destroy
12
+
13
+ puppet_class = FactoryBot.create(:puppetclass, :name => puppet_config.puppetclass_name)
14
+ server_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.server_param, :puppetclass_id => puppet_class.id)
15
+ port_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.port_param, :puppetclass_id => puppet_class.id)
16
+ policies_param = FactoryBot.create(:puppetclass_lookup_key, :key => puppet_config.policies_param, :puppetclass_id => puppet_class.id)
17
+
18
+ env = FactoryBot.create :environment
19
+
20
+ FactoryBot.create(:environment_class,
21
+ :puppetclass_id => puppet_class.id,
22
+ :environment_id => env.id,
23
+ :puppetclass_lookup_key_id => server_param.id)
24
+ FactoryBot.create(:environment_class,
25
+ :puppetclass_id => puppet_class.id,
26
+ :environment_id => env.id,
27
+ :puppetclass_lookup_key_id => port_param.id)
28
+ FactoryBot.create(:environment_class,
29
+ :puppetclass_id => puppet_class.id,
30
+ :environment_id => env.id,
31
+ :puppetclass_lookup_key_id => policies_param.id)
32
+ { :puppet_class => puppet_class, :env => env, :server_param => server_param, :port_param => port_param, :policies_param => policies_param }
13
33
  end
14
34
  end
15
35
 
@@ -45,7 +65,6 @@ end
45
65
 
46
66
  class ActionMailer::TestCase
47
67
  include ScapClientPuppetclass
48
- setup :skip_scap_callback
49
68
  end
50
69
 
51
70
  class ActionController::TestCase
@@ -53,7 +72,7 @@ class ActionController::TestCase
53
72
  include ScapTestProxy
54
73
  include ScapTestCommon
55
74
 
56
- setup :add_smart_proxy, :skip_scap_callback
75
+ setup :add_smart_proxy
57
76
  end
58
77
 
59
78
  class ActiveSupport::TestCase
@@ -61,5 +80,5 @@ class ActiveSupport::TestCase
61
80
  include ScapTestProxy
62
81
  include ScapTestCommon
63
82
 
64
- setup :add_smart_proxy, :skip_scap_callback
83
+ setup :add_smart_proxy
65
84
  end
@@ -4,8 +4,6 @@ class OpenscapHostTest < ActiveSupport::TestCase
4
4
  setup do
5
5
  disable_orchestration
6
6
  User.current = users :admin
7
- ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
8
- ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
9
7
  @policy = FactoryBot.create(:policy)
10
8
  end
11
9
 
@@ -2,7 +2,6 @@ require 'test_plugin_helper'
2
2
 
3
3
  class PolicyTest < ActiveSupport::TestCase
4
4
  setup do
5
- ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
6
5
  ForemanOpenscap::DataStreamValidator.any_instance.stubs(:validate)
7
6
  ForemanOpenscap::ScapContent.any_instance.stubs(:fetch_profiles).returns({ 'test_profile_key' => 'test_profile_title' })
8
7
  @scap_content = FactoryBot.create(:scap_content)
@@ -11,8 +10,6 @@ class PolicyTest < ActiveSupport::TestCase
11
10
  end
12
11
 
13
12
  test "should assign hostgroups by their ids" do
14
- ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
15
- ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
16
13
  hg1 = FactoryBot.create(:hostgroup)
17
14
  hg2 = FactoryBot.create(:hostgroup)
18
15
  host = FactoryBot.create(:compliance_host)
@@ -27,8 +24,6 @@ class PolicyTest < ActiveSupport::TestCase
27
24
  end
28
25
 
29
26
  test "should assign hosts by their ids" do
30
- ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
31
- ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
32
27
  host1 = FactoryBot.create(:compliance_host)
33
28
  host2 = FactoryBot.create(:compliance_host)
34
29
  hostgroup = FactoryBot.create(:hostgroup)
@@ -43,8 +38,6 @@ class PolicyTest < ActiveSupport::TestCase
43
38
  end
44
39
 
45
40
  test "should remove associated hostgroup" do
46
- ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
47
- ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
48
41
  hg = FactoryBot.create(:hostgroup)
49
42
  asset = FactoryBot.create(:asset, :assetable_id => hg.id, :assetable_type => 'Hostgroup')
50
43
  policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
@@ -59,7 +52,8 @@ class PolicyTest < ActiveSupport::TestCase
59
52
  :scap_content_id => @scap_content.id,
60
53
  :scap_content_profile_id => @scap_profile.id,
61
54
  :period => 'custom',
62
- :cron_line => '6 * 15 12 0')
55
+ :cron_line => '6 * 15 12 0',
56
+ :deploy_by => 'manual')
63
57
  assert p.save
64
58
  end
65
59
 
@@ -68,7 +62,8 @@ class PolicyTest < ActiveSupport::TestCase
68
62
  :scap_content_id => @scap_content.id,
69
63
  :scap_content_profile_id => @scap_profile.id,
70
64
  :period => 'custom',
71
- :cron_line => 'aaa')
65
+ :cron_line => 'aaa',
66
+ :deploy_by => 'manual')
72
67
  refute p.save
73
68
  assert p.errors[:cron_line].include?("does not consist of 5 parts separated by space")
74
69
  end
@@ -78,7 +73,8 @@ class PolicyTest < ActiveSupport::TestCase
78
73
  :scap_content_id => @scap_content.id,
79
74
  :scap_content_profile_id => @scap_profile.id,
80
75
  :period => 'weekly',
81
- :weekday => 'monday')
76
+ :weekday => 'monday',
77
+ :deploy_by => 'manual')
82
78
  assert p.save
83
79
  end
84
80
 
@@ -87,7 +83,8 @@ class PolicyTest < ActiveSupport::TestCase
87
83
  :scap_content_id => @scap_content.id,
88
84
  :scap_content_profile_id => @scap_profile.id,
89
85
  :period => 'weekly',
90
- :weekday => 'someday')
86
+ :weekday => 'someday',
87
+ :deploy_by => 'manual')
91
88
  refute p.save
92
89
  assert p.errors[:weekday].include?("is not a valid value")
93
90
  end
@@ -97,7 +94,8 @@ class PolicyTest < ActiveSupport::TestCase
97
94
  :scap_content_id => @scap_content.id,
98
95
  :scap_content_profile_id => @scap_profile.id,
99
96
  :period => 'monthly',
100
- :day_of_month => '1')
97
+ :day_of_month => '1',
98
+ :deploy_by => 'manual')
101
99
  assert p.save
102
100
  end
103
101
 
@@ -106,7 +104,8 @@ class PolicyTest < ActiveSupport::TestCase
106
104
  :scap_content_id => @scap_content.id,
107
105
  :scap_content_profile_id => @scap_profile.id,
108
106
  :period => 'monthly',
109
- :day_of_month => '0')
107
+ :day_of_month => '0',
108
+ :deploy_by => 'manual')
110
109
  refute p.save
111
110
  assert p.errors[:day_of_month].include?("must be between 1 and 31")
112
111
  end
@@ -117,13 +116,15 @@ class PolicyTest < ActiveSupport::TestCase
117
116
  :scap_content_profile_id => @scap_profile.id,
118
117
  :period => 'monthly',
119
118
  :weekday => 'tuesday',
120
- :cron_line => "0 0 0 0 0")
119
+ :cron_line => "0 0 0 0 0",
120
+ :deploy_by => 'manual')
121
121
  policy = ForemanOpenscap::Policy.new(:name => "test policy",
122
122
  :scap_content_id => @scap_content.id,
123
123
  :scap_content_profile_id => @scap_profile.id,
124
124
  :period => 'custom',
125
125
  :weekday => 'tuesday',
126
- :day_of_month => "15")
126
+ :day_of_month => "15",
127
+ :deploy_by => 'manual')
127
128
  refute p.save
128
129
  refute policy.save
129
130
  assert p.weekday.empty?
@@ -137,7 +138,8 @@ class PolicyTest < ActiveSupport::TestCase
137
138
  :scap_content_id => @scap_content.id,
138
139
  :scap_content_profile_id => @scap_profile.id,
139
140
  :period => 'monthly',
140
- :day_of_month => '5')
141
+ :day_of_month => '5',
142
+ :deploy_by => 'manual')
141
143
  assert p.save
142
144
  p.period = 'weekly'
143
145
  p.weekday = 'monday'
@@ -149,7 +151,8 @@ class PolicyTest < ActiveSupport::TestCase
149
151
  p = ForemanOpenscap::Policy.new(:name => "custom_policy",
150
152
  :scap_content_profile_id => @scap_profile.id,
151
153
  :period => 'monthly',
152
- :day_of_month => '5')
154
+ :day_of_month => '5',
155
+ :deploy_by => 'manual')
153
156
  refute p.save
154
157
  assert p.errors[:scap_content_id].include?("can't be blank")
155
158
  end
@@ -158,7 +161,8 @@ class PolicyTest < ActiveSupport::TestCase
158
161
  p = ForemanOpenscap::Policy.new(:name => "custom_policy",
159
162
  :scap_content_id => @scap_content.id,
160
163
  :period => 'monthly',
161
- :day_of_month => '5')
164
+ :day_of_month => '5',
165
+ :deploy_by => 'manual')
162
166
  assert p.save
163
167
  end
164
168
 
@@ -180,7 +184,8 @@ class PolicyTest < ActiveSupport::TestCase
180
184
  :scap_content => @scap_content,
181
185
  :scap_content_profile => @scap_profile,
182
186
  :tailoring_file => tailoring_file,
183
- :tailoring_file_profile => @scap_profile)
187
+ :tailoring_file_profile => @scap_profile,
188
+ :deploy_by => 'manual')
184
189
  refute p.valid?
185
190
  p.tailoring_file_profile = tailoring_profile
186
191
  assert p.save
@@ -191,7 +196,8 @@ class PolicyTest < ActiveSupport::TestCase
191
196
  :scap_content_id => @scap_content.id,
192
197
  :scap_content_profile_id => @scap_profile.id,
193
198
  :period => 'monthly',
194
- :day_of_month => '5')
199
+ :day_of_month => '5',
200
+ :deploy_by => 'manual')
195
201
  assert_equal 6, p.to_enc['download_path'].split('/').length
196
202
  assert_equal @scap_content.digest, p.to_enc['download_path'].split('/').last
197
203
  end
@@ -204,7 +210,8 @@ class PolicyTest < ActiveSupport::TestCase
204
210
  :tailoring_file => tailoring_file,
205
211
  :tailoring_file_profile => @tailoring_profile,
206
212
  :period => 'monthly',
207
- :day_of_month => '5')
213
+ :day_of_month => '5',
214
+ :deploy_by => 'manual')
208
215
  assert_equal 6, p.to_enc['tailoring_download_path'].split('/').length
209
216
  assert_equal tailoring_file.digest, p.to_enc['tailoring_download_path'].split('/').last
210
217
  end
@@ -215,13 +222,15 @@ class PolicyTest < ActiveSupport::TestCase
215
222
  :scap_content_id => @scap_content.id,
216
223
  :scap_content_profile_id => @scap_profile.id,
217
224
  :period => 'monthly',
218
- :day_of_month => '5')
225
+ :day_of_month => '5',
226
+ :deploy_by => 'manual')
219
227
  assert p.valid?
220
228
  q = ForemanOpenscap::Policy.create(:name => "invalid_profile_policy",
221
229
  :scap_content_id => scap_content_2.id,
222
230
  :scap_content_profile_id => @scap_profile.id,
223
231
  :period => 'monthly',
224
- :day_of_month => '5')
232
+ :day_of_month => '5',
233
+ :deploy_by => 'manual')
225
234
  refute q.valid?
226
235
  assert_equal "does not have the selected SCAP content profile", q.errors.messages[:scap_content_id].first
227
236
  end
@@ -0,0 +1,39 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ConfigNameServiceTest < ActiveSupport::TestCase
4
+ setup do
5
+ @name_service = ForemanOpenscap::ConfigNameService.new
6
+ end
7
+
8
+ test 'should find config for Puppet' do
9
+ assert @name_service.config_for(:puppet).is_a?(ForemanOpenscap::ClientConfig::Puppet)
10
+ end
11
+
12
+ test 'should find config for Ansible' do
13
+ assert @name_service.config_for(:ansible).is_a?(ForemanOpenscap::ClientConfig::Ansible)
14
+ end
15
+
16
+ test 'should find config for Manual' do
17
+ assert @name_service.config_for(:manual).is_a?(ForemanOpenscap::ClientConfig::Manual)
18
+ end
19
+
20
+ test 'should find all except Manual' do
21
+ configs = @name_service.all_except(:manual)
22
+ assert_equal 2, configs.size
23
+ refute configs.map(&:type).include?(:manual)
24
+ end
25
+
26
+ test 'should find all available except Manual' do
27
+ ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(false)
28
+ configs = @name_service.all_available_except(:manual)
29
+ assert_equal 1, configs.size
30
+ assert_equal :puppet, configs.first.type
31
+ end
32
+
33
+ test 'should find all available with overrides except Puppet' do
34
+ ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(true)
35
+ configs = @name_service.all_available_with_overrides_except(:puppet)
36
+ assert_equal 1, configs.size
37
+ assert_equal :ansible, configs.first.type
38
+ end
39
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class HostgroupOverriderTest < ActiveSupport::TestCase
4
+ setup do
5
+ ForemanOpenscap::ScapContent.any_instance.stubs(:fetch_profiles).returns({ 'test_profile_key' => 'test_profile_title' })
6
+
7
+ @scap_content = FactoryBot.create(:scap_content)
8
+ @scap_profile = FactoryBot.create(:scap_content_profile, :scap_content => @scap_content)
9
+ end
10
+
11
+ test 'should populate puppet overrides' do
12
+ puppet_class, env, port_param, server_param = setup_puppet_class.values_at :puppet_class, :env, :port_param, :server_param
13
+
14
+ proxy = FactoryBot.create(:openscap_proxy, :url => 'https://override-keys.example.com:8998')
15
+
16
+ hostgroup = FactoryBot.create(:hostgroup, :environment_id => env.id, :openscap_proxy_id => proxy.id)
17
+ refute hostgroup.puppetclasses.include? puppet_class
18
+ assert LookupValue.where(:match => "hostgroup=#{hostgroup.to_label}",
19
+ :lookup_key_id => port_param.id,
20
+ :value => '8998').empty?
21
+ assert LookupValue.where(:match => "hostgroup=#{hostgroup.to_label}",
22
+ :lookup_key_id => server_param.id,
23
+ :value => 'override-keys.example.com').empty?
24
+
25
+ port_param.override = true
26
+ port_param.save
27
+ server_param.override = true
28
+ server_param.save
29
+ hostgroup.puppetclasses << puppet_class
30
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
31
+ :scap_content_profile => @scap_profile,
32
+ :deploy_by => 'puppet',
33
+ :hostgroup_ids => [hostgroup.id])
34
+ policy.save
35
+ refute LookupValue.where(:match => "hostgroup=#{hostgroup.to_label}",
36
+ :lookup_key_id => port_param.id,
37
+ :value => 8998).empty?
38
+ refute LookupValue.where(:match => "hostgroup=#{hostgroup.to_label}",
39
+ :lookup_key_id => server_param.id,
40
+ :value => 'override-keys.example.com').empty?
41
+ end
42
+
43
+ test "should return when policy has blank deploy_by" do
44
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
45
+ :scap_content_profile => @scap_profile)
46
+ overrider = ForemanOpenscap::HostgroupOverrider.new(policy)
47
+ overrider.expects(:populate_overrides).never
48
+ overrider.populate
49
+ end
50
+
51
+ test "should return when deploy_by type is not supported" do
52
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
53
+ :scap_content_profile => @scap_profile,
54
+ :deploy_by => 'salt')
55
+ overrider = ForemanOpenscap::HostgroupOverrider.new(policy)
56
+ overrider.expects(:populate_overrides).never
57
+ overrider.populate
58
+ end
59
+
60
+ test "should return when deployment type is not available" do
61
+ ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(false)
62
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
63
+ :scap_content_profile => @scap_profile,
64
+ :deploy_by => 'ansible')
65
+ overrider = ForemanOpenscap::HostgroupOverrider.new(policy)
66
+ overrider.expects(:populate_overrides).never
67
+ overrider.populate
68
+ end
69
+
70
+ test "should return when config has unmanaged overrides" do
71
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
72
+ :scap_content_profile => @scap_profile,
73
+ :deploy_by => 'manual')
74
+ overrider = ForemanOpenscap::HostgroupOverrider.new(policy)
75
+ overrider.expects(:populate_overrides).never
76
+ overrider.populate
77
+ end
78
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class LookupKeyOverriderTest < ActiveSupport::TestCase
4
+ setup do
5
+ ForemanOpenscap::ScapContent.any_instance.stubs(:fetch_profiles).returns({ 'test_profile_key' => 'test_profile_title' })
6
+ @scap_content = FactoryBot.create(:scap_content)
7
+ @scap_profile = FactoryBot.create(:scap_content_profile, :scap_content => @scap_content)
8
+ end
9
+
10
+ test 'should override puppet class parameters' do
11
+ server_param, port_param, policies_param = setup_puppet_class.values_at :server_param, :port_param, :policies_param
12
+ refute server_param.override
13
+ refute port_param.override
14
+ refute policies_param.override
15
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_content_profile, :deploy_by => :puppet)
16
+ ForemanOpenscap::LookupKeyOverrider.new(policy).override
17
+ assert server_param.reload.override
18
+ assert port_param.reload.override
19
+ assert policies_param.reload.override
20
+ assert_equal '<%= @host.policies_enc %>', policies_param.default_value
21
+ end
22
+
23
+ test 'should add error when no puppet class found' do
24
+ puppet_class = Puppetclass.find_by :name => ForemanOpenscap::ClientConfig::Puppet.new.puppetclass_name
25
+ puppet_class.destroy if puppet_class
26
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_content_profile, :deploy_by => :puppet)
27
+ ForemanOpenscap::LookupKeyOverrider.new(policy).override
28
+ assert_equal ["Required Puppet class foreman_scap_client was not found, please ensure it is imported first."], policy.errors[:base]
29
+ end
30
+
31
+ test 'should add error when deployment type is not available' do
32
+ ForemanOpenscap::ClientConfig::Ansible.any_instance.stubs(:available?).returns(false)
33
+ policy = FactoryBot.build(:policy, :scap_content => @scap_content,
34
+ :scap_content_profile => @scap_profile,
35
+ :deploy_by => 'ansible')
36
+ overrider = ForemanOpenscap::LookupKeyOverrider.new(policy)
37
+ overrider.expects(:override_required_params).never
38
+ overrider.override
39
+ assert_equal "Ansible was selected to deploy policy to clients, but Ansible is not available. Are you missing a plugin?",
40
+ policy.errors[:deploy_by].first
41
+ end
42
+
43
+ test 'should add error when lookup keys not present' do
44
+ server_param, port_param, policies_param = setup_puppet_class.values_at :server_param, :port_param, :policies_param
45
+ server_param.destroy
46
+ port_param.destroy
47
+ policy = FactoryBot.create(:policy, :scap_content => @scap_content, :scap_content_profile => @scap_content_profile, :deploy_by => :puppet)
48
+ ForemanOpenscap::LookupKeyOverrider.new(policy).override
49
+ err = "The following Smart Class Parameters were missing for foreman_scap_client: port, server. Make sure they are imported before proceeding."
50
+ assert_equal err, policy.errors[:base].first
51
+ end
52
+ end