openscap 0.4.0 → 0.4.1
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/lib/openscap/ds/arf.rb +10 -12
- data/lib/openscap/ds/sds.rb +11 -12
- data/lib/openscap/exceptions.rb +1 -1
- data/lib/openscap/libc.rb +1 -1
- data/lib/openscap/openscap.rb +7 -7
- data/lib/openscap/source.rb +27 -19
- data/lib/openscap/text.rb +3 -3
- data/lib/openscap/version.rb +1 -1
- data/lib/openscap/xccdf/benchmark.rb +4 -3
- data/lib/openscap/xccdf/profile.rb +4 -4
- data/lib/openscap/xccdf/ruleresult.rb +14 -8
- data/lib/openscap/xccdf/session.rb +27 -25
- data/lib/openscap/xccdf/testresult.rb +11 -10
- data/test/common/testcase.rb +3 -2
- data/test/ds/arf_test.rb +28 -13
- data/test/ds/sds_test.rb +7 -6
- data/test/integration/arf_waiver_test.rb +6 -5
- data/test/openscap_test.rb +4 -4
- data/test/source_test.rb +16 -16
- data/test/xccdf/benchmark_test.rb +3 -3
- data/test/xccdf/session_ds_test.rb +34 -34
- data/test/xccdf/session_test.rb +6 -6
- data/test/xccdf/testresult_test.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 656bc0ebd59609bc9109fb6083ef128aeae3e33e
|
4
|
+
data.tar.gz: 71a336555edb6144fe9a70336c6ae84b90d9bfc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5ba959dbecb7a822016a7fd2dff3340aa26ee10a9527afb77049decd340d7039725ccdd6af90ef2216487c49dca1890e721e7d750f4ab8d6ef67fdfbc381d3f
|
7
|
+
data.tar.gz: 8902784778405499e98d60c5c486437c5b227ea2a29b3435bf9bff9c46b19edfdf935593b8ed45d5fbde5c1eb28e335b5464f94c41fa54cba65f68893ae57301
|
data/lib/openscap/ds/arf.rb
CHANGED
@@ -25,22 +25,20 @@ module OpenSCAP
|
|
25
25
|
@source = OpenSCAP::Source.new(param)
|
26
26
|
@session = OpenSCAP.ds_rds_session_new_from_source @source.raw
|
27
27
|
else
|
28
|
-
|
29
|
-
end
|
30
|
-
if @session.null?
|
31
|
-
OpenSCAP.raise!
|
28
|
+
fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::DS:Arf with '#{param}'"
|
32
29
|
end
|
30
|
+
OpenSCAP.raise! if @session.null?
|
33
31
|
end
|
34
32
|
|
35
33
|
def destroy
|
36
34
|
OpenSCAP.ds_rds_session_free(@session)
|
37
35
|
@session = nil
|
38
|
-
@source.destroy
|
36
|
+
@source.destroy
|
39
37
|
end
|
40
38
|
|
41
|
-
def test_result(id=nil)
|
39
|
+
def test_result(id = nil)
|
42
40
|
source = OpenSCAP.ds_rds_session_select_report(@session, id)
|
43
|
-
OpenSCAP.raise!
|
41
|
+
OpenSCAP.raise! if source.nil?
|
44
42
|
OpenSCAP::Xccdf::TestResult.new(source)
|
45
43
|
end
|
46
44
|
|
@@ -49,9 +47,9 @@ module OpenSCAP
|
|
49
47
|
OpenSCAP.raise! unless OpenSCAP.ds_rds_session_replace_report_with_source(@session, source.raw) == 0
|
50
48
|
end
|
51
49
|
|
52
|
-
def report_request(id=nil)
|
50
|
+
def report_request(id = nil)
|
53
51
|
source_p = OpenSCAP.ds_rds_session_select_report_request(@session, id)
|
54
|
-
|
52
|
+
source = OpenSCAP::Source.new source_p
|
55
53
|
OpenSCAP::DS::Sds.new(source)
|
56
54
|
end
|
57
55
|
|
@@ -59,9 +57,9 @@ module OpenSCAP
|
|
59
57
|
html_p = OpenSCAP.ds_rds_session_get_html_report @session
|
60
58
|
OpenSCAP.raise! if OpenSCAP.error?
|
61
59
|
return nil if html_p.null?
|
62
|
-
html = html_p.read_string
|
60
|
+
html = html_p.read_string
|
63
61
|
OpenSCAP::LibC.free html_p
|
64
|
-
|
62
|
+
html
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
@@ -72,4 +70,4 @@ module OpenSCAP
|
|
72
70
|
attach_function :ds_rds_session_replace_report_with_source, [:pointer, :pointer], :int
|
73
71
|
attach_function :ds_rds_session_select_report_request, [:pointer, :string], :pointer
|
74
72
|
attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
|
75
|
-
end
|
73
|
+
end
|
data/lib/openscap/ds/sds.rb
CHANGED
@@ -18,29 +18,29 @@ module OpenSCAP
|
|
18
18
|
|
19
19
|
def initialize(param)
|
20
20
|
@raw = case param
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
when OpenSCAP::Source
|
22
|
+
OpenSCAP.ds_sds_session_new_from_source param.raw
|
23
|
+
when Hash
|
24
|
+
OpenSCAP.ds_sds_session_new_from_source param[:source].raw
|
25
|
+
end
|
26
26
|
OpenSCAP.raise! if @raw.null?
|
27
27
|
end
|
28
28
|
|
29
|
-
def select_checklist(p={})
|
29
|
+
def select_checklist(p = {})
|
30
30
|
source_p = OpenSCAP.ds_sds_session_select_checklist(@raw, p[:datastream_id], p[:component_id], nil)
|
31
31
|
OpenSCAP::Source.new source_p
|
32
32
|
end
|
33
33
|
|
34
|
-
def select_checklist!(p={})
|
34
|
+
def select_checklist!(p = {})
|
35
35
|
checklist = select_checklist(p)
|
36
36
|
OpenSCAP.raise! if checklist.nil? or checklist.raw.null?
|
37
|
-
|
37
|
+
checklist
|
38
38
|
end
|
39
39
|
|
40
|
-
def html_guide(profile=nil)
|
40
|
+
def html_guide(profile = nil)
|
41
41
|
html = OpenSCAP.ds_sds_session_get_html_guide(@raw, profile)
|
42
42
|
OpenSCAP.raise! if html.nil?
|
43
|
-
|
43
|
+
html
|
44
44
|
end
|
45
45
|
|
46
46
|
def destroy
|
@@ -54,5 +54,4 @@ module OpenSCAP
|
|
54
54
|
attach_function :ds_sds_session_free, [:pointer], :void
|
55
55
|
attach_function :ds_sds_session_select_checklist, [:pointer, :string, :string, :string], :pointer
|
56
56
|
attach_function :ds_sds_session_get_html_guide, [:pointer, :string], :string
|
57
|
-
|
58
|
-
end
|
57
|
+
end
|
data/lib/openscap/exceptions.rb
CHANGED
data/lib/openscap/libc.rb
CHANGED
data/lib/openscap/openscap.rb
CHANGED
@@ -16,22 +16,22 @@ module OpenSCAP
|
|
16
16
|
ffi_lib ['libopenscap.so.8', 'openscap']
|
17
17
|
|
18
18
|
def self.error?
|
19
|
-
|
19
|
+
oscap_err
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
22
|
+
def self.full_error
|
23
23
|
err = oscap_err_get_full_error
|
24
|
-
|
24
|
+
err.null? ? nil : err.read_string
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.raise!(msg=nil)
|
28
|
-
err =
|
27
|
+
def self.raise!(msg = nil)
|
28
|
+
err = full_error
|
29
29
|
if err.nil?
|
30
30
|
err = msg.nil? ? '(unknown error)' : msg
|
31
31
|
else
|
32
32
|
err += "\n#{msg}"
|
33
33
|
end
|
34
|
-
|
34
|
+
fail OpenSCAPError, err
|
35
35
|
end
|
36
36
|
|
37
37
|
attach_function :oscap_init, [], :void
|
@@ -43,4 +43,4 @@ module OpenSCAP
|
|
43
43
|
attach_function :oscap_err, [], :bool
|
44
44
|
attach_function :oscap_err_get_full_error, [], :pointer
|
45
45
|
private_class_method :oscap_err, :oscap_err_get_full_error
|
46
|
-
end
|
46
|
+
end
|
data/lib/openscap/source.rb
CHANGED
@@ -9,59 +9,67 @@
|
|
9
9
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
10
|
#
|
11
11
|
|
12
|
+
require 'openscap'
|
13
|
+
|
12
14
|
module OpenSCAP
|
13
15
|
class Source
|
16
|
+
attr_reader :raw
|
17
|
+
|
14
18
|
def initialize(param)
|
15
19
|
case param
|
16
20
|
when nil
|
17
|
-
|
21
|
+
fail OpenSCAPError, 'No filename specified!'
|
18
22
|
when String
|
19
|
-
@
|
23
|
+
@raw = OpenSCAP.oscap_source_new_from_file(param)
|
20
24
|
when Hash
|
21
|
-
@
|
25
|
+
@raw = create_from_memory param
|
22
26
|
when FFI::Pointer
|
23
|
-
@
|
27
|
+
@raw = param
|
24
28
|
else
|
25
|
-
|
29
|
+
fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Source with '#{param}'"
|
26
30
|
end
|
27
|
-
OpenSCAP.raise! if @
|
31
|
+
OpenSCAP.raise! if @raw.null?
|
28
32
|
end
|
29
33
|
|
30
34
|
def type
|
31
|
-
OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@
|
35
|
+
OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@raw))
|
32
36
|
end
|
33
37
|
|
34
38
|
def validate!
|
35
39
|
e = FFI::MemoryPointer.new(:char, 4096)
|
36
|
-
if 0 != OpenSCAP.oscap_source_validate(@
|
40
|
+
if 0 != OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e)
|
37
41
|
OpenSCAP.raise! e.read_string
|
38
42
|
end
|
39
|
-
|
40
43
|
end
|
41
44
|
|
42
|
-
def
|
43
|
-
@
|
45
|
+
def save(filepath = nil)
|
46
|
+
OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath) == 0
|
44
47
|
end
|
45
48
|
|
46
|
-
def
|
47
|
-
OpenSCAP.
|
49
|
+
def destroy
|
50
|
+
OpenSCAP.oscap_source_free(@raw)
|
51
|
+
@raw = nil
|
48
52
|
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_from_memory(param)
|
57
|
+
param[:length] = param[:content].length unless param[:length]
|
58
|
+
buf = FFI::MemoryPointer.new(:char, param[:length])
|
59
|
+
buf.put_bytes(0, param[:content])
|
60
|
+
OpenSCAP.oscap_source_new_from_memory param[:content], param[:length], param[:path]
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
56
64
|
attach_function :oscap_source_new_from_file, [:string], :pointer
|
57
|
-
attach_function :oscap_source_new_from_memory, [:
|
65
|
+
attach_function :oscap_source_new_from_memory, [:pointer, :int, :string], :pointer
|
58
66
|
attach_function :oscap_source_get_scap_type, [:pointer], :int
|
59
67
|
attach_function :oscap_source_free, [:pointer], :void
|
60
68
|
attach_function :oscap_source_save_as, [:pointer, :string], :int
|
61
69
|
|
62
70
|
callback :xml_reporter, [:string, :int, :string, :pointer], :int
|
63
71
|
attach_function :oscap_source_validate, [:pointer, :xml_reporter, :pointer], :int
|
64
|
-
XmlReporterCallback =
|
72
|
+
XmlReporterCallback = proc do |filename, line_number, error_message, e|
|
65
73
|
offset = e.get_string(0).length
|
66
74
|
msg = "#{filename}:#{line_number}: #{error_message}"
|
67
75
|
if msg.length + offset + 1 < e.size
|
@@ -71,4 +79,4 @@ module OpenSCAP
|
|
71
79
|
1
|
72
80
|
end
|
73
81
|
end
|
74
|
-
end
|
82
|
+
end
|
data/lib/openscap/text.rb
CHANGED
@@ -27,7 +27,7 @@ module OpenSCAP
|
|
27
27
|
|
28
28
|
def destroy
|
29
29
|
OpenSCAP.oscap_text_free(raw)
|
30
|
-
raw = nil
|
30
|
+
@raw = nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,7 +36,7 @@ module OpenSCAP
|
|
36
36
|
@raw = oscap_text_iterator
|
37
37
|
end
|
38
38
|
|
39
|
-
def plaintext(lang=nil)
|
39
|
+
def plaintext(lang = nil)
|
40
40
|
OpenSCAP.oscap_textlist_get_preferred_plaintext @raw, lang
|
41
41
|
end
|
42
42
|
|
@@ -52,4 +52,4 @@ module OpenSCAP
|
|
52
52
|
|
53
53
|
attach_function :oscap_textlist_get_preferred_plaintext, [:pointer, :string], :string
|
54
54
|
attach_function :oscap_text_iterator_free, [:pointer], :void
|
55
|
-
end
|
55
|
+
end
|
data/lib/openscap/version.rb
CHANGED
@@ -22,8 +22,8 @@ module OpenSCAP
|
|
22
22
|
when OpenSCAP::Source
|
23
23
|
@raw = OpenSCAP.xccdf_benchmark_import_source p.raw
|
24
24
|
else
|
25
|
-
|
26
|
-
|
25
|
+
fail OpenSCAP::OpenSCAPError,
|
26
|
+
"Cannot initialize OpenSCAP::Xccdf::Benchmark with '#{p}'"
|
27
27
|
end
|
28
28
|
OpenSCAP.raise! if @raw.null?
|
29
29
|
end
|
@@ -38,6 +38,7 @@ module OpenSCAP
|
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
41
|
+
|
41
42
|
def profiles_init
|
42
43
|
profiles = {}
|
43
44
|
profit = OpenSCAP.xccdf_benchmark_get_profiles raw
|
@@ -59,4 +60,4 @@ module OpenSCAP
|
|
59
60
|
attach_function :xccdf_profile_iterator_has_more, [:pointer], :bool
|
60
61
|
attach_function :xccdf_profile_iterator_next, [:pointer], :pointer
|
61
62
|
attach_function :xccdf_profile_iterator_free, [:pointer], :void
|
62
|
-
end
|
63
|
+
end
|
@@ -21,7 +21,7 @@ module OpenSCAP
|
|
21
21
|
when FFI::Pointer
|
22
22
|
@raw = p
|
23
23
|
else
|
24
|
-
|
24
|
+
fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Profile with #{p}"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,15 +29,15 @@ module OpenSCAP
|
|
29
29
|
OpenSCAP.xccdf_profile_get_id raw
|
30
30
|
end
|
31
31
|
|
32
|
-
def title(prefered_lang=nil)
|
32
|
+
def title(prefered_lang = nil)
|
33
33
|
textlist = OpenSCAP::TextList.new(OpenSCAP.xccdf_profile_get_title(@raw))
|
34
34
|
title = textlist.plaintext(prefered_lang)
|
35
35
|
textlist.destroy
|
36
|
-
|
36
|
+
title
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
attach_function :xccdf_profile_get_id, [:pointer], :string
|
42
42
|
attach_function :xccdf_profile_get_title, [:pointer], :pointer
|
43
|
-
end
|
43
|
+
end
|
@@ -20,7 +20,7 @@ module OpenSCAP
|
|
20
20
|
when FFI::Pointer
|
21
21
|
@rr = t
|
22
22
|
else
|
23
|
-
|
23
|
+
fail OpenSCAP::OpenSCAPError, "Cannot initialize TestResult with #{t}"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -34,14 +34,12 @@ module OpenSCAP
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def override!(param)
|
37
|
-
|
38
|
-
raise OpenSCAPError, "Could not recognize result type: '#{param[:new_result]}'"
|
39
|
-
end
|
37
|
+
validate_xccdf_result! param[:new_result]
|
40
38
|
t = OpenSCAP::Text.new
|
41
39
|
t.text = param[:raw_text]
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
unless OpenSCAP.xccdf_rule_result_override(@rr,
|
41
|
+
OpenSCAP::XccdfResult[param[:new_result]],
|
42
|
+
param[:time], param[:authority], t.raw)
|
45
43
|
OpenSCAP.raise!
|
46
44
|
end
|
47
45
|
end
|
@@ -49,6 +47,14 @@ module OpenSCAP
|
|
49
47
|
def destroy
|
50
48
|
OpenSCAP.xccdf_rule_result_free @rr
|
51
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def validate_xccdf_result!(result_label)
|
54
|
+
if OpenSCAP::XccdfResult[result_label] > OpenSCAP::XccdfResult[:fixed]
|
55
|
+
fail OpenSCAPError, "Could not recognize result type: '#{result_label}'"
|
56
|
+
end
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
@@ -67,5 +73,5 @@ module OpenSCAP
|
|
67
73
|
:informational,
|
68
74
|
:fixed)
|
69
75
|
attach_function :xccdf_rule_result_override,
|
70
|
-
|
76
|
+
[:pointer, XccdfResult, :string, :string, :pointer], :bool
|
71
77
|
end
|
@@ -11,47 +11,40 @@
|
|
11
11
|
|
12
12
|
module OpenSCAP
|
13
13
|
module Xccdf
|
14
|
-
|
15
14
|
class Session
|
16
15
|
def initialize(input_filename)
|
17
|
-
|
16
|
+
fail OpenSCAPError, 'No filename specified!' unless input_filename
|
18
17
|
@input_filename = input_filename
|
19
18
|
@s = OpenSCAP.xccdf_session_new(input_filename)
|
20
|
-
if @s.null?
|
21
|
-
OpenSCAP.raise!
|
22
|
-
end
|
19
|
+
OpenSCAP.raise! if @s.null?
|
23
20
|
end
|
24
21
|
|
25
22
|
def sds?
|
26
|
-
|
23
|
+
OpenSCAP.xccdf_session_is_sds(@s)
|
27
24
|
end
|
28
25
|
|
29
26
|
def load(opts = {})
|
30
27
|
o = {
|
31
28
|
:datastream_id => nil,
|
32
|
-
:component_id => nil
|
29
|
+
:component_id => nil
|
33
30
|
}.merge(opts)
|
34
31
|
if sds?
|
35
32
|
OpenSCAP.xccdf_session_set_datastream_id(@s, o[:datastream_id])
|
36
33
|
OpenSCAP.xccdf_session_set_component_id(@s, o[:component_id])
|
37
34
|
end
|
38
|
-
if OpenSCAP.xccdf_session_load(@s) != 0
|
39
|
-
OpenSCAP.raise!
|
40
|
-
end
|
35
|
+
OpenSCAP.raise! if OpenSCAP.xccdf_session_load(@s) != 0
|
41
36
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_load_check_engine_plugins(@s) == 0
|
42
37
|
end
|
43
38
|
|
44
39
|
def profile=(p)
|
45
40
|
@profile = p
|
46
41
|
if OpenSCAP.xccdf_session_set_profile_id(@s, p) == false
|
47
|
-
|
42
|
+
fail OpenSCAPError, "No profile '" + p + "' found"
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
51
46
|
def evaluate
|
52
|
-
if OpenSCAP.xccdf_session_evaluate(@s) != 0
|
53
|
-
OpenSCAP.raise!
|
54
|
-
end
|
47
|
+
OpenSCAP.raise! if OpenSCAP.xccdf_session_evaluate(@s) != 0
|
55
48
|
end
|
56
49
|
|
57
50
|
def remediate
|
@@ -65,24 +58,33 @@ module OpenSCAP
|
|
65
58
|
:report_file => nil,
|
66
59
|
:oval_results => false,
|
67
60
|
:oval_variables => false,
|
68
|
-
:engines_results => false
|
61
|
+
:engines_results => false
|
69
62
|
}.merge!(opts)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
OpenSCAP.
|
63
|
+
export_targets o
|
64
|
+
export
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy
|
68
|
+
OpenSCAP.xccdf_session_free(@s)
|
69
|
+
@s = nil
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
76
73
|
|
74
|
+
def export
|
77
75
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_oval(@s) == 0
|
78
76
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_check_engine_plugins(@s) == 0
|
79
77
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_xccdf(@s) == 0
|
80
78
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_arf(@s) == 0
|
81
79
|
end
|
82
80
|
|
83
|
-
def
|
84
|
-
OpenSCAP.
|
85
|
-
@s
|
81
|
+
def export_targets(opts = {})
|
82
|
+
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_arf_export(@s, opts[:rds_file])
|
83
|
+
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_xccdf_export(@s, opts[:xccdf_file])
|
84
|
+
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_report_export(@s, opts[:report_file])
|
85
|
+
OpenSCAP.xccdf_session_set_oval_results_export(@s, opts[:oval_results])
|
86
|
+
OpenSCAP.xccdf_session_set_oval_variables_export(@s, opts[:oval_variables])
|
87
|
+
OpenSCAP.xccdf_session_set_check_engine_plugins_results_export(@s, opts[:engines_results])
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
@@ -109,4 +111,4 @@ module OpenSCAP
|
|
109
111
|
attach_function :xccdf_session_set_oval_variables_export, [:pointer, :bool], :void
|
110
112
|
attach_function :xccdf_session_set_oval_results_export, [:pointer, :bool], :void
|
111
113
|
attach_function :xccdf_session_set_check_engine_plugins_results_export, [:pointer, :bool], :void
|
112
|
-
end
|
114
|
+
end
|
@@ -29,17 +29,17 @@ module OpenSCAP
|
|
29
29
|
@raw = OpenSCAP.xccdf_result_import_source(t)
|
30
30
|
OpenSCAP.raise! if @raw.null?
|
31
31
|
else
|
32
|
-
|
32
|
+
fail OpenSCAP::OpenSCAPError, "Cannot initialize TestResult with #{t}"
|
33
33
|
end
|
34
34
|
init_ruleresults
|
35
35
|
end
|
36
36
|
|
37
37
|
def id
|
38
|
-
|
38
|
+
OpenSCAP.xccdf_result_get_id(@raw)
|
39
39
|
end
|
40
40
|
|
41
41
|
def profile
|
42
|
-
|
42
|
+
OpenSCAP.xccdf_result_get_profile(@raw)
|
43
43
|
end
|
44
44
|
|
45
45
|
def score
|
@@ -47,7 +47,7 @@ module OpenSCAP
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def score!(benchmark)
|
50
|
-
#recalculate the scores in the scope of given benchmark
|
50
|
+
# recalculate the scores in the scope of given benchmark
|
51
51
|
@score = nil
|
52
52
|
OpenSCAP.raise! unless OpenSCAP.xccdf_result_recalculate_scores(@raw, benchmark.raw) == 0
|
53
53
|
score
|
@@ -64,10 +64,11 @@ module OpenSCAP
|
|
64
64
|
end
|
65
65
|
|
66
66
|
private
|
67
|
+
|
67
68
|
def init_ruleresults
|
68
|
-
@rr =
|
69
|
+
@rr = {}
|
69
70
|
rr_it = OpenSCAP.xccdf_result_get_rule_results(@raw)
|
70
|
-
while OpenSCAP.xccdf_rule_result_iterator_has_more(rr_it)
|
71
|
+
while OpenSCAP.xccdf_rule_result_iterator_has_more(rr_it)
|
71
72
|
rr_raw = OpenSCAP.xccdf_rule_result_iterator_next(rr_it)
|
72
73
|
rr = OpenSCAP::Xccdf::RuleResult.new rr_raw
|
73
74
|
@rr[rr.id] = rr
|
@@ -76,15 +77,15 @@ module OpenSCAP
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def score_init
|
79
|
-
scores =
|
80
|
+
scores = {}
|
80
81
|
scorit = OpenSCAP.xccdf_result_get_scores(@raw)
|
81
|
-
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
|
82
|
+
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
|
82
83
|
s = OpenSCAP.xccdf_score_iterator_next(scorit)
|
83
84
|
scores[OpenSCAP.xccdf_score_get_system(s)] = {
|
84
85
|
:system => OpenSCAP.xccdf_score_get_system(s),
|
85
86
|
:value => OpenSCAP.xccdf_score_get_score(s),
|
86
87
|
:max => OpenSCAP.xccdf_score_get_maximum(s)
|
87
|
-
|
88
|
+
}
|
88
89
|
end
|
89
90
|
OpenSCAP.xccdf_score_iterator_free(scorit)
|
90
91
|
scores
|
@@ -99,7 +100,7 @@ module OpenSCAP
|
|
99
100
|
attach_function :xccdf_result_recalculate_scores, [:pointer, :pointer], :int
|
100
101
|
attach_function :xccdf_result_export_source, [:pointer, :string], :pointer
|
101
102
|
|
102
|
-
attach_function :xccdf_result_get_rule_results, [:pointer]
|
103
|
+
attach_function :xccdf_result_get_rule_results, [:pointer], :pointer
|
103
104
|
attach_function :xccdf_rule_result_iterator_has_more, [:pointer], :bool
|
104
105
|
attach_function :xccdf_rule_result_iterator_free, [:pointer], :void
|
105
106
|
attach_function :xccdf_rule_result_iterator_next, [:pointer], :pointer
|
data/test/common/testcase.rb
CHANGED
@@ -14,7 +14,7 @@ require 'test/unit'
|
|
14
14
|
module OpenSCAP
|
15
15
|
class TestCase < Test::Unit::TestCase
|
16
16
|
def setup
|
17
|
-
workdir =
|
17
|
+
workdir = 'test/output'
|
18
18
|
if Dir.pwd.end_with? 'test/output'
|
19
19
|
cleanup # Older TestCase do not run cleanup method.
|
20
20
|
end
|
@@ -27,7 +27,7 @@ module OpenSCAP
|
|
27
27
|
|
28
28
|
def cleanup
|
29
29
|
@s.destroy if @s
|
30
|
-
Dir.chdir
|
30
|
+
Dir.chdir '../..'
|
31
31
|
OpenSCAP.raise! if OpenSCAP.error?
|
32
32
|
OpenSCAP.oscap_cleanup
|
33
33
|
end
|
@@ -36,6 +36,7 @@ module OpenSCAP
|
|
36
36
|
end
|
37
37
|
|
38
38
|
protected
|
39
|
+
|
39
40
|
def assert_default_score(scores, low, high)
|
40
41
|
assert scores.size == 1
|
41
42
|
s = scores['urn:xccdf:scoring:default']
|
data/test/ds/arf_test.rb
CHANGED
@@ -14,34 +14,36 @@ require 'openscap/ds/arf'
|
|
14
14
|
require 'common/testcase'
|
15
15
|
|
16
16
|
class TestArf < OpenSCAP::TestCase
|
17
|
+
REPORT = 'report.rds.xml'
|
18
|
+
|
17
19
|
def test_arf_new_nil
|
18
20
|
msg = nil
|
19
21
|
begin
|
20
|
-
|
22
|
+
OpenSCAP::DS::Arf.new(nil)
|
21
23
|
assert false
|
22
24
|
rescue OpenSCAP::OpenSCAPError => e
|
23
25
|
msg = e.to_s
|
24
26
|
end
|
25
|
-
assert msg.start_with?("Cannot initialize OpenSCAP::DS:Arf with ''"),
|
27
|
+
assert msg.start_with?("Cannot initialize OpenSCAP::DS:Arf with ''"), 'Message was: ' + msg
|
26
28
|
end
|
27
29
|
|
28
30
|
def test_arf_new_wrong_format
|
29
31
|
msg = nil
|
30
32
|
begin
|
31
|
-
|
33
|
+
OpenSCAP::DS::Arf.new('../data/xccdf.xml')
|
32
34
|
assert false
|
33
35
|
rescue OpenSCAP::OpenSCAPError => e
|
34
36
|
msg = e.to_s
|
35
37
|
end
|
36
38
|
assert msg.include?('Could not create Result DataStream session: File is not Result DataStream.'),
|
37
|
-
|
39
|
+
'Message was: ' + msg
|
38
40
|
end
|
39
41
|
|
40
42
|
def test_create_arf_and_get_html
|
41
43
|
arf = new_arf
|
42
44
|
html = arf.html
|
43
45
|
arf.destroy
|
44
|
-
assert html.start_with?('<!DOCTYPE html><html'),
|
46
|
+
assert html.start_with?('<!DOCTYPE html><html'), 'DOCTYPE missing.'
|
45
47
|
assert html.include?('OpenSCAP')
|
46
48
|
assert html.include?('Compliance and Scoring')
|
47
49
|
end
|
@@ -50,30 +52,43 @@ class TestArf < OpenSCAP::TestCase
|
|
50
52
|
arf = new_arf
|
51
53
|
tr = arf.test_result
|
52
54
|
assert tr.profile == 'xccdf_moc.elpmaxe.www_profile_1',
|
53
|
-
|
55
|
+
"TestResult.profile was '#{tr.profile}'"
|
54
56
|
tr.destroy
|
55
57
|
arf.destroy
|
56
58
|
end
|
57
59
|
|
58
60
|
def test_new_memory
|
59
61
|
create_arf
|
60
|
-
raw_data = File.read(
|
62
|
+
raw_data = File.read(REPORT)
|
61
63
|
assert raw_data.length > 0
|
62
|
-
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path =>
|
64
|
+
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => REPORT
|
65
|
+
arf.destroy
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_new_bz_memory
|
69
|
+
create_arf
|
70
|
+
system('/bin/bzip2 ' + REPORT)
|
71
|
+
bziped_file = REPORT + '.bz2'
|
72
|
+
raw_data = File.open(bziped_file, 'rb').read
|
73
|
+
assert !raw_data.empty?
|
74
|
+
len = File.size(bziped_file)
|
75
|
+
FileUtils.rm bziped_file
|
76
|
+
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => bziped_file, :length => len
|
63
77
|
arf.destroy
|
64
78
|
end
|
65
79
|
|
66
80
|
private
|
81
|
+
|
67
82
|
def new_arf
|
68
83
|
create_arf
|
69
|
-
|
84
|
+
OpenSCAP::DS::Arf.new(REPORT)
|
70
85
|
end
|
71
86
|
|
72
87
|
def create_arf
|
73
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
74
|
-
@s.load(:component_id =>
|
75
|
-
@s.profile =
|
88
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
89
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
90
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
76
91
|
@s.evaluate
|
77
|
-
@s.export_results(:rds_file =>
|
92
|
+
@s.export_results(:rds_file => 'report.rds.xml')
|
78
93
|
end
|
79
94
|
end
|
data/test/ds/sds_test.rb
CHANGED
@@ -25,7 +25,7 @@ class TestSds < OpenSCAP::TestCase
|
|
25
25
|
assert !@s.nil?
|
26
26
|
msg = nil
|
27
27
|
begin
|
28
|
-
|
28
|
+
OpenSCAP::DS::Sds.new :source => @s
|
29
29
|
assert false
|
30
30
|
rescue OpenSCAP::OpenSCAPError => e
|
31
31
|
msg = e.to_s
|
@@ -44,11 +44,11 @@ class TestSds < OpenSCAP::TestCase
|
|
44
44
|
sds = new_sds
|
45
45
|
benchmark_source = sds.select_checklist!
|
46
46
|
benchmark = OpenSCAP::Xccdf::Benchmark.new benchmark_source
|
47
|
-
benchmark.profiles.keys.each
|
47
|
+
benchmark.profiles.keys.each do |id|
|
48
48
|
guide = sds.html_guide id
|
49
49
|
assert !guide.nil?
|
50
50
|
assert guide.include?(id)
|
51
|
-
|
51
|
+
end
|
52
52
|
benchmark.destroy
|
53
53
|
sds.destroy
|
54
54
|
end
|
@@ -57,7 +57,7 @@ class TestSds < OpenSCAP::TestCase
|
|
57
57
|
sds = new_sds
|
58
58
|
msg = nil
|
59
59
|
begin
|
60
|
-
benchmark = sds.select_checklist! :datastream_id =>
|
60
|
+
benchmark = sds.select_checklist! :datastream_id => 'wrong'
|
61
61
|
assert false
|
62
62
|
rescue OpenSCAP::OpenSCAPError => e
|
63
63
|
msg = e.to_s
|
@@ -68,12 +68,13 @@ class TestSds < OpenSCAP::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
|
+
|
71
72
|
def new_sds
|
72
73
|
filename = '../data/sds-complex.xml'
|
73
74
|
@s = OpenSCAP::Source.new filename
|
74
75
|
assert !@s.nil?
|
75
76
|
sds = OpenSCAP::DS::Sds.new :source => @s
|
76
77
|
assert !sds.nil?
|
77
|
-
|
78
|
+
sds
|
78
79
|
end
|
79
|
-
end
|
80
|
+
end
|
@@ -27,13 +27,13 @@ class TestArfWaiver < OpenSCAP::TestCase
|
|
27
27
|
:time => 'yesterday',
|
28
28
|
:authority => 'John Hacker',
|
29
29
|
:raw_text => 'This should have passed')
|
30
|
-
rr.result == 'pass'
|
30
|
+
assert rr.result == 'pass'
|
31
31
|
|
32
32
|
assert_default_score tr.score, -1, 1
|
33
33
|
assert_default_score tr.score!(benchmark), 99, 101
|
34
34
|
|
35
35
|
# create updated DOM (that includes the override element and new score)
|
36
|
-
arf.test_result=tr
|
36
|
+
arf.test_result = tr
|
37
37
|
arf.source.save('modified.rds.xml')
|
38
38
|
tr.destroy
|
39
39
|
arf.destroy
|
@@ -48,6 +48,7 @@ class TestArfWaiver < OpenSCAP::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
51
|
+
|
51
52
|
def benchmark
|
52
53
|
@benchmark ||= benchmark_init
|
53
54
|
end
|
@@ -90,10 +91,10 @@ class TestArfWaiver < OpenSCAP::TestCase
|
|
90
91
|
end
|
91
92
|
|
92
93
|
def arf_init
|
93
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
94
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
94
95
|
@s.load
|
95
96
|
@s.evaluate
|
96
|
-
@s.export_results(:rds_file =>
|
97
|
-
OpenSCAP::DS::Arf.new(
|
97
|
+
@s.export_results(:rds_file => 'report.rds.xml')
|
98
|
+
OpenSCAP::DS::Arf.new('report.rds.xml')
|
98
99
|
end
|
99
100
|
end
|
data/test/openscap_test.rb
CHANGED
@@ -17,14 +17,14 @@ class TestOscapVersion < OpenSCAP::TestCase
|
|
17
17
|
OpenSCAP.oscap_init
|
18
18
|
version = OpenSCAP.oscap_get_version
|
19
19
|
OpenSCAP.oscap_cleanup
|
20
|
-
assert version.include?(
|
20
|
+
assert version.include?('.')
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_double_read_error
|
24
|
-
assert !
|
25
|
-
msg = OpenSCAP.
|
24
|
+
assert !OpenSCAP.error?
|
25
|
+
msg = OpenSCAP.full_error
|
26
26
|
assert msg.nil?
|
27
|
-
msg = OpenSCAP.
|
27
|
+
msg = OpenSCAP.full_error
|
28
28
|
assert msg.nil?
|
29
29
|
end
|
30
30
|
end
|
data/test/source_test.rb
CHANGED
@@ -17,49 +17,49 @@ class TestSource < OpenSCAP::TestCase
|
|
17
17
|
def test_source_new_nil
|
18
18
|
msg = nil
|
19
19
|
begin
|
20
|
-
|
20
|
+
OpenSCAP::Source.new(nil)
|
21
21
|
assert false
|
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?('No filename specified!'), 'Message was: ' + msg
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_source_new_ok
|
29
|
-
s = OpenSCAP::Source.new(
|
29
|
+
s = OpenSCAP::Source.new('../data/xccdf.xml')
|
30
30
|
s.destroy
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_source_new_memory
|
34
|
-
raw_data = File.read(
|
34
|
+
raw_data = File.read('../data/xccdf.xml')
|
35
35
|
assert raw_data.length > 0
|
36
36
|
s = OpenSCAP::Source.new(:content => raw_data, :path => '/mytestpath')
|
37
37
|
s.destroy
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_type_xccdf
|
41
|
-
s = OpenSCAP::Source.new(
|
41
|
+
s = OpenSCAP::Source.new('../data/xccdf.xml')
|
42
42
|
assert s.type == 'XCCDF Checklist', "Type was #{s.type}"
|
43
43
|
s.validate!
|
44
44
|
s.destroy
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_type_sds
|
48
|
-
s = OpenSCAP::Source.new(
|
48
|
+
s = OpenSCAP::Source.new('../data/sds-complex.xml')
|
49
49
|
assert s.type == 'SCAP Source Datastream', "Type was #{s.type}"
|
50
50
|
s.validate!
|
51
51
|
s.destroy
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_type_test_result
|
55
|
-
s = OpenSCAP::Source.new(
|
55
|
+
s = OpenSCAP::Source.new('../data/testresult.xml')
|
56
56
|
assert s.type == 'XCCDF Checklist', "Type was #{s.type}"
|
57
57
|
s.validate!
|
58
58
|
s.destroy
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_validate_invalid
|
62
|
-
s = OpenSCAP::Source.new(
|
62
|
+
s = OpenSCAP::Source.new('../data/invalid.xml')
|
63
63
|
msg = nil
|
64
64
|
begin
|
65
65
|
s.validate!
|
@@ -68,20 +68,20 @@ class TestSource < OpenSCAP::TestCase
|
|
68
68
|
msg = e.to_s
|
69
69
|
end
|
70
70
|
assert msg.start_with?('Invalid XCCDF Checklist (1.2) content in ../data/invalid.xml.'),
|
71
|
-
|
71
|
+
'Message was: ' + msg
|
72
72
|
assert msg.include?("../data/invalid.xml:3: Element '{http"),
|
73
|
-
|
74
|
-
assert msg.include?(
|
75
|
-
|
73
|
+
'Message was: ' + msg
|
74
|
+
assert msg.include?('This element is not expected. Expected is'),
|
75
|
+
'Message was: ' + msg
|
76
76
|
s.destroy
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_save
|
80
|
-
s = OpenSCAP::Source.new(
|
80
|
+
s = OpenSCAP::Source.new('../data/testresult.xml')
|
81
81
|
filename = './newly_created.xml'
|
82
|
-
assert !File.
|
82
|
+
assert !File.exist?(filename)
|
83
83
|
s.save(filename)
|
84
|
-
assert File.
|
84
|
+
assert File.exist?(filename)
|
85
85
|
FileUtils.rm_rf filename
|
86
86
|
end
|
87
|
-
end
|
87
|
+
end
|
@@ -15,7 +15,7 @@ require 'openscap/ds/sds'
|
|
15
15
|
require 'openscap/source'
|
16
16
|
require 'openscap/xccdf/benchmark'
|
17
17
|
|
18
|
-
class TestBenchmark< OpenSCAP::TestCase
|
18
|
+
class TestBenchmark < OpenSCAP::TestCase
|
19
19
|
def test_new_from_file
|
20
20
|
@s = OpenSCAP::Source.new '../data/xccdf.xml'
|
21
21
|
b = OpenSCAP::Xccdf::Benchmark.new @s
|
@@ -38,11 +38,11 @@ class TestBenchmark< OpenSCAP::TestCase
|
|
38
38
|
@s = OpenSCAP::Source.new '../data/testresult.xml'
|
39
39
|
msg = nil
|
40
40
|
begin
|
41
|
-
|
41
|
+
OpenSCAP::Xccdf::Benchmark.new @s
|
42
42
|
assert false
|
43
43
|
rescue OpenSCAP::OpenSCAPError => e
|
44
44
|
msg = e.to_s
|
45
45
|
end
|
46
46
|
assert msg.start_with?('Failed to import XCCDF content from'), msg
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
@@ -14,27 +14,27 @@ require 'common/testcase'
|
|
14
14
|
|
15
15
|
class TestSessionDS < OpenSCAP::TestCase
|
16
16
|
def test_sds_true
|
17
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
17
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
18
18
|
assert @s.sds?
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_session_load
|
22
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
22
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
23
23
|
@s.load
|
24
24
|
@s.evaluate
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_session_load_ds_comp
|
28
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
29
|
-
@s.load(:datastream_id =>
|
28
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
29
|
+
@s.load(:datastream_id => 'scap_org.open-scap_datastream_tst2', :component_id => 'scap_org.open-scap_cref_second-xccdf.xml2')
|
30
30
|
@s.evaluate
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_session_load_bad_datastream
|
34
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
34
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
35
35
|
msg = nil
|
36
36
|
begin
|
37
|
-
@s.load(:datastream_id =>
|
37
|
+
@s.load(:datastream_id => 'nonexistent')
|
38
38
|
assert false
|
39
39
|
rescue OpenSCAP::OpenSCAPError => e
|
40
40
|
msg = e.to_s
|
@@ -43,10 +43,10 @@ class TestSessionDS < OpenSCAP::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_session_load_bad_component
|
46
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
46
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
47
47
|
msg = nil
|
48
48
|
begin
|
49
|
-
@s.load(:component_id =>
|
49
|
+
@s.load(:component_id => 'nonexistent')
|
50
50
|
assert false
|
51
51
|
rescue OpenSCAP::OpenSCAPError => e
|
52
52
|
msg = e.to_s
|
@@ -55,18 +55,18 @@ class TestSessionDS < OpenSCAP::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_session_set_profile
|
58
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
59
|
-
@s.load(:component_id =>
|
60
|
-
@s.profile =
|
58
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
59
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
60
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
61
61
|
@s.evaluate
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_session_set_profile_bad
|
65
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
65
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
66
66
|
@s.load
|
67
67
|
msg = nil
|
68
68
|
begin
|
69
|
-
@s.profile =
|
69
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
70
70
|
assert false
|
71
71
|
rescue OpenSCAP::OpenSCAPError => e
|
72
72
|
msg = e.to_s
|
@@ -75,51 +75,51 @@ class TestSessionDS < OpenSCAP::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_session_export_rds
|
78
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
78
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
79
79
|
@s.load
|
80
80
|
@s.evaluate
|
81
|
-
@s.export_results(:rds_file =>
|
82
|
-
assert_exported [
|
81
|
+
@s.export_results(:rds_file => 'report.rds.xml')
|
82
|
+
assert_exported ['report.rds.xml']
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_session_export_xccdf_results
|
86
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
87
|
-
@s.load(:component_id =>
|
88
|
-
@s.profile =
|
86
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
87
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
88
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
89
89
|
@s.evaluate
|
90
|
-
@s.export_results(:xccdf_file =>
|
91
|
-
assert_exported [
|
90
|
+
@s.export_results(:xccdf_file => 'result.xccdf.xml')
|
91
|
+
assert_exported ['result.xccdf.xml']
|
92
92
|
end
|
93
93
|
|
94
94
|
def test_session_export_html_report
|
95
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
96
|
-
@s.load(:component_id =>
|
97
|
-
@s.profile =
|
95
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
96
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
97
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
98
98
|
@s.evaluate
|
99
|
-
@s.export_results(:report_file =>
|
100
|
-
assert_exported [
|
99
|
+
@s.export_results(:report_file => 'report.html', :xccdf_file => 'result.xccdf.xml')
|
100
|
+
assert_exported ['report.html', 'result.xccdf.xml']
|
101
101
|
end
|
102
102
|
|
103
103
|
def test_session_export_oval_variables
|
104
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
105
|
-
@s.load(:component_id =>
|
106
|
-
@s.profile =
|
104
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
105
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
106
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
107
107
|
@s.evaluate
|
108
108
|
@s.export_results(:oval_variables => true)
|
109
109
|
assert_exported []
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_remediate
|
113
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
114
|
-
@s.load(:component_id =>
|
115
|
-
@s.profile =
|
113
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
|
114
|
+
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
|
115
|
+
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
|
116
116
|
@s.evaluate
|
117
117
|
@s.remediate
|
118
118
|
end
|
119
119
|
|
120
120
|
def assert_exported(files)
|
121
121
|
# libopenscap compiled with --enable-debug creates debug files
|
122
|
-
FileUtils.rm_rf(Dir.glob
|
123
|
-
assert files.sort == Dir.glob(
|
122
|
+
FileUtils.rm_rf(Dir.glob 'oscap_debug.log.*')
|
123
|
+
assert files.sort == Dir.glob('*').sort
|
124
124
|
end
|
125
125
|
end
|
data/test/xccdf/session_test.rb
CHANGED
@@ -16,28 +16,28 @@ class TestSession < OpenSCAP::TestCase
|
|
16
16
|
def test_session_new_bad
|
17
17
|
msg = nil
|
18
18
|
begin
|
19
|
-
|
19
|
+
OpenSCAP::Xccdf::Session.new('')
|
20
20
|
assert false
|
21
21
|
rescue OpenSCAP::OpenSCAPError => e
|
22
22
|
msg = e.to_s
|
23
23
|
end
|
24
|
-
assert msg.start_with?('failed to load external entity ""'),
|
25
|
-
assert msg.include?('Unable to parse XML at:'),
|
24
|
+
assert msg.start_with?('failed to load external entity ""'), 'Message was: ' + msg
|
25
|
+
assert msg.include?('Unable to parse XML at:'), 'Message was: ' + msg
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_session_new_nil
|
29
29
|
msg = nil
|
30
30
|
begin
|
31
|
-
|
31
|
+
OpenSCAP::Xccdf::Session.new(nil)
|
32
32
|
assert false
|
33
33
|
rescue OpenSCAP::OpenSCAPError => e
|
34
34
|
msg = e.to_s
|
35
35
|
end
|
36
|
-
assert msg.start_with?(
|
36
|
+
assert msg.start_with?('No filename specified!'), 'Message was: ' + msg
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_sds_false
|
40
|
-
@s = OpenSCAP::Xccdf::Session.new(
|
40
|
+
@s = OpenSCAP::Xccdf::Session.new('../data/xccdf.xml')
|
41
41
|
assert ! @s.sds?
|
42
42
|
end
|
43
43
|
end
|
@@ -9,6 +9,7 @@
|
|
9
9
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
10
|
#
|
11
11
|
|
12
|
+
require 'openscap'
|
12
13
|
require 'openscap/source'
|
13
14
|
require 'openscap/xccdf/benchmark'
|
14
15
|
require 'openscap/xccdf/testresult'
|
@@ -20,21 +21,21 @@ class TestTestResult < OpenSCAP::TestCase
|
|
20
21
|
assert !source.nil?
|
21
22
|
msg = nil
|
22
23
|
begin
|
23
|
-
|
24
|
+
OpenSCAP::Xccdf::TestResult.new(source)
|
24
25
|
assert false
|
25
26
|
rescue OpenSCAP::OpenSCAPError => e
|
26
27
|
msg = e.to_s
|
27
28
|
end
|
28
29
|
assert msg.start_with?("Expected 'TestResult' element while found 'Benchmark'."),
|
29
|
-
|
30
|
+
'Message was: ' + msg
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_result_create_and_query_properties
|
33
34
|
tr = new_tr
|
34
35
|
assert tr.id == 'xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_common',
|
35
|
-
|
36
|
+
"TestResult.id was '#{tr.id}"
|
36
37
|
assert tr.profile == 'xccdf_org.ssgproject.content_profile_common',
|
37
|
-
|
38
|
+
"TestResult.profile was '#{tr.profile}'"
|
38
39
|
tr.destroy
|
39
40
|
end
|
40
41
|
|
@@ -89,6 +90,7 @@ class TestTestResult < OpenSCAP::TestCase
|
|
89
90
|
end
|
90
91
|
|
91
92
|
private
|
93
|
+
|
92
94
|
def benchmark_for_tr
|
93
95
|
source = OpenSCAP::Source.new('../data/xccdf.xml')
|
94
96
|
benchmark = OpenSCAP::Xccdf::Benchmark.new source
|
@@ -101,6 +103,6 @@ class TestTestResult < OpenSCAP::TestCase
|
|
101
103
|
assert !source.nil?
|
102
104
|
tr = OpenSCAP::Xccdf::TestResult.new(source)
|
103
105
|
source.destroy
|
104
|
-
|
106
|
+
tr
|
105
107
|
end
|
106
|
-
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Lukasik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|