postfix_spec.rb 5.55 KB
Newer Older
1
2
3
require 'spec_helper'

describe 'postfix' do
Raphaël Pinson's avatar
Raphaël Pinson committed
4
5
6
7
8
9
10
11
12
13
14
  context 'when using defaults' do
    context 'when on Debian' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :fqdn            => 'fqdn.example.com',
      } }

      it { should contain_package('postfix') }
      it { should contain_package('mailx') }

Raphaël Pinson's avatar
Raphaël Pinson committed
15
16
      it { should contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") }
      it { should contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
Raphaël Pinson's avatar
Raphaël Pinson committed
17
      it { should contain_exec('newaliases').with_refreshonly('true') }
Raphaël Pinson's avatar
Raphaël Pinson committed
18
19
      it { should contain_file('/etc/postfix/master.cf').without('seltype') }
      it { should contain_file('/etc/postfix/main.cf').without('seltype') }
Raphaël Pinson's avatar
Raphaël Pinson committed
20

21
22
      it { should contain_postfix__config('myorigin').with_value('fqdn.example.com') }
      it { should contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
23
      it { should contain_postfix__config('inet_interfaces').with_value('all') }
Raphaël Pinson's avatar
Raphaël Pinson committed
24

Raphaël Pinson's avatar
Raphaël Pinson committed
25
      it { should contain_mailalias('root').with_recipient('nobody') }
Raphaël Pinson's avatar
Raphaël Pinson committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

      it {
        should contain_service('postfix').with(
          :ensure    => 'running',
          :enable    => 'true',
          :hasstatus => 'true',
          :restart   => '/etc/init.d/postfix reload'
      ) }
    end

    context 'when on RedHat' do
      let (:facts) { {
        :operatingsystem => 'RedHat',
        :osfamily        => 'RedHat',
        :fqdn            => 'fqdn.example.com',
      } }

      it { should contain_package('postfix') }
      it { should contain_package('mailx') }

Raphaël Pinson's avatar
Raphaël Pinson committed
46
47
      it { should contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") }
      it { should contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
Raphaël Pinson's avatar
Raphaël Pinson committed
48
      it { should contain_exec('newaliases').with_refreshonly('true') }
Raphaël Pinson's avatar
Raphaël Pinson committed
49
50
      it { should contain_file('/etc/postfix/master.cf').without('seltype') }
      it { should contain_file('/etc/postfix/main.cf').without('seltype') }
Raphaël Pinson's avatar
Raphaël Pinson committed
51

52
53
      it { should contain_postfix__config('myorigin').with_value('fqdn.example.com') }
      it { should contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
54
      it { should contain_postfix__config('inet_interfaces').with_value('all') }
Raphaël Pinson's avatar
Raphaël Pinson committed
55
56
57
58
      it { should contain_postfix__config('sendmail_path') }
      it { should contain_postfix__config('newaliases_path') }
      it { should contain_postfix__config('mailq_path') }

Raphaël Pinson's avatar
Raphaël Pinson committed
59
      it { should contain_mailalias('root').with_recipient('nobody') }
60

Raphaël Pinson's avatar
Raphaël Pinson committed
61
62
63
64
65
66
67
68
      it {
        should contain_service('postfix').with(
          :ensure    => 'running',
          :enable    => 'true',
          :hasstatus => 'true',
          :restart   => '/etc/init.d/postfix reload'
      ) }
    end
69
  end
Raphaël Pinson's avatar
Raphaël Pinson committed
70
71
72
73
74
75
76
77
78
79
80
81
82

  context 'when setting parameters' do
    context 'when on Debian' do
      context "when setting smtp_listen to 'all'" do
        let (:facts) { {
          :operatingsystem => 'Debian',
          :osfamily        => 'Debian',
          :fqdn            => 'fqdn.example.com',
        } }

        let (:params) { {
          :smtp_listen         => 'all',
          :root_mail_recipient => 'foo',
83
84
85
86
          :use_amavisd         => true,
          :use_dovecot_lda     => true,
          :use_schleuder       => true,
          :use_sympa           => true,
Raphaël Pinson's avatar
Raphaël Pinson committed
87
88
89
          :mail_user           => 'bar',
          :myorigin            => 'localhost',
          :inet_interfaces     => 'localhost2',
90
91
92
93
          :master_smtp         => "smtp      inet  n       -       -       -       -       smtpd
    -o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject",
          :master_smtps        => 'smtps     inet  n       -       -       -       -       smtpd',
          :master_submission   => 'submission inet n       -       -       -       -       smtpd',
Raphaël Pinson's avatar
Raphaël Pinson committed
94
95
96
97
98
99
100
101
102
103
104
        } }

        it { should contain_package('postfix') }
        it { should contain_package('mailx') }

        it { should contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") }
        it { should contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
        it { should contain_exec('newaliases').with_refreshonly('true') }
        it {
          should contain_file('/etc/postfix/master.cf').without('seltype').with_content(
            /smtp      inet  n       -       -       -       -       smtpd/
105
106
107
108
109
110
111
112
          ).with_content(
            /amavis unix/
          ).with_content(
            /dovecot.*\n.* user=bar:bar /
          ).with_content(
            /schleuder/
          ).with_content(
            /sympa/
Raphaël Pinson's avatar
Raphaël Pinson committed
113
114
          ).with_content(
            /user=bar/
115
116
117
118
119
120
          ).with_content(
            /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/
          ).with_content(
            /^smtps     inet  n/
          ).with_content(
            /^submission inet n/
121
122
          )
        }
Raphaël Pinson's avatar
Raphaël Pinson committed
123
124
        it { should contain_file('/etc/postfix/main.cf').without('seltype') }

125
126
127
        it { should contain_postfix__config('myorigin').with_value('localhost') }
        it { should contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
        it { should contain_postfix__config('inet_interfaces').with_value('localhost2') }
Raphaël Pinson's avatar
Raphaël Pinson committed
128

Raphaël Pinson's avatar
Raphaël Pinson committed
129
        it { should contain_mailalias('root').with_recipient('foo') }
Raphaël Pinson's avatar
Raphaël Pinson committed
130
131
132
133
134
135
136
137
138
139
140

        it {
          should contain_service('postfix').with(
            :ensure    => 'running',
            :enable    => 'true',
            :hasstatus => 'true',
            :restart   => '/etc/init.d/postfix reload'
        ) }
      end
    end
  end
141
end