Skip to content

Commit

Permalink
adjust chrony conf for arrays and strings from input and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
DMedina6 committed Oct 24, 2024
1 parent b9d3235 commit 48535dd
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions controls/SV-230484.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@
only_if('This control is Not Applicable to containers', impact: 0.0) {
!virtualization.system.eql?('docker')
}


# Get input, convert to array if string
authoritative_timeserver = input('authoritative_timeserver')
authoritative_timeserver = [authoritative_timeserver] if authoritative_timeserver.is_a? String

# No need to provide filepath
time_sources = chrony_conf.server

# Cover case when a single server is defined and resource returns a string and not an array
time_sources = [time_sources] if time_sources.is_a? String

# Get and map maxpoll values to an array
unless time_sources.nil?
max_poll_values = time_sources.map { |val|
val.match?(/.*maxpoll.*/) ? val.gsub(/.*maxpoll\s+(\d+)(\s+.*|$)/, '\1').to_i : 10
Expand All @@ -89,28 +96,17 @@
its('server') { should_not be_nil }
end

unless chrony_conf.server.nil?
# If there is only one server and the resource returns a string, check if the server matches the input
if chrony_conf.server.is_a? String
describe chrony_conf do
its('server') { should match input('authoritative_timeserver') }
end
end
unless time_sources.nil?
# Check if each server in the server array exists in the input
if chrony_conf.server.is_a? Array
chrony_conf.server.each do |server|
describe server do
it { should match input('authoritative_timeserver') }
end
time_sources.each do |server|
describe server do
it { should be_in authoritative_timeserver }
end
end

# All time sources must contain valid maxpoll entries
unless time_sources.nil?
describe 'chronyd maxpoll values (99=maxpoll absent)' do
subject { max_poll_values }
it { should all be < 17 }
end
describe 'chronyd maxpoll values (99=maxpoll absent)' do
subject { max_poll_values }
it { should all be < 17 }
end
end
end

0 comments on commit 48535dd

Please sign in to comment.