Merge pull request #7 from deric/more-tests

More tests
This commit is contained in:
duritong 2014-02-01 06:52:23 -08:00
commit dfc6d99c93
14 changed files with 192 additions and 27 deletions

3
.fixtures.yml Normal file
View file

@ -0,0 +1,3 @@
fixtures:
symlinks:
sshd: "#{source_dir}"

View file

@ -7,4 +7,4 @@ summary 'ssh daemon configuration'
description 'Manages sshd_config'
project_page 'https://github.com/duritong/puppet-sshd'
#dependency 'puppetlabs/stdlib', '>= 0.1.6'
dependency 'puppetlabs/stdlib', '>= 2.0.0'

View file

@ -1,3 +1,3 @@
forge 'http://forge.puppetlabs.com'
#mod 'puppetlabs/stdlib', '>=0.1.6'
mod 'puppetlabs/stdlib', '>=2.0.0'

View file

@ -1,2 +1,8 @@
DEPENDENCIES
FORGE
remote: http://forge.puppetlabs.com
specs:
puppetlabs/stdlib (4.1.0)
DEPENDENCIES
puppetlabs/stdlib (>= 2.0.0)

View file

@ -16,8 +16,7 @@ class declarations in your manifest !
This module requires puppet => 2.6, and the following modules are required
pre-dependencies:
- shared-common: `git://labs.riseup.net/shared-common`
- shared-lsb: `git://labs.riseup.net/shared-lsb`
- [puppetlabs/stdlib](https://github.com/puppetlabs/puppetlabs-stdlib) >= 2.x
## OpenSSH Server

View file

@ -8,15 +8,9 @@ require 'rspec-system/rake_task'
PuppetLint.configuration.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}'
PuppetLint.configuration.send("disable_80chars")
# use librarian-puppet to manage fixtures instead of .fixtures.yml
# offers more possibilities like explicit version management, forge downloads,...
puppet_module='sshd'
task :librarian_spec_prep do
sh "librarian-puppet install --path=spec/fixtures/modules/"
pwd = `pwd`.strip
unless File.directory?("#{pwd}/spec/fixtures/modules/#{puppet_module}")
sh "ln -s #{pwd} #{pwd}/spec/fixtures/modules/#{puppet_module}"
end
sh 'librarian-puppet install --path=spec/fixtures/modules/'
end
task :spec_prep => :librarian_spec_prep
task :default => [:spec, :lint]
task :default => [:spec, :lint]

View file

@ -6,6 +6,7 @@ class sshd::base {
}
file { 'sshd_config':
ensure => present,
path => '/etc/ssh/sshd_config',
content => $sshd_config_content,
notify => Service[sshd],

View file

@ -1,9 +1,10 @@
class sshd::client::base {
# this is needed because the gid might have changed
file { '/etc/ssh/ssh_known_hosts':
mode => '0644',
owner => root,
group => 0;
ensure => present,
mode => '0644',
owner => root,
group => 0;
}
# Now collect all server keys

View file

@ -1,21 +1,13 @@
class sshd::debian inherits sshd::linux {
# the templates for Debian need lsbdistcodename
require lsb
Package[openssh]{
name => 'openssh-server',
}
$sshd_restartandstatus = $::lsbdistcodename ? {
etch => false,
default => true
}
Service[sshd]{
name => 'ssh',
pattern => 'sshd',
hasstatus => $sshd_restartandstatus,
hasrestart => $sshd_restartandstatus,
hasstatus => true,
hasrestart => true,
}
}

View file

@ -36,6 +36,10 @@ class sshd(
$shorewall_source = 'net'
) {
validate_bool($manage_shorewall)
validate_array($listen_address)
validate_array($ports)
class{'sshd::client':
shared_ip => $sshd::shared_ip,
ensure_version => $sshd::ensure_version,

View file

@ -0,0 +1,42 @@
require 'spec_helper'
describe 'sshd::client' do
shared_examples "a Linux OS" do
it { should contain_file('/etc/ssh/ssh_known_hosts').with(
{
'ensure' => 'present',
'owner' => 'root',
'group' => '0',
'mode' => '0644',
}
)}
end
context "Debian OS" do
let :facts do
{
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
}
end
it_behaves_like "a Linux OS"
it { should contain_package('openssh-clients').with({
'name' => 'openssh-client'
}) }
end
context "CentOS" do
it_behaves_like "a Linux OS" do
let :facts do
{
:operatingsystem => 'CentOS',
:osfamily => 'RedHat',
:lsbdistcodename => 'Final',
}
end
end
end
end

122
spec/classes/init_spec.rb Normal file
View file

@ -0,0 +1,122 @@
require 'spec_helper'
describe 'sshd' do
shared_examples "a Linux OS" do
it { should compile.with_all_deps }
it { should contain_class('sshd') }
it { should contain_class('sshd::client') }
it { should contain_service('sshd').with({
:ensure => 'running',
:enable => true,
:hasstatus => true
})}
it { should contain_file('sshd_config').with(
{
'ensure' => 'present',
'owner' => 'root',
'group' => '0',
'mode' => '0600',
}
)}
context 'change ssh port' do
let(:params){{
:ports => [ 22222],
}}
it { should contain_file(
'sshd_config'
).with_content(/Port 22222/)}
end
end
context "Debian OS" do
let :facts do
{
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
}
end
it_behaves_like "a Linux OS"
it { should contain_package('openssh') }
it { should contain_class('sshd::debian') }
it { should contain_service('sshd').with(
:hasrestart => true
)}
context "Ubuntu" do
let :facts do
{
:operatingsystem => 'Ubuntu',
:lsbdistcodename => 'precise',
}
end
it_behaves_like "a Linux OS"
it { should contain_package('openssh') }
it { should contain_service('sshd').with({
:hasrestart => true
})}
end
end
# context "RedHat OS" do
# it_behaves_like "a Linux OS" do
# let :facts do
# {
# :operatingsystem => 'RedHat',
# :osfamily => 'RedHat',
# }
# end
# end
# end
context "CentOS" do
it_behaves_like "a Linux OS" do
let :facts do
{
:operatingsystem => 'CentOS',
:osfamily => 'RedHat',
:lsbdistcodename => 'Final',
}
end
end
end
context "Gentoo" do
let :facts do
{
:operatingsystem => 'Gentoo',
:osfamily => 'Gentoo',
}
end
it_behaves_like "a Linux OS"
it { should contain_class('sshd::gentoo') }
end
context "OpenBSD" do
let :facts do
{
:operatingsystem => 'OpenBSD',
:osfamily => 'OpenBSD',
}
end
it_behaves_like "a Linux OS"
it { should contain_class('sshd::openbsd') }
end
# context "FreeBSD" do
# it_behaves_like "a Linux OS" do
# let :facts do
# {
# :operatingsystem => 'FreeBSD',
# :osfamily => 'FreeBSD',
# }
# end
# end
# end
end

View file

@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.join(dir, 'lib')
require 'puppet'
require 'rspec'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-hiera-puppet'
#require 'rspec-hiera-puppet'
require 'rspec-puppet/coverage'
require 'rspec/autorun'

View file

@ -20,5 +20,6 @@ RSpec.configure do |c|
puppet_install
# Install modules and dependencies
puppet_module_install(:source => proj_root, :module_name => 'sshd')
shell('puppet module install puppetlabs-stdlib')
end
end