foreman_puppet 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 551d9a6cf7153dfc0bb5a4709bbd394bc6d2ba5354b16531de6787653ca1d185
4
- data.tar.gz: cacbf35dfb12c49175bd0ee95ea8cf4b441319c140b7401c5527b8231a9000f0
3
+ metadata.gz: 60ff3828222cc632f3ede70b60d3789bc68cd9565a501293ff037d16f089e875
4
+ data.tar.gz: 4446e0632671fe04ac826ae0c6ca1315ffe2dc4555acf252ee93c7a322b9f0fc
5
5
  SHA512:
6
- metadata.gz: 6c28a424fb8afdb633134b1f57fa7254ead445a7a1e45d3b8bc97cbfc3ffd42a0dbb80df33ae2d7cc52d55cc12575078a773b3ed5ae3b9a360f9afb26d2631b8
7
- data.tar.gz: d29c6598e1709bfddceb64e92fe16f33df55ce5eb85288e3f3ad14d590aa59d88515c37fd7116a252d889deb416bb652449c6fa6de3ef4baad5e27bfd9547bc8
6
+ metadata.gz: a8176437ecad24bbcbd707459114bedbadd20905ba031142cf9634aec2efe77adf6c790412b65162358c016df2999739c8b4b2f4d4c322d56673325ccf3aa65b
7
+ data.tar.gz: 723ab74a3fc1b20954e446018508bd61fd35ea04fce200049cb306f04ee6240289ec136d34b00a4873ec51e211781fdb93722baabf04bcf19b777a4f211a85af
@@ -3,7 +3,7 @@ module ForemanPuppet
3
3
  module HostsControllerExtensions
4
4
  extend ActiveSupport::Concern
5
5
 
6
- PUPPETMASTER_ACTIONS = %i[externalNodes lookup].freeze
6
+ PUPPETMASTER_ACTIONS = %i[externalNodes].freeze
7
7
  PUPPET_AJAX_REQUESTS = %w[hostgroup_or_environment_selected puppetclass_parameters].freeze
8
8
 
9
9
  MULTIPLE_EDIT_ACTIONS = %w[select_multiple_environment update_multiple_environment
@@ -9,7 +9,7 @@ module ForemanPuppet
9
9
  # ------ Host(group) Form Helpers -----
10
10
 
11
11
  def overridable_puppet_lookup_keys(klass, obj)
12
- klass.class_params.override.where(environment_classes: { environment_id: obj.environment_id })
12
+ klass.class_params.override.where(environment_classes: { environment_id: obj.environment })
13
13
  end
14
14
 
15
15
  def hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled)
@@ -45,7 +45,7 @@ module ForemanPuppet
45
45
  end
46
46
 
47
47
  def ca_defined?
48
- SETTINGS[:unattended] && host.puppetca_exists?
48
+ host.puppetca_exists?
49
49
  end
50
50
 
51
51
  def has_environment?
@@ -11,13 +11,14 @@
11
11
  <% end %>
12
12
 
13
13
  <%= render 'foreman_puppet/puppetclasses/class_selection', obj: obj, resource_type: resource_type %>
14
+
15
+ <fieldset id="puppet_klasses_parameters" data-url="<%= foreman_puppet.url_for(controller: resource_type.to_s.pluralize.to_sym, action: :puppetclass_parameters, only_path: true) %>">
16
+ <h2><%= _('Puppet Class Parameters') %></h2>
17
+ <%= render 'foreman_puppet/puppetclasses/classes_parameters', obj: subject %>
18
+ </fieldset>
14
19
  <% else %>
15
20
  <%= alert(class: alert_class(:info),
16
21
  header: _('Notice'),
17
22
  text: _('Please select an environment first')) %>
18
23
  <% end %>
19
24
 
20
- <fieldset id="puppet_klasses_parameters" data-url="<%= foreman_puppet.url_for(controller: resource_type.to_s.pluralize.to_sym, action: :puppetclass_parameters, only_path: true) %>">
21
- <h2><%= _('Puppet Class Parameters') %></h2>
22
- <%= render 'foreman_puppet/puppetclasses/classes_parameters', obj: subject %>
23
- </fieldset>
@@ -0,0 +1,9 @@
1
+ class MigrateHostClassPermission < ActiveRecord::Migration[6.0]
2
+ def up
3
+ Permission.where(resource_type: 'HostClass').update_all(resource_type: 'ForemanPuppet::HostClass')
4
+ end
5
+
6
+ def down
7
+ # no can do
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class MigrateEnvironmentIgnoreType < ActiveRecord::Migration[6.0]
2
+ def up
3
+ taxonomies = Taxonomy.unscoped.where("ignore_types LIKE '%Environment%'")
4
+ environment_ids = ForemanPuppet::Environment.unscoped.pluck(:id)
5
+
6
+ taxonomies.each do |tax|
7
+ new_types = tax.ignore_types.reject { |type| type == 'Environment' }
8
+ tax.update_columns(ignore_types: new_types)
9
+ taxable_rows = environment_ids.map do |env_id|
10
+ { taxable_id: env_id, taxable_type: 'ForemanPuppet::Environment', taxonomy_id: tax.id }
11
+ end
12
+ TaxableTaxonomy.insert_all(taxable_rows) if taxable_rows.any?
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,8 @@
1
1
  class CreateHostgroupsPuppetclasses < ActiveRecord::Migration[6.0]
2
2
  def up
3
- create_table :hostgroups_puppetclasses, id: false, if_not_exists: true do |t|
3
+ # this table is later renamed into hostgroup_classes and thus we don't want to create it if it exists under the later name
4
+ return if table_exists?(:hostgroups_puppetclasses) || table_exists?(:hostgroup_classes)
5
+ create_table :hostgroups_puppetclasses, id: false do |t|
4
6
  t.references :hostgroup, foreign_key: true, null: false
5
7
  t.references :puppetclass, foreign_key: true, null: false
6
8
  end
@@ -147,7 +147,8 @@ Foreman::Plugin.register :foreman_puppet do
147
147
  permission :import_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[import_environments obsolete_and_new],
148
148
  'foreman_puppet/api/v2/environments' => [:import_puppetclasses] },
149
149
  resource_type: 'ForemanPuppet::Puppetclass'
150
- permission :edit_classes, { 'foreman_puppet/api/v2/host_classes': %i[index create destroy] },
150
+ permission :edit_classes, { :host_editing => [:edit_classes],
151
+ 'foreman_puppet/api/v2/host_classes' => %i[index create destroy] },
151
152
  resource_type: 'ForemanPuppet::HostClass'
152
153
  end
153
154
 
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '3.0.2'.freeze
3
3
  end
@@ -79,12 +79,22 @@ module ForemanPuppet
79
79
 
80
80
  test 'should update with puppet class' do
81
81
  puppetclass = environment.puppetclasses.first
82
+ # uses the deprecated version of params passing without namespace, to test it works :)
82
83
  put :update, params: { id: host.id, host: { environment_id: environment.id, puppetclass_ids: [puppetclass.id] } }
83
84
  assert_response :success
84
85
  response = JSON.parse(@response.body)
85
86
  assert_equal environment.id, response['environment_id'], "Can't update host with environment #{environment}"
86
87
  assert_equal puppetclass.id, response['puppetclasses'][0]['id'], "Can't update host with puppetclass #{puppetclass}"
87
88
  end
89
+
90
+ test 'should remove puppetclass by passing empty array' do
91
+ host2 = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
92
+
93
+ put :update, params: { id: host2.id, host: { puppet_attributes: { puppetclass_ids: [] } } }
94
+ assert_response :success
95
+ response = JSON.parse(@response.body)
96
+ assert_empty(response['puppetclasses'], 'Can not remove puppetclasses')
97
+ end
88
98
  end
89
99
 
90
100
  describe '#enc' do
@@ -201,7 +201,6 @@ module ForemanPuppet
201
201
  test 'hosts with a registered smart proxy on should get externalNodes successfully' do
202
202
  User.current = nil
203
203
  Setting[:restrict_registered_smart_proxies] = true
204
- Setting[:require_ssl_smart_proxies] = false
205
204
 
206
205
  Resolv.any_instance.stubs(:getnames).returns(['else.where'])
207
206
  get :externalNodes, params: { name: host1.name, format: 'yml' }
@@ -211,7 +210,6 @@ module ForemanPuppet
211
210
  test 'hosts without a registered smart proxy on should not be able to get externalNodes' do
212
211
  User.current = nil
213
212
  Setting[:restrict_registered_smart_proxies] = true
214
- Setting[:require_ssl_smart_proxies] = false
215
213
 
216
214
  Resolv.any_instance.stubs(:getnames).returns(['another.host'])
217
215
  get :externalNodes, params: { name: host1.name, format: 'yml' }
@@ -221,7 +219,6 @@ module ForemanPuppet
221
219
  test 'hosts with a registered smart proxy and SSL cert should get externalNodes successfully' do
222
220
  User.current = nil
223
221
  Setting[:restrict_registered_smart_proxies] = true
224
- Setting[:require_ssl_smart_proxies] = true
225
222
 
226
223
  @request.env['HTTPS'] = 'on'
227
224
  @request.env['SSL_CLIENT_S_DN'] = 'CN=else.where'
@@ -234,7 +231,6 @@ module ForemanPuppet
234
231
  test 'hosts in trusted hosts list and SSL cert should get externalNodes successfully' do
235
232
  User.current = nil
236
233
  Setting[:restrict_registered_smart_proxies] = true
237
- Setting[:require_ssl_smart_proxies] = true
238
234
  Setting[:trusted_hosts] = ['else.where']
239
235
 
240
236
  @request.env['HTTPS'] = 'on'
@@ -248,7 +244,6 @@ module ForemanPuppet
248
244
  test 'hosts with comma-separated SSL DN should get externalNodes successfully' do
249
245
  User.current = nil
250
246
  Setting[:restrict_registered_smart_proxies] = true
251
- Setting[:require_ssl_smart_proxies] = true
252
247
  Setting[:trusted_hosts] = ['foreman.example']
253
248
 
254
249
  @request.env['HTTPS'] = 'on'
@@ -262,7 +257,6 @@ module ForemanPuppet
262
257
  test 'hosts with slash-separated SSL DN should get externalNodes successfully' do
263
258
  User.current = nil
264
259
  Setting[:restrict_registered_smart_proxies] = true
265
- Setting[:require_ssl_smart_proxies] = true
266
260
  Setting[:trusted_hosts] = ['foreman.linux.lab.local']
267
261
 
268
262
  @request.env['HTTPS'] = 'on'
@@ -276,53 +270,37 @@ module ForemanPuppet
276
270
  test 'hosts without a registered smart proxy but with an SSL cert should not be able to get externalNodes' do
277
271
  User.current = nil
278
272
  Setting[:restrict_registered_smart_proxies] = true
279
- Setting[:require_ssl_smart_proxies] = true
280
273
 
281
274
  @request.env['HTTPS'] = 'on'
282
275
  @request.env['SSL_CLIENT_S_DN'] = 'CN=another.host'
283
276
  @request.env['SSL_CLIENT_VERIFY'] = 'SUCCESS'
284
277
  get :externalNodes, params: { name: host1.name, format: 'yml' }
285
- assert_equal 403, @response.status
278
+ assert_response :forbidden
286
279
  end
287
280
 
288
281
  test 'hosts with an unverified SSL cert should not be able to get externalNodes' do
289
282
  User.current = nil
290
283
  Setting[:restrict_registered_smart_proxies] = true
291
- Setting[:require_ssl_smart_proxies] = true
292
284
 
293
285
  @request.env['HTTPS'] = 'on'
294
286
  @request.env['SSL_CLIENT_S_DN'] = 'CN=else.where'
295
287
  @request.env['SSL_CLIENT_VERIFY'] = 'FAILURE'
296
288
  get :externalNodes, params: { name: host1.name, format: 'yml' }
297
- assert_equal 403, @response.status
289
+ assert_response :forbidden
298
290
  end
299
291
 
300
- test 'when "require_ssl_smart_proxies" and "require_ssl" are true, HTTP requests should not be able to get externalNodes' do
292
+ test 'when "require_ssl" is true, HTTP requests should not be able to get externalNodes' do
301
293
  User.current = nil
302
294
  Setting[:restrict_registered_smart_proxies] = true
303
- Setting[:require_ssl_smart_proxies] = true
304
295
  SETTINGS[:require_ssl] = true
305
296
 
306
297
  Resolv.any_instance.stubs(:getnames).returns(['else.where'])
307
298
  get :externalNodes, params: { name: host1.name, format: 'yml' }
308
- assert_equal 403, @response.status
309
- end
310
-
311
- test 'when "require_ssl_smart_proxies" is true and "require_ssl" is false, HTTP requests should be able to get externalNodes' do
312
- User.current = nil
313
- # since require_ssl_smart_proxies is only applicable to HTTPS connections, both should be set
314
- Setting[:restrict_registered_smart_proxies] = true
315
- Setting[:require_ssl_smart_proxies] = true
316
- SETTINGS[:require_ssl] = false
317
-
318
- Resolv.any_instance.stubs(:getnames).returns(['else.where'])
319
- get :externalNodes, params: { name: host1.name, format: 'yml' }
320
- assert_response :success
299
+ assert_response :redirect
321
300
  end
322
301
 
323
302
  test 'authenticated users over HTTP should be able to get externalNodes' do
324
303
  Setting[:restrict_registered_smart_proxies] = true
325
- Setting[:require_ssl_smart_proxies] = true
326
304
  SETTINGS[:require_ssl] = false
327
305
 
328
306
  Resolv.any_instance.stubs(:getnames).returns(['users.host'])
@@ -332,7 +310,6 @@ module ForemanPuppet
332
310
 
333
311
  test 'authenticated users over HTTPS should be able to get externalNodes' do
334
312
  Setting[:restrict_registered_smart_proxies] = true
335
- Setting[:require_ssl_smart_proxies] = true
336
313
  SETTINGS[:require_ssl] = false
337
314
 
338
315
  Resolv.any_instance.stubs(:getnames).returns(['users.host'])
@@ -0,0 +1,34 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetclassLookupKeysHelperTest < ActionView::TestCase
5
+ include PuppetclassLookupKeysHelper
6
+
7
+ describe '#overridable_puppet_lookup_keys' do
8
+ let(:parent_puppet_var) { FactoryBot.create(:puppetclass_lookup_key) }
9
+ let(:parent_hg) { FactoryBot.create(:hostgroup, :with_puppet_enc, environment: parent_puppet_var.environments.first) }
10
+
11
+ context 'with new hostgroup' do
12
+ subject do
13
+ hg = Hostgroup.new(parent: parent_hg)
14
+ hg.build_puppet
15
+ hg
16
+ end
17
+
18
+ it 'returns inherited parameter' do
19
+ keys = overridable_puppet_lookup_keys(parent_puppet_var.param_classes.first, subject)
20
+ _(keys).must_include(parent_puppet_var)
21
+ end
22
+ end
23
+
24
+ context 'with new host' do
25
+ subject { Host.new(hostgroup: parent_hg) }
26
+
27
+ it 'returns inherited parameter' do
28
+ keys = overridable_puppet_lookup_keys(parent_puppet_var.param_classes.first, subject)
29
+ _(keys).must_include(parent_puppet_var)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -60,7 +60,8 @@ module ForemanPuppet
60
60
 
61
61
  close_interfaces_modal
62
62
 
63
- click_on_submit
63
+ click_button('Submit')
64
+ find('h5', text: /myhost1*/)
64
65
 
65
66
  host = Host::Managed.search_for('name ~ "myhost1"').first
66
67
  assert_equal env2.name, host.puppet.environment.name
@@ -94,8 +95,8 @@ module ForemanPuppet
94
95
  fill_in 'host_interfaces_attributes_0_mac', with: '00:11:11:11:11:11'
95
96
  fill_in 'host_interfaces_attributes_0_ip', with: '1.1.1.1'
96
97
  close_interfaces_modal
97
- click_on_submit
98
- find('#host-show') # wait for host details page
98
+ click_button('Submit')
99
+ find('h5', text: /myhost1*/) # wait for host details page
99
100
 
100
101
  host = Host::Managed.search_for('name ~ "myhost1"').first
101
102
  assert_equal env.name, host.puppet.environment.name
@@ -111,8 +112,9 @@ module ForemanPuppet
111
112
  visit edit_host_path(host)
112
113
 
113
114
  select2 env1.name, from: 'host_puppet_attributes_environment_id'
114
- click_on_submit
115
- assert_current_path(host_path(host), ignore_query: true)
115
+ click_button('Submit')
116
+ find('h5', text: /#{host.name}/)
117
+ assert_current_path(host_details_page_path(host), ignore_query: true)
116
118
 
117
119
  host.reload
118
120
  assert_equal env1.name, host.puppet.environment.name
@@ -201,7 +203,8 @@ module ForemanPuppet
201
203
  assert puppetclass_params.has_selector?("a[data-tag='override']", visible: :hidden)
202
204
  assert_equal('false', find("#s2id_host_lookup_values_attributes_#{lookup_key.id}_value .select2-chosen").text)
203
205
  select2 'true', from: "host_lookup_values_attributes_#{lookup_key.id}_value"
204
- click_on_submit
206
+ click_button('Submit')
207
+ find('h5', text: /#{host.name}/)
205
208
 
206
209
  visit edit_host_path(host)
207
210
  switch_form_tab('Puppet ENC')
@@ -217,7 +220,8 @@ module ForemanPuppet
217
220
  assert puppetclass_params.find('textarea:enabled')
218
221
  puppetclass_params.find("a[data-tag='remove']").click
219
222
  assert puppetclass_params.find('textarea:disabled')
220
- click_on_submit
223
+ click_button('Submit')
224
+ find('h5', text: /#{host.name}/)
221
225
 
222
226
  visit edit_host_path(host)
223
227
  switch_form_tab('Puppet ENC')
@@ -226,7 +230,8 @@ module ForemanPuppet
226
230
  puppetclass_params.find("a[data-tag='override']").click
227
231
  expect(puppetclass_params).must_have_selector('textarea:enabled')
228
232
  puppetclass_params.find('textarea').set('userCustom')
229
- click_on_submit
233
+ click_button('Submit')
234
+ find('h5', text: /#{host.name}/)
230
235
 
231
236
  visit edit_host_path(host)
232
237
  switch_form_tab('Puppet ENC')
@@ -271,7 +276,7 @@ module ForemanPuppet
271
276
  switch_form_tab('Puppet ENC')
272
277
  assert puppetclass_params.find('textarea').disabled?
273
278
  click_button('Submit')
274
- assert page.has_link?('Edit')
279
+ find('h5', text: /#{host.name}/)
275
280
  end
276
281
  end
277
282
 
@@ -53,6 +53,17 @@ module ForemanPuppet
53
53
  end
54
54
  end
55
55
 
56
+ describe '#puppetclass_ids=' do
57
+ test 'allows empting classes' do
58
+ host = FactoryBot.create(:host, :with_puppet_enc,
59
+ environment: environment,
60
+ puppetclasses: [puppetclass_both])
61
+ host.attributes = { puppet_attributes: { puppetclass_ids: [] } }
62
+ assert host.save, 'Host could not be saved after updating puppetclasses'
63
+ assert_empty host.reload.all_puppetclasses, 'Puppetclasses were not removed successfuly'
64
+ end
65
+ end
66
+
56
67
  describe '#all_puppetclasses' do
57
68
  test 'should return all classes for environment only' do
58
69
  host = FactoryBot.create(:host, :with_puppet_enc,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-12-29 00:00:00.000000000 Z
12
+ date: 2022-02-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environments and classes to the Foreman Hosts.
15
15
  email:
@@ -188,6 +188,8 @@ files:
188
188
  - db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb
189
189
  - db/migrate/20211111125003_drop_puppetclasses_direct_references.foreman_puppet.rb
190
190
  - db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb
191
+ - db/migrate/20220201205305_migrate_host_class_permission.foreman_puppet.rb
192
+ - db/migrate/20220208135305_migrate_environment_ignore_type.foreman_puppet.rb
191
193
  - db/migrate_foreman/20090722141107_create_environments.foreman_puppet.rb
192
194
  - db/migrate_foreman/20090802062223_create_puppetclasses.foreman_puppet.rb
193
195
  - db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb
@@ -292,6 +294,7 @@ files:
292
294
  - test/graphql/queries/puppetclass_query_test.rb
293
295
  - test/graphql/queries/puppetclasses_query_test.rb
294
296
  - test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb
297
+ - test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb
295
298
  - test/helpers/foreman_puppet/puppetclasses_helper_test.rb
296
299
  - test/integration/foreman_puppet/dashboard_js_test.rb
297
300
  - test/integration/foreman_puppet/environment_js_test.rb
@@ -364,7 +367,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
367
  - !ruby/object:Gem::Version
365
368
  version: '0'
366
369
  requirements: []
367
- rubygems_version: 3.1.6
370
+ rubygems_version: 3.3.4
368
371
  signing_key:
369
372
  specification_version: 4
370
373
  summary: Add Puppet features to Foreman
@@ -389,6 +392,7 @@ test_files:
389
392
  - test/graphql/queries/hostgroup_puppet_query_test.rb
390
393
  - test/graphql/queries/environments_query_test.rb
391
394
  - test/integration_puppet_helper.rb
395
+ - test/helpers/foreman_puppet/puppetclass_lookup_keys_helper_test.rb
392
396
  - test/helpers/foreman_puppet/puppetclasses_helper_test.rb
393
397
  - test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb
394
398
  - test/models/foreman_puppet/config_group_class_test.rb