Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Chrony_Conf Control #31

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
31 changes: 13 additions & 18 deletions controls/SV-230484.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@
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 +95,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
Loading