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

describe 'postfix' do
Raphaël Pinson's avatar
Raphaël Pinson committed
4
5
6
  context 'when using defaults' do
    context 'when on Debian' do
      let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
7
        :lsbdistcodename => 'wheezy',
Raphaël Pinson's avatar
Raphaël Pinson committed
8
9
10
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :fqdn            => 'fqdn.example.com',
11
        :path            => '/foo/bar',
Raphaël Pinson's avatar
Raphaël Pinson committed
12
13
      } }

Raphaël Pinson's avatar
Raphaël Pinson committed
14
15
      it { is_expected.to contain_package('postfix') }
      it { is_expected.to contain_package('mailx') }
Raphaël Pinson's avatar
Raphaël Pinson committed
16

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

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

Raphaël Pinson's avatar
Raphaël Pinson committed
27
      it { is_expected.to contain_mailalias('root').with_recipient('nobody') }
Raphaël Pinson's avatar
Raphaël Pinson committed
28
29

      it {
Raphaël Pinson's avatar
Raphaël Pinson committed
30
        is_expected.to contain_service('postfix').with(
Raphaël Pinson's avatar
Raphaël Pinson committed
31
32
33
34
35
36
37
38
39
          :ensure    => 'running',
          :enable    => 'true',
          :hasstatus => 'true',
          :restart   => '/etc/init.d/postfix reload'
      ) }
    end

    context 'when on RedHat' do
      let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
40
41
42
43
44
        :fqdn                      => 'fqdn.example.com',
        :operatingsystem           => 'RedHat',
        :operatingsystemmajrelease => '7',
        :osfamily                  => 'RedHat',
        :path                      => '/foo/bar',
Raphaël Pinson's avatar
Raphaël Pinson committed
45
46
      } }

Raphaël Pinson's avatar
Raphaël Pinson committed
47
48
      it { is_expected.to contain_package('postfix') }
      it { is_expected.to contain_package('mailx') }
Raphaël Pinson's avatar
Raphaël Pinson committed
49

Raphaël Pinson's avatar
Raphaël Pinson committed
50
51
52
53
54
      it { is_expected.to contain_file('/etc/mailname').with_seltype('postfix_etc_t').with_content("fqdn.example.com\n") }
      it { is_expected.to contain_file('/etc/aliases').with_seltype('postfix_etc_t').with_content("# file managed by puppet\n") }
      it { is_expected.to contain_exec('newaliases').with_refreshonly('true') }
      it { is_expected.to contain_file('/etc/postfix/master.cf').with_seltype('postfix_etc_t') }
      it { is_expected.to contain_file('/etc/postfix/main.cf').with_seltype('postfix_etc_t') }
Raphaël Pinson's avatar
Raphaël Pinson committed
55

Raphaël Pinson's avatar
Raphaël Pinson committed
56
57
58
59
60
61
      it { is_expected.to contain_postfix__config('myorigin').with_value('fqdn.example.com') }
      it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
      it { is_expected.to contain_postfix__config('inet_interfaces').with_value('all') }
      it { is_expected.to contain_postfix__config('sendmail_path') }
      it { is_expected.to contain_postfix__config('newaliases_path') }
      it { is_expected.to contain_postfix__config('mailq_path') }
Raphaël Pinson's avatar
Raphaël Pinson committed
62

Raphaël Pinson's avatar
Raphaël Pinson committed
63
      it { is_expected.to contain_mailalias('root').with_recipient('nobody') }
64

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

  context 'when setting parameters' do
    context 'when on Debian' do
      context "when setting smtp_listen to 'all'" do
        let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
79
          :lsbdistcodename => 'wheezy',
Raphaël Pinson's avatar
Raphaël Pinson committed
80
81
82
          :operatingsystem => 'Debian',
          :osfamily        => 'Debian',
          :fqdn            => 'fqdn.example.com',
83
          :path            => '/foo/bar',
Raphaël Pinson's avatar
Raphaël Pinson committed
84
85
86
87
88
        } }

        let (:params) { {
          :smtp_listen         => 'all',
          :root_mail_recipient => 'foo',
89
90
91
92
          :use_amavisd         => true,
          :use_dovecot_lda     => true,
          :use_schleuder       => true,
          :use_sympa           => true,
Raphaël Pinson's avatar
Raphaël Pinson committed
93
94
95
          :mail_user           => 'bar',
          :myorigin            => 'localhost',
          :inet_interfaces     => 'localhost2',
96
97
98
99
          :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
100
101
        } }

Raphaël Pinson's avatar
Raphaël Pinson committed
102
103
        it { is_expected.to contain_package('postfix') }
        it { is_expected.to contain_package('mailx') }
Raphaël Pinson's avatar
Raphaël Pinson committed
104

Raphaël Pinson's avatar
Raphaël Pinson committed
105
106
107
        it { is_expected.to contain_file('/etc/mailname').without('seltype').with_content("fqdn.example.com\n") }
        it { is_expected.to contain_file('/etc/aliases').without('seltype').with_content("# file managed by puppet\n") }
        it { is_expected.to contain_exec('newaliases').with_refreshonly('true') }
Raphaël Pinson's avatar
Raphaël Pinson committed
108
        it {
Raphaël Pinson's avatar
Raphaël Pinson committed
109
          is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(
Raphaël Pinson's avatar
Raphaël Pinson committed
110
            /smtp      inet  n       -       -       -       -       smtpd/
111
112
113
114
115
116
117
118
          ).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
119
120
          ).with_content(
            /user=bar/
121
122
123
124
125
126
          ).with_content(
            /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/
          ).with_content(
            /^smtps     inet  n/
          ).with_content(
            /^submission inet n/
127
128
          )
        }
Raphaël Pinson's avatar
Raphaël Pinson committed
129
        it { is_expected.to contain_file('/etc/postfix/main.cf').without('seltype') }
Raphaël Pinson's avatar
Raphaël Pinson committed
130

Raphaël Pinson's avatar
Raphaël Pinson committed
131
132
133
        it { is_expected.to contain_postfix__config('myorigin').with_value('localhost') }
        it { is_expected.to contain_postfix__config('alias_maps').with_value('hash:/etc/aliases') }
        it { is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2') }
Raphaël Pinson's avatar
Raphaël Pinson committed
134

Raphaël Pinson's avatar
Raphaël Pinson committed
135
        it { is_expected.to contain_mailalias('root').with_recipient('foo') }
Raphaël Pinson's avatar
Raphaël Pinson committed
136
137

        it {
Raphaël Pinson's avatar
Raphaël Pinson committed
138
          is_expected.to contain_service('postfix').with(
Raphaël Pinson's avatar
Raphaël Pinson committed
139
140
141
142
143
144
145
            :ensure    => 'running',
            :enable    => 'true',
            :hasstatus => 'true',
            :restart   => '/etc/init.d/postfix reload'
        ) }
      end
    end
146
147
    context 'when on RedHat' do
      let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
148
149
        :augeasversion   => '1.2.0',
        :lsbdistcodename => 'wheezy',
150
151
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
Mickaël Canévet's avatar
Mickaël Canévet committed
152
        :rubyversion     => '1.9.7',
153
        :fqdn            => 'fqdn.example.com',
154
        :path            => '/foo/bar',
155
156
157
158
159
160
      } }
      context 'when specifying inet_interfaces' do
        let (:params) { {
          :inet_interfaces => 'localhost2'
        } }
        it 'should create a postfix::config defined type with inet_interfaces specified properly' do
Raphaël Pinson's avatar
Raphaël Pinson committed
161
          is_expected.to contain_postfix__config('inet_interfaces').with_value('localhost2')
162
163
164
165
        end
      end
      context 'when enabling ldap' do
        it 'should do stuff' do
166
          skip 'need to write this still'
167
168
169
170
171
172
173
        end
      end
      context 'when a custom mail_user is specified' do
        let (:params) { {
          :mail_user => 'bar'
        } }
        it 'should adjust the content of /etc/postfix/master.cf specifying the user' do
Raphaël Pinson's avatar
Raphaël Pinson committed
174
          is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(/user=bar/)
175
176
177
178
179
180
181
        end
      end
      context 'when mailman is true' do
        let (:params) { {
          :mailman => true
        } }
        it 'should do stuff' do
182
          skip 'need to write this still'
183
184
185
186
187
188
189
        end
      end
      context 'when specifying a custom mastercf_source' do
        let (:params) { {
          :mastercf_source => 'testy'
        } }
        it 'should do stuff' do
190
          skip 'need to write this still'
191
192
193
194
195
196
197
198
        end
      end
      context 'when specifying a custom master_smtp' do
        let (:params) { {
          :master_smtp         => "smtp      inet  n       -       -       -       -       smtpd
    -o smtpd_client_restrictions=check_client_access,hash:/etc/postfix/access,reject",
        } }
        it 'should update master.cf with the specified flags to smtp' do 
Raphaël Pinson's avatar
Raphaël Pinson committed
199
          is_expected.to contain_file('/etc/postfix/master.cf').without('seltype').with_content(
200
201
202
203
204
205
206
207
208
209
            /smtp      inet  n       -       -       -       -       smtpd/).with_content(
            /^smtp.*\n.*smtpd_client_restrictions=check_client_access,hash:/
          )
        end
      end
      context 'when specifying a custom master_smtps' do
        let (:params) { {
          :master_smtps        => 'smtps     inet  n       -       -       -       -       smtpd'
        } }
        it 'should update master.cf with the specified flags to smtps' do
Raphaël Pinson's avatar
Raphaël Pinson committed
210
          is_expected.to contain_file('/etc/postfix/master.cf').with_content(/^smtps     inet  n/)
211
212
213
214
215
        end
      end
      context 'when mta is enabled' do
        let (:params) { { :mta => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
        it 'should configure postfix as a minimal MTA, delivering mail to the mydestination param' do
Raphaël Pinson's avatar
Raphaël Pinson committed
216
217
218
219
220
          is_expected.to contain_postfix__config('mydestination').with_value('1.2.3.4')
          is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.0/8')
          is_expected.to contain_postfix__config('relayhost').with_value('2.3.4.5')
          is_expected.to contain_postfix__config('virtual_alias_maps').with_value('hash:/etc/postfix/virtual')
          is_expected.to contain_postfix__config('transport_maps').with_value('hash:/etc/postfix/transport')
221
        end
Raphaël Pinson's avatar
Raphaël Pinson committed
222
        it { is_expected.to contain_class('postfix::mta') }
223
224
225
        context 'and satellite is also enabled' do
          let (:params) { { :mta => true, :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
          it 'should fail' do
226
            expect { should compile }.to raise_error(/Please disable one/)
227
228
229
230
231
          end
        end
      end
      context 'when specifying mydesitination' do
        it 'should do stuff' do
232
          skip 'need to write this still'
233
234
235
236
        end
      end
      context 'when specifying mynetworks' do
        it 'should do stuff' do
237
          skip 'need to write this still'
238
239
240
241
242
        end
      end
      context 'when specifying myorigin' do
        let (:params) { { :myorigin => 'localhost'} }
        it 'should create a postfix::config defined type with myorigin specified properly' do
Raphaël Pinson's avatar
Raphaël Pinson committed
243
          is_expected.to contain_postfix__config('myorigin').with_value('localhost')
244
245
246
247
        end
      end
      context 'when specifying relayhost' do
        it 'should do stuff' do
248
          skip 'need to write this still'
249
250
251
252
253
        end
      end
      context 'when specifying a root_mail_recipient' do
        let (:params) { { :root_mail_recipient => 'foo'} }
        it 'should contain a Mailalias resource directing roots mail to the required user' do
Raphaël Pinson's avatar
Raphaël Pinson committed
254
          is_expected.to contain_mailalias('root').with_recipient('foo')
255
256
257
258
        end
      end
      context 'when specifying satellite' do
        let (:params) { { :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
Mickaël Canévet's avatar
Mickaël Canévet committed
259
260
261
        let :pre_condition do
          "class { 'augeas': }"
        end
262
        it 'should configure all local email to be forwarded to $root_mail_recipient delivered through $relayhost' do
Raphaël Pinson's avatar
Raphaël Pinson committed
263
264
265
266
267
          is_expected.to contain_postfix__config('mydestination').with_value('1.2.3.4')
          is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.0/8')
          is_expected.to contain_postfix__config('relayhost').with_value('2.3.4.5')
          is_expected.to contain_postfix__config('virtual_alias_maps').with_value('hash:/etc/postfix/virtual')
          is_expected.to contain_postfix__config('transport_maps').with_value('hash:/etc/postfix/transport')
268
269
270
271
        end
        context 'and mta is also enabled' do
          let (:params) { { :mta => true, :satellite => true, :mydestination => '1.2.3.4', :relayhost => '2.3.4.5' } }
          it 'should fail' do
272
            expect { should compile }.to raise_error(/Please disable one/)
273
274
275
276
277
278
          end
        end
      end
      context 'when specifying smtp_listen' do
        let (:params) { { :smtp_listen => 'all' } }
        it 'should do stuff' do
279
          skip 'need to write this still'
280
281
282
283
284
        end
      end
      context 'when use_amavisd is true' do
        let (:params) { { :use_amavisd => true } }
        it 'should update master.cf with the specified flags to amavis' do
Raphaël Pinson's avatar
Raphaël Pinson committed
285
          is_expected.to contain_file('/etc/postfix/master.cf').with_content(/amavis unix/)
286
287
288
289
290
        end
      end
      context 'when use_dovecot_lda is true' do
        let (:params) { { :use_dovecot_lda => true } }
        it 'should update master.cf with the specified flags to dovecot' do
Raphaël Pinson's avatar
Raphaël Pinson committed
291
          is_expected.to contain_file('/etc/postfix/master.cf').with_content(/dovecot.*\n.* user=vmail:vmail /)
292
293
294
295
296
        end
      end
      context 'when use_schleuder is true' do
        let (:params) { { :use_schleuder => true } }
        it 'should update master.cf with the specified flags to schleuder' do
Raphaël Pinson's avatar
Raphaël Pinson committed
297
          is_expected.to contain_file('/etc/postfix/master.cf').with_content(/schleuder/)
298
299
300
301
302
        end
      end
      context 'when use_sympa is true' do
        let (:params) { { :use_sympa => true } }
        it 'should update master.cf to include sympa' do
Raphaël Pinson's avatar
Raphaël Pinson committed
303
          is_expected.to contain_file('/etc/postfix/master.cf').with_content(/sympa/)
304
305
306
        end
      end
    end
Raphaël Pinson's avatar
Raphaël Pinson committed
307
  end
308
end