Skip to content

Commit

Permalink
modernize hash and array style
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed May 24, 2023
1 parent 05dd408 commit 28a7412
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 97 deletions.
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ Metrics/MethodLength:
Exclude:
- 'test/**/*'

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/SymbolArray:
EnforcedStyle: brackets

Naming/MethodParameterName:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'bundler'

Bundler::GemHelper.install_tasks :name => 'openscap'
Bundler::GemHelper.install_tasks name: 'openscap'

task :test do
$LOAD_PATH.unshift('lib')
Expand Down
6 changes: 3 additions & 3 deletions lib/openscap/ds/arf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/openscap/ds/sds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lib/openscap/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions lib/openscap/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lib/openscap/xccdf/fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/openscap/xccdf/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def html_link

def to_hash
{
:title => title,
:href => href,
:html_link => html_link
title:,
href:,
html_link:
}
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/openscap/xccdf/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions lib/openscap/xccdf/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/openscap/xccdf/tailoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/openscap/xccdf/testresult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,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)
Expand All @@ -87,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
Expand Down
8 changes: 4 additions & 4 deletions test/ds/arf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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

Expand All @@ -62,7 +62,7 @@ def test_new_bz_memory
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

Expand All @@ -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
6 changes: 3 additions & 3 deletions test/ds/sds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/integration/arf_waiver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions test/xccdf/benchmark_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "<a href='http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf'>SC-7</a>" },
{ :title => '1263',
:href => 'http://iase.disa.mil/cci/index.html',
:html_link => "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
expected_references = [{ title: 'SC-7',
href: 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
html_link: "<a href='http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf'>SC-7</a>" },
{ title: '1263',
href: 'http://iase.disa.mil/cci/index.html',
html_link: "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
assert_equal(expected_references, install_hids_rule.references.map(&:to_hash), 'Install hids references should be equal')
b.destroy
end
Expand All @@ -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=\"<sub xmlns=\"http://checklists.nist.gov/xccdf/1.2\" idref=\"xccdf_org.ssgproject.content_value_var_accounts_minimum_age_login_defs\" use=\"legacy\"/>\"\ngrep -q ^PASS_MIN_DAYS /etc/login.defs &amp;&amp; \\\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\" &gt;&gt; /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')
Expand Down
Loading

0 comments on commit 28a7412

Please sign in to comment.