foreman_openscap 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +8 -12
- data/app/views/api/v2/compliance/policies/children.json.rabl +9 -0
- data/app/views/api/v2/compliance/policies/main.json.rabl +1 -0
- data/app/views/api/v2/compliance/policies/show.json.rabl +1 -4
- data/lib/foreman_openscap/version.rb +1 -1
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +105 -1
- data/test/functional/api/v2/compliance/policies_controller_test.rb +48 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a91e2bc0562de60ea4959460a9afe2029dddcc
|
4
|
+
data.tar.gz: 5b1ed88b9b0d29381eccff2d5349c965b99c65d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 199215c239ad13dd1e5ed6c971bd324f9dad62f138c5c0d42689dfa85050c71020514d247610e3c81d3acad4420927dc25d3e22cfe84355576b7067ecef914ab
|
7
|
+
data.tar.gz: 51af4f9460056312001d0b7edec878a28adc6aba39876682f36825fe9decb9f206acaff598981958704699497d0aebb3282912d60dd8b6ea5f25f9499f79d770
|
@@ -15,11 +15,9 @@ module ForemanOpenscap
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def search_by_policy_name(_key, _operator, policy_name)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
.of_policy(Policy.find_by(name: cond).id).ast
|
22
|
-
).to_sql }
|
18
|
+
query = PolicyArfReport.of_policy(Policy.find_by(:name => policy_name))
|
19
|
+
.select(PolicyArfReport.arel_table[:arf_report_id]).to_sql
|
20
|
+
query_conditions query
|
23
21
|
end
|
24
22
|
|
25
23
|
def search_by_comply_with(_key, _operator, policy_name)
|
@@ -35,11 +33,9 @@ module ForemanOpenscap
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def search_by_policy_results(policy_name, &selection)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
.latest_of_policy(Policy.find_by(name: cond)).instance_eval(&selection).ast
|
42
|
-
).to_sql }
|
36
|
+
query = ArfReport.of_policy(Policy.find_by(:name => policy_name).id)
|
37
|
+
.instance_eval(&selection).select(ArfReport.arel_table[:id]).to_sql
|
38
|
+
query_conditions query
|
43
39
|
end
|
44
40
|
|
45
41
|
def search_by_last_for(key, operator, by)
|
@@ -66,8 +62,8 @@ module ForemanOpenscap
|
|
66
62
|
|
67
63
|
private
|
68
64
|
|
69
|
-
def
|
70
|
-
|
65
|
+
def query_conditions(query)
|
66
|
+
{ :conditions => "reports.id IN (#{query})" }
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
@@ -14,6 +14,7 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
14
14
|
|
15
15
|
@from_json = arf_from_json "#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.json"
|
16
16
|
@cname = '9521a5c5-8f44-495f-b087-20e86b30bf67'
|
17
|
+
@proxy = FactoryBot.create(:smart_proxy, :url => "http://smart-proxy.org:8000")
|
17
18
|
end
|
18
19
|
|
19
20
|
test "should get index" do
|
@@ -144,6 +145,99 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
144
145
|
assert_equal new_msgs.first.digest, Digest::SHA1.hexdigest("Disable Firefox Configuration File ROT-13 Encoding Changed For Test")
|
145
146
|
end
|
146
147
|
|
148
|
+
test "should find reports by policy name" do
|
149
|
+
reports_cleanup
|
150
|
+
report_a = create_arf_report
|
151
|
+
report_b = create_arf_report
|
152
|
+
policy = FactoryBot.create(:policy)
|
153
|
+
FactoryBot.create(:policy_arf_report, :policy_id => @policy.id, :arf_report_id => report_a.id)
|
154
|
+
FactoryBot.create(:policy_arf_report, :policy_id => policy.id, :arf_report_id => report_b.id)
|
155
|
+
|
156
|
+
get :index, :params => { :search => "compliance_policy=#{policy.name}" }, :session => set_session_user
|
157
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
158
|
+
assert_response :success
|
159
|
+
assert_equal 1, response['results'].count
|
160
|
+
end
|
161
|
+
|
162
|
+
test "should find reports compliant with policy" do
|
163
|
+
reports_cleanup
|
164
|
+
policy = FactoryBot.create(:policy)
|
165
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 3 }, @policy)
|
166
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, @policy)
|
167
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 0 }, @policy)
|
168
|
+
create_arf_report_for_search({ "passed" => 3, "othered" => 0, "failed" => 0 }, @policy)
|
169
|
+
create_arf_report_for_search({ "passed" => 5, "othered" => 0, "failed" => 0 }, policy)
|
170
|
+
|
171
|
+
get :index, :params => { :search => "comply_with=#{@policy.name}" }, :session => set_session_user
|
172
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
173
|
+
assert_response :success
|
174
|
+
assert_equal 2, response['results'].count
|
175
|
+
end
|
176
|
+
|
177
|
+
test "should find reports inconclusive for policy" do
|
178
|
+
reports_cleanup
|
179
|
+
policy = FactoryBot.create(:policy)
|
180
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 5, "failed" => 0 }, @policy)
|
181
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 3 }, @policy)
|
182
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, @policy)
|
183
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 0 }, @policy)
|
184
|
+
create_arf_report_for_search({ "passed" => 2, "othered" => 3, "failed" => 0 }, policy)
|
185
|
+
|
186
|
+
get :index, :params => { :search => "inconclusive_with=#{@policy.name}" }, :session => set_session_user
|
187
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
188
|
+
assert_response :success
|
189
|
+
assert_equal 2, response['results'].count
|
190
|
+
end
|
191
|
+
|
192
|
+
test "should find reports failing for policy" do
|
193
|
+
reports_cleanup
|
194
|
+
policy = FactoryBot.create(:policy)
|
195
|
+
create_arf_report_for_search({ "passed" => 0, "othered" => 0, "failed" => 1 }, @policy)
|
196
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, @policy)
|
197
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 0 }, @policy)
|
198
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 2, "failed" => 4 }, @policy)
|
199
|
+
create_arf_report_for_search({ "passed" => 2, "othered" => 3, "failed" => 7 }, policy)
|
200
|
+
|
201
|
+
get :index, :params => { :search => "not_comply_with=#{@policy.name}" }, :session => set_session_user
|
202
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
203
|
+
assert_response :success
|
204
|
+
assert_equal 2, response['results'].count
|
205
|
+
end
|
206
|
+
|
207
|
+
test "should find last report for policy" do
|
208
|
+
reports_cleanup
|
209
|
+
policy = FactoryBot.create(:policy)
|
210
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, @policy)
|
211
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 4 }, @policy)
|
212
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, policy)
|
213
|
+
create_arf_report_for_search({ "passed" => 2, "othered" => 3, "failed" => 7 }, policy)
|
214
|
+
|
215
|
+
get :index, :params => { :search => "last_for=policy" }, :session => set_session_user
|
216
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
217
|
+
assert_response :success
|
218
|
+
assert_equal 2, response['results'].count
|
219
|
+
assert_equal 7, response['results'].find { |hash| hash["policy"]["name"] == policy.name }["failed"]
|
220
|
+
assert_equal 4, response['results'].find { |hash| hash["policy"]["name"] == @policy.name }["failed"]
|
221
|
+
end
|
222
|
+
|
223
|
+
test "should find last report for hosts" do
|
224
|
+
reports_cleanup
|
225
|
+
host_a = FactoryBot.create(:compliance_host)
|
226
|
+
host_b = FactoryBot.create(:compliance_host)
|
227
|
+
policy = FactoryBot.create(:policy)
|
228
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, policy, host_a)
|
229
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 4 }, policy, host_a)
|
230
|
+
create_arf_report_for_search({ "passed" => 1, "othered" => 0, "failed" => 0 }, policy, host_b)
|
231
|
+
create_arf_report_for_search({ "passed" => 2, "othered" => 3, "failed" => 7 }, policy, host_b)
|
232
|
+
|
233
|
+
get :index, :params => { :search => "last_for=host" }, :session => set_session_user
|
234
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
235
|
+
assert_response :success
|
236
|
+
assert_equal 2, response['results'].count
|
237
|
+
assert_equal 4, response['results'].find { |hash| hash["host"]["name"] == host_a.name }["failed"]
|
238
|
+
assert_equal 7, response['results'].find { |hash| hash["host"]["name"] == host_b.name }["failed"]
|
239
|
+
end
|
240
|
+
|
147
241
|
private
|
148
242
|
|
149
243
|
def reports_cleanup
|
@@ -161,9 +255,19 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
161
255
|
JSON.parse file_content
|
162
256
|
end
|
163
257
|
|
258
|
+
def create_arf_report_for_search(status, policy, host = @host)
|
259
|
+
report = FactoryBot.create(:arf_report,
|
260
|
+
:host_id => host.id,
|
261
|
+
:status => status,
|
262
|
+
:metrics => status,
|
263
|
+
:openscap_proxy => @proxy)
|
264
|
+
FactoryBot.create(:policy_arf_report, :policy_id => policy.id, :arf_report_id => report.id)
|
265
|
+
report
|
266
|
+
end
|
267
|
+
|
164
268
|
def create_arf_report
|
165
269
|
FactoryBot.create(:arf_report,
|
166
270
|
:host_id => @host.id,
|
167
|
-
:openscap_proxy =>
|
271
|
+
:openscap_proxy => @proxy)
|
168
272
|
end
|
169
273
|
end
|
@@ -19,6 +19,39 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
|
|
19
19
|
assert_response :success
|
20
20
|
end
|
21
21
|
|
22
|
+
test "should get index without hosts and hostgroups" do
|
23
|
+
FactoryBot.create(:policy)
|
24
|
+
get :index, :session => set_session_user
|
25
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
26
|
+
assert response['results'][0]['hosts'].empty?
|
27
|
+
assert response['results'][0]['hostgroups'].empty?
|
28
|
+
assert_response :success
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should get index and show hosts" do
|
32
|
+
host = FactoryBot.create(:host)
|
33
|
+
asset = FactoryBot.create(:asset, :assetable_id => host.id, :assetable_type => 'Host::Base')
|
34
|
+
policy = FactoryBot.create(:policy, :assets => [asset])
|
35
|
+
get :index, :session => set_session_user
|
36
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
37
|
+
assert !response['results'].empty?
|
38
|
+
assert !response['results'][0]['hosts'].empty?
|
39
|
+
assert_response :success
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should get index and show hostgroups" do
|
43
|
+
ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
|
44
|
+
ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
|
45
|
+
hostgroup = FactoryBot.create(:hostgroup)
|
46
|
+
asset = FactoryBot.create(:asset, :assetable_id => hostgroup.id, :assetable_type => 'Hostgroup')
|
47
|
+
policy = FactoryBot.create(:policy, :assets => [asset])
|
48
|
+
get :index, :session => set_session_user
|
49
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
50
|
+
assert !response['results'].empty?
|
51
|
+
assert !response['results'][0]['hostgroups'].empty?
|
52
|
+
assert_response :success
|
53
|
+
end
|
54
|
+
|
22
55
|
test "should show a policy" do
|
23
56
|
policy = FactoryBot.create(:policy)
|
24
57
|
get :show, :params => { :id => policy.to_param }, :session => set_session_user
|
@@ -27,6 +60,21 @@ class Api::V2::Compliance::PoliciesControllerTest < ActionController::TestCase
|
|
27
60
|
assert_response :success
|
28
61
|
end
|
29
62
|
|
63
|
+
test "should show a policy hosts and hostgroups" do
|
64
|
+
ForemanOpenscap::Policy.any_instance.stubs(:find_scap_puppetclass).returns(FactoryBot.create(:puppetclass, :name => 'foreman_scap_client'))
|
65
|
+
ForemanOpenscap::Policy.any_instance.stubs(:populate_overrides)
|
66
|
+
hostgroup = FactoryBot.create(:hostgroup)
|
67
|
+
host = FactoryBot.create(:host)
|
68
|
+
hostgroup_asset = FactoryBot.create(:asset, :assetable_id => hostgroup.id, :assetable_type => 'Hostgroup')
|
69
|
+
host_asset = FactoryBot.create(:asset, :assetable_id => host.id, :assetable_type => 'Host::Base')
|
70
|
+
policy = FactoryBot.create(:policy, :assets => [hostgroup_asset, host_asset])
|
71
|
+
get :show, :params => { :id => policy.to_param }, :session => set_session_user
|
72
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
73
|
+
assert !response['hosts'].empty?
|
74
|
+
assert !response['hostgroups'].empty?
|
75
|
+
assert_response :success
|
76
|
+
end
|
77
|
+
|
30
78
|
test "should update a policy" do
|
31
79
|
policy = FactoryBot.create(:policy)
|
32
80
|
put :update, :params => { :id => policy.id, :policy => { :period => 'monthly', :day_of_month => 15 } }
|
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.
|
4
|
+
version: 0.10.1
|
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-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- app/views/api/v2/compliance/common/_loc.json.rabl
|
107
107
|
- app/views/api/v2/compliance/common/_org.json.rabl
|
108
108
|
- app/views/api/v2/compliance/policies/base.json.rabl
|
109
|
+
- app/views/api/v2/compliance/policies/children.json.rabl
|
109
110
|
- app/views/api/v2/compliance/policies/create.json.rabl
|
110
111
|
- app/views/api/v2/compliance/policies/index.json.rabl
|
111
112
|
- app/views/api/v2/compliance/policies/main.json.rabl
|