openscap 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/openscap/ds/arf.rb +32 -3
- data/lib/openscap/ds/sds.rb +58 -0
- data/lib/openscap/openscap.rb +6 -2
- data/lib/openscap/source.rb +45 -5
- data/lib/openscap/text.rb +55 -0
- data/lib/openscap/version.rb +1 -1
- data/lib/openscap/{helper.rb → xccdf.rb} +6 -6
- data/lib/openscap/xccdf/benchmark.rb +62 -0
- data/lib/openscap/xccdf/profile.rb +43 -0
- data/lib/openscap/xccdf/ruleresult.rb +71 -0
- data/lib/openscap/xccdf/testresult.rb +114 -0
- data/test/common/testcase.rb +11 -0
- data/test/data/invalid.xml +20 -0
- data/test/data/testresult.xml +225 -0
- data/test/data/xccdf.xml +3043 -17
- data/test/ds/arf_test.rb +36 -10
- data/test/ds/sds_test.rb +79 -0
- data/test/integration/arf_waiver_test.rb +99 -0
- data/test/source_test.rb +56 -1
- data/test/text_test.rb +28 -0
- data/test/xccdf/benchmark_test.rb +48 -0
- data/test/xccdf/profile_test.rb +29 -0
- data/test/xccdf/testresult_test.rb +106 -0
- metadata +17 -3
data/test/ds/arf_test.rb
CHANGED
@@ -13,7 +13,7 @@ require 'openscap'
|
|
13
13
|
require 'openscap/ds/arf'
|
14
14
|
require 'common/testcase'
|
15
15
|
|
16
|
-
class
|
16
|
+
class TestArf < OpenSCAP::TestCase
|
17
17
|
def test_arf_new_nil
|
18
18
|
msg = nil
|
19
19
|
begin
|
@@ -22,32 +22,58 @@ class TestSession < OpenSCAP::TestCase
|
|
22
22
|
rescue OpenSCAP::OpenSCAPError => e
|
23
23
|
msg = e.to_s
|
24
24
|
end
|
25
|
-
assert msg.start_with?("
|
25
|
+
assert msg.start_with?("Cannot initialize OpenSCAP::DS:Arf with ''"), "Message was: " + msg
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_arf_new_wrong_format
|
29
29
|
msg = nil
|
30
30
|
begin
|
31
|
-
s = OpenSCAP::DS::Arf.new("data/xccdf.xml")
|
31
|
+
s = OpenSCAP::DS::Arf.new("../data/xccdf.xml")
|
32
32
|
assert false
|
33
33
|
rescue OpenSCAP::OpenSCAPError => e
|
34
34
|
msg = e.to_s
|
35
35
|
end
|
36
|
-
assert msg.start_with?('failed to load external entity "data/xccdf.xml"'), "Message was: " + msg
|
37
36
|
assert msg.include?('Could not create Result DataStream session: File is not Result DataStream.'),
|
38
37
|
"Message was: " + msg
|
39
38
|
end
|
40
39
|
|
41
40
|
def test_create_arf_and_get_html
|
41
|
+
arf = new_arf
|
42
|
+
html = arf.html
|
43
|
+
arf.destroy
|
44
|
+
assert html.start_with?('<!DOCTYPE html><html'), "DOCTYPE missing."
|
45
|
+
assert html.include?('OpenSCAP')
|
46
|
+
assert html.include?('Compliance and Scoring')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_create_arf_and_get_profile
|
50
|
+
arf = new_arf
|
51
|
+
tr = arf.test_result
|
52
|
+
assert tr.profile == 'xccdf_moc.elpmaxe.www_profile_1',
|
53
|
+
"TestResult.profile was '#{tr.profile}'"
|
54
|
+
tr.destroy
|
55
|
+
arf.destroy
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_new_memory
|
59
|
+
create_arf
|
60
|
+
raw_data = File.read("report.rds.xml")
|
61
|
+
assert raw_data.length > 0
|
62
|
+
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => "report.rds.xml"
|
63
|
+
arf.destroy
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def new_arf
|
68
|
+
create_arf
|
69
|
+
arf = OpenSCAP::DS::Arf.new("report.rds.xml")
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_arf
|
42
73
|
@s = OpenSCAP::Xccdf::Session.new("../data/sds-complex.xml")
|
43
74
|
@s.load(:component_id => "scap_org.open-scap_cref_second-xccdf.xml")
|
44
75
|
@s.profile = "xccdf_moc.elpmaxe.www_profile_1"
|
45
76
|
@s.evaluate
|
46
77
|
@s.export_results(:rds_file => "report.rds.xml")
|
47
|
-
arf = OpenSCAP::DS::Arf.new("report.rds.xml")
|
48
|
-
html = arf.html
|
49
|
-
assert html.start_with?('<!DOCTYPE html><html'), "DOCTYPE missing."
|
50
|
-
assert html.include?('OpenSCAP')
|
51
|
-
assert html.include?('Compliance and Scoring')
|
52
78
|
end
|
53
|
-
end
|
79
|
+
end
|
data/test/ds/sds_test.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'openscap'
|
13
|
+
require 'openscap/source'
|
14
|
+
require 'openscap/ds/sds'
|
15
|
+
require 'common/testcase'
|
16
|
+
|
17
|
+
class TestSds < OpenSCAP::TestCase
|
18
|
+
def test_new
|
19
|
+
new_sds.destroy
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_new_non_sds
|
23
|
+
filename = '../data/xccdf.xml'
|
24
|
+
@s = OpenSCAP::Source.new filename
|
25
|
+
assert !@s.nil?
|
26
|
+
msg = nil
|
27
|
+
begin
|
28
|
+
sds = OpenSCAP::DS::Sds.new :source => @s
|
29
|
+
assert false
|
30
|
+
rescue OpenSCAP::OpenSCAPError => e
|
31
|
+
msg = e.to_s
|
32
|
+
end
|
33
|
+
assert msg.start_with?('Could not create Source DataStream session: File is not Source DataStream.'), msg
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_select_checklist
|
37
|
+
sds = new_sds
|
38
|
+
benchmark = sds.select_checklist!
|
39
|
+
assert !benchmark.nil?
|
40
|
+
sds.destroy
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_show_guides
|
44
|
+
sds = new_sds
|
45
|
+
benchmark_source = sds.select_checklist!
|
46
|
+
benchmark = OpenSCAP::Xccdf::Benchmark.new benchmark_source
|
47
|
+
benchmark.profiles.keys.each { |id|
|
48
|
+
guide = sds.html_guide id
|
49
|
+
assert !guide.nil?
|
50
|
+
assert guide.include?(id)
|
51
|
+
}
|
52
|
+
benchmark.destroy
|
53
|
+
sds.destroy
|
54
|
+
end
|
55
|
+
|
56
|
+
def tests_select_checklist_wrong
|
57
|
+
sds = new_sds
|
58
|
+
msg = nil
|
59
|
+
begin
|
60
|
+
benchmark = sds.select_checklist! :datastream_id => "wrong"
|
61
|
+
assert false
|
62
|
+
rescue OpenSCAP::OpenSCAPError => e
|
63
|
+
msg = e.to_s
|
64
|
+
end
|
65
|
+
assert msg.start_with?('Failed to locate a datastream with ID matching'), msg
|
66
|
+
assert benchmark.nil?
|
67
|
+
sds.destroy
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def new_sds
|
72
|
+
filename = '../data/sds-complex.xml'
|
73
|
+
@s = OpenSCAP::Source.new filename
|
74
|
+
assert !@s.nil?
|
75
|
+
sds = OpenSCAP::DS::Sds.new :source => @s
|
76
|
+
assert !sds.nil?
|
77
|
+
return sds
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'openscap'
|
13
|
+
require 'openscap/xccdf/benchmark'
|
14
|
+
require 'openscap/xccdf/ruleresult'
|
15
|
+
require 'openscap/xccdf/session'
|
16
|
+
require 'openscap/xccdf/testresult'
|
17
|
+
require 'openscap/ds/arf'
|
18
|
+
require 'openscap/ds/sds'
|
19
|
+
require 'common/testcase'
|
20
|
+
|
21
|
+
class TestArfWaiver < OpenSCAP::TestCase
|
22
|
+
def test_waiver_and_score
|
23
|
+
assert_default_score tr.score, -1, 1
|
24
|
+
assert_default_score tr.score!(benchmark), -1, 1
|
25
|
+
|
26
|
+
rr.override!(:new_result => :pass,
|
27
|
+
:time => 'yesterday',
|
28
|
+
:authority => 'John Hacker',
|
29
|
+
:raw_text => 'This should have passed')
|
30
|
+
rr.result == 'pass'
|
31
|
+
|
32
|
+
assert_default_score tr.score, -1, 1
|
33
|
+
assert_default_score tr.score!(benchmark), 99, 101
|
34
|
+
|
35
|
+
# create updated DOM (that includes the override element and new score)
|
36
|
+
arf.test_result=tr
|
37
|
+
arf.source.save('modified.rds.xml')
|
38
|
+
tr.destroy
|
39
|
+
arf.destroy
|
40
|
+
|
41
|
+
arf2 = OpenSCAP::DS::Arf.new('modified.rds.xml')
|
42
|
+
tr2 = arf2.test_result('xccdf1')
|
43
|
+
assert_default_score tr.score, 99, 101
|
44
|
+
rr2 = tr2.rr['xccdf_moc.elpmaxe.www_rule_first']
|
45
|
+
assert rr2.result == 'pass'
|
46
|
+
tr2.destroy
|
47
|
+
arf2.destroy
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def benchmark
|
52
|
+
@benchmark ||= benchmark_init
|
53
|
+
end
|
54
|
+
|
55
|
+
def benchmark_init
|
56
|
+
sds = arf.report_request
|
57
|
+
bench_source = sds.select_checklist!
|
58
|
+
bench = OpenSCAP::Xccdf::Benchmark.new bench_source
|
59
|
+
sds.destroy
|
60
|
+
bench
|
61
|
+
end
|
62
|
+
|
63
|
+
def rr
|
64
|
+
@rr ||= rr_init
|
65
|
+
end
|
66
|
+
|
67
|
+
def rr_init
|
68
|
+
assert tr.rr.size == 1
|
69
|
+
rr = tr.rr['xccdf_moc.elpmaxe.www_rule_first']
|
70
|
+
assert rr.result == 'fail'
|
71
|
+
rr
|
72
|
+
end
|
73
|
+
|
74
|
+
def tr
|
75
|
+
@tr ||= tr_init
|
76
|
+
end
|
77
|
+
|
78
|
+
def tr_init
|
79
|
+
tr = arf.test_result
|
80
|
+
assert tr.score.size == 1
|
81
|
+
score = tr.score['urn:xccdf:scoring:default']
|
82
|
+
assert score[:system] == 'urn:xccdf:scoring:default'
|
83
|
+
assert score[:max] == 100.0
|
84
|
+
assert score[:value] == 0.0
|
85
|
+
tr
|
86
|
+
end
|
87
|
+
|
88
|
+
def arf
|
89
|
+
@arf ||= arf_init
|
90
|
+
end
|
91
|
+
|
92
|
+
def arf_init
|
93
|
+
@s = OpenSCAP::Xccdf::Session.new("../data/sds-complex.xml")
|
94
|
+
@s.load
|
95
|
+
@s.evaluate
|
96
|
+
@s.export_results(:rds_file => "report.rds.xml")
|
97
|
+
OpenSCAP::DS::Arf.new("report.rds.xml")
|
98
|
+
end
|
99
|
+
end
|
data/test/source_test.rb
CHANGED
@@ -26,7 +26,62 @@ class TestSource < OpenSCAP::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_source_new_ok
|
29
|
-
s = OpenSCAP::Source.new("data/xccdf.xml")
|
29
|
+
s = OpenSCAP::Source.new("../data/xccdf.xml")
|
30
30
|
s.destroy
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_source_new_memory
|
34
|
+
raw_data = File.read("../data/xccdf.xml")
|
35
|
+
assert raw_data.length > 0
|
36
|
+
s = OpenSCAP::Source.new(:content => raw_data, :path => '/mytestpath')
|
37
|
+
s.destroy
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_type_xccdf
|
41
|
+
s = OpenSCAP::Source.new("../data/xccdf.xml")
|
42
|
+
assert s.type == 'XCCDF Checklist', "Type was #{s.type}"
|
43
|
+
s.validate!
|
44
|
+
s.destroy
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_type_sds
|
48
|
+
s = OpenSCAP::Source.new("../data/sds-complex.xml")
|
49
|
+
assert s.type == 'SCAP Source Datastream', "Type was #{s.type}"
|
50
|
+
s.validate!
|
51
|
+
s.destroy
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_type_test_result
|
55
|
+
s = OpenSCAP::Source.new("../data/testresult.xml")
|
56
|
+
assert s.type == 'XCCDF Checklist', "Type was #{s.type}"
|
57
|
+
s.validate!
|
58
|
+
s.destroy
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_validate_invalid
|
62
|
+
s = OpenSCAP::Source.new("../data/invalid.xml")
|
63
|
+
msg = nil
|
64
|
+
begin
|
65
|
+
s.validate!
|
66
|
+
assert false
|
67
|
+
rescue OpenSCAP::OpenSCAPError => e
|
68
|
+
msg = e.to_s
|
69
|
+
end
|
70
|
+
assert msg.start_with?('Invalid XCCDF Checklist (1.2) content in ../data/invalid.xml.'),
|
71
|
+
"Message was: " + msg
|
72
|
+
assert msg.include?("../data/invalid.xml:3: Element '{http"),
|
73
|
+
"Message was: " + msg
|
74
|
+
assert msg.include?("This element is not expected. Expected is"),
|
75
|
+
"Message was: " + msg
|
76
|
+
s.destroy
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_save
|
80
|
+
s = OpenSCAP::Source.new("../data/testresult.xml")
|
81
|
+
filename = './newly_created.xml'
|
82
|
+
assert !File.exists?(filename)
|
83
|
+
s.save(filename)
|
84
|
+
assert File.exists?(filename)
|
85
|
+
FileUtils.rm_rf filename
|
86
|
+
end
|
32
87
|
end
|
data/test/text_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'openscap'
|
13
|
+
require 'openscap/text'
|
14
|
+
require 'common/testcase'
|
15
|
+
|
16
|
+
class TestText < OpenSCAP::TestCase
|
17
|
+
def test_text_new
|
18
|
+
t = OpenSCAP::Text.new
|
19
|
+
t.destroy
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_text_set_text
|
23
|
+
t = OpenSCAP::Text.new
|
24
|
+
t.text = 'blah'
|
25
|
+
assert t.text == 'blah', "Text was: #{t.text}"
|
26
|
+
t.destroy
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'common/testcase'
|
13
|
+
require 'openscap'
|
14
|
+
require 'openscap/ds/sds'
|
15
|
+
require 'openscap/source'
|
16
|
+
require 'openscap/xccdf/benchmark'
|
17
|
+
|
18
|
+
class TestBenchmark< OpenSCAP::TestCase
|
19
|
+
def test_new_from_file
|
20
|
+
@s = OpenSCAP::Source.new '../data/xccdf.xml'
|
21
|
+
b = OpenSCAP::Xccdf::Benchmark.new @s
|
22
|
+
assert !b.nil?
|
23
|
+
b.destroy
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_new_from_sds
|
27
|
+
@s = OpenSCAP::Source.new '../data/sds-complex.xml'
|
28
|
+
sds = OpenSCAP::DS::Sds.new @s
|
29
|
+
bench_source = sds.select_checklist!
|
30
|
+
assert !bench_source.nil?
|
31
|
+
b = OpenSCAP::Xccdf::Benchmark.new bench_source
|
32
|
+
assert !b.nil?
|
33
|
+
b.destroy
|
34
|
+
sds.destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_new_from_wrong
|
38
|
+
@s = OpenSCAP::Source.new '../data/testresult.xml'
|
39
|
+
msg = nil
|
40
|
+
begin
|
41
|
+
bench = OpenSCAP::Xccdf::Benchmark.new @s
|
42
|
+
assert false
|
43
|
+
rescue OpenSCAP::OpenSCAPError => e
|
44
|
+
msg = e.to_s
|
45
|
+
end
|
46
|
+
assert msg.start_with?('Failed to import XCCDF content from'), msg
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'common/testcase'
|
13
|
+
require 'openscap'
|
14
|
+
require 'openscap/source'
|
15
|
+
require 'openscap/xccdf/benchmark'
|
16
|
+
require 'openscap/xccdf/profile'
|
17
|
+
|
18
|
+
class TestProfile < OpenSCAP::TestCase
|
19
|
+
def test_new_from_file
|
20
|
+
@s = OpenSCAP::Source.new '../data/xccdf.xml'
|
21
|
+
b = OpenSCAP::Xccdf::Benchmark.new @s
|
22
|
+
assert !b.nil?
|
23
|
+
assert b.profiles.size == 1, b.profiles.to_s
|
24
|
+
profile1 = b.profiles['xccdf_org.ssgproject.content_profile_common']
|
25
|
+
assert profile1
|
26
|
+
assert profile1.title == 'Common Profile for General-Purpose Fedora Systems'
|
27
|
+
b.destroy
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
+
# along with this software; if not, see
|
9
|
+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'openscap/source'
|
13
|
+
require 'openscap/xccdf/benchmark'
|
14
|
+
require 'openscap/xccdf/testresult'
|
15
|
+
require 'common/testcase'
|
16
|
+
|
17
|
+
class TestTestResult < OpenSCAP::TestCase
|
18
|
+
def test_testresult_new_bad
|
19
|
+
source = OpenSCAP::Source.new('../data/xccdf.xml')
|
20
|
+
assert !source.nil?
|
21
|
+
msg = nil
|
22
|
+
begin
|
23
|
+
s = OpenSCAP::Xccdf::TestResult.new(source)
|
24
|
+
assert false
|
25
|
+
rescue OpenSCAP::OpenSCAPError => e
|
26
|
+
msg = e.to_s
|
27
|
+
end
|
28
|
+
assert msg.start_with?("Expected 'TestResult' element while found 'Benchmark'."),
|
29
|
+
"Message was: " + msg
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_result_create_and_query_properties
|
33
|
+
tr = new_tr
|
34
|
+
assert tr.id == 'xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_common',
|
35
|
+
"TestResult.id was '#{tr.id}"
|
36
|
+
assert tr.profile == 'xccdf_org.ssgproject.content_profile_common',
|
37
|
+
"TestResult.profile was '#{tr.profile}'"
|
38
|
+
tr.destroy
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_result_create_and_query_rr
|
42
|
+
tr = new_tr
|
43
|
+
assert tr.rr.size == 28
|
44
|
+
assert tr.rr.key?('xccdf_org.ssgproject.content_rule_disable_prelink')
|
45
|
+
assert tr.rr.key?('xccdf_org.ssgproject.content_rule_no_direct_root_logins')
|
46
|
+
assert 'fail' == tr.rr['xccdf_org.ssgproject.content_rule_disable_prelink'].result
|
47
|
+
assert 'notchecked' == tr.rr['xccdf_org.ssgproject.content_rule_no_direct_root_logins'].result
|
48
|
+
tr.destroy
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_override
|
52
|
+
tr = new_tr
|
53
|
+
rr = tr.rr['xccdf_org.ssgproject.content_rule_disable_prelink']
|
54
|
+
assert 'fail' == rr.result
|
55
|
+
rr.override!(:new_result => :pass,
|
56
|
+
:time => 'yesterday',
|
57
|
+
:authority => 'John Hacker',
|
58
|
+
:raw_text => 'We are testing prelink on this machine')
|
59
|
+
assert 'pass' == rr.result
|
60
|
+
tr.destroy
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_score
|
64
|
+
tr = new_tr
|
65
|
+
assert_default_score tr.score, 34, 35
|
66
|
+
tr.destroy
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_waive_and_score
|
70
|
+
tr = new_tr
|
71
|
+
benchmark = benchmark_for_tr
|
72
|
+
|
73
|
+
assert_default_score tr.score, 34, 35
|
74
|
+
assert_default_score tr.score!(benchmark), 34, 35
|
75
|
+
|
76
|
+
rr = tr.rr['xccdf_org.ssgproject.content_rule_disable_prelink']
|
77
|
+
assert 'fail' == rr.result
|
78
|
+
rr.override!(:new_result => :pass,
|
79
|
+
:time => 'yesterday',
|
80
|
+
:authority => 'John Hacker',
|
81
|
+
:raw_text => 'We are testing prelink on this machine')
|
82
|
+
assert 'pass' == rr.result
|
83
|
+
|
84
|
+
assert_default_score tr.score, 34, 35
|
85
|
+
assert_default_score tr.score!(benchmark), 47, 48
|
86
|
+
|
87
|
+
benchmark.destroy
|
88
|
+
tr.destroy
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def benchmark_for_tr
|
93
|
+
source = OpenSCAP::Source.new('../data/xccdf.xml')
|
94
|
+
benchmark = OpenSCAP::Xccdf::Benchmark.new source
|
95
|
+
source.destroy
|
96
|
+
benchmark
|
97
|
+
end
|
98
|
+
|
99
|
+
def new_tr
|
100
|
+
source = OpenSCAP::Source.new('../data/testresult.xml')
|
101
|
+
assert !source.nil?
|
102
|
+
tr = OpenSCAP::Xccdf::TestResult.new(source)
|
103
|
+
source.destroy
|
104
|
+
return tr
|
105
|
+
end
|
106
|
+
end
|