mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
derive xinetd protocol from socket_type when not defined in the config file
Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
parent
a060e65b23
commit
495185b581
2 changed files with 29 additions and 2 deletions
|
@ -92,8 +92,23 @@ module Inspec::Resources
|
|||
params
|
||||
end
|
||||
|
||||
# Method used to derive the default protocol used from the socket_type
|
||||
def default_protocol(type)
|
||||
case type
|
||||
when 'stream'
|
||||
'tcp'
|
||||
when 'dgram'
|
||||
'udp'
|
||||
else
|
||||
'unknown'
|
||||
end
|
||||
end
|
||||
|
||||
def service_lines
|
||||
@services ||= params['services'].values.flatten.map(&:params)
|
||||
@services ||= params['services'].values.flatten.map { |service|
|
||||
service.params['protocol'] ||= default_protocol(service.params['socket_type'])
|
||||
service.params
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,12 +34,24 @@ describe 'Inspec::Resources::XinetdConf' do
|
|||
_(one.ids).must_equal %w{chargen-dgram}
|
||||
end
|
||||
|
||||
it 'get all protocols' do
|
||||
it 'get all protocols for echo' do
|
||||
one = resource.services('echo')
|
||||
_(one.protocols).must_equal %w{tcp udp}
|
||||
_(one.ids).must_equal %w{echo-stream echo-dgram}
|
||||
end
|
||||
|
||||
it 'get all protocols for chargen, including derived from socket_type' do
|
||||
one = resource.services('chargen')
|
||||
_(one.protocols).must_equal %w{tcp udp}
|
||||
_(one.ids).must_equal %w{chargen-stream chargen-dgram}
|
||||
end
|
||||
|
||||
it 'params has only the protocols parsed from the config files' do
|
||||
one = resource.params['services']['chargen'].map{|x| x.params['protocol']}
|
||||
# in this example(CentOS), protocol is not defined in the config
|
||||
_(one).must_equal [nil, nil]
|
||||
end
|
||||
|
||||
it 'can filter by protocols' do
|
||||
one = resource.services('echo')
|
||||
_(one.protocols(/tcp.*/).ids).must_equal %w{echo-stream}
|
||||
|
|
Loading…
Reference in a new issue