ssh_config parse should be case insensitive

This commit is contained in:
Victoria Jeffrey 2016-08-15 16:03:44 -04:00 committed by Christoph Hartmann
parent b86c1bd4c5
commit cf771ab967
3 changed files with 17 additions and 2 deletions

View file

@ -32,8 +32,16 @@ module Inspec::Resources
end
end
def convert_hash(hash)
new_hash = {}
hash.each do |k,v|
new_hash[k.downcase] = v
end
new_hash
end
def method_missing(name)
param = read_params[name.to_s]
param = read_params[name.to_s.downcase]
return nil if param.nil?
# extract first value if we have only one value in array
return param[0] if param.length == 1
@ -69,7 +77,7 @@ module Inspec::Resources
assignment_re: /^\s*(\S+?)\s+(.*?)\s*$/,
multiple_values: true,
)
@params = conf.params
@params = convert_hash(conf.params)
end
end

View file

@ -3,3 +3,4 @@ Host *
# Tunnel no
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication no

View file

@ -14,6 +14,12 @@ describe 'Inspec::Resources::SshConf' do
_(resource.Tunnel).must_equal nil
_(resource.SendEnv).must_equal 'LANG LC_*'
_(resource.HashKnownHosts).must_equal 'yes'
puts resource
end
it 'is case insensitive' do
resource = load_resource('ssh_config')
_(resource.gssapiauthentication).must_equal 'no'
end
end