openscap 0.2.0 → 0.3.0

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: 0bd3f590e5876554843cf78f32d92869dcfcad36
4
- data.tar.gz: 3daf5f1520a8932045a9ba0f43916934d114b66c
3
+ metadata.gz: 074803ceb32fdfbe49ce4a347e166b33ae2737d7
4
+ data.tar.gz: 628f26e6b604746130063faf1eecec3aaba118c0
5
5
  SHA512:
6
- metadata.gz: abef2aa76207a6ba403dd7ba219672970b3ac51616972d5113ac944f70912ecdb23a143ad90d7d6a699cced9b57c24bd6bf649632f3ec3b8d5a87e0be40faa39
7
- data.tar.gz: d26290405c9d441ab477730d8e1de22bd95bf3d0a274cc9ad0ac794ca7c9104a570561e924ad5c166ca5b54b96d3f048c33fe0aedb5f9dfdcd6389c1924b62bf
6
+ metadata.gz: 6fdb0130e40eab32d48982683e0f01363936f8b5ad01d7be8ff7b41b86081529354ab7732f0dca12ea4c397547eb0deab5f080043c64176c534a651306568933
7
+ data.tar.gz: 4e90b1f1ea0fc9e905879125001357e06f1c8ff64c3684f437193193e44cafb3607d7719bed4a04a4730230631b188582808a9f1e1ca6003184d3ac48648fd17
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'bundler'
2
2
 
3
- Bundler::GemHelper.install_tasks
3
+ Bundler::GemHelper.install_tasks :name => 'openscap'
4
4
 
5
5
  task :test do
6
6
  $LOAD_PATH.unshift('lib')
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ require 'openscap/source'
13
+ require 'openscap/libc'
14
+
15
+ module OpenSCAP
16
+ module DS
17
+ class Arf
18
+ def initialize(input_filename)
19
+ @source = OpenSCAP::Source.new(input_filename)
20
+ @session = OpenSCAP.ds_rds_session_new_from_source @source.raw
21
+ if @session.null?
22
+ OpenSCAP.raise!
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ OpenSCAP.ds_rds_session_free(@session)
28
+ @session = nil
29
+ @source.destroy()
30
+ end
31
+
32
+ def html
33
+ html_p = OpenSCAP.ds_rds_session_get_html_report @session
34
+ OpenSCAP.raise! if OpenSCAP.error?
35
+ return nil if html_p.null?
36
+ html = html_p.read_string()
37
+ OpenSCAP::LibC.free html_p
38
+ return html
39
+ end
40
+ end
41
+ end
42
+
43
+ attach_function :ds_rds_session_new_from_source, [:pointer], :pointer
44
+ attach_function :ds_rds_session_free, [:pointer], :void
45
+ attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
46
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ module OpenSCAP::Helper
13
+ def self.get_html_report_for_arf
14
+ # This is workaround function for the installation with
15
+ # old OpenSCAP without the oscap_source functionality
16
+
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ require 'ffi'
13
+
14
+ module OpenSCAP
15
+ module LibC
16
+ extend FFI::Library
17
+
18
+ ffi_lib FFI::Library::LIBC
19
+
20
+ attach_function :free, [:pointer], :void
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ module OpenSCAP
13
+ class Source
14
+ def initialize(input_filename)
15
+ raise OpenSCAPError, "No filename specified!" unless input_filename
16
+ @s = OpenSCAP.oscap_source_new_from_file(input_filename)
17
+ if @s.null?
18
+ OpenSCAP.raise!
19
+ end
20
+ end
21
+
22
+ def raw
23
+ @s
24
+ end
25
+
26
+ def destroy
27
+ OpenSCAP.oscap_source_free(@s)
28
+ @s = nil
29
+ end
30
+ end
31
+
32
+ attach_function :oscap_source_new_from_file, [:string], :pointer
33
+ attach_function :oscap_source_free, [:pointer], :void
34
+ end
@@ -0,0 +1,14 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ module OpenSCAP
13
+ VERSION = "0.3.0"
14
+ end
@@ -13,16 +13,6 @@ require 'test/unit'
13
13
 
14
14
  module OpenSCAP
15
15
  class TestCase < Test::Unit::TestCase
16
- class << self
17
- def startup
18
- OpenSCAP.oscap_init
19
- end
20
-
21
- def shutdown
22
- OpenSCAP.oscap_cleanup
23
- end
24
- end
25
-
26
16
  def setup
27
17
  workdir = "test/output"
28
18
  if Dir.pwd.end_with? 'test/output'
@@ -32,12 +22,14 @@ module OpenSCAP
32
22
  Dir.mkdir workdir
33
23
  Dir.chdir workdir
34
24
  @s = nil
25
+ OpenSCAP.oscap_init
35
26
  end
36
27
 
37
28
  def cleanup
38
29
  @s.destroy if @s
39
30
  Dir.chdir "../.."
40
31
  OpenSCAP.raise! if OpenSCAP.error?
32
+ OpenSCAP.oscap_cleanup
41
33
  end
42
34
 
43
35
  def test_x
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ require 'openscap'
13
+ require 'openscap/ds/arf'
14
+ require 'common/testcase'
15
+
16
+ class TestSession < OpenSCAP::TestCase
17
+ def test_arf_new_nil
18
+ msg = nil
19
+ begin
20
+ s = OpenSCAP::DS::Arf.new(nil)
21
+ assert false
22
+ rescue OpenSCAP::OpenSCAPError => e
23
+ msg = e.to_s
24
+ end
25
+ assert msg.start_with?("No filename specified!"), "Message was: " + msg
26
+ end
27
+
28
+ def test_arf_new_wrong_format
29
+ msg = nil
30
+ begin
31
+ s = OpenSCAP::DS::Arf.new("data/xccdf.xml")
32
+ assert false
33
+ rescue OpenSCAP::OpenSCAPError => e
34
+ msg = e.to_s
35
+ end
36
+ assert msg.start_with?('failed to load external entity "data/xccdf.xml"'), "Message was: " + msg
37
+ assert msg.include?('Could not create Result DataStream session: File is not Result DataStream.'),
38
+ "Message was: " + msg
39
+ end
40
+
41
+ def test_create_arf_and_get_html
42
+ @s = OpenSCAP::Xccdf::Session.new("../data/sds-complex.xml")
43
+ @s.load(:component_id => "scap_org.open-scap_cref_second-xccdf.xml")
44
+ @s.profile = "xccdf_moc.elpmaxe.www_profile_1"
45
+ @s.evaluate
46
+ @s.export_results(:rds_file => "report.rds.xml")
47
+ arf = OpenSCAP::DS::Arf.new("report.rds.xml")
48
+ html = arf.html
49
+ assert html.start_with?('<!DOCTYPE html><html'), "DOCTYPE missing."
50
+ assert html.include?('OpenSCAP')
51
+ assert html.include?('Compliance and Scoring')
52
+ end
53
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright (c) 2014 Red Hat Inc.
3
+ #
4
+ # This software is licensed to you under the GNU General Public License,
5
+ # version 2 (GPLv2). There is NO WARRANTY for this software, express or
6
+ # implied, including the implied warranties of MERCHANTABILITY or FITNESS
7
+ # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
8
+ # along with this software; if not, see
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10
+ #
11
+
12
+ require 'openscap'
13
+ require 'openscap/source'
14
+ require 'common/testcase'
15
+
16
+ class TestSource < OpenSCAP::TestCase
17
+ def test_source_new_nil
18
+ msg = nil
19
+ begin
20
+ s = OpenSCAP::Source.new(nil)
21
+ assert false
22
+ rescue OpenSCAP::OpenSCAPError => e
23
+ msg = e.to_s
24
+ end
25
+ assert msg.start_with?("No filename specified!"), "Message was: " + msg
26
+ end
27
+
28
+ def test_source_new_ok
29
+ s = OpenSCAP::Source.new("data/xccdf.xml")
30
+ s.destroy
31
+ end
32
+ end
@@ -21,7 +21,8 @@ class TestSession < OpenSCAP::TestCase
21
21
  rescue OpenSCAP::OpenSCAPError => e
22
22
  msg = e.to_s
23
23
  end
24
- assert msg.start_with?("Unable to open file: ''"), "Message was: " + msg
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
25
26
  end
26
27
 
27
28
  def test_session_new_nil
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Šimon Lukašík
7
+ - Simon Lukasik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-25 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: 1.0.9
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: 1.0.9
41
41
  description: |-
42
42
  A FFI wrapper around the OpenSCAP library.
43
43
  Currently it provides only subset of libopenscap functionality.
@@ -46,22 +46,26 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
50
- - COPYING
51
- - README.md
52
- - Rakefile
53
- - VERSION
54
49
  - lib/openscap.rb
55
- - lib/openscap/exceptions.rb
56
- - lib/openscap/openscap.rb
50
+ - lib/openscap/ds/arf.rb
51
+ - lib/openscap/libc.rb
57
52
  - lib/openscap/xccdf/session.rb
58
- - openscap.gemspec
59
- - test/common/testcase.rb
53
+ - lib/openscap/helper.rb
54
+ - lib/openscap/source.rb
55
+ - lib/openscap/openscap.rb
56
+ - lib/openscap/version.rb
57
+ - lib/openscap/exceptions.rb
58
+ - test/openscap_test.rb
59
+ - test/ds/arf_test.rb
60
60
  - test/data/sds-complex.xml
61
61
  - test/data/xccdf.xml
62
- - test/openscap_test.rb
63
- - test/xccdf/session_ds_test.rb
64
62
  - test/xccdf/session_test.rb
63
+ - test/xccdf/session_ds_test.rb
64
+ - test/common/testcase.rb
65
+ - test/source_test.rb
66
+ - COPYING
67
+ - README.md
68
+ - Rakefile
65
69
  homepage: https://github.com/OpenSCAP/ruby-openscap
66
70
  licenses:
67
71
  - GPL-2.0
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .buildpath
2
- .project
3
- .settings
4
- test/output
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'date'
3
-
4
- GEMSPEC = Gem::Specification.new do |gem|
5
- gem.name = "openscap"
6
- gem.version = File.open('VERSION').readline.chomp
7
- gem.date = Date.today.to_s
8
- gem.platform = Gem::Platform::RUBY
9
-
10
- gem.author = "Šimon Lukašík"
11
- gem.email = "isimluk@fedoraproject.org"
12
- gem.homepage = "https://github.com/OpenSCAP/ruby-openscap"
13
- gem.license = "GPL-2.0"
14
-
15
- gem.summary = "A FFI wrapper around the OpenSCAP library"
16
- gem.description = "A FFI wrapper around the OpenSCAP library.
17
- Currently it provides only subset of libopenscap functionality."
18
-
19
- gem.add_development_dependency "bundler", ">=1.0.0"
20
- gem.add_runtime_dependency "ffi", ">= 1.4.0"
21
-
22
- gem.files = `git ls-files`.split("\n")
23
- gem.require_path = 'lib'
24
- end