openscap 0.4.4 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6755fff46b8c00f6c8c1a8e04a65c8b9cd2dc370
4
- data.tar.gz: 681a7c26c5b44410f12f077e8962055c0e4dc087
3
+ metadata.gz: 68763a1de74c96941fe0bc5d05e9f732d40543af
4
+ data.tar.gz: a078eeb8d275edf2266ec60beaf6e93e33816ca7
5
5
  SHA512:
6
- metadata.gz: 10da3a43917ea9e91a8aeca225eb0f1a66e8668b03ef4cbdcbae53e2bfa548988d0bd842096a2988073702c38b13bbbed844dd2cec92d3e0049f99c7965b792a
7
- data.tar.gz: 5f69ab678008e3f0abf948dab540db1c82a0d9fe4b1793676de2ffe7c8d7b26cd167ed276c683165bdfe76f1d8d1aca5eafca32dc0852c07c65c7368adcb18e4
6
+ metadata.gz: ddf72e5c02430a421eb6a9f330132d8a3c525c0ea349fd5559c7856c9122ad12da3d069a6a1e960d1ae2c615b69b4e39f746c176ffa3bb15060a0544e5df408f
7
+ data.tar.gz: 055c061de134281428336f53932a97bf0413729fc3a01a1d235b8d1fc668c393ae038e0965eb1970989204d6c9483c1d46a954094656545ba0ae2e64245e0c49
@@ -0,0 +1,12 @@
1
+ #
2
+ # Copyright (c) 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
+ #
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), '{xccdf,ds,}', '*.rb'), &method(:require))
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -25,7 +25,7 @@ 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
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::DS:Arf with '#{param}'"
28
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{param}'"
29
29
  end
30
30
  OpenSCAP.raise! if @session.null?
31
31
  end
@@ -44,7 +44,7 @@ module OpenSCAP
44
44
 
45
45
  def test_result=(tr)
46
46
  source = tr.source
47
- OpenSCAP.raise! unless OpenSCAP.ds_rds_session_replace_report_with_source(@session, source.raw) == 0
47
+ OpenSCAP.raise! unless OpenSCAP.ds_rds_session_replace_report_with_source(@session, source.raw).zero?
48
48
  end
49
49
 
50
50
  def report_request(id = nil)
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -31,7 +31,7 @@ module OpenSCAP
31
31
  else
32
32
  err += "\n#{msg}"
33
33
  end
34
- fail OpenSCAPError, err
34
+ raise OpenSCAPError, err
35
35
  end
36
36
 
37
37
  attach_function :oscap_init, [], :void
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -18,7 +18,7 @@ module OpenSCAP
18
18
  def initialize(param)
19
19
  case param
20
20
  when nil
21
- fail OpenSCAPError, 'No filename specified!'
21
+ raise OpenSCAPError, 'No filename specified!'
22
22
  when String
23
23
  @raw = OpenSCAP.oscap_source_new_from_file(param)
24
24
  when Hash
@@ -26,7 +26,7 @@ module OpenSCAP
26
26
  when FFI::Pointer
27
27
  @raw = param
28
28
  else
29
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Source with '#{param}'"
29
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{param}'"
30
30
  end
31
31
  OpenSCAP.raise! if @raw.null?
32
32
  end
@@ -37,13 +37,13 @@ module OpenSCAP
37
37
 
38
38
  def validate!
39
39
  e = FFI::MemoryPointer.new(:char, 4096)
40
- if 0 != OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e)
40
+ unless OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e).zero?
41
41
  OpenSCAP.raise! e.read_string
42
42
  end
43
43
  end
44
44
 
45
45
  def save(filepath = nil)
46
- OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath) == 0
46
+ OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath).zero?
47
47
  end
48
48
 
49
49
  def destroy
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014--2015 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -10,5 +10,5 @@
10
10
  #
11
11
 
12
12
  module OpenSCAP
13
- VERSION = '0.4.4'
13
+ VERSION = '0.4.7'.freeze
14
14
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -23,8 +23,8 @@ module OpenSCAP
23
23
  when OpenSCAP::Source
24
24
  @raw = OpenSCAP.xccdf_benchmark_import_source p.raw
25
25
  else
26
- fail OpenSCAP::OpenSCAPError,
27
- "Cannot initialize OpenSCAP::Xccdf::Benchmark with '#{p}'"
26
+ raise OpenSCAP::OpenSCAPError,
27
+ "Cannot initialize OpenSCAP::Xccdf::Benchmark with '#{p}'"
28
28
  end
29
29
  OpenSCAP.raise! if @raw.null?
30
30
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2015 Red Hat Inc.
2
+ # Copyright (c) 2015--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -13,7 +13,7 @@ module OpenSCAP
13
13
  module Xccdf
14
14
  class Fix
15
15
  def initialize(raw)
16
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Reference with '#{raw}'" \
16
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" \
17
17
  unless raw.is_a?(FFI::Pointer)
18
18
  @raw = raw
19
19
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2015 Red Hat Inc.
2
+ # Copyright (c) 2015--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -19,7 +19,7 @@ module OpenSCAP
19
19
  module Xccdf
20
20
  class Item
21
21
  def self.build(t)
22
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Item with #{t}" \
22
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{t}" \
23
23
  unless t.is_a?(FFI::Pointer)
24
24
  # This is Abstract base class that enables you to build its child
25
25
  case OpenSCAP.xccdf_item_get_type t
@@ -28,13 +28,13 @@ module OpenSCAP
28
28
  when :rule
29
29
  OpenSCAP::Xccdf::Rule.new t
30
30
  else
31
- fail OpenSCAP::OpenSCAPError, "Unknown Xccdf::Item type: #{OpenSCAP.xccdf_item_get_type t}"
31
+ raise OpenSCAP::OpenSCAPError, "Unknown #{self.class.name} type: #{OpenSCAP.xccdf_item_get_type t}"
32
32
  end
33
33
  end
34
34
 
35
35
  def initialize(t)
36
36
  if self.class == OpenSCAP::Xccdf::Item
37
- fail OpenSCAP::OpenSCAPError, 'Cannot initialize Xccdf::Item abstract base class.'
37
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} abstract base class."
38
38
  end
39
39
  @raw = t
40
40
  end
@@ -68,7 +68,7 @@ module OpenSCAP
68
68
  refs = []
69
69
  refs_it = OpenSCAP.xccdf_item_get_references(@raw)
70
70
  while OpenSCAP.oscap_reference_iterator_has_more refs_it
71
- ref = OpenSCAP::Xccdf::Reference.new(OpenSCAP.oscap_reference_iterator_next refs_it)
71
+ ref = OpenSCAP::Xccdf::Reference.new(OpenSCAP.oscap_reference_iterator_next(refs_it))
72
72
  refs << ref
73
73
  end
74
74
  OpenSCAP.oscap_reference_iterator_free refs_it
@@ -0,0 +1,37 @@
1
+ #
2
+ # Copyright (c) 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
+ #
11
+
12
+ require 'openscap/exceptions'
13
+
14
+ module OpenSCAP
15
+ module Xccdf
16
+ class Policy
17
+ attr_reader :raw
18
+
19
+ def initialize(p)
20
+ case p
21
+ when FFI::Pointer
22
+ @raw = p
23
+ else
24
+ raise OpenSCAP::OpenSCAPError,
25
+ "Cannot initialize OpenSCAP::Xccdf::Policy with '#{p}'"
26
+ end
27
+ OpenSCAP.raise! if @raw.null?
28
+ end
29
+
30
+ def id
31
+ OpenSCAP.xccdf_policy_get_id raw
32
+ end
33
+ end
34
+ end
35
+
36
+ attach_function :xccdf_policy_get_id, [:pointer], :string
37
+ end
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright (c) 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
+ #
11
+
12
+ require 'openscap/exceptions'
13
+ require 'openscap/xccdf/benchmark'
14
+ require 'openscap/xccdf/policy'
15
+
16
+ module OpenSCAP
17
+ module Xccdf
18
+ class PolicyModel
19
+ attr_reader :raw
20
+
21
+ def initialize(b)
22
+ case b
23
+ when OpenSCAP::Xccdf::Benchmark
24
+ @raw = OpenSCAP.xccdf_policy_model_new(b.raw)
25
+ else
26
+ raise OpenSCAP::OpenSCAPError,
27
+ "Cannot initialize OpenSCAP::Xccdf::PolicyModel with '#{b}'"
28
+ end
29
+ OpenSCAP.raise! if @raw.null?
30
+ end
31
+
32
+ def policies
33
+ @policies ||= policies_init
34
+ end
35
+
36
+ def destroy
37
+ OpenSCAP.xccdf_policy_model_free @raw
38
+ @raw = nil
39
+ end
40
+
41
+ private
42
+
43
+ def policies_init
44
+ policies = {}
45
+ OpenSCAP.raise! unless OpenSCAP.xccdf_policy_model_build_all_useful_policies(raw).zero?
46
+ polit = OpenSCAP.xccdf_policy_model_get_policies raw
47
+ while OpenSCAP.xccdf_policy_iterator_has_more polit
48
+ policy_p = OpenSCAP.xccdf_policy_iterator_next polit
49
+ policy = OpenSCAP::Xccdf::Policy.new policy_p
50
+ policies[policy.id] = policy
51
+ end
52
+ OpenSCAP.xccdf_policy_iterator_free polit
53
+ policies
54
+ end
55
+ end
56
+ end
57
+
58
+ attach_function :xccdf_policy_model_new, [:pointer], :pointer
59
+ attach_function :xccdf_policy_model_free, [:pointer], :void
60
+ attach_function :xccdf_policy_model_build_all_useful_policies, [:pointer], :int
61
+
62
+ attach_function :xccdf_policy_model_get_policies, [:pointer], :pointer
63
+ attach_function :xccdf_policy_iterator_has_more, [:pointer], :bool
64
+ attach_function :xccdf_policy_iterator_next, [:pointer], :pointer
65
+ attach_function :xccdf_policy_iterator_free, [:pointer], :void
66
+ end
@@ -21,7 +21,7 @@ module OpenSCAP
21
21
  when FFI::Pointer
22
22
  @raw = p
23
23
  else
24
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Profile with #{p}"
24
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{p}"
25
25
  end
26
26
  end
27
27
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2015 Red Hat Inc.
2
+ # Copyright (c) 2015--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -13,7 +13,7 @@ module OpenSCAP
13
13
  module Xccdf
14
14
  class Reference
15
15
  def initialize(raw)
16
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Reference with '#{raw}'" \
16
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" \
17
17
  unless raw.is_a?(FFI::Pointer)
18
18
  @raw = raw
19
19
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -20,7 +20,7 @@ module OpenSCAP
20
20
  when FFI::Pointer
21
21
  @rr = t
22
22
  else
23
- fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::RuleResult with #{t}"
23
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{t}"
24
24
  end
25
25
  end
26
26
 
@@ -52,7 +52,7 @@ module OpenSCAP
52
52
 
53
53
  def validate_xccdf_result!(result_label)
54
54
  if OpenSCAP::XccdfResult[result_label] > OpenSCAP::XccdfResult[:fixed]
55
- fail OpenSCAPError, "Could not recognize result type: '#{result_label}'"
55
+ raise OpenSCAPError, "Could not recognize result type: '#{result_label}'"
56
56
  end
57
57
  end
58
58
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -13,7 +13,7 @@ module OpenSCAP
13
13
  module Xccdf
14
14
  class Session
15
15
  def initialize(input_filename)
16
- fail OpenSCAPError, 'No filename specified!' unless input_filename
16
+ raise OpenSCAPError, 'No filename specified!' unless input_filename
17
17
  @input_filename = input_filename
18
18
  @s = OpenSCAP.xccdf_session_new(input_filename)
19
19
  OpenSCAP.raise! if @s.null?
@@ -32,23 +32,23 @@ module OpenSCAP
32
32
  OpenSCAP.xccdf_session_set_datastream_id(@s, o[:datastream_id])
33
33
  OpenSCAP.xccdf_session_set_component_id(@s, o[:component_id])
34
34
  end
35
- OpenSCAP.raise! if OpenSCAP.xccdf_session_load(@s) != 0
36
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_load_check_engine_plugins(@s) == 0
35
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_load(@s).zero?
36
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_load_check_engine_plugins(@s).zero?
37
37
  end
38
38
 
39
39
  def profile=(p)
40
40
  @profile = p
41
41
  if OpenSCAP.xccdf_session_set_profile_id(@s, p) == false
42
- fail OpenSCAPError, "No profile '" + p + "' found"
42
+ raise OpenSCAPError, "No profile '" + p + "' found"
43
43
  end
44
44
  end
45
45
 
46
46
  def evaluate
47
- OpenSCAP.raise! if OpenSCAP.xccdf_session_evaluate(@s) != 0
47
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_evaluate(@s).zero?
48
48
  end
49
49
 
50
50
  def remediate
51
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_remediate(@s) == 0
51
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_remediate(@s).zero?
52
52
  end
53
53
 
54
54
  def export_results(opts = {})
@@ -72,10 +72,10 @@ module OpenSCAP
72
72
  private
73
73
 
74
74
  def export
75
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_oval(@s) == 0
76
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_check_engine_plugins(@s) == 0
77
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_xccdf(@s) == 0
78
- OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_arf(@s) == 0
75
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_oval(@s).zero?
76
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_check_engine_plugins(@s).zero?
77
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_xccdf(@s).zero?
78
+ OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_arf(@s).zero?
79
79
  end
80
80
 
81
81
  def export_targets(opts = {})
@@ -0,0 +1,62 @@
1
+ #
2
+ # Copyright (c) 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
+ #
11
+
12
+ require 'openscap/source'
13
+ require 'openscap/xccdf/profile'
14
+
15
+ module OpenSCAP
16
+ module Xccdf
17
+ class Tailoring
18
+ attr_reader :raw
19
+
20
+ def initialize(source, benchmark)
21
+ case source
22
+ when OpenSCAP::Source
23
+ @raw = OpenSCAP.xccdf_tailoring_import_source source.raw, benchmark
24
+ else
25
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{source}'"
26
+ end
27
+ OpenSCAP.raise! if @raw.null?
28
+ end
29
+
30
+ def profiles
31
+ @profiles ||= profiles_init
32
+ end
33
+
34
+ def destroy
35
+ OpenSCAP.xccdf_tailoring_free @raw
36
+ @raw = nil
37
+ end
38
+
39
+ private
40
+
41
+ def profiles_init
42
+ profiles = {}
43
+ profit = OpenSCAP.xccdf_tailoring_get_profiles raw
44
+ while OpenSCAP.xccdf_profile_iterator_has_more profit
45
+ profile_p = OpenSCAP.xccdf_profile_iterator_next profit
46
+ profile = OpenSCAP::Xccdf::Profile.new profile_p
47
+ profiles[profile.id] = profile
48
+ end
49
+ OpenSCAP.xccdf_profile_iterator_free profit
50
+ profiles
51
+ end
52
+ end
53
+ end
54
+
55
+ attach_function :xccdf_tailoring_import_source, [:pointer, :pointer], :pointer
56
+ attach_function :xccdf_tailoring_free, [:pointer], :void
57
+
58
+ attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
59
+ attach_function :xccdf_profile_iterator_has_more, [:pointer], :bool
60
+ attach_function :xccdf_profile_iterator_next, [:pointer], :pointer
61
+ attach_function :xccdf_profile_iterator_free, [:pointer], :void
62
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -29,7 +29,7 @@ module OpenSCAP
29
29
  @raw = OpenSCAP.xccdf_result_import_source(t)
30
30
  OpenSCAP.raise! if @raw.null?
31
31
  else
32
- fail OpenSCAP::OpenSCAPError, "Cannot initialize TestResult with #{t}"
32
+ raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{t}"
33
33
  end
34
34
  init_ruleresults
35
35
  end
@@ -49,7 +49,7 @@ module OpenSCAP
49
49
  def score!(benchmark)
50
50
  # recalculate the scores in the scope of given benchmark
51
51
  @score = nil
52
- OpenSCAP.raise! unless OpenSCAP.xccdf_result_recalculate_scores(@raw, benchmark.raw) == 0
52
+ OpenSCAP.raise! unless OpenSCAP.xccdf_result_recalculate_scores(@raw, benchmark.raw).zero?
53
53
  score
54
54
  end
55
55
 
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xccdf:Tailoring xmlns:xccdf="http://checklists.nist.gov/xccdf/1.2" id="xccdf_scap-workbench_tailoring_default">
3
+ <xccdf:benchmark href="/usr/share/xml/scap/ssg/content/ssg-firefox-ds.xml"/>
4
+ <xccdf:version time="2016-11-10T11:24:26">1</xccdf:version>
5
+ <xccdf:Profile id="xccdf_org.ssgproject.content_profile_stig-firefox-upstream_customized" extends="xccdf_org.ssgproject.content_profile_stig-firefox-upstream">
6
+ <xccdf:title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Upstream Firefox STIG [CUSTOMIZED]</xccdf:title>
7
+ <xccdf:description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This profile is developed under the DoD consensus model and DISA FSO Vendor STIG process,
8
+ serving as the upstream development environment for the Firefox STIG.
9
+
10
+ As a result of the upstream/downstream relationship between the SCAP Security Guide project
11
+ and the official DISA FSO STIG baseline, users should expect variance between SSG and DISA FSO content.
12
+ For official DISA FSO STIG content, refer to http://iase.disa.mil/stigs/app-security/browser-guidance/Pages/index.aspx.
13
+
14
+ While this profile is packaged by Red Hat as part of the SCAP Security Guide package, please note
15
+ that commercial support of this SCAP content is NOT available. This profile is provided as example
16
+ SCAP content with no endorsement for suitability or production readiness. Support for this
17
+ profile is provided by the upstream SCAP Security Guide community on a best-effort basis. The
18
+ upstream project homepage is https://fedorahosted.org/scap-security-guide/.
19
+ </xccdf:description>
20
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-non-secure_page_warning" selected="true"/>
21
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_status_bar_text" selected="true"/>
22
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_context_menus" selected="true"/>
23
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_status_bar_changes" selected="true"/>
24
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_window_resizing" selected="true"/>
25
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-javascript_window_changes" selected="true"/>
26
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-auto-update_of_firefox" selected="false"/>
27
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-autofill_passwords" selected="false"/>
28
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-autofill_forms" selected="false"/>
29
+ <xccdf:select idref="xccdf_org.ssgproject.content_rule_firefox_preferences-addons_plugin_updates" selected="false"/>
30
+ </xccdf:Profile>
31
+ </xccdf:Tailoring>
@@ -14,7 +14,7 @@ require 'openscap/ds/arf'
14
14
  require 'common/testcase'
15
15
 
16
16
  class TestArf < OpenSCAP::TestCase
17
- REPORT = 'report.rds.xml'
17
+ REPORT = 'report.rds.xml'.freeze
18
18
 
19
19
  def test_arf_new_nil
20
20
  msg = nil
@@ -24,7 +24,7 @@ class TestArf < OpenSCAP::TestCase
24
24
  rescue OpenSCAP::OpenSCAPError => e
25
25
  msg = e.to_s
26
26
  end
27
- assert msg.start_with?("Cannot initialize OpenSCAP::DS:Arf with ''"), 'Message was: ' + msg
27
+ assert msg.start_with?("Cannot initialize OpenSCAP::DS::Arf with ''"), 'Message was: ' + msg
28
28
  end
29
29
 
30
30
  def test_arf_new_wrong_format
@@ -60,15 +60,13 @@ class TestArf < OpenSCAP::TestCase
60
60
  def test_new_memory
61
61
  create_arf
62
62
  raw_data = File.read(REPORT)
63
- assert raw_data.length > 0
63
+ refute raw_data.empty?
64
64
  arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => REPORT
65
65
  arf.destroy
66
66
  end
67
67
 
68
68
  def test_new_bz_memory
69
- create_arf
70
- system('/usr/bin/bzip2 ' + REPORT)
71
- bziped_file = REPORT + '.bz2'
69
+ bziped_file = new_arf_bz
72
70
  raw_data = File.open(bziped_file, 'rb').read
73
71
  assert !raw_data.empty?
74
72
  len = File.size(bziped_file)
@@ -77,8 +75,21 @@ class TestArf < OpenSCAP::TestCase
77
75
  arf.destroy
78
76
  end
79
77
 
78
+ def test_new_bz_file
79
+ bziped_file = new_arf_bz
80
+ arf = OpenSCAP::DS::Arf.new(bziped_file)
81
+ arf.destroy
82
+ FileUtils.rm bziped_file
83
+ end
84
+
80
85
  private
81
86
 
87
+ def new_arf_bz
88
+ create_arf
89
+ system('/usr/bin/bzip2 ' + REPORT)
90
+ REPORT + '.bz2'
91
+ end
92
+
82
93
  def new_arf
83
94
  create_arf
84
95
  OpenSCAP::DS::Arf.new(REPORT)
@@ -32,7 +32,7 @@ class TestSource < OpenSCAP::TestCase
32
32
 
33
33
  def test_source_new_memory
34
34
  raw_data = File.read('../data/xccdf.xml')
35
- assert raw_data.length > 0
35
+ refute raw_data.empty?
36
36
  s = OpenSCAP::Source.new(:content => raw_data, :path => '/mytestpath')
37
37
  s.destroy
38
38
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2014 Red Hat Inc.
2
+ # Copyright (c) 2014--2016 Red Hat Inc.
3
3
  #
4
4
  # This software is licensed to you under the GNU General Public License,
5
5
  # version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -41,7 +41,7 @@ class TestBenchmark < OpenSCAP::TestCase
41
41
  rescue OpenSCAP::OpenSCAPError => e
42
42
  msg = e.to_s
43
43
  end
44
- assert msg.start_with?('Failed to import XCCDF content from'), msg
44
+ assert msg.start_with?("Find element 'TestResult' while expecting element: 'Benchmark'"), msg
45
45
  end
46
46
 
47
47
  def test_items_in_benchmark
@@ -94,6 +94,7 @@ class TestBenchmark < OpenSCAP::TestCase
94
94
  :href => 'http://iase.disa.mil/cci/index.html',
95
95
  :html_link => "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
96
96
  assert_equal(expected_references, install_hids_rule.references.map(&:to_hash), 'Install hids references should be equal')
97
+ b.destroy
97
98
  end
98
99
 
99
100
  def test_items_fixes
@@ -108,6 +109,7 @@ class TestBenchmark < OpenSCAP::TestCase
108
109
  }]
109
110
  assert_equal(expected_content, login_defs_rule.fixes.map(&:content), 'Fix content should match')
110
111
  assert_equal(expected_hashes, login_defs_rule.fixes.map(&:to_hash), 'Fix hash should match')
112
+ b.destroy
111
113
  end
112
114
 
113
115
  private
@@ -0,0 +1,29 @@
1
+ #
2
+ # Copyright (c) 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
+ #
11
+
12
+ require 'common/testcase'
13
+ require 'openscap'
14
+ require 'openscap/source'
15
+ require 'openscap/xccdf/benchmark'
16
+ require 'openscap/xccdf/policy'
17
+ require 'openscap/xccdf/policy_model'
18
+
19
+ class TestPolicy < OpenSCAP::TestCase
20
+ def test_new_policy_model
21
+ @s = OpenSCAP::Source.new '../data/xccdf.xml'
22
+ b = OpenSCAP::Xccdf::Benchmark.new @s
23
+ pm = OpenSCAP::Xccdf::PolicyModel.new b
24
+ assert !b.nil?
25
+ assert pm.policies.size == 1, pm.policies.to_s
26
+ assert pm.policies['xccdf_org.ssgproject.content_profile_common']
27
+ pm.destroy
28
+ end
29
+ end
@@ -119,7 +119,7 @@ class TestSessionDS < OpenSCAP::TestCase
119
119
 
120
120
  def assert_exported(files)
121
121
  # libopenscap compiled with --enable-debug creates debug files
122
- FileUtils.rm_rf(Dir.glob 'oscap_debug.log.*')
122
+ FileUtils.rm_rf(Dir.glob('oscap_debug.log.*'))
123
123
  assert files.sort == Dir.glob('*').sort
124
124
  end
125
125
  end
@@ -37,6 +37,6 @@ class TestSession < OpenSCAP::TestCase
37
37
 
38
38
  def test_sds_false
39
39
  @s = OpenSCAP::Xccdf::Session.new('../data/xccdf.xml')
40
- assert ! @s.sds?
40
+ refute @s.sds?
41
41
  end
42
42
  end
@@ -0,0 +1,39 @@
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
+ #
11
+
12
+ require 'openscap'
13
+ require 'openscap/source'
14
+ require 'openscap/xccdf/tailoring'
15
+ require 'common/testcase'
16
+
17
+ class TailoringTest < OpenSCAP::TestCase
18
+ def test_new_from_file
19
+ tailoring = tailoring_from_file
20
+ tailoring.destroy
21
+ refute tailoring.raw
22
+ end
23
+
24
+ def test_profiles
25
+ profiles = tailoring_from_file.profiles
26
+ assert_equal 1, profiles.length
27
+ assert profiles.values.first.is_a?(OpenSCAP::Xccdf::Profile)
28
+ end
29
+
30
+ private
31
+
32
+ def tailoring_from_file
33
+ source = OpenSCAP::Source.new '../data/tailoring.xml'
34
+ tailoring = OpenSCAP::Xccdf::Tailoring.new source, nil
35
+ source.destroy
36
+ assert tailoring
37
+ tailoring
38
+ end
39
+ 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
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Lukasik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-27 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,6 +50,7 @@ files:
50
50
  - README.md
51
51
  - Rakefile
52
52
  - lib/openscap.rb
53
+ - lib/openscap/all.rb
53
54
  - lib/openscap/ds/arf.rb
54
55
  - lib/openscap/ds/sds.rb
55
56
  - lib/openscap/exceptions.rb
@@ -63,16 +64,20 @@ files:
63
64
  - lib/openscap/xccdf/fix.rb
64
65
  - lib/openscap/xccdf/group.rb
65
66
  - lib/openscap/xccdf/item.rb
67
+ - lib/openscap/xccdf/policy.rb
68
+ - lib/openscap/xccdf/policy_model.rb
66
69
  - lib/openscap/xccdf/profile.rb
67
70
  - lib/openscap/xccdf/reference.rb
68
71
  - lib/openscap/xccdf/rule.rb
69
72
  - lib/openscap/xccdf/ruleresult.rb
70
73
  - lib/openscap/xccdf/session.rb
74
+ - lib/openscap/xccdf/tailoring.rb
71
75
  - lib/openscap/xccdf/testresult.rb
72
76
  - lib/openscap/xccdf/value.rb
73
77
  - test/common/testcase.rb
74
78
  - test/data/invalid.xml
75
79
  - test/data/sds-complex.xml
80
+ - test/data/tailoring.xml
76
81
  - test/data/testresult.xml
77
82
  - test/data/xccdf.xml
78
83
  - test/ds/arf_test.rb
@@ -82,9 +87,11 @@ files:
82
87
  - test/source_test.rb
83
88
  - test/text_test.rb
84
89
  - test/xccdf/benchmark_test.rb
90
+ - test/xccdf/policy_test.rb
85
91
  - test/xccdf/profile_test.rb
86
92
  - test/xccdf/session_ds_test.rb
87
93
  - test/xccdf/session_test.rb
94
+ - test/xccdf/tailoring_test.rb
88
95
  - test/xccdf/testresult_test.rb
89
96
  homepage: https://github.com/OpenSCAP/ruby-openscap
90
97
  licenses: