openscap 0.4.8 → 0.5.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 +5 -5
- data/README.md +7 -18
- data/Rakefile +4 -2
- data/lib/openscap/all.rb +2 -11
- data/lib/openscap/ds/arf.rb +5 -13
- data/lib/openscap/ds/sds.rb +9 -12
- data/lib/openscap/exceptions.rb +1 -10
- data/lib/openscap/libc.rb +1 -10
- data/lib/openscap/openscap.rb +11 -11
- data/lib/openscap/source.rb +12 -17
- data/lib/openscap/text.rb +35 -15
- data/lib/openscap/version.rb +2 -11
- data/lib/openscap/xccdf/benchmark.rb +65 -22
- data/lib/openscap/xccdf/fix.rb +6 -14
- data/lib/openscap/xccdf/group.rb +33 -10
- data/lib/openscap/xccdf/ident.rb +2 -10
- data/lib/openscap/xccdf/item.rb +36 -71
- data/lib/openscap/xccdf/item_common.rb +40 -0
- data/lib/openscap/xccdf/policy.rb +11 -10
- data/lib/openscap/xccdf/policy_model.rb +16 -16
- data/lib/openscap/xccdf/profile.rb +10 -19
- data/lib/openscap/xccdf/reference.rb +5 -13
- data/lib/openscap/xccdf/rule.rb +12 -25
- data/lib/openscap/xccdf/ruleresult.rb +1 -10
- data/lib/openscap/xccdf/session.rb +20 -30
- data/lib/openscap/xccdf/status.rb +35 -0
- data/lib/openscap/xccdf/tailoring.rb +4 -16
- data/lib/openscap/xccdf/testresult.rb +11 -26
- data/lib/openscap/xccdf/value.rb +1 -10
- data/lib/openscap/xccdf.rb +2 -11
- data/lib/openscap.rb +1 -10
- data/test/common/testcase.rb +2 -11
- data/test/data/sds-complex.xml +1 -1
- data/test/data/xccdf.xml +2 -1
- data/test/ds/arf_test.rb +11 -20
- data/test/ds/sds_test.rb +24 -15
- data/test/integration/arf_waiver_test.rb +6 -15
- data/test/openscap_test.rb +1 -10
- data/test/source_test.rb +14 -23
- data/test/text_test.rb +1 -10
- data/test/xccdf/arf_test.rb +2 -12
- data/test/xccdf/benchmark_test.rb +97 -20
- data/test/xccdf/item_test.rb +82 -0
- data/test/xccdf/policy_test.rb +36 -17
- data/test/xccdf/profile_test.rb +51 -18
- data/test/xccdf/session_ds_test.rb +14 -23
- data/test/xccdf/session_test.rb +3 -12
- data/test/xccdf/tailoring_test.rb +1 -10
- data/test/xccdf/testresult_test.rb +10 -19
- data/test/xccdf/value_test.rb +67 -0
- metadata +16 -27
data/lib/openscap/xccdf/value.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2015 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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/exceptions'
|
13
4
|
require 'openscap/xccdf/item'
|
data/lib/openscap/xccdf.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/openscap'
|
13
4
|
|
@@ -15,7 +6,7 @@ module OpenSCAP
|
|
15
6
|
module Xccdf
|
16
7
|
NUMERIC = :float
|
17
8
|
|
18
|
-
class Item
|
9
|
+
class Item # rubocop:disable Lint/EmptyClass
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
data/lib/openscap.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/openscap'
|
13
4
|
require 'openscap/exceptions'
|
data/test/common/testcase.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'test/unit'
|
13
4
|
|
@@ -26,7 +17,7 @@ module OpenSCAP
|
|
26
17
|
end
|
27
18
|
|
28
19
|
def cleanup
|
29
|
-
@s
|
20
|
+
@s&.destroy
|
30
21
|
Dir.chdir '../..'
|
31
22
|
OpenSCAP.raise! if OpenSCAP.error?
|
32
23
|
OpenSCAP.oscap_cleanup
|
data/test/data/sds-complex.xml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" id="scap_org.open-scap_collection_from_xccdf_first-xccdf.xml" schematron-version="1.
|
2
|
+
<ds:data-stream-collection xmlns:ds="http://scap.nist.gov/schema/scap/source/1.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" id="scap_org.open-scap_collection_from_xccdf_first-xccdf.xml" schematron-version="1.2">
|
3
3
|
<!-- This is bit more complex Datastream. The purpose is to test that scanner is able to find
|
4
4
|
* datastream-id scap_org.open-scap_datastream_tst2
|
5
5
|
* xccdf-id scap_org.open-scap_cref_second-xccdf.xml2
|
data/test/data/xccdf.xml
CHANGED
@@ -71,6 +71,7 @@ respective companies.</rear-matter>
|
|
71
71
|
<version>0.0.4</version>
|
72
72
|
<model system="urn:xccdf:scoring:default"/>
|
73
73
|
<Profile id="xccdf_org.ssgproject.content_profile_common">
|
74
|
+
<version>3.2.1</version>
|
74
75
|
<title xml:lang="en-US">Common Profile for General-Purpose Fedora Systems</title>
|
75
76
|
<description xml:lang="en-US">This profile contains items common to general-purpose Fedora installations.</description>
|
76
77
|
<select idref="xccdf_org.ssgproject.content_rule_disable_prelink" selected="true"/>
|
@@ -461,7 +462,7 @@ If this check produces any unexpected output, investigate.
|
|
461
462
|
<reference href="http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf">SC-28</reference>
|
462
463
|
<reference href="http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf">SI-7</reference>
|
463
464
|
<rationale xml:lang="en-US">
|
464
|
-
For AIDE to be effective, an initial database of "known-good" information about files
|
465
|
+
For AIDE to be effective, an initial database of <i xmlns="http://www.w3.org/1999/xhtml">"known-good"</i> information about files
|
465
466
|
must be captured and it should be able to be verified against the installed files.
|
466
467
|
</rationale>
|
467
468
|
</Rule>
|
data/test/ds/arf_test.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
require 'openscap/ds/arf'
|
14
5
|
require 'common/testcase'
|
15
6
|
|
16
7
|
class TestArf < OpenSCAP::TestCase
|
17
|
-
REPORT = 'report.rds.xml'
|
8
|
+
REPORT = 'report.rds.xml'
|
18
9
|
|
19
10
|
def test_arf_new_nil
|
20
11
|
msg = nil
|
@@ -24,7 +15,7 @@ class TestArf < OpenSCAP::TestCase
|
|
24
15
|
rescue OpenSCAP::OpenSCAPError => e
|
25
16
|
msg = e.to_s
|
26
17
|
end
|
27
|
-
assert msg.start_with?("Cannot initialize OpenSCAP::DS::Arf with ''"),
|
18
|
+
assert msg.start_with?("Cannot initialize OpenSCAP::DS::Arf with ''"), "Message was: #{msg}"
|
28
19
|
end
|
29
20
|
|
30
21
|
def test_arf_new_wrong_format
|
@@ -36,7 +27,7 @@ class TestArf < OpenSCAP::TestCase
|
|
36
27
|
msg = e.to_s
|
37
28
|
end
|
38
29
|
assert msg.include?('Could not create Result DataStream session: File is not Result DataStream.'),
|
39
|
-
|
30
|
+
"Message was: #{msg}"
|
40
31
|
end
|
41
32
|
|
42
33
|
def test_create_arf_and_get_html
|
@@ -61,17 +52,17 @@ class TestArf < OpenSCAP::TestCase
|
|
61
52
|
create_arf
|
62
53
|
raw_data = File.read(REPORT)
|
63
54
|
refute raw_data.empty?
|
64
|
-
arf = OpenSCAP::DS::Arf.new :
|
55
|
+
arf = OpenSCAP::DS::Arf.new content: raw_data, path: REPORT
|
65
56
|
arf.destroy
|
66
57
|
end
|
67
58
|
|
68
59
|
def test_new_bz_memory
|
69
60
|
bziped_file = new_arf_bz
|
70
|
-
raw_data = File.
|
61
|
+
raw_data = File.binread(bziped_file)
|
71
62
|
assert !raw_data.empty?
|
72
63
|
len = File.size(bziped_file)
|
73
64
|
FileUtils.rm bziped_file
|
74
|
-
arf = OpenSCAP::DS::Arf.new :
|
65
|
+
arf = OpenSCAP::DS::Arf.new content: raw_data, path: bziped_file, length: len
|
75
66
|
arf.destroy
|
76
67
|
end
|
77
68
|
|
@@ -86,8 +77,8 @@ class TestArf < OpenSCAP::TestCase
|
|
86
77
|
|
87
78
|
def new_arf_bz
|
88
79
|
create_arf
|
89
|
-
system(
|
90
|
-
REPORT
|
80
|
+
system("/usr/bin/bzip2 #{REPORT}")
|
81
|
+
"#{REPORT}.bz2"
|
91
82
|
end
|
92
83
|
|
93
84
|
def new_arf
|
@@ -97,9 +88,9 @@ class TestArf < OpenSCAP::TestCase
|
|
97
88
|
|
98
89
|
def create_arf
|
99
90
|
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
100
|
-
@s.load(:
|
91
|
+
@s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
|
101
92
|
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
102
93
|
@s.evaluate
|
103
|
-
@s.export_results(:
|
94
|
+
@s.export_results(rds_file: 'report.rds.xml')
|
104
95
|
end
|
105
96
|
end
|
data/test/ds/sds_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
require 'openscap/source'
|
@@ -15,6 +6,8 @@ require 'openscap/ds/sds'
|
|
15
6
|
require 'common/testcase'
|
16
7
|
|
17
8
|
class TestSds < OpenSCAP::TestCase
|
9
|
+
DS_FILE = '../data/sds-complex.xml'
|
10
|
+
|
18
11
|
def test_new
|
19
12
|
new_sds.destroy
|
20
13
|
end
|
@@ -25,7 +18,7 @@ class TestSds < OpenSCAP::TestCase
|
|
25
18
|
assert !@s.nil?
|
26
19
|
msg = nil
|
27
20
|
begin
|
28
|
-
OpenSCAP::DS::Sds.new :
|
21
|
+
OpenSCAP::DS::Sds.new source: @s
|
29
22
|
assert false
|
30
23
|
rescue OpenSCAP::OpenSCAPError => e
|
31
24
|
msg = e.to_s
|
@@ -57,7 +50,7 @@ class TestSds < OpenSCAP::TestCase
|
|
57
50
|
sds = new_sds
|
58
51
|
msg = nil
|
59
52
|
begin
|
60
|
-
benchmark = sds.select_checklist! :
|
53
|
+
benchmark = sds.select_checklist! datastream_id: 'wrong'
|
61
54
|
assert false
|
62
55
|
rescue OpenSCAP::OpenSCAPError => e
|
63
56
|
msg = e.to_s
|
@@ -67,13 +60,29 @@ class TestSds < OpenSCAP::TestCase
|
|
67
60
|
sds.destroy
|
68
61
|
end
|
69
62
|
|
63
|
+
def tests_use_through_yields
|
64
|
+
OpenSCAP::Source.new DS_FILE do |source|
|
65
|
+
assert_equal 'SCAP Source Datastream', source.type
|
66
|
+
OpenSCAP::DS::Sds.new source: do |sds|
|
67
|
+
benchmark_source = sds.select_checklist!
|
68
|
+
html = sds.html_guide
|
69
|
+
assert_include html, 'bootstrap'
|
70
|
+
|
71
|
+
OpenSCAP::Xccdf::Benchmark.new benchmark_source do |benchmark|
|
72
|
+
assert_empty benchmark.profiles
|
73
|
+
assert benchmark.items.length == 1
|
74
|
+
assert benchmark.items.keys.first == 'xccdf_moc.elpmaxe.www_rule_first'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
70
80
|
private
|
71
81
|
|
72
82
|
def new_sds
|
73
|
-
|
74
|
-
@s = OpenSCAP::Source.new filename
|
83
|
+
@s = OpenSCAP::Source.new DS_FILE
|
75
84
|
assert !@s.nil?
|
76
|
-
sds = OpenSCAP::DS::Sds.new :
|
85
|
+
sds = OpenSCAP::DS::Sds.new source: @s
|
77
86
|
assert !sds.nil?
|
78
87
|
sds
|
79
88
|
end
|
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
require 'openscap/xccdf/benchmark'
|
@@ -23,10 +14,10 @@ class TestArfWaiver < OpenSCAP::TestCase
|
|
23
14
|
assert_default_score tr.score, -1, 1
|
24
15
|
assert_default_score tr.score!(benchmark), -1, 1
|
25
16
|
|
26
|
-
rr.override!(:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
17
|
+
rr.override!(new_result: :pass,
|
18
|
+
time: 'yesterday',
|
19
|
+
authority: 'John Hacker',
|
20
|
+
raw_text: 'This should have passed')
|
30
21
|
assert rr.result == 'pass'
|
31
22
|
|
32
23
|
assert_default_score tr.score, -1, 1
|
@@ -94,7 +85,7 @@ class TestArfWaiver < OpenSCAP::TestCase
|
|
94
85
|
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
95
86
|
@s.load
|
96
87
|
@s.evaluate
|
97
|
-
@s.export_results(:
|
88
|
+
@s.export_results(rds_file: 'report.rds.xml')
|
98
89
|
OpenSCAP::DS::Arf.new('report.rds.xml')
|
99
90
|
end
|
100
91
|
end
|
data/test/openscap_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'common/testcase'
|
13
4
|
require 'openscap'
|
data/test/source_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
require 'openscap/source'
|
@@ -22,7 +13,7 @@ class TestSource < OpenSCAP::TestCase
|
|
22
13
|
rescue OpenSCAP::OpenSCAPError => e
|
23
14
|
msg = e.to_s
|
24
15
|
end
|
25
|
-
assert msg.start_with?('No filename specified!'),
|
16
|
+
assert msg.start_with?('No filename specified!'), "Message was: #{msg}"
|
26
17
|
end
|
27
18
|
|
28
19
|
def test_source_new_ok
|
@@ -33,22 +24,22 @@ class TestSource < OpenSCAP::TestCase
|
|
33
24
|
def test_source_new_memory
|
34
25
|
raw_data = File.read('../data/xccdf.xml')
|
35
26
|
refute raw_data.empty?
|
36
|
-
s = OpenSCAP::Source.new(:
|
27
|
+
s = OpenSCAP::Source.new(content: raw_data, path: '/mytestpath')
|
37
28
|
s.destroy
|
38
29
|
end
|
39
30
|
|
40
31
|
def test_type_xccdf
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
OpenSCAP::Source.new('../data/xccdf.xml') do |s|
|
33
|
+
assert s.type == 'XCCDF Checklist', "Type was #{s.type}"
|
34
|
+
s.validate!
|
35
|
+
end
|
45
36
|
end
|
46
37
|
|
47
38
|
def test_type_sds
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
OpenSCAP::Source.new('../data/sds-complex.xml') do |s|
|
40
|
+
assert s.type == 'SCAP Source Datastream', "Type was #{s.type}"
|
41
|
+
s.validate!
|
42
|
+
end
|
52
43
|
end
|
53
44
|
|
54
45
|
def test_type_test_result
|
@@ -68,11 +59,11 @@ class TestSource < OpenSCAP::TestCase
|
|
68
59
|
msg = e.to_s
|
69
60
|
end
|
70
61
|
assert msg.start_with?('Invalid XCCDF Checklist (1.2) content in ../data/invalid.xml.'),
|
71
|
-
|
62
|
+
"Message was: #{msg}"
|
72
63
|
assert msg.include?("../data/invalid.xml:3: Element '{http"),
|
73
|
-
|
64
|
+
"Message was: #{msg}"
|
74
65
|
assert msg.include?('This element is not expected. Expected is'),
|
75
|
-
|
66
|
+
"Message was: #{msg}"
|
76
67
|
s.destroy
|
77
68
|
end
|
78
69
|
|
data/test/text_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
require 'openscap/text'
|
data/test/xccdf/arf_test.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'common/testcase'
|
13
4
|
require 'openscap'
|
@@ -47,7 +38,6 @@ class TestArf < OpenSCAP::TestCase
|
|
47
38
|
_test_results = arf.test_result
|
48
39
|
source_datastream = arf.report_request
|
49
40
|
bench_source = source_datastream.select_checklist!
|
50
|
-
|
51
|
-
benchmark
|
41
|
+
OpenSCAP::Xccdf::Benchmark.new(bench_source)
|
52
42
|
end
|
53
43
|
end
|
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'common/testcase'
|
13
4
|
require 'openscap'
|
@@ -87,12 +78,12 @@ class TestBenchmark < OpenSCAP::TestCase
|
|
87
78
|
def test_items_references
|
88
79
|
b = benchmark_from_file
|
89
80
|
install_hids_rule = b.items['xccdf_org.ssgproject.content_rule_install_hids']
|
90
|
-
expected_references = [{ :
|
91
|
-
:
|
92
|
-
:
|
93
|
-
{ :
|
94
|
-
:
|
95
|
-
:
|
81
|
+
expected_references = [{ title: 'SC-7',
|
82
|
+
href: 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
|
83
|
+
html_link: "<a href='http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf'>SC-7</a>" },
|
84
|
+
{ title: '1263',
|
85
|
+
href: 'http://iase.disa.mil/cci/index.html',
|
86
|
+
html_link: "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
|
96
87
|
assert_equal(expected_references, install_hids_rule.references.map(&:to_hash), 'Install hids references should be equal')
|
97
88
|
b.destroy
|
98
89
|
end
|
@@ -102,16 +93,75 @@ class TestBenchmark < OpenSCAP::TestCase
|
|
102
93
|
login_defs_rule = b.items['xccdf_org.ssgproject.content_rule_accounts_minimum_age_login_defs']
|
103
94
|
expected_content = ["var_accounts_minimum_age_login_defs=\"<sub xmlns=\"http://checklists.nist.gov/xccdf/1.2\" idref=\"xccdf_org.ssgproject.content_value_var_accounts_minimum_age_login_defs\" use=\"legacy\"/>\"\ngrep -q ^PASS_MIN_DAYS /etc/login.defs && \\\nsed -i \"s/PASS_MIN_DAYS.*/PASS_MIN_DAYS\\t$var_accounts_minimum_age_login_defs/g\" /etc/login.defs\nif ! [ $? -eq 0 ]\nthen\n echo -e \"PASS_MIN_DAYS\\t$var_accounts_minimum_age_login_defs\" >> /etc/login.defs\nfi\n"]
|
104
95
|
expected_hashes = [{
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
96
|
+
id: nil,
|
97
|
+
platform: nil,
|
98
|
+
content: expected_content.first,
|
99
|
+
system: 'urn:xccdf:fix:script:sh'
|
109
100
|
}]
|
110
101
|
assert_equal(expected_content, login_defs_rule.fixes.map(&:content), 'Fix content should match')
|
111
102
|
assert_equal(expected_hashes, login_defs_rule.fixes.map(&:to_hash), 'Fix hash should match')
|
112
103
|
b.destroy
|
113
104
|
end
|
114
105
|
|
106
|
+
def test_benchamrk_id
|
107
|
+
with_benchmark do |b|
|
108
|
+
assert_equal b.id, 'xccdf_org.ssgproject.content_benchmark_FEDORA'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_status_current
|
113
|
+
with_benchmark do |b|
|
114
|
+
status = b.status_current
|
115
|
+
assert_equal status.status, :draft
|
116
|
+
release_date = status.date
|
117
|
+
assert_equal release_date.year, 2014
|
118
|
+
assert_equal release_date.month, 10
|
119
|
+
assert_equal release_date.day, 2
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_title
|
124
|
+
with_benchmark do |b|
|
125
|
+
assert_equal b.title, 'Guide to the Secure Configuration of Fedora'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_description
|
130
|
+
with_benchmark do |b|
|
131
|
+
assert_equal b.description, DESCRIPTION
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_version
|
136
|
+
with_benchmark do |b|
|
137
|
+
assert_equal b.version, '0.0.4'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_references
|
142
|
+
with_benchmark do |b|
|
143
|
+
assert_equal b.references, []
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_resolved
|
148
|
+
with_benchmark do |b|
|
149
|
+
assert b.resolved?
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_policy_model
|
154
|
+
with_benchmark do |b|
|
155
|
+
assert b.policy_model.policies.keys == ['xccdf_org.ssgproject.content_profile_common']
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_schema_version
|
160
|
+
with_benchmark do |b|
|
161
|
+
assert_equal b.schema_version, '1.2'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
115
165
|
private
|
116
166
|
|
117
167
|
def benchmark_from_file
|
@@ -121,4 +171,31 @@ class TestBenchmark < OpenSCAP::TestCase
|
|
121
171
|
assert !b.nil?
|
122
172
|
b
|
123
173
|
end
|
174
|
+
|
175
|
+
def with_benchmark(&)
|
176
|
+
OpenSCAP::Source.new '../data/xccdf.xml' do |source|
|
177
|
+
OpenSCAP::Xccdf::Benchmark.new(source, &)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
DESCRIPTION = "This guide presents a catalog of security-relevant configuration\n" \
|
182
|
+
"settings for Fedora operating system formatted in the eXtensible Configuration\n" \
|
183
|
+
"Checklist Description Format (XCCDF).\n" \
|
184
|
+
"<br xmlns=\"http://www.w3.org/1999/xhtml\"/>\n" \
|
185
|
+
"<br xmlns=\"http://www.w3.org/1999/xhtml\"/>\n" \
|
186
|
+
"Providing system administrators with such guidance informs them how to securely\n" \
|
187
|
+
"configure systems under their control in a variety of network roles. Policy\n" \
|
188
|
+
"makers and baseline creators can use this catalog of settings, with its\n" \
|
189
|
+
"associated references to higher-level security control catalogs, in order to\n" \
|
190
|
+
"assist them in security baseline creation. This guide is a <i xmlns=\"http://www.w3.org/1999/xhtml\">catalog, not a\n" \
|
191
|
+
"checklist,</i> and satisfaction of every item is not likely to be possible or\n" \
|
192
|
+
"sensible in many operational scenarios. However, the XCCDF format enables\n" \
|
193
|
+
"granular selection and adjustment of settings, and their association with OVAL\n" \
|
194
|
+
"and OCIL content provides an automated checking capability. Transformations of\n" \
|
195
|
+
"this document, and its associated automated checking content, are capable of\n" \
|
196
|
+
"providing baselines that meet a diverse set of policy objectives. Some example\n" \
|
197
|
+
"XCCDF <i xmlns=\"http://www.w3.org/1999/xhtml\">Profiles</i>, which are selections of items that form checklists and\n" \
|
198
|
+
"can be used as baselines, are available with this guide. They can be\n" \
|
199
|
+
"processed, in an automated fashion, with tools that support the Security\n" \
|
200
|
+
"Content Automation Protocol (SCAP).\n"
|
124
201
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openscap'
|
4
|
+
require 'openscap/xccdf/benchmark'
|
5
|
+
require 'common/testcase'
|
6
|
+
|
7
|
+
class ItemTest < OpenSCAP::TestCase
|
8
|
+
def test_description_html
|
9
|
+
expected_markup = "\n" \
|
10
|
+
"Most of the actions listed in this document are written with the\n" \
|
11
|
+
"assumption that they will be executed by the root user running the\n" \
|
12
|
+
"<xhtml:code xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">/bin/bash</xhtml:code> shell. Commands preceded with a hash mark (#)\n" \
|
13
|
+
"assume that the administrator will execute the commands as root, i.e.\n" \
|
14
|
+
"apply the command via <xhtml:code xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">sudo</xhtml:code> whenever possible, or use\n" \
|
15
|
+
"<xhtml:code xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">su</xhtml:code> to gain root privileges if <xhtml:code xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">sudo</xhtml:code> cannot be\n" \
|
16
|
+
"used. Commands which can be executed as a non-root user are are preceded\n" \
|
17
|
+
"by a dollar sign ($) prompt.\n"
|
18
|
+
with_item 'xccdf_org.ssgproject.content_group_intro-root-shell-assumed' do |item|
|
19
|
+
assert_equal item.description(markup: true), expected_markup
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_rationale_html
|
24
|
+
expected_markup = "\n" \
|
25
|
+
"For AIDE to be effective, an initial database of <i xmlns=\"http://www.w3.org/1999/xhtml\">\"known-good\"</i> information about files\n" \
|
26
|
+
"must be captured and it should be able to be verified against the installed files.\n"
|
27
|
+
with_item 'xccdf_org.ssgproject.content_rule_aide_build_database' do |item|
|
28
|
+
assert_equal item.rationale(markup: true), expected_markup
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_missing_rationale
|
33
|
+
with_item 'xccdf_org.ssgproject.content_group_intro' do |item_sans_rationale|
|
34
|
+
assert_equal item_sans_rationale.rationale(markup: true), nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_version
|
39
|
+
with_item 'xccdf_org.ssgproject.content_group_intro' do |item_sans_version|
|
40
|
+
assert_nil item_sans_version.version
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_references
|
45
|
+
with_item 'xccdf_org.ssgproject.content_rule_disable_prelink' do |item|
|
46
|
+
item.references.tap do |refs|
|
47
|
+
assert_equal refs.length, 4
|
48
|
+
assert_equal refs.collect(&:title), ['CM-6(d)', 'CM-6(3)', 'SC-28', 'SI-7']
|
49
|
+
assert_equal refs.collect(&:href).uniq, ['http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_warnings
|
55
|
+
expected_text = 'If verbose logging to <xhtml:code xmlns:xhtml="http://www.w3.org/1999/xhtml">vsftpd.log</xhtml:code> is done, sparse logging of downloads to <xhtml:code xmlns:xhtml="http://www.w3.org/1999/xhtml">/var/log/xferlog</xhtml:code> will not also occur. However, the information about what files were downloaded is included in the information logged to <xhtml:code xmlns:xhtml="http://www.w3.org/1999/xhtml">vsftpd.log</xhtml:code>'
|
56
|
+
with_item 'xccdf_org.ssgproject.content_rule_ftp_log_transactions' do |item|
|
57
|
+
warns = item.warnings
|
58
|
+
assert_equal warns.length, 1
|
59
|
+
warning = warns[0]
|
60
|
+
assert warning.instance_of?(Hash)
|
61
|
+
assert warning.keys.length == 2
|
62
|
+
assert warning[:category] == :general
|
63
|
+
assert warning[:text].text == expected_text
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def with_item(id, &)
|
70
|
+
with_benchmark do |b|
|
71
|
+
item = b.items[id]
|
72
|
+
refute_nil item
|
73
|
+
yield item
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def with_benchmark(&)
|
78
|
+
OpenSCAP::Source.new '../data/xccdf.xml' do |source|
|
79
|
+
OpenSCAP::Xccdf::Benchmark.new(source, &)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|