2015-09-05 17:05:07 +02:00
|
|
|
# encoding: utf-8
|
2015-10-06 18:55:44 +02:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-05 17:05:07 +02:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 04:04:18 +01:00
|
|
|
require 'inspec/resource'
|
2015-09-05 17:05:07 +02:00
|
|
|
|
2015-10-26 04:04:18 +01:00
|
|
|
describe 'Inspec::Resources::SshConf' do
|
2015-09-05 17:05:07 +02:00
|
|
|
|
|
|
|
describe 'ssh_config' do
|
|
|
|
it 'check ssh config parsing' do
|
2015-10-12 13:21:50 +02:00
|
|
|
resource = load_resource('ssh_config')
|
2015-09-05 17:05:07 +02:00
|
|
|
_(resource.Host).must_equal '*'
|
2017-06-11 06:16:10 -04:00
|
|
|
_(resource.Tunnel).must_be_nil
|
2015-09-05 17:05:07 +02:00
|
|
|
_(resource.SendEnv).must_equal 'LANG LC_*'
|
|
|
|
_(resource.HashKnownHosts).must_equal 'yes'
|
2016-08-15 16:03:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is case insensitive' do
|
|
|
|
resource = load_resource('ssh_config')
|
|
|
|
_(resource.gssapiauthentication).must_equal 'no'
|
2016-08-15 17:39:28 -04:00
|
|
|
_(resource.GSSAPIAuthentication).must_equal 'no'
|
2015-09-05 17:05:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'sshd_config' do
|
|
|
|
it 'check protocol version' do
|
2015-10-12 13:21:50 +02:00
|
|
|
resource = load_resource('sshd_config')
|
2015-09-05 17:05:07 +02:00
|
|
|
_(resource.Port).must_equal '22'
|
|
|
|
_(resource.UsePAM).must_equal 'yes'
|
2017-06-11 06:16:10 -04:00
|
|
|
_(resource.ListenAddress).must_be_nil
|
2015-09-05 17:05:07 +02:00
|
|
|
_(resource.HostKey).must_equal [
|
|
|
|
'/etc/ssh/ssh_host_rsa_key',
|
|
|
|
'/etc/ssh/ssh_host_dsa_key',
|
2015-10-12 13:21:50 +02:00
|
|
|
'/etc/ssh/ssh_host_ecdsa_key',
|
2015-09-05 17:05:07 +02:00
|
|
|
]
|
|
|
|
end
|
2017-10-06 09:41:48 -04:00
|
|
|
|
|
|
|
it 'check bad path' do
|
|
|
|
resource = load_resource('sshd_config', '/etc/ssh/sshd_config_does_not_exist')
|
|
|
|
_(resource.send(:read_content)).must_equal "Can't find file \"/etc/ssh/sshd_config_does_not_exist\""
|
|
|
|
_(resource.Protocol).must_be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'check cannot read' do
|
|
|
|
Inspec::Resources::FileResource.any_instance.stubs(:size).at_least_once.returns(5)
|
|
|
|
resource = load_resource('sshd_config', '/etc/ssh/sshd_config_empty')
|
|
|
|
_(resource.send(:read_content)).must_equal "Can't read file \"/etc/ssh/sshd_config_empty\""
|
|
|
|
_(resource.Protocol).must_be_nil
|
|
|
|
end
|
2015-09-05 17:05:07 +02:00
|
|
|
end
|
|
|
|
end
|