summaryrefslogtreecommitdiff
path: root/puppet/modules/sshd/spec/classes/init_spec.rb
blob: e3003d14a3e1b490cfbe981bb90348d3fd307449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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