]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/rabbitmq/spec/classes/rabbitmq_spec.rb
move to puppetlabs rabbitmq module
[dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / classes / rabbitmq_spec.rb
1 require 'spec_helper'
2
3 describe 'rabbitmq' do
4
5   context 'on unsupported distributions' do
6     let(:facts) {{ :osfamily => 'Unsupported' }}
7
8     it 'we fail' do
9       expect { catalogue }.to raise_error(Puppet::Error, /not supported on an Unsupported/)
10     end
11   end
12
13   context 'on Debian' do
14     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
15     it 'includes rabbitmq::repo::apt' do
16       should contain_class('rabbitmq::repo::apt')
17     end
18
19     describe 'apt::source default values' do
20       it 'should add a repo with defaults values' do
21         should contain_apt__source('rabbitmq').with( {
22           :ensure   => 'present',
23           :location => 'http://www.rabbitmq.com/debian/',
24           :release  => 'testing',
25           :repos    => 'main',
26         })
27       end
28     end
29   end
30
31   context 'on Debian' do
32     let(:params) {{ :manage_repos => false }}
33     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
34     it 'does ensure rabbitmq apt::source is absent when manage_repos is false' do
35       should_not contain_apt__source('rabbitmq')
36     end
37   end
38
39   context 'on Debian' do
40     let(:params) {{ :manage_repos => true }}
41     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
42
43     it 'includes rabbitmq::repo::apt' do
44       should contain_class('rabbitmq::repo::apt')
45     end
46
47     describe 'apt::source default values' do
48       it 'should add a repo with defaults values' do
49         should contain_apt__source('rabbitmq').with( {
50           :ensure   => 'present',
51           :location => 'http://www.rabbitmq.com/debian/',
52           :release  => 'testing',
53           :repos    => 'main',
54         })
55       end
56     end
57   end
58
59   context 'on Debian' do
60     let(:params) {{ :repos_ensure => false }}
61     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
62     it 'does ensure rabbitmq apt::source is absent when repos_ensure is false' do
63       should contain_apt__source('rabbitmq').with(
64         'ensure'  => 'absent'
65       )
66     end
67   end
68
69   context 'on Debian' do
70     let(:params) {{ :repos_ensure => true }}
71     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
72
73     it 'includes rabbitmq::repo::apt' do
74       should contain_class('rabbitmq::repo::apt')
75     end
76
77     describe 'apt::source default values' do
78       it 'should add a repo with defaults values' do
79         should contain_apt__source('rabbitmq').with( {
80           :ensure   => 'present',
81           :location => 'http://www.rabbitmq.com/debian/',
82           :release  => 'testing',
83           :repos    => 'main',
84         })
85       end
86     end
87   end
88
89   context 'on Debian' do
90     let(:params) {{ :manage_repos => true, :repos_ensure => false }}
91     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
92
93     it 'includes rabbitmq::repo::apt' do
94       should contain_class('rabbitmq::repo::apt')
95     end
96
97     describe 'apt::source default values' do
98       it 'should add a repo with defaults values' do
99         should contain_apt__source('rabbitmq').with( {
100           :ensure => 'absent',
101         })
102       end
103     end
104   end
105
106   context 'on Debian' do
107     let(:params) {{ :manage_repos => true, :repos_ensure => true }}
108     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
109
110     it 'includes rabbitmq::repo::apt' do
111       should contain_class('rabbitmq::repo::apt')
112     end
113
114     describe 'apt::source default values' do
115       it 'should add a repo with defaults values' do
116         should contain_apt__source('rabbitmq').with( {
117           :ensure   => 'present',
118           :location => 'http://www.rabbitmq.com/debian/',
119           :release  => 'testing',
120           :repos    => 'main',
121         })
122       end
123     end
124   end
125
126   context 'on Debian' do
127     let(:params) {{ :manage_repos => false, :repos_ensure => true }}
128     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
129     it 'does ensure rabbitmq apt::source is absent when manage_repos is false and repos_ensure is true' do
130       should_not contain_apt__source('rabbitmq')
131     end
132   end
133
134   context 'on Debian' do
135     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
136     context 'with manage_repos => false and repos_ensure => false' do
137       let(:params) {{ :manage_repos => false, :repos_ensure => false }}
138       it 'does ensure rabbitmq apt::source is absent when manage_repos is false and repos_ensure is false' do
139         should_not contain_apt__source('rabbitmq')
140       end
141     end
142
143     context 'with file_limit => unlimited' do
144       let(:params) {{ :file_limit => 'unlimited' }}
145       it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n unlimited/) }
146     end
147
148     context 'with file_limit => infinity' do
149       let(:params) {{ :file_limit => 'infinity' }}
150       it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n infinity/) }
151     end
152
153     context 'with file_limit => -1' do
154       let(:params) {{ :file_limit => -1 }}
155       it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n -1/) }
156     end
157
158     context 'with file_limit => \'1234\'' do
159       let(:params) {{ :file_limit => '1234' }}
160       it { should contain_file('/etc/default/rabbitmq-server').with_content(/ulimit -n 1234/) }
161     end
162
163     context 'with file_limit => foo' do
164       let(:params) {{ :file_limit => 'foo' }}
165       it 'does not compile' do
166         expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
167       end
168     end
169   end
170
171   context 'on Redhat' do
172     let(:facts) {{ :osfamily => 'RedHat' }}
173     it 'includes rabbitmq::repo::rhel' do
174       should contain_class('rabbitmq::repo::rhel')
175       should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
176     end
177   end
178
179   context 'on Redhat' do
180     let(:params) {{ :repos_ensure => false }}
181     let(:facts) {{ :osfamily => 'RedHat' }}
182     it 'does not import repo public key when repos_ensure is false' do
183       should contain_class('rabbitmq::repo::rhel')
184       should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
185     end
186   end
187
188   context 'on Redhat' do
189     let(:params) {{ :repos_ensure => true }}
190     let(:facts) {{ :osfamily => 'RedHat' }}
191     it 'does import repo public key when repos_ensure is true' do
192       should contain_class('rabbitmq::repo::rhel')
193       should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
194     end
195   end
196
197   context 'on Redhat' do
198     let(:params) {{ :manage_repos => false }}
199     let(:facts) {{ :osfamily => 'RedHat' }}
200     it 'does not import repo public key when manage_repos is false' do
201       should_not contain_class('rabbitmq::repo::rhel')
202       should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
203     end
204   end
205
206   context 'on Redhat' do
207     let(:params) {{ :manage_repos => true }}
208     let(:facts) {{ :osfamily => 'RedHat' }}
209     it 'does import repo public key when manage_repos is true' do
210       should contain_class('rabbitmq::repo::rhel')
211       should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
212     end
213   end
214
215   context 'on Redhat' do
216     let(:params) {{ :manage_repos => false, :repos_ensure => true }}
217     let(:facts) {{ :osfamily => 'RedHat' }}
218     it 'does not import repo public key when manage_repos is false and repos_ensure is true' do
219       should_not contain_class('rabbitmq::repo::rhel')
220       should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
221     end
222   end
223
224   context 'on Redhat' do
225     let(:params) {{ :manage_repos => true, :repos_ensure => true }}
226     let(:facts) {{ :osfamily => 'RedHat' }}
227     it 'does import repo public key when manage_repos is true and repos_ensure is true' do
228       should contain_class('rabbitmq::repo::rhel')
229       should contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
230     end
231   end
232
233   context 'on Redhat' do
234     let(:params) {{ :manage_repos => false, :repos_ensure => false }}
235     let(:facts) {{ :osfamily => 'RedHat' }}
236     it 'does not import repo public key when manage_repos is false and repos_ensure is false' do
237       should_not contain_class('rabbitmq::repo::rhel')
238       should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
239     end
240   end
241
242   context 'on Redhat' do
243     let(:params) {{ :manage_repos => true, :repos_ensure => false }}
244     let(:facts) {{ :osfamily => 'RedHat' }}
245     it 'does not import repo public key when manage_repos is true and repos_ensure is false' do
246       should contain_class('rabbitmq::repo::rhel')
247       should_not contain_exec('rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc')
248     end
249   end
250
251   context 'on RedHat 7.0 or more' do
252     let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}
253
254     it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d').with(
255       'ensure'                  => 'directory',
256       'owner'                   => '0',
257       'group'                   => '0',
258       'mode'                    => '0755',
259       'selinux_ignore_defaults' => true
260     ) }
261
262     it { should contain_exec('rabbitmq-systemd-reload').with(
263       'command'     => '/usr/bin/systemctl daemon-reload',
264       'notify'      => 'Class[Rabbitmq::Service]',
265       'refreshonly' => true
266     ) }
267     context 'with file_limit => unlimited' do
268       let(:params) {{ :file_limit => 'unlimited' }}
269       it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
270         'owner'   => '0',
271         'group'   => '0',
272         'mode'    => '0644',
273         'notify'  => 'Exec[rabbitmq-systemd-reload]',
274         'content' => '[Service]
275 LimitNOFILE=unlimited
276 '
277       ) }
278     end
279
280     context 'with file_limit => infinity' do
281       let(:params) {{ :file_limit => 'infinity' }}
282       it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
283         'owner'   => '0',
284         'group'   => '0',
285         'mode'    => '0644',
286         'notify'  => 'Exec[rabbitmq-systemd-reload]',
287         'content' => '[Service]
288 LimitNOFILE=infinity
289 '
290       ) }
291     end
292
293     context 'with file_limit => -1' do
294       let(:params) {{ :file_limit => -1 }}
295       it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
296         'owner'   => '0',
297         'group'   => '0',
298         'mode'    => '0644',
299         'notify'  => 'Exec[rabbitmq-systemd-reload]',
300         'content' => '[Service]
301 LimitNOFILE=-1
302 '
303       ) }
304     end
305
306     context 'with file_limit => \'1234\'' do
307       let(:params) {{ :file_limit => '1234' }}
308       it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
309         'owner'   => '0',
310         'group'   => '0',
311         'mode'    => '0644',
312         'notify'  => 'Exec[rabbitmq-systemd-reload]',
313         'content' => '[Service]
314 LimitNOFILE=1234
315 '
316       ) }
317     end
318
319     context 'with file_limit => foo' do
320       let(:params) {{ :file_limit => 'foo' }}
321       it 'does not compile' do
322         expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
323       end
324     end
325   end
326
327   context 'on RedHat before 7.0' do
328     let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}
329
330     context 'with file_limit => unlimited' do
331       let(:params) {{ :file_limit => 'unlimited' }}
332       it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
333         'owner'   => '0',
334         'group'   => '0',
335         'mode'    => '0644',
336         'notify'  => 'Class[Rabbitmq::Service]',
337         'content' => 'rabbitmq soft nofile unlimited
338 rabbitmq hard nofile unlimited
339 '
340       ) }
341     end
342
343     context 'with file_limit => infinity' do
344       let(:params) {{ :file_limit => 'infinity' }}
345       it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
346         'owner'   => '0',
347         'group'   => '0',
348         'mode'    => '0644',
349         'notify'  => 'Class[Rabbitmq::Service]',
350         'content' => 'rabbitmq soft nofile infinity
351 rabbitmq hard nofile infinity
352 '
353       ) }
354     end
355
356     context 'with file_limit => -1' do
357       let(:params) {{ :file_limit => -1 }}
358       it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
359         'owner'   => '0',
360         'group'   => '0',
361         'mode'    => '0644',
362         'notify'  => 'Class[Rabbitmq::Service]',
363         'content' => 'rabbitmq soft nofile -1
364 rabbitmq hard nofile -1
365 '
366       ) }
367     end
368
369     context 'with file_limit => \'1234\'' do
370       let(:params) {{ :file_limit => '1234' }}
371       it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
372         'owner'   => '0',
373         'group'   => '0',
374         'mode'    => '0644',
375         'notify'  => 'Class[Rabbitmq::Service]',
376         'content' => 'rabbitmq soft nofile 1234
377 rabbitmq hard nofile 1234
378 '
379       ) }
380     end
381
382     context 'with file_limit => foo' do
383       let(:params) {{ :file_limit => 'foo' }}
384       it 'does not compile' do
385         expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
386       end
387     end
388   end
389
390   ['Debian', 'RedHat', 'SUSE', 'Archlinux'].each do |distro|
391     context "on #{distro}" do
392       let(:facts) {{
393         :osfamily => distro,
394         :lsbdistcodename => 'squeeze',
395         :lsbdistid => 'Debian'
396       }}
397
398       it { should contain_class('rabbitmq::install') }
399       it { should contain_class('rabbitmq::config') }
400       it { should contain_class('rabbitmq::service') }
401
402      context 'with admin_enable set to true' do
403         let(:params) {{ :admin_enable => true }}
404         context 'with service_manage set to true' do
405           it 'we enable the admin interface by default' do
406             should contain_class('rabbitmq::install::rabbitmqadmin')
407             should contain_rabbitmq_plugin('rabbitmq_management').with(
408               'require' => 'Class[Rabbitmq::Install]',
409               'notify'  => 'Class[Rabbitmq::Service]'
410             )
411             should contain_staging__file('rabbitmqadmin').with_source("http://guest:guest@localhost:15672/cli/rabbitmqadmin")
412           end
413         end
414         context 'with service_manage set to true and default user/pass specified' do
415           let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2' }}
416           it 'we use the correct URL to rabbitmqadmin' do
417             should contain_staging__file('rabbitmqadmin').with_source("http://foobar:hunter2@localhost:15672/cli/rabbitmqadmin")
418           end
419         end
420         context 'with service_manage set to true and management port specified' do
421           # note that the 2.x management port is 55672 not 15672
422           let(:params) {{ :admin_enable => true, :management_port => '55672' }}
423           it 'we use the correct URL to rabbitmqadmin' do
424             should contain_staging__file('rabbitmqadmin').with_source("http://guest:guest@localhost:55672/cli/rabbitmqadmin")
425           end
426         end
427         context 'with service_manage set to false' do
428           let(:params) {{ :admin_enable => true, :service_manage => false }}
429           it 'should do nothing' do
430             should_not contain_class('rabbitmq::install::rabbitmqadmin')
431             should_not contain_rabbitmq_plugin('rabbitmq_management')
432           end
433         end
434       end
435
436       describe 'manages configuration directory correctly' do
437         it { should contain_file('/etc/rabbitmq').with(
438           'ensure' => 'directory'
439         )}
440       end
441
442       describe 'manages configuration file correctly' do
443         it { should contain_file('rabbitmq.config') }
444       end
445
446       context 'configures config_cluster' do
447         let(:facts) {{ :osfamily => distro, :lsbdistid => 'Debian' }}
448         let(:params) {{
449           :config_cluster           => true,
450           :cluster_nodes            => ['hare-1', 'hare-2'],
451           :cluster_node_type        => 'ram',
452           :wipe_db_on_cookie_change => false
453         }}
454
455         describe 'with defaults' do
456           it 'fails' do
457             expect { catalogue }.to raise_error(Puppet::Error, /You must set the \$erlang_cookie value/)
458           end
459         end
460
461         describe 'with erlang_cookie set' do
462           let(:params) {{
463             :config_cluster           => true,
464             :cluster_nodes            => ['hare-1', 'hare-2'],
465             :cluster_node_type        => 'ram',
466             :erlang_cookie            => 'TESTCOOKIE',
467             :wipe_db_on_cookie_change => true
468           }}
469           it 'contains the rabbitmq_erlang_cookie' do
470             should contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
471           end
472         end
473
474         describe 'and sets appropriate configuration' do
475           let(:params) {{
476             :config_cluster           => true,
477             :cluster_nodes            => ['hare-1', 'hare-2'],
478             :cluster_node_type        => 'ram',
479             :erlang_cookie            => 'ORIGINAL',
480             :wipe_db_on_cookie_change => true
481           }}
482           it 'for cluster_nodes' do
483             should contain_file('rabbitmq.config').with({
484               'content' => /cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram/,
485             })
486           end
487
488         end
489       end
490
491       describe 'rabbitmq-env configuration' do
492         let(:params) {{ :environment_variables => {
493           'NODE_IP_ADDRESS'    => '1.1.1.1',
494           'NODE_PORT'          => '5656',
495           'NODENAME'           => 'HOSTNAME',
496           'SERVICENAME'        => 'RabbitMQ',
497           'CONSOLE_LOG'        => 'RabbitMQ.debug',
498           'CTL_ERL_ARGS'       => 'verbose',
499           'SERVER_ERL_ARGS'    => 'v',
500           'SERVER_START_ARGS'  => 'debug'
501         }}}
502         it 'should set environment variables' do
503           should contain_file('rabbitmq-env.config') \
504             .with_content(/NODE_IP_ADDRESS=1.1.1.1/) \
505             .with_content(/NODE_PORT=5656/) \
506             .with_content(/NODENAME=HOSTNAME/) \
507             .with_content(/SERVICENAME=RabbitMQ/) \
508             .with_content(/CONSOLE_LOG=RabbitMQ.debug/) \
509             .with_content(/CTL_ERL_ARGS=verbose/) \
510             .with_content(/SERVER_ERL_ARGS=v/) \
511             .with_content(/SERVER_START_ARGS=debug/)
512         end
513       end
514
515       context 'delete_guest_user' do
516         describe 'should do nothing by default' do
517           it { should_not contain_rabbitmq_user('guest') }
518         end
519
520         describe 'delete user when delete_guest_user set' do
521           let(:params) {{ :delete_guest_user => true }}
522           it 'removes the user' do
523             should contain_rabbitmq_user('guest').with(
524               'ensure'   => 'absent',
525               'provider' => 'rabbitmqctl'
526             )
527           end
528         end
529       end
530
531       context 'configuration setting' do
532         describe 'node_ip_address when set' do
533           let(:params) {{ :node_ip_address => '172.0.0.1' }}
534           it 'should set NODE_IP_ADDRESS to specified value' do
535             should contain_file('rabbitmq-env.config').
536               with_content(%r{NODE_IP_ADDRESS=172\.0\.0\.1})
537           end
538         end
539
540         describe 'stomp by default' do
541           it 'should not specify stomp parameters in rabbitmq.config' do
542             should contain_file('rabbitmq.config').without({
543               'content' => /stomp/,})
544           end
545         end
546         describe 'stomp when set' do
547           let(:params) {{ :config_stomp => true, :stomp_port => 5679 }}
548           it 'should specify stomp port in rabbitmq.config' do
549             should contain_file('rabbitmq.config').with({
550               'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\]/m,
551             })
552           end
553         end
554         describe 'stomp when set ssl port w/o ssl enabled' do
555           let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => false, :ssl_stomp_port => 5680 }}
556           it 'should not configure ssl_listeners in rabbitmq.config' do
557             should contain_file('rabbitmq.config').without({
558               'content' => /rabbitmq_stomp.*ssl_listeners, \[5680\]/m,
559             })
560           end
561         end
562         describe 'stomp when set with ssl' do
563           let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => true, :ssl_stomp_port => 5680 }}
564           it 'should specify stomp port and ssl stomp port in rabbitmq.config' do
565             should contain_file('rabbitmq.config').with({
566               'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]/m,
567             })
568           end
569         end
570       end
571
572       describe 'configuring ldap authentication' do
573         let :params do
574           { :config_stomp          => true,
575             :ldap_auth             => true,
576             :ldap_server           => 'ldap.example.com',
577             :ldap_user_dn_pattern  => 'ou=users,dc=example,dc=com',
578             :ldap_other_bind       => 'as_user',
579             :ldap_use_ssl          => false,
580             :ldap_port             => '389',
581             :ldap_log              => true,
582             :ldap_config_variables => { 'foo' => 'bar' }
583           }
584         end
585
586         it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
587
588         it 'should contain ldap parameters' do
589           verify_contents(catalogue, 'rabbitmq.config',
590                           ['[', '  {rabbit, [', '    {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', '  ]}',
591                             '  {rabbitmq_auth_backend_ldap, [', '    {other_bind, as_user},',
592                             '    {servers, ["ldap.example.com"]},',
593                             '    {user_dn_pattern, "ou=users,dc=example,dc=com"},', '    {use_ssl, false},',
594                             '    {port, 389},', '    {foo, bar},', '    {log, true}'])
595         end
596       end
597
598       describe 'configuring ldap authentication' do
599         let :params do
600           { :config_stomp         => false,
601             :ldap_auth            => true,
602             :ldap_server          => 'ldap.example.com',
603             :ldap_user_dn_pattern => 'ou=users,dc=example,dc=com',
604             :ldap_other_bind      => 'as_user',
605             :ldap_use_ssl         => false,
606             :ldap_port            => '389',
607             :ldap_log             => true,
608             :ldap_config_variables => { 'foo' => 'bar' }
609           }
610         end
611
612         it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
613
614         it 'should contain ldap parameters' do
615           verify_contents(catalogue, 'rabbitmq.config',
616                           ['[', '  {rabbit, [', '    {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', '  ]}',
617                             '  {rabbitmq_auth_backend_ldap, [', '    {other_bind, as_user},',
618                             '    {servers, ["ldap.example.com"]},',
619                             '    {user_dn_pattern, "ou=users,dc=example,dc=com"},', '    {use_ssl, false},',
620                             '    {port, 389},', '    {foo, bar},', '    {log, true}'])
621         end
622       end
623
624       describe 'default_user and default_pass set' do
625         let(:params) {{ :default_user => 'foo', :default_pass => 'bar' }}
626         it 'should set default_user and default_pass to specified values' do
627           should contain_file('rabbitmq.config').with({
628             'content' => /default_user, <<"foo">>.*default_pass, <<"bar">>/m,
629           })
630         end
631       end
632
633       describe 'interfaces option with no ssl' do
634         let(:params) {
635           { :interface => '0.0.0.0',
636         } }
637
638         it 'should set ssl options to specified values' do
639           should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\{"0.0.0.0", 5672\}\]})
640         end
641       end
642
643       describe 'ssl options' do
644         let(:params) {
645           { :ssl => true,
646             :ssl_port => 3141,
647             :ssl_cacert => '/path/to/cacert',
648             :ssl_cert => '/path/to/cert',
649             :ssl_key => '/path/to/key'
650         } }
651
652         it 'should set ssl options to specified values' do
653           should contain_file('rabbitmq.config').with_content(
654             %r{ssl_listeners, \[3141\]}
655           )
656           should contain_file('rabbitmq.config').with_content(
657             %r{ssl_options, \[}
658           )
659           should contain_file('rabbitmq.config').with_content(
660             %r{cacertfile,"/path/to/cacert"}
661           )
662           should contain_file('rabbitmq.config').with_content(
663             %r{certfile,"/path/to/cert"}
664           )
665           should contain_file('rabbitmq.config').with_content(
666             %r{keyfile,"/path/to/key"}
667           )
668         end
669       end
670
671
672       describe 'ssl options with ssl_interfaces' do
673         let(:params) {
674           { :ssl => true,
675             :ssl_port => 3141,
676             :ssl_interface => '0.0.0.0',
677             :ssl_cacert => '/path/to/cacert',
678             :ssl_cert => '/path/to/cert',
679             :ssl_key => '/path/to/key'
680         } }
681
682         it 'should set ssl options to specified values' do
683           should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]})
684           should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
685           should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
686           should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
687         end
688       end
689
690
691
692       describe 'ssl options with ssl_only' do
693         let(:params) {
694           { :ssl => true,
695             :ssl_only => true,
696             :ssl_port => 3141,
697             :ssl_cacert => '/path/to/cacert',
698             :ssl_cert => '/path/to/cert',
699             :ssl_key => '/path/to/key'
700         } }
701
702         it 'should set ssl options to specified values' do
703           should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]})
704           should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]})
705           should contain_file('rabbitmq.config').with_content(%r{ssl_options, \[})
706           should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
707           should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
708           should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
709         end
710       end
711
712       describe 'ssl options with ssl_only and ssl_interfaces' do
713         let(:params) {
714           { :ssl => true,
715             :ssl_only => true,
716             :ssl_port => 3141,
717             :ssl_interface => '0.0.0.0',
718             :ssl_cacert => '/path/to/cacert',
719             :ssl_cert => '/path/to/cert',
720             :ssl_key => '/path/to/key'
721         } }
722
723         it 'should set ssl options to specified values' do
724           should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]})
725           should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]})
726           should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
727           should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
728           should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
729         end
730       end
731
732       describe 'ssl options with specific ssl versions' do
733         let(:params) {
734           { :ssl => true,
735             :ssl_port => 3141,
736             :ssl_cacert => '/path/to/cacert',
737             :ssl_cert => '/path/to/cert',
738             :ssl_key => '/path/to/key',
739             :ssl_versions => ['tlsv1.2', 'tlsv1.1']
740         } }
741
742         it 'should set ssl options to specified values' do
743           should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]})
744           should contain_file('rabbitmq.config').with_content(%r{ssl_options, \[})
745           should contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
746           should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
747           should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
748           should contain_file('rabbitmq.config').with_content(%r{ssl, \[\{versions, \['tlsv1.1', 'tlsv1.2'\]\}\]})
749           should contain_file('rabbitmq.config').with_content(%r{versions, \['tlsv1.1', 'tlsv1.2'\]})
750         end
751       end
752
753       describe 'ssl options with invalid ssl_versions type' do
754         let(:params) {
755           { :ssl => true,
756             :ssl_port => 3141,
757             :ssl_cacert => '/path/to/cacert',
758             :ssl_cert => '/path/to/cert',
759             :ssl_key => '/path/to/key',
760             :ssl_versions => 'tlsv1.2, tlsv1.1'
761         } }
762
763         it 'fails' do
764           expect { catalogue }.to raise_error(Puppet::Error, /is not an Array/)
765         end
766       end
767
768       describe 'ssl options with ssl_versions and not ssl' do
769         let(:params) {
770           { :ssl => false,
771             :ssl_port => 3141,
772             :ssl_cacert => '/path/to/cacert',
773             :ssl_cert => '/path/to/cert',
774             :ssl_key => '/path/to/key',
775             :ssl_versions => ['tlsv1.2', 'tlsv1.1']
776         } }
777
778         it 'fails' do
779           expect { catalogue }.to raise_error(Puppet::Error, /\$ssl_versions requires that \$ssl => true/)
780         end
781       end
782
783       describe 'ssl options with ssl ciphers' do
784         let(:params) {
785           { :ssl => true,
786             :ssl_port => 3141,
787             :ssl_cacert => '/path/to/cacert',
788             :ssl_cert => '/path/to/cert',
789             :ssl_key => '/path/to/key',
790             :ssl_ciphers => ['ecdhe_rsa,aes_256_cbc,sha', 'dhe_rsa,aes_256_cbc,sha']
791         } }
792
793         it 'should set ssl ciphers to specified values' do
794           should contain_file('rabbitmq.config').with_content(%r{ciphers,\[[[:space:]]+{dhe_rsa,aes_256_cbc,sha},[[:space:]]+{ecdhe_rsa,aes_256_cbc,sha}[[:space:]]+\]})
795         end
796       end
797
798       describe 'ssl admin options with specific ssl versions' do
799         let(:params) {
800           { :ssl => true,
801             :ssl_management_port => 5926,
802             :ssl_cacert => '/path/to/cacert',
803             :ssl_cert => '/path/to/cert',
804             :ssl_key => '/path/to/key',
805             :ssl_versions => ['tlsv1.2', 'tlsv1.1'],
806             :admin_enable => true
807         } }
808
809         it 'should set admin ssl opts to specified values' do
810           should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
811           should contain_file('rabbitmq.config').with_content(%r{listener, \[})
812           should contain_file('rabbitmq.config').with_content(%r{port, 5926\}})
813           should contain_file('rabbitmq.config').with_content(%r{ssl, true\}})
814           should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[\{cacertfile, "/path/to/cacert"\},})
815           should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
816           should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}})
817           should contain_file('rabbitmq.config').with_content(%r{,\{versions, \['tlsv1.1', 'tlsv1.2'\]\}[\r\n ]*\]\}})
818         end
819       end
820
821       describe 'ssl admin options' do
822         let(:params) {
823           { :ssl => true,
824             :ssl_management_port => 3141,
825             :ssl_cacert => '/path/to/cacert',
826             :ssl_cert => '/path/to/cert',
827             :ssl_key => '/path/to/key',
828             :admin_enable => true
829         } }
830
831         it 'should set rabbitmq_management ssl options to specified values' do
832           should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
833           should contain_file('rabbitmq.config').with_content(%r{listener, \[})
834           should contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
835           should contain_file('rabbitmq.config').with_content(%r{ssl, true\}})
836           should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[\{cacertfile, "/path/to/cacert"\},})
837           should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
838           should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}[\r\n ]*\]\}})
839         end
840       end
841
842       describe 'admin without ssl' do
843         let(:params) {
844           { :ssl => false,
845             :management_port => 3141,
846             :admin_enable => true
847         } }
848
849         it 'should set rabbitmq_management  options to specified values' do
850           should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
851           should contain_file('rabbitmq.config').with_content(%r{listener, \[})
852           should contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
853         end
854       end
855
856       describe 'ssl admin options' do
857         let(:params) {
858           { :ssl => true,
859             :ssl_management_port => 3141,
860             :ssl_cacert => '/path/to/cacert',
861             :ssl_cert => '/path/to/cert',
862             :ssl_key => '/path/to/key',
863             :admin_enable => true
864         } }
865
866         it 'should set rabbitmq_management ssl options to specified values' do
867           should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
868           should contain_file('rabbitmq.config').with_content(%r{listener, \[})
869           should contain_file('rabbitmq.config').with_content(%r{port, 3141\},})
870           should contain_file('rabbitmq.config').with_content(%r{ssl, true\},})
871           should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[\{cacertfile, "/path/to/cacert"\},})
872           should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
873           should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}[\r\n ]*\]\}})
874         end
875       end
876
877       describe 'admin without ssl' do
878         let(:params) {
879           { :ssl => false,
880             :management_port => 3141,
881             :admin_enable => true
882         } }
883
884         it 'should set rabbitmq_management  options to specified values' do
885           should contain_file('rabbitmq.config') \
886             .with_content(/\{rabbitmq_management, \[/) \
887             .with_content(/\{listener, \[/) \
888             .with_content(/\{port, 3141\}/)
889         end
890       end
891
892       describe 'config_variables options' do
893         let(:params) {{ :config_variables => {
894             'hipe_compile'                  => true,
895             'vm_memory_high_watermark'      => 0.4,
896             'frame_max'                     => 131072,
897             'collect_statistics'            => "none",
898             'auth_mechanisms'               => "['PLAIN', 'AMQPLAIN']",
899         }}}
900         it 'should set environment variables' do
901           should contain_file('rabbitmq.config') \
902             .with_content(/\{hipe_compile, true\}/) \
903             .with_content(/\{vm_memory_high_watermark, 0.4\}/) \
904             .with_content(/\{frame_max, 131072\}/) \
905             .with_content(/\{collect_statistics, none\}/) \
906             .with_content(/\{auth_mechanisms, \['PLAIN', 'AMQPLAIN'\]\}/)
907         end
908       end
909
910       describe 'config_kernel_variables options' do
911         let(:params) {{ :config_kernel_variables => {
912             'inet_dist_listen_min'      => 9100,
913             'inet_dist_listen_max'      => 9105,
914         }}}
915         it 'should set config variables' do
916           should contain_file('rabbitmq.config') \
917             .with_content(/\{inet_dist_listen_min, 9100\}/) \
918             .with_content(/\{inet_dist_listen_max, 9105\}/)
919         end
920       end
921
922       describe 'tcp_keepalive enabled' do
923         let(:params) {{ :tcp_keepalive => true }}
924         it 'should set tcp_listen_options keepalive true' do
925           should contain_file('rabbitmq.config') \
926             .with_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/)
927         end
928       end
929
930       describe 'tcp_keepalive disabled (default)' do
931         it 'should not set tcp_listen_options' do
932           should contain_file('rabbitmq.config') \
933             .without_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/)
934         end
935       end
936
937       describe 'non-bool tcp_keepalive parameter' do
938         let :params do
939           { :tcp_keepalive => 'string' }
940         end
941
942         it 'should raise an error' do
943           expect {
944             should contain_file('rabbitmq.config')
945           }.to raise_error(Puppet::Error, /is not a boolean/)
946         end
947       end
948
949       context 'delete_guest_user' do
950         describe 'should do nothing by default' do
951           it { should_not contain_rabbitmq_user('guest') }
952         end
953
954         describe 'delete user when delete_guest_user set' do
955           let(:params) {{ :delete_guest_user => true }}
956           it 'removes the user' do
957             should contain_rabbitmq_user('guest').with(
958               'ensure'   => 'absent',
959               'provider' => 'rabbitmqctl'
960             )
961           end
962         end
963       end
964
965       ##
966       ## rabbitmq::service
967       ##
968       describe 'service with default params' do
969         it { should contain_service('rabbitmq-server').with(
970           'ensure'     => 'running',
971           'enable'     => 'true',
972           'hasstatus'  => 'true',
973           'hasrestart' => 'true'
974         )}
975       end
976
977       describe 'service with ensure stopped' do
978         let :params do
979           { :service_ensure => 'stopped' }
980         end
981
982         it { should contain_service('rabbitmq-server').with(
983           'ensure'    => 'stopped',
984           'enable'    => false
985         ) }
986       end
987
988       describe 'service with ensure neither running neither stopped' do
989         let :params do
990           { :service_ensure => 'foo' }
991         end
992
993         it 'should raise an error' do
994           expect {
995             should contain_service('rabbitmq-server').with(
996               'ensure' => 'stopped' )
997           }.to raise_error(Puppet::Error, /validate_re\(\): "foo" does not match "\^\(running\|stopped\)\$"/)
998         end
999       end
1000
1001       describe 'service with service_manage equal to false' do
1002         let :params do
1003           { :service_manage => false }
1004         end
1005
1006         it { should_not contain_service('rabbitmq-server') }
1007       end
1008
1009     end
1010   end
1011
1012   ##
1013   ## rabbitmq::install
1014   ##
1015   context "on RHEL" do
1016     let(:facts) {{ :osfamily => 'RedHat' }}
1017     let(:params) {{ :package_source => 'http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.3/rabbitmq-server-3.2.3-1.noarch.rpm' }}
1018     it 'installs the rabbitmq package' do
1019       should contain_package('rabbitmq-server').with(
1020         'ensure'   => 'installed',
1021         'name'     => 'rabbitmq-server',
1022         'provider' => 'rpm',
1023         'source'   => 'http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.3/rabbitmq-server-3.2.3-1.noarch.rpm'
1024       )
1025     end
1026   end
1027
1028   context "on Debian" do
1029     let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'precise' }}
1030     it 'installs the rabbitmq package' do
1031       should contain_package('rabbitmq-server').with(
1032         'ensure'   => 'installed',
1033         'name'     => 'rabbitmq-server',
1034         'provider' => 'apt'
1035       )
1036     end
1037   end
1038
1039   context "on Archlinux" do
1040     let(:facts) {{ :osfamily => 'Archlinux' }}
1041     it 'installs the rabbitmq package' do
1042       should contain_package('rabbitmq-server').with(
1043         'ensure'   => 'installed',
1044         'name'     => 'rabbitmq')
1045     end
1046   end
1047
1048   describe 'repo management on Debian' do
1049     let(:facts)  {{ :osfamily => 'Debian', :lsbdistid => 'Debian' }}
1050
1051     context 'with no pin' do
1052       let(:params) {{ :package_apt_pin => '' }}
1053       describe 'it sets up an apt::source' do
1054
1055         it { should contain_apt__source('rabbitmq').with(
1056           'location'    => 'http://www.rabbitmq.com/debian/',
1057           'release'     => 'testing',
1058           'repos'       => 'main',
1059           'include_src' => false,
1060           'key'         => 'F78372A06FF50C80464FC1B4F7B8CEA6056E8E56'
1061         ) }
1062       end
1063     end
1064
1065     context 'with pin' do
1066       let(:params) {{ :package_apt_pin => '700' }}
1067       describe 'it sets up an apt::source and pin' do
1068
1069         it { should contain_apt__source('rabbitmq').with(
1070           'location'    => 'http://www.rabbitmq.com/debian/',
1071           'release'     => 'testing',
1072           'repos'       => 'main',
1073           'include_src' => false,
1074           'key'         => 'F78372A06FF50C80464FC1B4F7B8CEA6056E8E56'
1075         ) }
1076
1077         it { should contain_apt__pin('rabbitmq').with(
1078           'packages' => 'rabbitmq-server',
1079           'priority' => '700'
1080         ) }
1081
1082       end
1083     end
1084   end
1085
1086   ['RedHat', 'SuSE'].each do |distro|
1087     describe "repo management on #{distro}" do
1088       describe 'imports the key' do
1089         let(:facts) {{ :osfamily => distro }}
1090         let(:params) {{ :package_gpg_key => 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc' }}
1091
1092         it { should contain_exec("rpm --import #{params[:package_gpg_key]}").with(
1093           'path' => ['/bin','/usr/bin','/sbin','/usr/sbin']
1094         ) }
1095       end
1096     end
1097   end
1098
1099 end