diff options
author | duritong <peter.meier+github@immerda.ch> | 2014-02-01 06:52:23 -0800 |
---|---|---|
committer | duritong <peter.meier+github@immerda.ch> | 2014-02-01 06:52:23 -0800 |
commit | dfc6d99c931ae9cba373903b4f9da94ca7db41c1 (patch) | |
tree | f83dcf203e6d3132a29b7c56974eeb1139112e18 | |
parent | aee6885940cad29ff4ab7437e89c394bc1c19a46 (diff) | |
parent | bf425e96b1acc9c17b51600aeecd34a1d91b62e7 (diff) | |
download | puppet-sshd-dfc6d99c931ae9cba373903b4f9da94ca7db41c1.tar.gz puppet-sshd-dfc6d99c931ae9cba373903b4f9da94ca7db41c1.tar.bz2 |
Merge pull request #7 from deric/more-tests
More tests
-rw-r--r-- | .fixtures.yml | 3 | ||||
-rw-r--r-- | Modulefile | 2 | ||||
-rw-r--r-- | Puppetfile | 2 | ||||
-rw-r--r-- | Puppetfile.lock | 6 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | Rakefile | 10 | ||||
-rw-r--r-- | manifests/base.pp | 1 | ||||
-rw-r--r-- | manifests/client/base.pp | 7 | ||||
-rw-r--r-- | manifests/debian.pp | 12 | ||||
-rw-r--r-- | manifests/init.pp | 4 | ||||
-rw-r--r-- | spec/classes/client_spec.rb | 42 | ||||
-rw-r--r-- | spec/classes/init_spec.rb | 122 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper_system.rb | 1 |
14 files changed, 191 insertions, 26 deletions
diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..42598a6 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,3 @@ +fixtures: + symlinks: + sshd: "#{source_dir}"
\ No newline at end of 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'
\ No newline at end of file +dependency 'puppetlabs/stdlib', '>= 2.0.0'
\ No newline at end of file @@ -1,3 +1,3 @@ forge 'http://forge.puppetlabs.com' -#mod 'puppetlabs/stdlib', '>=0.1.6'
\ No newline at end of file +mod 'puppetlabs/stdlib', '>=2.0.0'
\ No newline at end of file diff --git a/Puppetfile.lock b/Puppetfile.lock index 51949ef..f938185 100644 --- a/Puppetfile.lock +++ b/Puppetfile.lock @@ -1,2 +1,8 @@ +FORGE + remote: http://forge.puppetlabs.com + specs: + puppetlabs/stdlib (4.1.0) + DEPENDENCIES + puppetlabs/stdlib (>= 2.0.0) @@ -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 @@ -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]
\ No newline at end of file +task :default => [:spec, :lint] diff --git a/manifests/base.pp b/manifests/base.pp index ef066e0..a0f1872 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -6,6 +6,7 @@ class sshd::base { } file { 'sshd_config': + ensure => present, path => '/etc/ssh/sshd_config', content => $sshd_config_content, notify => Service[sshd], diff --git a/manifests/client/base.pp b/manifests/client/base.pp index 6687d65..4925c2d 100644 --- a/manifests/client/base.pp +++ b/manifests/client/base.pp @@ -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 diff --git a/manifests/debian.pp b/manifests/debian.pp index ced5db7..d827078 100644 --- a/manifests/debian.pp +++ b/manifests/debian.pp @@ -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, } } diff --git a/manifests/init.pp b/manifests/init.pp index 307fc8a..fb76438 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb new file mode 100644 index 0000000..bd3e35a --- /dev/null +++ b/spec/classes/client_spec.rb @@ -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
\ No newline at end of file diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..e3003d1 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -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
\ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d83617..b4123fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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' diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index 44e0337..2c6812f 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -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 |