foreman_openscap 0.10.3 → 0.10.4

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
  SHA1:
3
- metadata.gz: a8a1469f7adb801cd2a0546ae4ee61e2fe2161d5
4
- data.tar.gz: 5f0e0fb1d2749991765d97548e144df5e837fe35
3
+ metadata.gz: 9b441309459cd62b0c525d1b51dd856b28bf3b2e
4
+ data.tar.gz: 2b98addfa0d16368c3f9d9be4af017047ba56036
5
5
  SHA512:
6
- metadata.gz: 0ef9439800ec792c4982c86e77702a04079bee39797c3ef07de41b9cacd4de64ace28a60f15646ccae66d6eace541bb6c4473aaad3db491a8b18498cfb270f18
7
- data.tar.gz: 12600506e0dc3c9abdeda73b14d7f43ab98910ec0c6fe89379a50d84800cfbb2a7401f00d4a2bf8deafb6059b9057049227a832d93938223e9e9a1e295f72dd0
6
+ metadata.gz: ddae8417386fa6877ce9b2873b94f1750dde15217cf29cc2fbb3d2e5e2ae7f07ee4905da0702a45c00d26b6ad8c20c5b0aa43d89b11becf04344feabba1d7af5
7
+ data.tar.gz: 6b843df78415ac1c53ee199e06abba468f0d3e0c121c890b0565aec35c38a788d9fde4092fcdd59a4410b97eb6f8c3039b2cc8228787e34866f7d5829e95b630
@@ -14,8 +14,8 @@ module Api
14
14
  before_action :find_resources_before_create, :only => %w[create]
15
15
  skip_after_action :log_response_body, :only => %w[download download_html]
16
16
 
17
- def resource_name
18
- '::ForemanOpenscap::ArfReport'
17
+ def resource_name(resource = '::ForemanOpenscap::ArfReport')
18
+ super resource
19
19
  end
20
20
 
21
21
  def get_resource(message = 'no resource loaded')
@@ -10,8 +10,8 @@ module Api::V2
10
10
 
11
11
  skip_after_action :log_response_body, :only => [:content]
12
12
 
13
- def resource_name
14
- '::ForemanOpenscap::Policy'
13
+ def resource_name(resource = '::ForemanOpenscap::Policy')
14
+ super resource
15
15
  end
16
16
 
17
17
  def get_resource(message = 'no resource loaded')
@@ -4,8 +4,8 @@ module Api::V2
4
4
  include Foreman::Controller::Parameters::ScapContent
5
5
  before_action :find_resource, :except => %w[index create]
6
6
 
7
- def resource_name
8
- '::ForemanOpenscap::ScapContent'
7
+ def resource_name(resource = '::ForemanOpenscap::ScapContent')
8
+ super resource
9
9
  end
10
10
 
11
11
  def get_resource(message = 'no resource loaded')
@@ -5,8 +5,8 @@ module Api::V2
5
5
  before_action :find_resource, :except => %w[index create]
6
6
  before_action :openscap_proxy_check, :only => %w[create]
7
7
 
8
- def resource_name
9
- '::ForemanOpenscap::TailoringFile'
8
+ def resource_name(resource = '::ForemanOpenscap::TailoringFile')
9
+ super resource
10
10
  end
11
11
 
12
12
  def get_resource(message = 'no resource loaded')
@@ -52,7 +52,7 @@ module ForemanOpenscap
52
52
  end
53
53
 
54
54
  def policies=(policies)
55
- self.create_asset(:assetable => self) if self.asset.blank?
55
+ self.build_asset(:assetable => self) if self.asset.blank?
56
56
  self.asset.policies = policies
57
57
  end
58
58
 
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "0.10.3".freeze
2
+ VERSION = "0.10.4".freeze
3
3
  end
@@ -5,7 +5,6 @@ FactoryBot.define do
5
5
  policy_arf_report nil
6
6
  sequence(:reported_at) { |n| Time.new(1490 + n, 0o1, 13, 15, 24, 0o0) }
7
7
  sequence(:created_at) { |n| Time.new(1490 + n, 0o1, 13, 15, 24, 0o0) }
8
- logs []
9
8
  status 0
10
9
  metrics({})
11
10
  openscap_proxy nil
@@ -11,50 +11,57 @@ module ForemanOpenscap
11
11
  @host = FactoryBot.create(:compliance_host)
12
12
  @failed_source = FactoryBot.create(:source)
13
13
  @passed_source = FactoryBot.create(:source)
14
- @log_1 = FactoryBot.create(:compliance_log, :result => "pass", :source => @passed_source)
15
- @log_2 = FactoryBot.create(:compliance_log, :result => "fail", :source => @failed_source)
16
- @log_3 = FactoryBot.create(:compliance_log, :result => "pass", :source => @passed_source)
14
+
15
+ @passed_log_params = { :result => "pass", :source => @passed_source }
16
+ @failed_log_params = { :result => "fail", :source => @failed_source }
17
17
  @status = { :passed => 5, :failed => 1, :othered => 7 }.with_indifferent_access
18
18
  end
19
19
 
20
20
  test 'equal? should return true when there is no change in report results' do
21
- log_4 = FactoryBot.create(:compliance_log, :result => "fail", :source => @failed_source)
22
- report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
23
- report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_3, log_4])
21
+ report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
22
+ report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
23
+ create_logs_for_report(report_1, [@passed_log_params, @failed_log_params])
24
+ create_logs_for_report(report_2, [@passed_log_params, @failed_log_params])
24
25
 
25
26
  assert(report_1.equal?(report_2))
26
27
  end
27
28
 
28
29
  test 'equal? should return false when there is change in report results' do
29
30
  new_source = FactoryBot.create(:source)
30
- log_4 = FactoryBot.build(:compliance_log, :result => "pass", :source => new_source)
31
- report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
32
- report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_3, log_4])
31
+
32
+ report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
33
+ report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
34
+ create_logs_for_report(report_1, [@passed_log_params, @failed_log_params])
35
+ create_logs_for_report(report_2, [@passed_log_params, @passed_log_params])
33
36
 
34
37
  refute(report_1.equal?(report_2))
35
38
  end
36
39
 
37
40
  test 'equal? should return false when reports have different sets of rules' do
38
- report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
39
- report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_3])
41
+ report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
42
+ report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
43
+ create_logs_for_report(report_1, [@passed_log_params, @failed_log_params])
44
+ create_logs_for_report(report_2, [@passed_log_params])
40
45
 
41
46
  refute(report_1.equal?(report_2))
42
47
  end
43
48
 
44
49
  test 'equal? should return false when reports have different hosts' do
45
50
  host = FactoryBot.create(:compliance_host)
46
- log_4 = FactoryBot.create(:compliance_log, :result => "fail", :source => @failed_source)
47
- report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
48
- report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => host.id, :logs => [@log_3, log_4])
51
+ report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
52
+ report_2 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => host.id)
53
+ create_logs_for_report(report_1, [@passed_log_params, @failed_log_params])
54
+ create_logs_for_report(report_2, [@passed_log_params, @failed_log_params])
49
55
 
50
56
  refute(report_1.equal?(report_2))
51
57
  end
52
58
 
53
59
  test 'equal? should return false when reports have different policies' do
54
60
  policy = FactoryBot.create(:policy)
55
- log_4 = FactoryBot.create(:compliance_log, :result => "fail", :source => @failed_source)
56
- report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
57
- report_2 = FactoryBot.create(:arf_report, :policy => policy, :host_id => @host.id, :logs => [@log_3, log_4])
61
+ report_1 = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
62
+ report_2 = FactoryBot.create(:arf_report, :policy => policy, :host_id => @host.id)
63
+ create_logs_for_report(report_1, [@passed_log_params, @failed_log_params])
64
+ create_logs_for_report(report_2, [@passed_log_params, @failed_log_params])
58
65
 
59
66
  refute(report_1.equal?(report_2))
60
67
  end
@@ -151,9 +158,19 @@ module ForemanOpenscap
151
158
  openscap_proxy_api.stubs(:destroy_report).returns(true)
152
159
  ForemanOpenscap::Helper.stubs(:find_name_or_uuid_by_host).returns("abcde")
153
160
  ForemanOpenscap::ArfReport.any_instance.stubs(:openscap_proxy_api).returns(openscap_proxy_api)
154
- report = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id, :logs => [@log_1, @log_2])
161
+ report = FactoryBot.create(:arf_report, :policy => @policy, :host_id => @host.id)
162
+ create_logs_for_report(report, [@passed_log_params, @failed_log_params])
163
+
155
164
  report.destroy
156
165
  refute ForemanOpenscap::ArfReport.all.include? report
157
166
  end
167
+
168
+ private
169
+
170
+ def create_logs_for_report(report, log_params)
171
+ log_params.each do |param_group|
172
+ FactoryBot.create(:compliance_log, param_group.merge(:report_id => report.id))
173
+ end
174
+ end
158
175
  end
159
176
  end
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: 0.10.3
4
+ version: 0.10.4
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: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2018-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface