freeradius_spec.rb 14.2 KB
Newer Older
1
2
3
require 'spec_helper'

describe 'freeradius' do
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
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      include_context 'redhat_params'

      let(:facts) { os_facts }

      # Empty params hash by default so we can super().merge
      let(:params) { {} }

      it do
        is_expected.to contain_file('radiusd.conf')
          .with(
            'group'  => 'radiusd',
            'mode'   => '0644',
            'path'   => '/etc/raddb/radiusd.conf',
            'notify' => 'Service[radiusd]',
            'owner'  => 'root',
          )
          .that_requires('Package[freeradius]')
          .that_requires('Group[radiusd]')
      end

      it do
        [
          '/etc/raddb/statusclients.d',
          '/etc/raddb',
          '/etc/raddb/conf.d',
          '/etc/raddb/attr.d',
          '/etc/raddb/users.d',
          '/etc/raddb/policy.d',
          '/etc/raddb/dictionary.d',
          '/etc/raddb/scripts',
          '/etc/raddb/mods-config',
          '/etc/raddb/mods-config/attr_filter',
          '/etc/raddb/mods-config/preprocess',
          '/etc/raddb/mods-config/sql',
          '/etc/raddb/sites-available',
          '/etc/raddb/mods-available',
        ].each do |file|
          is_expected.to contain_file(file)
            .with(
              'ensure'  => 'directory',
              'group'   => 'radiusd',
              'mode'    => '0755',
              'notify'  => 'Service[radiusd]',
              'owner'   => 'root',
            )
            .that_requires('Package[freeradius]')
            .that_requires('Group[radiusd]')
        end
      end

      it do
        [
          '/etc/raddb/certs',
          '/etc/raddb/clients.d',
          '/etc/raddb/listen.d',
          '/etc/raddb/sites-enabled',
Nathan Ward's avatar
Nathan Ward committed
62
          '/etc/raddb/instantiate',
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
        ].each do |file|
          is_expected.to contain_file(file)
            .with(
              'ensure'  => 'directory',
              'group'   => 'radiusd',
              'mode'    => '0755',
              'notify'  => 'Service[radiusd]',
              'owner'   => 'root',
              'purge'   => 'true',
              'recurse' => 'true',
            )
            .that_requires('Package[freeradius]')
            .that_requires('Group[radiusd]')
        end
      end

      it do
        is_expected.to contain_concat('/etc/raddb/policy.conf')
          .with(
            'group'   => 'radiusd',
            'mode'    => '0640',
            'notify'  => 'Service[radiusd]',
            'owner'   => 'root',
          )
          .that_requires('Package[freeradius]')
          .that_requires('Group[radiusd]')
      end

      it do
        is_expected.to contain_concat__fragment('policy_header')
          .with(
            'content' => 'policy {',
            'order'   => '10',
Nathan Ward's avatar
Nathan Ward committed
96
            'target'  => '/etc/raddb/policy.conf',
97
98
99
100
101
102
103
104
          )
      end

      it do
        is_expected.to contain_concat__fragment('policy_footer')
          .with(
            'content' => '}',
            'order'   => '99',
Nathan Ward's avatar
Nathan Ward committed
105
            'target'  => '/etc/raddb/policy.conf',
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
          )
      end

      it do
        is_expected.to contain_concat('/etc/raddb/proxy.conf')
          .with(
            'group'   => 'radiusd',
            'mode'    => '0640',
            'notify'  => 'Service[radiusd]',
            'owner'   => 'root',
          )
          .that_requires('Package[freeradius]')
          .that_requires('Group[radiusd]')
      end

      it do
        is_expected.to contain_concat__fragment('proxy_header')
          .with(
Paul's avatar
Paul committed
124
            'content' => "# Proxy config\n",
125
            'order'   => '05',
Nathan Ward's avatar
Nathan Ward committed
126
            'target'  => '/etc/raddb/proxy.conf',
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
          )
      end

      it do
        is_expected.to contain_concat('/etc/raddb/mods-available/attr_filter')
          .with(
            'group'   => 'radiusd',
            'mode'    => '0640',
            'notify'  => 'Service[radiusd]',
            'owner'   => 'root',
          )
          .that_requires('Package[freeradius]')
          .that_requires('Group[radiusd]')
      end

      it do
        is_expected.to contain_concat__fragment('attr-default')
          .with(
            'order'   => '10',
Nathan Ward's avatar
Nathan Ward committed
146
            'target'  => '/etc/raddb/mods-available/attr_filter',
147
148
149
150
151
152
153
          )
      end

      it do
        is_expected.to contain_concat('/etc/raddb/dictionary')
          .with(
            'group'   => 'radiusd',
154
            'mode'    => '0644',
155
156
157
158
159
160
161
162
163
164
165
            'owner'   => 'root',
          )
          .that_requires('Package[freeradius]')
          .that_requires('Group[radiusd]')
      end

      it do
        is_expected.to contain_concat__fragment('dictionary_header')
          .with(
            'order'  => '10',
            'source' => 'puppet:///modules/freeradius/dictionary.header',
Nathan Ward's avatar
Nathan Ward committed
166
            'target' => '/etc/raddb/dictionary',
167
168
169
170
171
172
173
174
          )
      end

      it do
        is_expected.to contain_concat__fragment('dictionary_footer')
          .with(
            'order'  => '90',
            'source' => 'puppet:///modules/freeradius/dictionary.footer',
Nathan Ward's avatar
Nathan Ward committed
175
            'target' => '/etc/raddb/dictionary',
176
177
178
179
180
181
182
          )
      end

      it do
        is_expected.to contain_package('freeradius')
          .with(
            'ensure' => 'installed',
Nathan Ward's avatar
Nathan Ward committed
183
            'name'   => 'freeradius',
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
          )
      end

      it do
        is_expected.to contain_service('radiusd')
          .with(
            'enable'     => 'true',
            'ensure'     => 'running',
            'hasrestart' => 'true',
            'hasstatus'  => 'true',
            'name'       => 'radiusd',
          )
          .that_requires('Package[freeradius]')
          .that_requires('User[radiusd]')
          .that_requires('Exec[radiusd-config-test]')
          .that_requires('File[radiusd.conf]')
      end

      it do
        is_expected.to contain_user('radiusd')
          .with(
            'ensure'  => 'present',
            'groups'  => nil,
          )
          .that_requires('Package[freeradius]')
      end

      context 'with winbind support' do
        let(:params) do
          {
            winbind_support: true,
          }
        end

        it do
          is_expected.to contain_user('radiusd')
            .with(
              'groups'  => 'wbpriv',
            )
        end
      end

      it do
        is_expected.to contain_group('radiusd')
          .with(
Nathan Ward's avatar
Nathan Ward committed
229
            'ensure' => 'present',
230
231
232
233
234
235
          )
          .that_requires('Package[freeradius]')
      end

      it do
        is_expected.to contain_freeradius__module('always')
Nathan Ward's avatar
Nathan Ward committed
236
          .with_preserve(true)
237
238
239
240
      end

      it do
        is_expected.to contain_freeradius__module('detail')
Nathan Ward's avatar
Nathan Ward committed
241
          .with_preserve(true)
242
243
244
245
      end

      it do
        is_expected.to contain_freeradius__module('detail.log')
Nathan Ward's avatar
Nathan Ward committed
246
          .with_preserve(true)
247
248
249
250
251
      end

      it do
        [
          '/var/log/radius',
Nathan Ward's avatar
Nathan Ward committed
252
          '/var/log/radius/radacct',
253
254
255
256
        ].each do |file|
          is_expected.to contain_file(file)
            .with(
              'mode'    => '0750',
257
258
              'owner' => 'radiusd',
              'group' => 'radiusd',
259
260
261
262
263
264
265
266
267
268
            )
            .that_requires('Package[freeradius]')
        end
      end

      it do
        is_expected.to contain_file('/var/log/radius/radius.log')
          .with(
            'group'   => 'radiusd',
            'owner'   => 'radiusd',
Nathan Ward's avatar
Nathan Ward committed
269
            'seltype' => 'radiusd_log_t',
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
          )
          .that_requires('Package[freeradius]')
          .that_requires('User[radiusd]')
          .that_requires('Group[radiusd]')
      end

      it do
        is_expected.to contain_logrotate__rule('radacct')
          .with(
            'compress'      => 'true',
            'create'        => 'false',
            'missingok'     => 'true',
            'path'          => '/var/log/radius/radacct/*/*.log',
            'postrotate'    => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
            'rotate'        => '7',
            'rotate_every'  => 'day',
Nathan Ward's avatar
Nathan Ward committed
286
            'sharedscripts' => 'true',
287
288
289
290
291
292
293
294
295
296
297
298
299
          )
      end

      it do
        is_expected.to contain_logrotate__rule('checkrad')
          .with(
            'compress'      => 'true',
            'create'        => 'true',
            'missingok'     => 'true',
            'path'          => '/var/log/radius/checkrad.log',
            'postrotate'    => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
            'rotate'        => '1',
            'rotate_every'  => 'week',
Nathan Ward's avatar
Nathan Ward committed
300
            'sharedscripts' => 'true',
301
302
303
304
305
306
307
308
309
310
311
312
313
          )
      end

      it do
        is_expected.to contain_logrotate__rule('radiusd')
          .with(
            'compress'      => 'true',
            'create'        => 'true',
            'missingok'     => 'true',
            'path'          => '/var/log/radius/radius*.log',
            'postrotate'    => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`',
            'rotate'        => '26',
            'rotate_every'  => 'week',
Nathan Ward's avatar
Nathan Ward committed
314
            'sharedscripts' => 'true',
315
316
317
318
319
320
          )
      end

      it do
        [
          '/etc/raddb/certs/dh',
Nathan Ward's avatar
Nathan Ward committed
321
          '/etc/raddb/certs/random',
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
        ].each do |file|
          is_expected.to contain_file(file)
            .that_requires('Exec[dh]')
            .that_requires('Exec[random]')
        end
      end

      it do
        is_expected.to contain_exec('dh')
          .with(
            'command' => 'openssl dhparam -out /etc/raddb/certs/dh 1024',
            'creates' => '/etc/raddb/certs/dh',
            'path'    => '/usr/bin',
          )
          .that_requires('File[/etc/raddb/certs]')
      end

      it do
        is_expected.to contain_exec('random')
          .with(
            'command' => 'dd if=/dev/urandom of=/etc/raddb/certs/random count=10 >/dev/null 2>&1',
            'creates' => '/etc/raddb/certs/random',
            'path'    => '/bin',
          )
          .that_requires('File[/etc/raddb/certs]')
      end

      it do
        is_expected.to contain_exec('radiusd-config-test')
          .with(
            'command'     => 'sudo radiusd -XC | grep \'Configuration appears to be OK.\' | wc -l',
            'logoutput'   => 'on_failure',
            'path'        => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
            'refreshonly' => 'true',
Nathan Ward's avatar
Nathan Ward committed
356
            'returns'     => '0',
357
358
359
360
361
362
363
364
365
366
          )
      end

      it do
        [
          '/etc/raddb/clients.conf',
          '/etc/raddb/sql.conf',
        ].each do |file|
          is_expected.to contain_file(file)
            .with(
Paul's avatar
Paul committed
367
              'content' => "# FILE INTENTIONALLY BLANK\n",
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
              'group'   => 'radiusd',
              'mode'    => '0644',
              'notify'  => 'Service[radiusd]',
              'owner'   => 'root',
            )
            .that_requires('Package[freeradius]')
            .that_requires('Group[radiusd]')
        end
      end

      context 'with mysql' do
        let(:params) do
          super().merge(
            'mysql_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-mysql')
            .with(
Nathan Ward's avatar
Nathan Ward committed
388
              'ensure' => 'installed',
389
390
391
392
393
394
395
396
397
398
399
400
401
402
            )
        end
      end

      context 'with pgsql' do
        let(:params) do
          super().merge(
            'pgsql_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-postgresql')
            .with(
Nathan Ward's avatar
Nathan Ward committed
403
              'ensure' => 'installed',
404
405
406
407
408
409
410
411
412
413
414
415
416
417
            )
        end
      end

      context 'with perl' do
        let(:params) do
          super().merge(
            'perl_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-perl')
            .with(
Nathan Ward's avatar
Nathan Ward committed
418
              'ensure' => 'installed',
419
420
421
422
423
424
425
426
427
428
429
430
431
432
            )
        end
      end

      context 'with utils' do
        let(:params) do
          super().merge(
            'utils_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-utils')
            .with(
Nathan Ward's avatar
Nathan Ward committed
433
              'ensure' => 'installed',
434
435
436
437
438
439
440
441
442
443
444
445
446
447
            )
        end
      end

      context 'with ldap' do
        let(:params) do
          super().merge(
            'ldap_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-ldap')
            .with(
Nathan Ward's avatar
Nathan Ward committed
448
              'ensure' => 'installed',
449
450
451
452
453
454
455
456
457
458
459
460
461
462
            )
        end
      end

      context 'with dhcp' do
        let(:params) do
          super().merge(
            'dhcp_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-dhcp')
            .with(
Nathan Ward's avatar
Nathan Ward committed
463
              'ensure' => 'installed',
464
465
466
467
468
469
470
471
472
473
474
475
476
477
            )
        end
      end

      context 'with krb5' do
        let(:params) do
          super().merge(
            'krb5_support' => true,
          )
        end

        it do
          is_expected.to contain_package('freeradius-krb5')
            .with(
Nathan Ward's avatar
Nathan Ward committed
478
              'ensure' => 'installed',
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
            )
        end
      end

      context 'with wpa_supplicant' do
        let(:params) do
          super().merge(
            'wpa_supplicant' => true,
          )
        end

        it do
          is_expected.to contain_package('wpa_supplicant')
            .with(
              'ensure' => 'installed',
Nathan Ward's avatar
Nathan Ward committed
494
              'name'   => 'wpa_supplicant',
495
            )
Nathan Ward's avatar
Nathan Ward committed
496
        end
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
      end

      context 'with syslog' do
        let(:params) do
          super().merge(
            'syslog' => true,
          )
        end

        it do
          is_expected.to contain_rsyslog__snippet('12-radiusd-log')
            .with(
              'content' => %r{^if \$programname == \'radiusd\' then /var/log/radius/radius.log},
            )
        end
      end

      case os_facts[:osfamily]
      when 'Redhat'
        it do
          is_expected.to contain_exec('delete-radius-rpmnew')
            .with(
              'command' => 'find /etc/raddb -name *.rpmnew -delete',
              'onlyif'  => 'find /etc/raddb -name *.rpmnew | grep rpmnew',
              'path'    => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
            )
        end

        it do
          is_expected.to contain_exec('delete-radius-rpmsave')
            .with(
              'command' => 'find /etc/raddb -name *.rpmsave -delete',
              'onlyif'  => 'find /etc/raddb -name *.rpmsave | grep rpmsave',
              'path'    => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
            )
        end
      end
    end
535
536
  end
end