diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..77073e1
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,24 @@
+name: test
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: "3.2"
+ bundler-cache: true
+ - run: |
+ sudo apt-get update
+ sudo apt-get -y install libopenscap8
+ - run: |
+ bundle install
+ - run: |
+ ./runtest.sh
diff --git a/.rubocop.yml b/.rubocop.yml
index 6976402..6f8bf55 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,27 +1,38 @@
inherit_from:
- .rubocop_todo.yml
+require:
+ - rubocop-performance
+ - rubocop-thread_safety
+
+AllCops:
+ NewCops: enable
+ TargetRubyVersion: 3.2.2
+ AllowSymlinksInCacheRootDirectory: true
+ SuggestExtensions:
+ rubocop-rake: false
+
Metrics/AbcSize:
Max: 16
Exclude:
- 'test/**/*'
-Metrics/LineLength:
+Layout/LineLength:
Max: 110
Exclude:
- 'test/**/*'
+Lint/FloatComparison:
+ Exclude:
+ - 'test/**/*'
+
Metrics/MethodLength:
Max: 13
Exclude:
- 'test/**/*'
-Style/HashSyntax:
- EnforcedStyle: hash_rockets
-
-Style/SymbolArray:
- EnforcedStyle: brackets
+Naming/MethodParameterName:
+ Enabled: false
-Naming/UncommunicativeMethodParamName:
- Exclude:
- - '**/*'
+Gemspec/RequireMFA:
+ Enabled: false
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..59a32cc
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+source 'https://rubygems.org'
+
+gemspec
+
+group :development do
+ gem 'rake'
+ gem 'rubocop'
+ gem 'rubocop-performance'
+ gem 'rubocop-thread_safety'
+ gem 'test-unit'
+end
diff --git a/README.md b/README.md
index 5a60b1e..ddbcc17 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ A FFI wrapper around the OpenSCAP library.
Features/problems
-------------
-Current version supports minimal set of functions needed to build own scanner. This module
+Current version supports minimal set of functions needed to build own scanner. This gem
is self documented by its test suite.
Sample Scanner Implementation
@@ -23,28 +23,17 @@ Sample Scanner Implementation
Development Requirements
-------------
-On Fedora, command is
+On Fedora, commands are
- dnf install ruby-devel rubygem-rake rubygem-ffi rubygem-bundler openscap
-
-On RHEL you can install requirements by issuing
-
- yum install ruby-devel rubygem-rake rubygem-bundler openscap
- gem install ffi # or install rubygem-ffi RPM package from EPEL
+ dnf install openscap
+ bundle install
Test Requirements
-------------
On Fedora, more packages are necessary, but rubocop can be of the latest version
- dnf install rubygem-minitest rubygem-test-unit rubygems-devel bzip2
- gem install rubocop
-
-For tests on RHEL7, you need minitest package and specific older version of rubocop.
-Newer versions of rubocop requires Ruby >= 2.1.0
-
- yum install rubygem-minitest bzip2
- gem install rubocop -v 0.50.0
+ dnf install bzip2
Tests are then performed using script
diff --git a/Rakefile b/Rakefile
index 128eb0e..778307e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,10 +2,10 @@
require 'bundler'
-Bundler::GemHelper.install_tasks :name => 'openscap'
+Bundler::GemHelper.install_tasks name: 'openscap'
task :test do
$LOAD_PATH.unshift('lib')
$LOAD_PATH.unshift('test')
- Dir.glob('./test/**/*_test.rb') { |f| require f }
+ Dir.glob('./test/**/*_test.rb').each { |f| require f }
end
diff --git a/lib/openscap/ds/arf.rb b/lib/openscap/ds/arf.rb
index d7904d3..7254cbc 100644
--- a/lib/openscap/ds/arf.rb
+++ b/lib/openscap/ds/arf.rb
@@ -58,8 +58,8 @@ def html
attach_function :ds_rds_session_new_from_source, [:pointer], :pointer
attach_function :ds_rds_session_free, [:pointer], :void
- attach_function :ds_rds_session_select_report, [:pointer, :string], :pointer
- attach_function :ds_rds_session_replace_report_with_source, [:pointer, :pointer], :int
- attach_function :ds_rds_session_select_report_request, [:pointer, :string], :pointer
+ attach_function :ds_rds_session_select_report, %i[pointer string], :pointer
+ attach_function :ds_rds_session_replace_report_with_source, %i[pointer pointer], :int
+ attach_function :ds_rds_session_select_report_request, %i[pointer string], :pointer
attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
end
diff --git a/lib/openscap/ds/sds.rb b/lib/openscap/ds/sds.rb
index 9642adb..ae88be3 100644
--- a/lib/openscap/ds/sds.rb
+++ b/lib/openscap/ds/sds.rb
@@ -43,6 +43,6 @@ def destroy
attach_function :ds_sds_session_new_from_source, [:pointer], :pointer
attach_function :ds_sds_session_free, [:pointer], :void
- attach_function :ds_sds_session_select_checklist, [:pointer, :string, :string, :string], :pointer
- attach_function :ds_sds_session_get_html_guide, [:pointer, :string], :string
+ attach_function :ds_sds_session_select_checklist, %i[pointer string string string], :pointer
+ attach_function :ds_sds_session_get_html_guide, %i[pointer string], :string
end
diff --git a/lib/openscap/source.rb b/lib/openscap/source.rb
index 9f50485..702bf9d 100644
--- a/lib/openscap/source.rb
+++ b/lib/openscap/source.rb
@@ -51,13 +51,13 @@ def create_from_memory(param)
end
attach_function :oscap_source_new_from_file, [:string], :pointer
- attach_function :oscap_source_new_from_memory, [:pointer, :int, :string], :pointer
+ attach_function :oscap_source_new_from_memory, %i[pointer int string], :pointer
attach_function :oscap_source_get_scap_type, [:pointer], :int
attach_function :oscap_source_free, [:pointer], :void
- attach_function :oscap_source_save_as, [:pointer, :string], :int
+ attach_function :oscap_source_save_as, %i[pointer string], :int
- callback :xml_reporter, [:string, :int, :string, :pointer], :int
- attach_function :oscap_source_validate, [:pointer, :xml_reporter, :pointer], :int
+ callback :xml_reporter, %i[string int string pointer], :int
+ attach_function :oscap_source_validate, %i[pointer xml_reporter pointer], :int
XmlReporterCallback = proc do |filename, line_number, error_message, e|
offset = e.get_string(0).length
msg = "#{filename}:#{line_number}: #{error_message}"
diff --git a/lib/openscap/text.rb b/lib/openscap/text.rb
index 6a1141c..89a9422 100644
--- a/lib/openscap/text.rb
+++ b/lib/openscap/text.rb
@@ -37,10 +37,10 @@ def destroy
end
attach_function :oscap_text_new, [], :pointer
- attach_function :oscap_text_set_text, [:pointer, :string], :bool
+ attach_function :oscap_text_set_text, %i[pointer string], :bool
attach_function :oscap_text_get_text, [:pointer], :string
attach_function :oscap_text_free, [:pointer], :void
- attach_function :oscap_textlist_get_preferred_plaintext, [:pointer, :string], :string
+ attach_function :oscap_textlist_get_preferred_plaintext, %i[pointer string], :string
attach_function :oscap_text_iterator_free, [:pointer], :void
end
diff --git a/lib/openscap/xccdf.rb b/lib/openscap/xccdf.rb
index 7b907a6..e8c0033 100644
--- a/lib/openscap/xccdf.rb
+++ b/lib/openscap/xccdf.rb
@@ -6,7 +6,7 @@ module OpenSCAP
module Xccdf
NUMERIC = :float
- class Item
+ class Item # rubocop:disable Lint/EmptyClass
end
end
end
diff --git a/lib/openscap/xccdf/fix.rb b/lib/openscap/xccdf/fix.rb
index fbf1acb..57ac09b 100644
--- a/lib/openscap/xccdf/fix.rb
+++ b/lib/openscap/xccdf/fix.rb
@@ -29,10 +29,10 @@ def content
def to_hash
{
- :id => id,
- :platform => platform,
- :system => fix_system,
- :content => content
+ id:,
+ platform:,
+ system: fix_system,
+ content:
}
end
end
diff --git a/lib/openscap/xccdf/item.rb b/lib/openscap/xccdf/item.rb
index a75a9a8..32302a2 100644
--- a/lib/openscap/xccdf/item.rb
+++ b/lib/openscap/xccdf/item.rb
@@ -25,7 +25,7 @@ def self.build(t)
end
def initialize(t)
- if self.class == OpenSCAP::Xccdf::Item
+ if instance_of?(OpenSCAP::Xccdf::Item)
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} abstract base class."
end
diff --git a/lib/openscap/xccdf/reference.rb b/lib/openscap/xccdf/reference.rb
index c8335f1..0d61271 100644
--- a/lib/openscap/xccdf/reference.rb
+++ b/lib/openscap/xccdf/reference.rb
@@ -24,9 +24,9 @@ def html_link
def to_hash
{
- :title => title,
- :href => href,
- :html_link => html_link
+ title:,
+ href:,
+ html_link:
}
end
end
diff --git a/lib/openscap/xccdf/rule.rb b/lib/openscap/xccdf/rule.rb
index fc192c0..93d2f85 100644
--- a/lib/openscap/xccdf/rule.rb
+++ b/lib/openscap/xccdf/rule.rb
@@ -11,12 +11,12 @@ class Rule < Item
def severity
severity = OpenSCAP.xccdf_rule_get_severity(@raw)
severity_mapping = {
- :xccdf_level_not_defined => 'Not defined',
- :xccdf_unknown => 'Unknown',
- :xccdf_info => 'Info',
- :xccdf_low => 'Low',
- :xccdf_medium => 'Medium',
- :xccdf_high => 'High'
+ xccdf_level_not_defined: 'Not defined',
+ xccdf_unknown: 'Unknown',
+ xccdf_info: 'Info',
+ xccdf_low: 'Low',
+ xccdf_medium: 'Medium',
+ xccdf_high: 'High'
}
severity_mapping[severity] || severity_mapping[:xccdf_unknown]
end
diff --git a/lib/openscap/xccdf/session.rb b/lib/openscap/xccdf/session.rb
index 70fc918..3bb3af5 100644
--- a/lib/openscap/xccdf/session.rb
+++ b/lib/openscap/xccdf/session.rb
@@ -17,8 +17,8 @@ def sds?
def load(opts = {})
o = {
- :datastream_id => nil,
- :component_id => nil
+ datastream_id: nil,
+ component_id: nil
}.merge(opts)
if sds?
OpenSCAP.xccdf_session_set_datastream_id(@s, o[:datastream_id])
@@ -31,7 +31,7 @@ def load(opts = {})
def profile=(p)
@profile = p
if OpenSCAP.xccdf_session_set_profile_id(@s, p) == false
- raise OpenSCAPError, "No profile '" + p + "' found"
+ raise OpenSCAPError, "No profile '#{p}' found"
end
end
@@ -45,12 +45,12 @@ def remediate
def export_results(opts = {})
o = {
- :rds_file => nil,
- :xccdf_file => nil,
- :report_file => nil,
- :oval_results => false,
- :oval_variables => false,
- :engines_results => false
+ rds_file: nil,
+ xccdf_file: nil,
+ report_file: nil,
+ oval_results: false,
+ oval_variables: false,
+ engines_results: false
}.merge!(opts)
export_targets o
export
@@ -94,13 +94,13 @@ def export_targets(opts = {})
attach_function :xccdf_session_is_sds, [:pointer], :bool
- attach_function :xccdf_session_set_profile_id, [:pointer, :string], :bool
- attach_function :xccdf_session_set_datastream_id, [:pointer, :string], :void
- attach_function :xccdf_session_set_component_id, [:pointer, :string], :void
- attach_function :xccdf_session_set_arf_export, [:pointer, :string], :bool
- attach_function :xccdf_session_set_xccdf_export, [:pointer, :string], :bool
- attach_function :xccdf_session_set_report_export, [:pointer, :string], :bool
- attach_function :xccdf_session_set_oval_variables_export, [:pointer, :bool], :void
- attach_function :xccdf_session_set_oval_results_export, [:pointer, :bool], :void
- attach_function :xccdf_session_set_check_engine_plugins_results_export, [:pointer, :bool], :void
+ attach_function :xccdf_session_set_profile_id, %i[pointer string], :bool
+ attach_function :xccdf_session_set_datastream_id, %i[pointer string], :void
+ attach_function :xccdf_session_set_component_id, %i[pointer string], :void
+ attach_function :xccdf_session_set_arf_export, %i[pointer string], :bool
+ attach_function :xccdf_session_set_xccdf_export, %i[pointer string], :bool
+ attach_function :xccdf_session_set_report_export, %i[pointer string], :bool
+ attach_function :xccdf_session_set_oval_variables_export, %i[pointer bool], :void
+ attach_function :xccdf_session_set_oval_results_export, %i[pointer bool], :void
+ attach_function :xccdf_session_set_check_engine_plugins_results_export, %i[pointer bool], :void
end
diff --git a/lib/openscap/xccdf/tailoring.rb b/lib/openscap/xccdf/tailoring.rb
index 11a15d0..5b5c6d3 100644
--- a/lib/openscap/xccdf/tailoring.rb
+++ b/lib/openscap/xccdf/tailoring.rb
@@ -43,7 +43,7 @@ def profiles_init
end
end
- attach_function :xccdf_tailoring_import_source, [:pointer, :pointer], :pointer
+ attach_function :xccdf_tailoring_import_source, %i[pointer pointer], :pointer
attach_function :xccdf_tailoring_free, [:pointer], :void
attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
diff --git a/lib/openscap/xccdf/testresult.rb b/lib/openscap/xccdf/testresult.rb
index ec51cd2..8461198 100644
--- a/lib/openscap/xccdf/testresult.rb
+++ b/lib/openscap/xccdf/testresult.rb
@@ -8,8 +8,7 @@
module OpenSCAP
module Xccdf
class TestResult
- attr_reader :rr
- attr_reader :raw
+ attr_reader :rr, :raw
def initialize(t)
case t
@@ -73,9 +72,9 @@ def score_init
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
s = OpenSCAP.xccdf_score_iterator_next(scorit)
scores[OpenSCAP.xccdf_score_get_system(s)] = {
- :system => OpenSCAP.xccdf_score_get_system(s),
- :value => OpenSCAP.xccdf_score_get_score(s),
- :max => OpenSCAP.xccdf_score_get_maximum(s)
+ system: OpenSCAP.xccdf_score_get_system(s),
+ value: OpenSCAP.xccdf_score_get_score(s),
+ max: OpenSCAP.xccdf_score_get_maximum(s)
}
end
OpenSCAP.xccdf_score_iterator_free(scorit)
@@ -88,8 +87,8 @@ def score_init
attach_function :xccdf_result_free, [:pointer], :void
attach_function :xccdf_result_get_id, [:pointer], :string
attach_function :xccdf_result_get_profile, [:pointer], :string
- attach_function :xccdf_result_recalculate_scores, [:pointer, :pointer], :int
- attach_function :xccdf_result_export_source, [:pointer, :string], :pointer
+ attach_function :xccdf_result_recalculate_scores, %i[pointer pointer], :int
+ attach_function :xccdf_result_export_source, %i[pointer string], :pointer
attach_function :xccdf_result_get_rule_results, [:pointer], :pointer
attach_function :xccdf_rule_result_iterator_has_more, [:pointer], :bool
diff --git a/openscap.gemspec b/openscap.gemspec
index 5427a61..a782026 100644
--- a/openscap.gemspec
+++ b/openscap.gemspec
@@ -6,8 +6,8 @@ require File.expand_path('lib/openscap/version', __dir__)
GEMSPEC = Gem::Specification.new do |gem|
gem.name = 'openscap'
gem.version = OpenSCAP::VERSION
- gem.date = Date.today.to_s
gem.platform = Gem::Platform::RUBY
+ gem.required_ruby_version = '>= 3.2.2'
gem.author = 'Simon Lukasik'
gem.email = 'isimluk@fedoraproject.org'
@@ -18,8 +18,7 @@ GEMSPEC = Gem::Specification.new do |gem|
gem.description = "A FFI wrapper around the OpenSCAP library.
Currently it provides only subset of libopenscap functionality."
- gem.add_development_dependency 'bundler', '>=1.0.0'
- gem.add_runtime_dependency 'ffi', '>= 1.0.9'
+ gem.add_runtime_dependency 'ffi', '~> 1.15.5'
gem.files = Dir['{lib,test}/**/*'] + ['COPYING', 'README.md', 'Rakefile']
gem.require_path = 'lib'
diff --git a/runtest.sh b/runtest.sh
index c1409c9..5e813fa 100755
--- a/runtest.sh
+++ b/runtest.sh
@@ -1,8 +1,9 @@
+#!/bin/bash
set -e -o pipefail
set -x
rm -f openscap-*.gem
gem build openscap.gemspec
-gem install openscap-*.gem
-rake test
-rubocop
+#gem install openscap-*.gem
+bundle exec rake test
+bundle exec rubocop
diff --git a/test/ds/arf_test.rb b/test/ds/arf_test.rb
index d8b36a7..6306ad4 100644
--- a/test/ds/arf_test.rb
+++ b/test/ds/arf_test.rb
@@ -15,7 +15,7 @@ def test_arf_new_nil
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
end
- assert msg.start_with?("Cannot initialize OpenSCAP::DS::Arf with ''"), 'Message was: ' + msg
+ assert msg.start_with?("Cannot initialize OpenSCAP::DS::Arf with ''"), "Message was: #{msg}"
end
def test_arf_new_wrong_format
@@ -27,7 +27,7 @@ def test_arf_new_wrong_format
msg = e.to_s
end
assert msg.include?('Could not create Result DataStream session: File is not Result DataStream.'),
- 'Message was: ' + msg
+ "Message was: #{msg}"
end
def test_create_arf_and_get_html
@@ -52,17 +52,17 @@ def test_new_memory
create_arf
raw_data = File.read(REPORT)
refute raw_data.empty?
- arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => REPORT
+ arf = OpenSCAP::DS::Arf.new content: raw_data, path: REPORT
arf.destroy
end
def test_new_bz_memory
bziped_file = new_arf_bz
- raw_data = File.open(bziped_file, 'rb').read
+ raw_data = File.binread(bziped_file)
assert !raw_data.empty?
len = File.size(bziped_file)
FileUtils.rm bziped_file
- arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => bziped_file, :length => len
+ arf = OpenSCAP::DS::Arf.new content: raw_data, path: bziped_file, length: len
arf.destroy
end
@@ -77,8 +77,8 @@ def test_new_bz_file
def new_arf_bz
create_arf
- system('/usr/bin/bzip2 ' + REPORT)
- REPORT + '.bz2'
+ system("/usr/bin/bzip2 #{REPORT}")
+ "#{REPORT}.bz2"
end
def new_arf
@@ -88,9 +88,9 @@ def new_arf
def create_arf
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
- @s.export_results(:rds_file => 'report.rds.xml')
+ @s.export_results(rds_file: 'report.rds.xml')
end
end
diff --git a/test/ds/sds_test.rb b/test/ds/sds_test.rb
index d7e2ff1..c541fd5 100644
--- a/test/ds/sds_test.rb
+++ b/test/ds/sds_test.rb
@@ -16,7 +16,7 @@ def test_new_non_sds
assert !@s.nil?
msg = nil
begin
- OpenSCAP::DS::Sds.new :source => @s
+ OpenSCAP::DS::Sds.new source: @s
assert false
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
@@ -48,7 +48,7 @@ def tests_select_checklist_wrong
sds = new_sds
msg = nil
begin
- benchmark = sds.select_checklist! :datastream_id => 'wrong'
+ benchmark = sds.select_checklist! datastream_id: 'wrong'
assert false
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
@@ -64,7 +64,7 @@ def new_sds
filename = '../data/sds-complex.xml'
@s = OpenSCAP::Source.new filename
assert !@s.nil?
- sds = OpenSCAP::DS::Sds.new :source => @s
+ sds = OpenSCAP::DS::Sds.new source: @s
assert !sds.nil?
sds
end
diff --git a/test/integration/arf_waiver_test.rb b/test/integration/arf_waiver_test.rb
index d8703ff..738bdc8 100644
--- a/test/integration/arf_waiver_test.rb
+++ b/test/integration/arf_waiver_test.rb
@@ -14,10 +14,10 @@ def test_waiver_and_score
assert_default_score tr.score, -1, 1
assert_default_score tr.score!(benchmark), -1, 1
- rr.override!(:new_result => :pass,
- :time => 'yesterday',
- :authority => 'John Hacker',
- :raw_text => 'This should have passed')
+ rr.override!(new_result: :pass,
+ time: 'yesterday',
+ authority: 'John Hacker',
+ raw_text: 'This should have passed')
assert rr.result == 'pass'
assert_default_score tr.score, -1, 1
@@ -85,7 +85,7 @@ def arf_init
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
@s.load
@s.evaluate
- @s.export_results(:rds_file => 'report.rds.xml')
+ @s.export_results(rds_file: 'report.rds.xml')
OpenSCAP::DS::Arf.new('report.rds.xml')
end
end
diff --git a/test/source_test.rb b/test/source_test.rb
index ad6a600..e6aa17a 100644
--- a/test/source_test.rb
+++ b/test/source_test.rb
@@ -13,7 +13,7 @@ def test_source_new_nil
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
end
- assert msg.start_with?('No filename specified!'), 'Message was: ' + msg
+ assert msg.start_with?('No filename specified!'), "Message was: #{msg}"
end
def test_source_new_ok
@@ -24,7 +24,7 @@ def test_source_new_ok
def test_source_new_memory
raw_data = File.read('../data/xccdf.xml')
refute raw_data.empty?
- s = OpenSCAP::Source.new(:content => raw_data, :path => '/mytestpath')
+ s = OpenSCAP::Source.new(content: raw_data, path: '/mytestpath')
s.destroy
end
@@ -59,11 +59,11 @@ def test_validate_invalid
msg = e.to_s
end
assert msg.start_with?('Invalid XCCDF Checklist (1.2) content in ../data/invalid.xml.'),
- 'Message was: ' + msg
+ "Message was: #{msg}"
assert msg.include?("../data/invalid.xml:3: Element '{http"),
- 'Message was: ' + msg
+ "Message was: #{msg}"
assert msg.include?('This element is not expected. Expected is'),
- 'Message was: ' + msg
+ "Message was: #{msg}"
s.destroy
end
diff --git a/test/xccdf/arf_test.rb b/test/xccdf/arf_test.rb
index 47a7244..c2e853b 100644
--- a/test/xccdf/arf_test.rb
+++ b/test/xccdf/arf_test.rb
@@ -38,7 +38,6 @@ def benchmark_from_arf_file
_test_results = arf.test_result
source_datastream = arf.report_request
bench_source = source_datastream.select_checklist!
- benchmark = OpenSCAP::Xccdf::Benchmark.new(bench_source)
- benchmark
+ OpenSCAP::Xccdf::Benchmark.new(bench_source)
end
end
diff --git a/test/xccdf/benchmark_test.rb b/test/xccdf/benchmark_test.rb
index f73d0d1..c4493c5 100644
--- a/test/xccdf/benchmark_test.rb
+++ b/test/xccdf/benchmark_test.rb
@@ -78,12 +78,12 @@ def test_items_severity
def test_items_references
b = benchmark_from_file
install_hids_rule = b.items['xccdf_org.ssgproject.content_rule_install_hids']
- expected_references = [{ :title => 'SC-7',
- :href => 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
- :html_link => "SC-7" },
- { :title => '1263',
- :href => 'http://iase.disa.mil/cci/index.html',
- :html_link => "1263" }]
+ expected_references = [{ title: 'SC-7',
+ href: 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
+ html_link: "SC-7" },
+ { title: '1263',
+ href: 'http://iase.disa.mil/cci/index.html',
+ html_link: "1263" }]
assert_equal(expected_references, install_hids_rule.references.map(&:to_hash), 'Install hids references should be equal')
b.destroy
end
@@ -93,10 +93,10 @@ def test_items_fixes
login_defs_rule = b.items['xccdf_org.ssgproject.content_rule_accounts_minimum_age_login_defs']
expected_content = ["var_accounts_minimum_age_login_defs=\"\"\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"]
expected_hashes = [{
- :id => nil,
- :platform => nil,
- :content => expected_content.first,
- :system => 'urn:xccdf:fix:script:sh'
+ id: nil,
+ platform: nil,
+ content: expected_content.first,
+ system: 'urn:xccdf:fix:script:sh'
}]
assert_equal(expected_content, login_defs_rule.fixes.map(&:content), 'Fix content should match')
assert_equal(expected_hashes, login_defs_rule.fixes.map(&:to_hash), 'Fix hash should match')
diff --git a/test/xccdf/session_ds_test.rb b/test/xccdf/session_ds_test.rb
index 37b1cca..45a4986 100644
--- a/test/xccdf/session_ds_test.rb
+++ b/test/xccdf/session_ds_test.rb
@@ -17,7 +17,7 @@ def test_session_load
def test_session_load_ds_comp
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:datastream_id => 'scap_org.open-scap_datastream_tst2', :component_id => 'scap_org.open-scap_cref_second-xccdf.xml2')
+ @s.load(datastream_id: 'scap_org.open-scap_datastream_tst2', component_id: 'scap_org.open-scap_cref_second-xccdf.xml2')
@s.evaluate
end
@@ -25,7 +25,7 @@ def test_session_load_bad_datastream
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
msg = nil
begin
- @s.load(:datastream_id => 'nonexistent')
+ @s.load(datastream_id: 'nonexistent')
assert false
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
@@ -37,7 +37,7 @@ def test_session_load_bad_component
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
msg = nil
begin
- @s.load(:component_id => 'nonexistent')
+ @s.load(component_id: 'nonexistent')
assert false
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
@@ -47,7 +47,7 @@ def test_session_load_bad_component
def test_session_set_profile
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
end
@@ -69,40 +69,40 @@ def test_session_export_rds
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
@s.load
@s.evaluate
- @s.export_results(:rds_file => 'report.rds.xml')
+ @s.export_results(rds_file: 'report.rds.xml')
assert_exported ['report.rds.xml']
end
def test_session_export_xccdf_results
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
- @s.export_results(:xccdf_file => 'result.xccdf.xml')
+ @s.export_results(xccdf_file: 'result.xccdf.xml')
assert_exported ['result.xccdf.xml']
end
def test_session_export_html_report
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
- @s.export_results(:report_file => 'report.html', :xccdf_file => 'result.xccdf.xml')
+ @s.export_results(report_file: 'report.html', xccdf_file: 'result.xccdf.xml')
assert_exported ['report.html', 'result.xccdf.xml']
end
def test_session_export_oval_variables
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
- @s.export_results(:oval_variables => true)
+ @s.export_results(oval_variables: true)
assert_exported []
end
def test_remediate
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
- @s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
+ @s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
@s.evaluate
@s.remediate
@@ -111,6 +111,6 @@ def test_remediate
def assert_exported(files)
# libopenscap compiled with --enable-debug creates debug files
FileUtils.rm_rf(Dir.glob('oscap_debug.log.*'))
- assert files.sort == Dir.glob('*').sort
+ assert files.sort == Dir.glob('*')
end
end
diff --git a/test/xccdf/session_test.rb b/test/xccdf/session_test.rb
index 64115e3..b341a9f 100644
--- a/test/xccdf/session_test.rb
+++ b/test/xccdf/session_test.rb
@@ -12,7 +12,7 @@ def test_session_new_bad
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
end
- assert msg.start_with?("Unable to open file: ''"), 'Message was: ' + msg
+ assert msg.start_with?("Unable to open file: ''"), "Message was: #{msg}"
end
def test_session_new_nil
@@ -23,7 +23,7 @@ def test_session_new_nil
rescue OpenSCAP::OpenSCAPError => e
msg = e.to_s
end
- assert msg.start_with?('No filename specified!'), 'Message was: ' + msg
+ assert msg.start_with?('No filename specified!'), "Message was: #{msg}"
end
def test_sds_false
diff --git a/test/xccdf/testresult_test.rb b/test/xccdf/testresult_test.rb
index babfd29..af702bb 100644
--- a/test/xccdf/testresult_test.rb
+++ b/test/xccdf/testresult_test.rb
@@ -18,7 +18,7 @@ def test_testresult_new_bad
msg = e.to_s
end
assert msg.start_with?("Expected 'TestResult' element while found 'Benchmark'."),
- 'Message was: ' + msg
+ "Message was: #{msg}"
end
def test_result_create_and_query_properties
@@ -44,10 +44,10 @@ def test_override
tr = new_tr
rr = tr.rr['xccdf_org.ssgproject.content_rule_disable_prelink']
assert rr.result == 'fail'
- rr.override!(:new_result => :pass,
- :time => 'yesterday',
- :authority => 'John Hacker',
- :raw_text => 'We are testing prelink on this machine')
+ rr.override!(new_result: :pass,
+ time: 'yesterday',
+ authority: 'John Hacker',
+ raw_text: 'We are testing prelink on this machine')
assert rr.result == 'pass'
tr.destroy
end
@@ -67,10 +67,10 @@ def test_waive_and_score
rr = tr.rr['xccdf_org.ssgproject.content_rule_disable_prelink']
assert rr.result == 'fail'
- rr.override!(:new_result => :pass,
- :time => 'yesterday',
- :authority => 'John Hacker',
- :raw_text => 'We are testing prelink on this machine')
+ rr.override!(new_result: :pass,
+ time: 'yesterday',
+ authority: 'John Hacker',
+ raw_text: 'We are testing prelink on this machine')
assert rr.result == 'pass'
assert_default_score tr.score, 34, 35