foreman_openscap 4.0.0 → 4.0.5

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: 1f968e87b516e2d4c5741f81baaa0b600a0fa22e27cc66de44c0564ca409ab6f
4
- data.tar.gz: f2a64b24fd9222676b6a91d315e792114627380fa6264acb2a229a7d939de024
3
+ metadata.gz: 956d9e3fe1db2b42e88e44e4a6ba71831011f89786ca0f985a565b78b455e985
4
+ data.tar.gz: 115326eadadbb7eeeb179299327e58a51036228a561b8b8aad91d69fe5a2dd53
5
5
  SHA512:
6
- metadata.gz: 250422cf84eebf5f22bfc1954d567b7af7851477534fcea29581af421a066fb1904ec3279386aae69777f1212526b83de3460f9da3549a9c3935619d9ea7d51f
7
- data.tar.gz: ae5d719e7467bf7b5850864e02e7335befab425035e763299e6a2fe0bbcf24835a1e0c58af22878d5a46278dbf520f5d5bd76c58ce4b3e25d3837a80ae8d6b47
6
+ metadata.gz: b995ec07848fcb27313a4a75ba2971d9b7da32b4c53a5366cadbb858e3a8abc32bb80123494e666b2266ac0c31ad452631e961bbeb7f69b5d0bad42edaa2b9ad
7
+ data.tar.gz: 4a521e80f3b3b273b12c1c8d80e5a3f655ce9a01ce79cb641f1b3342a9b959abca8e8a941c702344fc290e4fa194d346a399400de041cacff465f4160d32b328
@@ -90,12 +90,14 @@ module Api
90
90
  end
91
91
 
92
92
  def find_resources_before_create
93
- unless ForemanOpenscap::Policy.where(:id => params[:policy_id]).any?
94
- upload_fail(_("Policy with id %s not found.") % params[:policy_id])
93
+ policy_id = params[:policy_id].to_i
94
+
95
+ unless ForemanOpenscap::Policy.where(:id => policy_id).any?
96
+ upload_fail(_("Policy with id %s not found.") % policy_id)
95
97
  return
96
98
  end
97
99
 
98
- @asset = ForemanOpenscap::Helper::get_asset(params[:cname], params[:policy_id])
100
+ @asset = ForemanOpenscap::Helper::get_asset(params[:cname], policy_id)
99
101
 
100
102
  unless @asset
101
103
  upload_fail(_('Could not find host identified by: %s') % params[:cname])
@@ -22,18 +22,10 @@ module ForemanOpenscap
22
22
  end
23
23
 
24
24
  def inherited_openscap_proxy_id
25
- inherited_ancestry_attribute(:openscap_proxy_id)
26
- end
27
-
28
- unless defined?(Katello::System)
29
- private
30
-
31
- def inherited_ancestry_attribute(attribute)
32
- if ancestry.present?
33
- self[attribute] || self.class.sort_by_ancestry(ancestors.where("#{attribute} is not NULL")).last.try(attribute)
34
- else
35
- self.send(attribute)
36
- end
25
+ if ancestry.present?
26
+ self[:openscap_proxy_id] || self.class.sort_by_ancestry(ancestors.where.not(openscap_proxy_id: nil)).last.try(:openscap_proxy_id)
27
+ else
28
+ self.send(:openscap_proxy_id)
37
29
  end
38
30
  end
39
31
  end
@@ -33,10 +33,6 @@ module ForemanOpenscap
33
33
  end
34
34
  end
35
35
 
36
- def inherited_openscap_proxy_id
37
- inherited_ancestry_attribute(:openscap_proxy_id)
38
- end
39
-
40
36
  private
41
37
 
42
38
  def scap_client_lookup_values_for(lookup_keys, model_match)
@@ -312,7 +312,7 @@ module ForemanOpenscap
312
312
  end
313
313
 
314
314
  def assign_ids(ids, class_name)
315
- new_assets = ids.reject { |id| id.respond_to?(:empty?) && id.empty? }.reduce([]) do |memo, id|
315
+ new_assets = ids.uniq.reject { |id| id.respond_to?(:empty?) && id.empty? }.reduce([]) do |memo, id|
316
316
  memo << assets.where(:assetable_type => class_name, :assetable_id => id).first_or_initialize
317
317
  end
318
318
  complimentary_class_name = class_name == 'Host::Base' ? 'Hostgroup' : 'Host::Base'
@@ -0,0 +1,34 @@
1
+ class MigratePortOverridesForAnsible < ActiveRecord::Migration[6.0]
2
+ def up
3
+ transform_lookup_values :to_i
4
+ end
5
+
6
+ def down
7
+ transform_lookup_values :to_s
8
+ end
9
+
10
+ private
11
+
12
+ def transform_lookup_values(method)
13
+ return unless defined?(ForemanAnsible)
14
+ role = AnsibleRole.find_by :name => 'theforeman.foreman_scap_client'
15
+ return unless role
16
+ port_key = role.ansible_variables.find_by :key => 'foreman_scap_client_port'
17
+ return unless port_key
18
+ if method == :to_i
19
+ port_key.key_type = "integer"
20
+ port_key.default_value = 8080
21
+ else
22
+ port_key.key_type == "string"
23
+ port_key.default_value = ""
24
+ end
25
+
26
+ port_key.save
27
+ port_key.lookup_values.in_batches do |batch|
28
+ batch.each do |lookup_value|
29
+ lookup_value.value = lookup_value.value.send(method)
30
+ lookup_value.save
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ class UpdatePuppetPortParamType < ActiveRecord::Migration[6.0]
2
+ def up
3
+ update_port_type :to_i
4
+ end
5
+
6
+ def down
7
+ update_port_type :to_s
8
+ end
9
+
10
+ private
11
+
12
+ def update_port_type(method)
13
+ puppet_class = Puppetclass.find_by :name => 'foreman_scap_client'
14
+ return unless puppet_class
15
+ port_key = puppet_class.class_params.find_by :key => 'port'
16
+ return unless port_key
17
+ def_value = port_key.default_value
18
+
19
+ if method == :to_i
20
+ port_key.key_type = "integer"
21
+ port_key.default_value = def_value.to_i
22
+ else
23
+ port_key.key_type == "string"
24
+ port_key.default_value = port_key.default_value.to_s
25
+ end
26
+ port_key.save!
27
+ end
28
+ end
@@ -7,9 +7,9 @@ if ForemanOpenscap.with_remote_execution?
7
7
  sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
8
8
  # import! was renamed to import_raw! around 1.3.1
9
9
  if JobTemplate.respond_to?('import_raw!')
10
- template = JobTemplate.import_raw!(File.read(template), :default => true, :locked => true, :update => sync)
10
+ template = JobTemplate.import_raw!(File.read(template), :default => true, :lock => true, :update => sync)
11
11
  else
12
- template = JobTemplate.import!(File.read(template), :default => true, :locked => true, :update => sync)
12
+ template = JobTemplate.import!(File.read(template), :default => true, :lock => true, :update => sync)
13
13
  end
14
14
  template.organizations = organizations if SETTINGS[:organizations_enabled] && template.present?
15
15
  template.locations = locations if SETTINGS[:locations_enabled] && template.present?
@@ -2,7 +2,7 @@ module ForemanOpenscap::Helper
2
2
  def self.get_asset(cname, policy_id)
3
3
  asset = find_host_by_name_or_uuid(cname)&.get_asset
4
4
  return unless asset
5
- asset.policy_ids += [policy_id]
5
+ asset.policy_ids += [policy_id] unless asset.policy_ids.include?(policy_id)
6
6
  asset
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "4.0.0".freeze
2
+ VERSION = "4.0.5".freeze
3
3
  end
@@ -37,6 +37,15 @@ class PolicyTest < ActiveSupport::TestCase
37
37
  assert_equal hostgroup, policy.hostgroups.first
38
38
  end
39
39
 
40
+ test "should not raise when assiging same host by id" do
41
+ host1 = FactoryBot.create(:compliance_host)
42
+ asset = FactoryBot.create(:asset, :assetable_id => host1.id, :assetable_type => 'Host::Base')
43
+ policy = FactoryBot.create(:policy, :assets => [asset], :scap_content => @scap_content, :scap_content_profile => @scap_profile)
44
+ policy.host_ids = [host1, host1].map(&:id)
45
+ policy.save!
46
+ assert_equal 1, policy.hosts.count
47
+ end
48
+
40
49
  test "should remove associated hostgroup" do
41
50
  hg = FactoryBot.create(:hostgroup)
42
51
  asset = FactoryBot.create(:asset, :assetable_id => hg.id, :assetable_type => 'Hostgroup')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openscap
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - slukasik@redhat.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -244,6 +244,8 @@ files:
244
244
  - db/migrate/20171016125613_add_content_title_unique_constraint.foreman_openscap.rb
245
245
  - db/migrate/20190103093409_add_deployment_option_to_policy.foreman_openscap.rb
246
246
  - db/migrate/20200117135424_migrate_port_overrides_to_int.rb
247
+ - db/migrate/20200803065041_migrate_port_overrides_for_ansible.rb
248
+ - db/migrate/20201202110213_update_puppet_port_param_type.rb
247
249
  - db/seeds.d/75-job_templates.rb
248
250
  - db/seeds.d/openscap_feature.rb
249
251
  - db/seeds.d/openscap_policy_notification.rb
@@ -348,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
350
  - !ruby/object:Gem::Version
349
351
  version: '0'
350
352
  requirements: []
351
- rubygems_version: 3.0.8
353
+ rubygems_version: 3.1.2
352
354
  signing_key:
353
355
  specification_version: 4
354
356
  summary: Foreman plug-in for displaying OpenSCAP audit reports
@@ -356,10 +358,10 @@ test_files:
356
358
  - test/factories/arf_report_factory.rb
357
359
  - test/factories/asset_factory.rb
358
360
  - test/factories/compliance_host_factory.rb
359
- - test/factories/compliance_log_factory.rb
360
361
  - test/factories/policy_arf_report_factory.rb
361
362
  - test/factories/policy_factory.rb
362
363
  - test/factories/scap_content_related.rb
364
+ - test/factories/compliance_log_factory.rb
363
365
  - test/files/arf_report/arf_report.bz2
364
366
  - test/files/arf_report/arf_report.html
365
367
  - test/files/arf_report/arf_report.json
@@ -368,11 +370,11 @@ test_files:
368
370
  - test/files/scap_contents/ssg-fedora-ds.xml
369
371
  - test/files/tailoring_files/ssg-firefox-ds-tailoring-2.xml
370
372
  - test/files/tailoring_files/ssg-firefox-ds-tailoring.xml
371
- - test/functional/api/v2/compliance/arf_reports_controller_test.rb
372
373
  - test/functional/api/v2/compliance/policies_controller_test.rb
373
374
  - test/functional/api/v2/compliance/scap_content_profiles_controller_test.rb
374
375
  - test/functional/api/v2/compliance/scap_contents_controller_test.rb
375
376
  - test/functional/api/v2/compliance/tailoring_files_controller_test.rb
377
+ - test/functional/api/v2/compliance/arf_reports_controller_test.rb
376
378
  - test/functional/api/v2/hosts_controller_test.rb
377
379
  - test/functional/arf_reports_controller_test.rb
378
380
  - test/functional/openscap_proxies_controller_test.rb
@@ -380,7 +382,6 @@ test_files:
380
382
  - test/helpers/arf_report_dashboard_helper_test.rb
381
383
  - test/helpers/policy_dashboard_helper_test.rb
382
384
  - test/lib/foreman_openscap/bulk_upload_test.rb
383
- - test/test_plugin_helper.rb
384
385
  - test/unit/arf_report_status_calculator_test.rb
385
386
  - test/unit/arf_report_test.rb
386
387
  - test/unit/compliance_status_test.rb
@@ -389,7 +390,6 @@ test_files:
389
390
  - test/unit/message_cleaner_test.rb
390
391
  - test/unit/openscap_host_test.rb
391
392
  - test/unit/policy_mailer_test.rb
392
- - test/unit/policy_test.rb
393
393
  - test/unit/scap_content_test.rb
394
394
  - test/unit/services/config_name_service_test.rb
395
395
  - test/unit/services/hostgroup_overrider_test.rb
@@ -397,3 +397,5 @@ test_files:
397
397
  - test/unit/services/report_dashboard/data_test.rb
398
398
  - test/unit/services/tailoring_files_proxy_check_test.rb
399
399
  - test/unit/tailoring_file_test.rb
400
+ - test/unit/policy_test.rb
401
+ - test/test_plugin_helper.rb