From 2a0b58d6a8c2934ac2cd96364d6a3a6caee81a04 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sat, 25 Jan 2014 19:08:04 +0100 Subject: testing infastructure, rspec tests --- spec/functions/ssh_keygen_spec.rb | 116 +++++++++++++++++++++++++++++++ spec/spec.opts | 6 -- spec/spec_helper.rb | 29 ++++---- spec/spec_helper_system.rb | 24 +++++++ spec/unit/parser/functions/ssh_keygen.rb | 104 --------------------------- 5 files changed, 157 insertions(+), 122 deletions(-) create mode 100644 spec/functions/ssh_keygen_spec.rb delete mode 100644 spec/spec.opts create mode 100644 spec/spec_helper_system.rb delete mode 100644 spec/unit/parser/functions/ssh_keygen.rb (limited to 'spec') diff --git a/spec/functions/ssh_keygen_spec.rb b/spec/functions/ssh_keygen_spec.rb new file mode 100644 index 0000000..0d2100d --- /dev/null +++ b/spec/functions/ssh_keygen_spec.rb @@ -0,0 +1,116 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' +require 'rspec-puppet' +require 'mocha' +require 'fileutils' + +describe 'ssh_keygen' do + + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it 'should exist' do + Puppet::Parser::Functions.function("ssh_keygen").should == "function_ssh_keygen" + end + + it 'should raise a ParseError if no argument is passed' do + lambda { + scope.function_ssh_keygen([]) + }.should(raise_error(Puppet::ParseError)) + end + + it 'should raise a ParseError if there is more than 1 arguments' do + lambda { + scope.function_ssh_keygen(["foo", "bar"]) + }.should( raise_error(Puppet::ParseError)) + end + + it 'should raise a ParseError if the argument is not fully qualified' do + lambda { + scope.function_ssh_keygen(["foo"]) + }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the private key path is a directory" do + File.stubs(:directory?).with("/some_dir").returns(true) + lambda { + scope.function_ssh_keygen(["/some_dir"]) + }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the public key path is a directory" do + File.stubs(:directory?).with("/some_dir.pub").returns(true) + lambda { + scope.function_ssh_keygen(["/some_dir.pub"]) + }.should( raise_error(Puppet::ParseError)) + end + + describe 'when executing properly' do + before do + File.stubs(:directory?).with('/tmp/a/b/c').returns(false) + File.stubs(:directory?).with('/tmp/a/b/c.pub').returns(false) + File.stubs(:read).with('/tmp/a/b/c').returns('privatekey') + File.stubs(:read).with('/tmp/a/b/c.pub').returns('publickey') + end + + it 'should fail if the public but not the private key exists' do + File.stubs(:exists?).with('/tmp/a/b/c').returns(true) + File.stubs(:exists?).with('/tmp/a/b/c.pub').returns(false) + lambda { + scope.function_ssh_keygen(['/tmp/a/b/c']) + }.should( raise_error(Puppet::ParseError)) + end + + it "should fail if the private but not the public key exists" do + File.stubs(:exists?).with("/tmp/a/b/c").returns(false) + File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(true) + lambda { + scope.function_ssh_keygen(["/tmp/a/b/c"]) + }.should( raise_error(Puppet::ParseError)) + end + + + it "should return an array of size 2 with the right conent if the keyfiles exists" do + File.stubs(:exists?).with("/tmp/a/b/c").returns(true) + File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(true) + File.stubs(:directory?).with('/tmp/a/b').returns(true) + Puppet::Util.expects(:execute).never + result = scope.function_ssh_keygen(['/tmp/a/b/c']) + result.length.should == 2 + result[0].should == 'privatekey' + result[1].should == 'publickey' + end + + xit "should create the directory path if it does not exist" do + File.stubs(:exists?).with("/tmp/a/b/c").returns(false) + File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) + File.stubs(:directory?).with("/tmp/a/b").returns(false) + FileUtils.expects(:mkdir_p).with("/tmp/a/b", :mode => 0700) + Puppet::Util.expects(:execute).returns("") + result = scope.function_ssh_keygen(['/tmp/a/b/c']) + result.length.should == 2 + result[0].should == 'privatekey' + result[1].should == 'publickey' + end + + xit "should generate the key if the keyfiles do not exist" do + File.stubs(:exists?).with("/tmp/a/b/c").returns(false) + File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) + File.stubs(:directory?).with("/tmp/a/b").returns(true) + Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("") + result = scope.function_ssh_keygen(['/tmp/a/b/c']) + result.length.should == 2 + result[0].should == 'privatekey' + result[1].should == 'publickey' + end + + xit "should fail if something goes wrong during generation" do + File.stubs(:exists?).with("/tmp/a/b/c").returns(false) + File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) + File.stubs(:directory?).with("/tmp/a/b").returns(true) + Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("something is wrong") + lambda { + scope.function_ssh_keygen(["/tmp/a/b/c"]) + }.should( raise_error(Puppet::ParseError)) + end + end +end diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index 91cd642..0000000 --- a/spec/spec.opts +++ /dev/null @@ -1,6 +0,0 @@ ---format -s ---colour ---loadby -mtime ---backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ba62e1..2d83617 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,21 @@ -require 'pathname' -dir = Pathname.new(__FILE__).parent -$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') +dir = File.expand_path(File.dirname(__FILE__)) +$LOAD_PATH.unshift File.join(dir, 'lib') require 'puppet' -gem 'rspec', '>= 1.2.9' -require 'spec/autorun' +require 'rspec' +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-hiera-puppet' +require 'rspec-puppet/coverage' +require 'rspec/autorun' -Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file| - require support_file -end +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + c.pattern = "spec/*/*_spec.rb" end + +Puppet::Util::Log.level = :warning +Puppet::Util::Log.newdestination(:console) + +at_exit { RSpec::Puppet::Coverage.report! } \ No newline at end of file diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 0000000..44e0337 --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,24 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'sshd') + end +end diff --git a/spec/unit/parser/functions/ssh_keygen.rb b/spec/unit/parser/functions/ssh_keygen.rb deleted file mode 100644 index da45779..0000000 --- a/spec/unit/parser/functions/ssh_keygen.rb +++ /dev/null @@ -1,104 +0,0 @@ -#! /usr/bin/env ruby - - -require File.dirname(__FILE__) + '/../../../spec_helper' - -require 'mocha' -require 'fileutils' - -describe "the ssh_keygen function" do - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("ssh_keygen").should == "function_ssh_keygen" - end - - it "should raise a ParseError if no argument is passed" do - lambda { @scope.function_ssh_keygen }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there is more than 1 arguments" do - lambda { @scope.function_ssh_keygen("foo", "bar") }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the argument is not fully qualified" do - lambda { @scope.function_ssh_keygen("foo") }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the private key path is a directory" do - File.stubs(:directory?).with("/some_dir").returns(true) - lambda { @scope.function_ssh_keygen("/some_dir") }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the public key path is a directory" do - File.stubs(:directory?).with("/some_dir.pub").returns(true) - lambda { @scope.function_ssh_keygen("/some_dir") }.should( raise_error(Puppet::ParseError)) - end - - describe "when executing properly" do - before do - File.stubs(:directory?).with('/tmp/a/b/c').returns(false) - File.stubs(:directory?).with('/tmp/a/b/c.pub').returns(false) - File.stubs(:read).with('/tmp/a/b/c').returns('privatekey') - File.stubs(:read).with('/tmp/a/b/c.pub').returns('publickey') - end - - it "should fail if the public but not the private key exists" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(true) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) - lambda { @scope.function_ssh_keygen("/tmp/a/b/c") }.should( raise_error(Puppet::ParseError)) - end - - it "should fail if the private but not the public key exists" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(false) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(true) - lambda { @scope.function_ssh_keygen("/tmp/a/b/c") }.should( raise_error(Puppet::ParseError)) - end - - - it "should return an array of size 2 with the right conent if the keyfiles exists" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(true) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(true) - File.stubs(:directory?).with('/tmp/a/b').returns(true) - Puppet::Util.expects(:execute).never - result = @scope.function_ssh_keygen('/tmp/a/b/c') - result.length.should == 2 - result[0].should == 'privatekey' - result[1].should == 'publickey' - end - - it "should create the directory path if it does not exist" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(false) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) - File.stubs(:directory?).with("/tmp/a/b").returns(false) - FileUtils.expects(:mkdir_p).with("/tmp/a/b", :mode => 0700) - Puppet::Util.expects(:execute).returns("") - result = @scope.function_ssh_keygen('/tmp/a/b/c') - result.length.should == 2 - result[0].should == 'privatekey' - result[1].should == 'publickey' - end - - it "should generate the key if the keyfiles do not exist" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(false) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) - File.stubs(:directory?).with("/tmp/a/b").returns(true) - Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("") - result = @scope.function_ssh_keygen('/tmp/a/b/c') - result.length.should == 2 - result[0].should == 'privatekey' - result[1].should == 'publickey' - end - - it "should fail if something goes wrong during generation" do - File.stubs(:exists?).with("/tmp/a/b/c").returns(false) - File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) - File.stubs(:directory?).with("/tmp/a/b").returns(true) - Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("something is wrong") - lambda { @scope.function_ssh_keygen("/tmp/a/b/c") }.should( raise_error(Puppet::ParseError)) - end - end -end -- cgit v1.2.3 From a9f0dad383bb1c9f8e1dfc2e766e0871b6c35be4 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 26 Jan 2014 15:25:48 +0100 Subject: fix broken tests These tests were broken before, because they didn't mock the right method. --- spec/functions/ssh_keygen_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/functions/ssh_keygen_spec.rb b/spec/functions/ssh_keygen_spec.rb index 0d2100d..a6b5117 100644 --- a/spec/functions/ssh_keygen_spec.rb +++ b/spec/functions/ssh_keygen_spec.rb @@ -80,34 +80,34 @@ describe 'ssh_keygen' do result[1].should == 'publickey' end - xit "should create the directory path if it does not exist" do + it "should create the directory path if it does not exist" do File.stubs(:exists?).with("/tmp/a/b/c").returns(false) File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) File.stubs(:directory?).with("/tmp/a/b").returns(false) FileUtils.expects(:mkdir_p).with("/tmp/a/b", :mode => 0700) - Puppet::Util.expects(:execute).returns("") + Puppet::Util::Execution.expects(:execute).returns("") result = scope.function_ssh_keygen(['/tmp/a/b/c']) result.length.should == 2 result[0].should == 'privatekey' result[1].should == 'publickey' end - xit "should generate the key if the keyfiles do not exist" do + it "should generate the key if the keyfiles do not exist" do File.stubs(:exists?).with("/tmp/a/b/c").returns(false) File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) File.stubs(:directory?).with("/tmp/a/b").returns(true) - Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("") + Puppet::Util::Execution.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("") result = scope.function_ssh_keygen(['/tmp/a/b/c']) result.length.should == 2 result[0].should == 'privatekey' result[1].should == 'publickey' end - xit "should fail if something goes wrong during generation" do + it "should fail if something goes wrong during generation" do File.stubs(:exists?).with("/tmp/a/b/c").returns(false) File.stubs(:exists?).with("/tmp/a/b/c.pub").returns(false) File.stubs(:directory?).with("/tmp/a/b").returns(true) - Puppet::Util.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("something is wrong") + Puppet::Util::Execution.expects(:execute).with(['/usr/bin/ssh-keygen','-t', 'rsa', '-b', '4096', '-f', '/tmp/a/b/c', '-P', '', '-q']).returns("something is wrong") lambda { scope.function_ssh_keygen(["/tmp/a/b/c"]) }.should( raise_error(Puppet::ParseError)) -- cgit v1.2.3 From 78f1ff00d09d0ebf8f132e70444b9bcf030b6711 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 26 Jan 2014 09:36:35 +0100 Subject: replaces shared-lsb by puppetlabs/stdlib --- Modulefile | 2 +- Puppetfile | 2 +- Puppetfile.lock | 6 ++++++ README.md | 2 +- manifests/debian.pp | 4 +++- spec/classes/init_spec.rb | 24 ++++++++++++++++++++++++ spec/spec_helper.rb | 2 +- spec/spec_helper_system.rb | 1 + 8 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 spec/classes/init_spec.rb (limited to 'spec') diff --git a/Modulefile b/Modulefile index 5954df4..5e4f92d 100644 --- a/Modulefile +++ b/Modulefile @@ -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 diff --git a/Puppetfile b/Puppetfile index 113b12f..166d3b4 100644 --- a/Puppetfile +++ b/Puppetfile @@ -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) diff --git a/README.md b/README.md index bc85552..cafdf11 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 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 diff --git a/manifests/debian.pp b/manifests/debian.pp index ced5db7..baacbba 100644 --- a/manifests/debian.pp +++ b/manifests/debian.pp @@ -1,7 +1,9 @@ class sshd::debian inherits sshd::linux { # the templates for Debian need lsbdistcodename - require lsb + ensure_resource('package', 'lsb-release', {'ensure' => 'present' }) + #requires stdlib >= 3.2 + #ensure_packages(['lsb-release']) Package[openssh]{ name => 'openssh-server', diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..c1d9b6f --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,24 @@ +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') } + 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('lsb-release') } + 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 -- cgit v1.2.3 From 035161ef168ca331bc47548af87ee872f550c33d Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 26 Jan 2014 11:19:11 +0100 Subject: basic init class specs --- manifests/base.pp | 1 + spec/classes/init_spec.rb | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) (limited to 'spec') 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/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c1d9b6f..794a92e 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -7,6 +7,21 @@ describe 'sshd' 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', + } + )} end context "Debian OS" do @@ -19,6 +34,83 @@ describe 'sshd' do end it_behaves_like "a Linux OS" it { should contain_package('lsb-release') } + 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('lsb-release') } + 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 -- cgit v1.2.3 From 550e78a4e673e89e5632c5b346952c47debbe36b Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 26 Jan 2014 11:25:11 +0100 Subject: ruby 1.8.7 compatibility --- spec/classes/init_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 794a92e..1bf0750 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -8,11 +8,11 @@ describe 'sshd' do it { should contain_class('sshd') } it { should contain_class('sshd::client') } - it { should contain_service('sshd').with( + it { should contain_service('sshd').with({ :ensure => 'running', :enable => true, - :hasstatus => true, - )} + :hasstatus => true + })} it { should contain_file('sshd_config').with( { @@ -50,9 +50,9 @@ describe 'sshd' do it_behaves_like "a Linux OS" it { should contain_package('lsb-release') } it { should contain_package('openssh') } - it { should contain_service('sshd').with( + it { should contain_service('sshd').with({ :hasrestart => true - )} + })} end end -- cgit v1.2.3 From 5ce0dcda9776ada2b556f7e1de31702a32a9b318 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 26 Jan 2014 11:33:41 +0100 Subject: client spec --- manifests/client/base.pp | 7 ++++--- spec/classes/client_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 spec/classes/client_spec.rb (limited to 'spec') 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/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 -- cgit v1.2.3 From c1588ff6c304aeb1a8c8c39e3c8c957eedfac160 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 26 Jan 2014 11:59:34 +0100 Subject: test changing port --- spec/classes/init_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 1bf0750..7628be0 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe 'sshd' do - shared_examples "a Linux OS" do it { should compile.with_all_deps } it { should contain_class('sshd') } @@ -22,6 +21,15 @@ describe 'sshd' do '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 -- cgit v1.2.3 From bf16ec7bc701ea7cfda7d64319920e3b9cca4a16 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Mon, 27 Jan 2014 00:14:34 +0100 Subject: removed lsb-release package --- manifests/debian.pp | 5 ----- spec/classes/init_spec.rb | 2 -- 2 files changed, 7 deletions(-) (limited to 'spec') diff --git a/manifests/debian.pp b/manifests/debian.pp index ff2d7b1..d827078 100644 --- a/manifests/debian.pp +++ b/manifests/debian.pp @@ -1,10 +1,5 @@ class sshd::debian inherits sshd::linux { - # the templates for Debian need lsbdistcodename - ensure_resource('package', 'lsb-release', {'ensure' => 'present' }) - #requires stdlib >= 3.2 - #ensure_packages(['lsb-release']) - Package[openssh]{ name => 'openssh-server', } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 7628be0..e3003d1 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -41,7 +41,6 @@ describe 'sshd' do } end it_behaves_like "a Linux OS" - it { should contain_package('lsb-release') } it { should contain_package('openssh') } it { should contain_class('sshd::debian') } it { should contain_service('sshd').with( @@ -56,7 +55,6 @@ describe 'sshd' do } end it_behaves_like "a Linux OS" - it { should contain_package('lsb-release') } it { should contain_package('openssh') } it { should contain_service('sshd').with({ :hasrestart => true -- cgit v1.2.3 From a0e961674b96c070e0a32bce3f224a1512aa128d Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Sun, 2 Feb 2014 17:48:24 +0100 Subject: tests for ssh authorized key --- spec/defines/ssh_authorized_key_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/defines/ssh_authorized_key_spec.rb (limited to 'spec') diff --git a/spec/defines/ssh_authorized_key_spec.rb b/spec/defines/ssh_authorized_key_spec.rb new file mode 100644 index 0000000..a554d9d --- /dev/null +++ b/spec/defines/ssh_authorized_key_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'sshd::ssh_authorized_key' do + + context 'add authorized key' do + let(:title) { 'foo' } + let(:ssh_key) { 'some_secret_ssh_key' } + + let(:params) {{ + :key => ssh_key, + }} + + it { should contain_ssh_authorized_key('foo').with({ + 'ensure' => 'present', + 'type' => 'ssh-dss', + 'user' => 'foo', + 'target' => '/home/foo/.ssh/authorized_keys', + 'key' => ssh_key, + }) + } + end +end -- cgit v1.2.3 From 15a1a734627e76e9294886a47ce70578fe8436c7 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 5 Feb 2014 23:17:36 +0100 Subject: wording --- spec/defines/ssh_authorized_key_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/defines/ssh_authorized_key_spec.rb b/spec/defines/ssh_authorized_key_spec.rb index a554d9d..0cc4eb8 100644 --- a/spec/defines/ssh_authorized_key_spec.rb +++ b/spec/defines/ssh_authorized_key_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'sshd::ssh_authorized_key' do - context 'add authorized key' do + context 'manage authorized key' do let(:title) { 'foo' } let(:ssh_key) { 'some_secret_ssh_key' } -- cgit v1.2.3 From 253e4f1ceddb8666281c207bb41af1e8a167ee0d Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 5 Feb 2014 23:21:36 +0100 Subject: add test for options --- spec/defines/ssh_authorized_key_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'spec') diff --git a/spec/defines/ssh_authorized_key_spec.rb b/spec/defines/ssh_authorized_key_spec.rb index 0cc4eb8..c73a91c 100644 --- a/spec/defines/ssh_authorized_key_spec.rb +++ b/spec/defines/ssh_authorized_key_spec.rb @@ -19,4 +19,27 @@ describe 'sshd::ssh_authorized_key' do }) } end + context 'manage authoried key with options' do + let(:title) { 'foo2' } + let(:ssh_key) { 'some_secret_ssh_key' } + + let(:params) {{ + :key => ssh_key, + :options => ['command="/usr/bin/date"', + 'no-pty','no-X11-forwarding','no-agent-forwarding', + 'no-port-forwarding'] + }} + + it { should contain_ssh_authorized_key('foo2').with({ + 'ensure' => 'present', + 'type' => 'ssh-dss', + 'user' => 'foo2', + 'target' => '/home/foo2/.ssh/authorized_keys', + 'key' => ssh_key, + 'options' => ['command="/usr/bin/date"', + 'no-pty','no-X11-forwarding','no-agent-forwarding', + 'no-port-forwarding'] + }) + } + end end -- cgit v1.2.3