-
Notifications
You must be signed in to change notification settings - Fork 8
/
arf_waiver_test.rb
100 lines (85 loc) · 2.47 KB
/
arf_waiver_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Copyright (c) 2014 Red Hat Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
require 'openscap'
require 'openscap/xccdf/benchmark'
require 'openscap/xccdf/ruleresult'
require 'openscap/xccdf/session'
require 'openscap/xccdf/testresult'
require 'openscap/ds/arf'
require 'openscap/ds/sds'
require 'common/testcase'
class TestArfWaiver < OpenSCAP::TestCase
def test_waiver_and_score
assert_default_score tr.score, -1, 1
assert_default_score tr.score!(benchmark), -1, 1
rr.override!(:new_result => :pass,
:time => 'yesterday',
:authority => 'John Hacker',
:raw_text => 'This should have passed')
rr.result == 'pass'
assert_default_score tr.score, -1, 1
assert_default_score tr.score!(benchmark), 99, 101
# create updated DOM (that includes the override element and new score)
arf.test_result = tr
arf.source.save('modified.rds.xml')
tr.destroy
arf.destroy
arf2 = OpenSCAP::DS::Arf.new('modified.rds.xml')
tr2 = arf2.test_result('xccdf1')
assert_default_score tr.score, 99, 101
rr2 = tr2.rr['xccdf_moc.elpmaxe.www_rule_first']
assert rr2.result == 'pass'
tr2.destroy
arf2.destroy
end
private
def benchmark
@benchmark ||= benchmark_init
end
def benchmark_init
sds = arf.report_request
bench_source = sds.select_checklist!
bench = OpenSCAP::Xccdf::Benchmark.new bench_source
sds.destroy
bench
end
def rr
@rr ||= rr_init
end
def rr_init
assert tr.rr.size == 1
rr = tr.rr['xccdf_moc.elpmaxe.www_rule_first']
assert rr.result == 'fail'
rr
end
def tr
@tr ||= tr_init
end
def tr_init
tr = arf.test_result
assert tr.score.size == 1
score = tr.score['urn:xccdf:scoring:default']
assert score[:system] == 'urn:xccdf:scoring:default'
assert score[:max] == 100.0
assert score[:value] == 0.0
tr
end
def arf
@arf ||= arf_init
end
def arf_init
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
@s.load
@s.evaluate
@s.export_results(:rds_file => 'report.rds.xml')
OpenSCAP::DS::Arf.new('report.rds.xml')
end
end