Note that exim contains tracker-specific configuration
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / classes / rabbitmq_spec.rb
1 require 'spec_helper'
2
3 describe 'rabbitmq' do
4   context 'on unsupported distributions' do
5     let(:facts) do
6       {
7         os: { family: 'Unsupported' }
8       }
9     end
10
11     it 'we fail' do
12       expect { catalogue }.to raise_error(Puppet::Error, %r{not supported on an Unsupported})
13     end
14   end
15
16   # TODO: get Archlinux & OpenBSD facts from facterdb
17
18   on_supported_os.each do |os, facts|
19     context "on #{os}" do
20       let(:facts) { facts }
21
22       packagename = case facts[:osfamily]
23                     when 'Archlinux'
24                       'rabbitmq'
25                     else
26                       'rabbitmq-server'
27                     end
28       has_systemd = (
29         (facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
30         (facts[:os]['family'] == 'Debian' && facts[:os]['release']['full'] == '16.04') ||
31         (facts[:os]['family'] == 'Archlinux')
32       )
33
34       it { is_expected.to compile.with_all_deps }
35       it { is_expected.to contain_class('rabbitmq::install') }
36       it { is_expected.to contain_class('rabbitmq::config') }
37       it { is_expected.to contain_class('rabbitmq::service') }
38
39       it { is_expected.to contain_package(packagename).with_ensure('installed').with_name(packagename) }
40       if facts[:os]['family'] == 'Suse'
41         it { is_expected.to contain_package('rabbitmq-server-plugins') }
42       end
43
44       context 'with default params' do
45         it { is_expected.not_to contain_class('rabbitmq::repo::apt') }
46         it { is_expected.not_to contain_apt__source('rabbitmq') }
47         it { is_expected.not_to contain_class('rabbitmq::repo::rhel') }
48         it { is_expected.not_to contain_yumrepo('rabbitmq') }
49       end
50
51       context 'with repos_ensure => true' do
52         let(:params) { { repos_ensure: true } }
53
54         if facts[:os]['family'] == 'Debian'
55           it 'includes rabbitmq::repo::apt' do
56             is_expected.to contain_class('rabbitmq::repo::apt').
57               with_key_source('https://packagecloud.io/gpg.key').
58               with_key_content(nil)
59           end
60
61           it 'adds a repo with default values' do
62             is_expected.to contain_apt__source('rabbitmq').
63               with_ensure('present').
64               with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}").
65               with_release(nil).
66               with_repos('main')
67           end
68         else
69           it { is_expected.not_to contain_class('rabbitmq::repo::apt') }
70           it { is_expected.not_to contain_apt__souce('rabbitmq') }
71         end
72
73         if facts[:os]['family'] == 'RedHat'
74           it { is_expected.to contain_class('rabbitmq::repo::rhel') }
75
76           it 'the repo should be present, and contain the expected values' do
77             is_expected.to contain_yumrepo('rabbitmq').
78               with_ensure('present').
79               with_baseurl(%r{https://packagecloud.io/rabbitmq/rabbitmq-server/el/\d+/\$basearch$}).
80               with_gpgkey('https://www.rabbitmq.com/rabbitmq-release-signing-key.asc')
81           end
82         else
83           it { is_expected.not_to contain_class('rabbitmq::repo::rhel') }
84           it { is_expected.not_to contain_yumrepo('rabbitmq') }
85         end
86       end
87
88       context 'with no pin', if: facts[:os]['family'] == 'Debian' do
89         let(:params) { { repos_ensure: true, package_apt_pin: '' } }
90
91         describe 'it sets up an apt::source' do
92           it {
93             is_expected.to contain_apt__source('rabbitmq').with(
94               'location'    => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}",
95               'repos'       => 'main',
96               'key'         => '{"id"=>"418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB", "source"=>"https://packagecloud.io/gpg.key", "content"=>:undef}'
97             )
98           }
99         end
100       end
101
102       context 'with pin', if: facts[:os]['family'] == 'Debian' do
103         let(:params) { { repos_ensure: true, package_apt_pin: '700' } }
104
105         describe 'it sets up an apt::source and pin' do
106           it {
107             is_expected.to contain_apt__source('rabbitmq').with(
108               'location'    => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}",
109               'repos'       => 'main',
110               'key'         => '{"id"=>"418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB", "source"=>"https://packagecloud.io/gpg.key", "content"=>:undef}'
111             )
112           }
113
114           it {
115             is_expected.to contain_apt__pin('rabbitmq').with(
116               'packages' => '*',
117               'priority' => '700',
118               'origin'   => 'packagecloud.io'
119             )
120           }
121         end
122       end
123
124       ['unlimited', 'infinity', -1, 1234].each do |value|
125         context "with file_limit => '#{value}'" do
126           let(:params) { { file_limit: value } }
127
128           if facts[:os]['family'] == 'RedHat'
129             it do
130               is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').
131                 with_owner('0').
132                 with_group('0').
133                 with_mode('0644').
134                 that_notifies('Class[Rabbitmq::Service]').
135                 with_content("rabbitmq soft nofile #{value}\nrabbitmq hard nofile #{value}\n")
136             end
137           else
138             it { is_expected.not_to contain_file('/etc/security/limits.d/rabbitmq-server.conf') }
139           end
140
141           if facts[:os]['family'] == 'Debian'
142             it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n #{value}}) }
143           else
144             it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
145           end
146
147           if has_systemd
148             it do
149               is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf").
150                 with_owner('0').
151                 with_group('0').
152                 with_mode('0644').
153                 that_notifies('Exec[rabbitmq-systemd-reload]').
154                 with_content("[Service]\nLimitNOFILE=#{value}\n")
155             end
156           else
157             it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
158           end
159         end
160       end
161
162       [-42, '-42', 'foo', '42'].each do |value|
163         context "with file_limit => '#{value}'" do
164           let(:params) { { file_limit: value } }
165
166           it 'does not compile' do
167             expect { catalogue }.to raise_error(Puppet::PreformattedError, %r{Error while evaluating a Resource Statement})
168           end
169         end
170       end
171
172       context 'on systems with systemd', if: has_systemd do
173         it {
174           is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d").with(
175             'ensure'                  => 'directory',
176             'owner'                   => '0',
177             'group'                   => '0',
178             'mode'                    => '0755',
179             'selinux_ignore_defaults' => true
180           )
181         }
182
183         it { is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf") }
184
185         it {
186           is_expected.to contain_exec('rabbitmq-systemd-reload').with(
187             command: '/bin/systemctl daemon-reload',
188             notify: 'Class[Rabbitmq::Service]',
189             refreshonly: true
190           )
191         }
192       end
193
194       context 'on systems without systemd', unless: has_systemd do
195         it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d') }
196         it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
197         it { is_expected.not_to contain_exec('rabbitmq-systemd-reload') }
198       end
199
200       context 'with admin_enable set to true' do
201         let(:params) { { admin_enable: true, management_ip_address: '1.1.1.1' } }
202
203         context 'with service_manage set to true' do
204           let(:params) { { admin_enable: true, management_ip_address: '1.1.1.1', service_manage: true } }
205
206           context 'with rabbitmqadmin_package set to blub' do
207             let(:params) { { rabbitmqadmin_package: 'blub' } }
208
209             it 'installs a package called blub' do
210               is_expected.to contain_package('rabbitmqadmin').with_name('blub')
211             end
212           end
213           if facts[:os]['family'] == 'Archlinux'
214             it 'installs a package called rabbitmqadmin' do
215               is_expected.to contain_package('rabbitmqadmin').with_name('rabbitmqadmin')
216             end
217           else
218             it 'we enable the admin interface by default' do
219               is_expected.to contain_class('rabbitmq::install::rabbitmqadmin')
220               is_expected.to contain_rabbitmq_plugin('rabbitmq_management').with(
221                 notify: 'Class[Rabbitmq::Service]'
222               )
223               is_expected.to contain_archive('rabbitmqadmin').with_source('http://1.1.1.1:15672/cli/rabbitmqadmin')
224             end
225           end
226           if %w[RedHat Debian SUSE].include?(facts[:os]['family'])
227             it { is_expected.to contain_package('python') }
228           end
229           if %w[FreeBSD OpenBSD].include?(facts[:os]['family'])
230             it { is_expected.to contain_package('python2') }
231           end
232         end
233         context 'with manage_python false' do
234           let(:params) { { manage_python: false } }
235
236           it do
237             is_expected.to contain_class('rabbitmq::install::rabbitmqadmin')
238             is_expected.not_to contain_package('python')
239             is_expected.not_to contain_package('python2')
240           end
241         end
242
243         context 'with $management_ip_address undef and service_manage set to true', unless: facts[:osfamily] == 'Archlinux' do
244           let(:params) { { admin_enable: true, management_ip_address: :undef } }
245
246           it 'we enable the admin interface by default' do
247             is_expected.to contain_class('rabbitmq::install::rabbitmqadmin')
248             is_expected.to contain_rabbitmq_plugin('rabbitmq_management').with(
249               notify: 'Class[Rabbitmq::Service]'
250             )
251             is_expected.to contain_archive('rabbitmqadmin').with_source('http://127.0.0.1:15672/cli/rabbitmqadmin')
252           end
253         end
254         context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do
255           let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', node_ip_address: :undef } }
256
257           it 'we use the correct URL to rabbitmqadmin' do
258             is_expected.to contain_archive('rabbitmqadmin').with(
259               source: 'http://127.0.0.1:15672/cli/rabbitmqadmin',
260               username: 'foobar',
261               password: 'hunter2'
262             )
263           end
264         end
265         context 'with service_manage set to true and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do
266           let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', management_ip_address: '1.1.1.1' } }
267
268           it 'we use the correct URL to rabbitmqadmin' do
269             is_expected.to contain_archive('rabbitmqadmin').with(
270               source: 'http://1.1.1.1:15672/cli/rabbitmqadmin',
271               username: 'foobar',
272               password: 'hunter2'
273             )
274           end
275         end
276         context 'with service_manage set to true and archive_options set', unless: facts[:osfamily] == 'Archlinux' do
277           let(:params) do
278             {
279               admin_enable: true,
280               management_ip_address: '1.1.1.1',
281               archive_options: %w[fizz pop]
282             }
283           end
284
285           it 'we use the correct archive_options to rabbitmqadmin' do
286             is_expected.to contain_archive('rabbitmqadmin').with(
287               source: 'http://1.1.1.1:15672/cli/rabbitmqadmin',
288               download_options: %w[fizz pop]
289             )
290           end
291         end
292         context 'with service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do
293           # note that the 2.x management port is 55672 not 15672
294           let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '1.1.1.1' } }
295
296           it 'we use the correct URL to rabbitmqadmin' do
297             is_expected.to contain_archive('rabbitmqadmin').with(
298               source: 'http://1.1.1.1:55672/cli/rabbitmqadmin',
299               username: 'guest',
300               password: 'guest'
301             )
302           end
303         end
304         context 'with ipv6, service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do
305           # note that the 2.x management port is 55672 not 15672
306           let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '::1' } }
307
308           it 'we use the correct URL to rabbitmqadmin' do
309             is_expected.to contain_archive('rabbitmqadmin').with(
310               source: 'http://[::1]:55672/cli/rabbitmqadmin',
311               username: 'guest',
312               password: 'guest'
313             )
314           end
315         end
316         context 'with service_manage set to false' do
317           let(:params) { { admin_enable: true, service_manage: false } }
318
319           it 'does nothing' do
320             is_expected.not_to contain_class('rabbitmq::install::rabbitmqadmin')
321             is_expected.not_to contain_rabbitmq_plugin('rabbitmq_management')
322           end
323         end
324       end
325
326       describe 'manages configuration directory correctly' do
327         it {
328           is_expected.to contain_file('/etc/rabbitmq').with(
329             'ensure' => 'directory',
330             'mode'   => '0755'
331           )
332         }
333       end
334
335       describe 'manages configuration file correctly' do
336         it {
337           is_expected.to contain_file('rabbitmq.config').with(
338             'owner' => '0',
339             'group' => 'rabbitmq',
340             'mode'  => '0640'
341           )
342         }
343       end
344
345       describe 'does not contain pre-ranch settings with default config' do
346         it do
347           is_expected.to contain_file('rabbitmq.config'). \
348             without_content(%r{binary,}).                 \
349             without_content(%r{\{packet,        raw\},}). \
350             without_content(%r{\{reuseaddr,     true\},})
351         end
352       end
353
354       describe 'contains pre-ranch settings with config_ranch set to false' do
355         let(:params) { { config_ranch: false } }
356
357         it do
358           is_expected.to contain_file('rabbitmq.config'). \
359             with_content(%r{binary,}).                 \
360             with_content(%r{\{packet,        raw\},}). \
361             with_content(%r{\{reuseaddr,     true\},})
362         end
363       end
364
365       context 'configures config_cluster' do
366         let(:params) do
367           {
368             config_cluster: true,
369             cluster_nodes: ['hare-1', 'hare-2'],
370             cluster_node_type: 'ram',
371             wipe_db_on_cookie_change: false
372           }
373         end
374
375         describe 'with erlang_cookie set' do
376           let(:params) do
377             {
378               config_cluster: true,
379               cluster_nodes: ['hare-1', 'hare-2'],
380               cluster_node_type: 'ram',
381               erlang_cookie: 'TESTCOOKIE',
382               wipe_db_on_cookie_change: true
383             }
384           end
385
386           it 'contains the rabbitmq_erlang_cookie' do
387             is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
388           end
389         end
390
391         describe 'with erlang_cookie set but without config_cluster' do
392           let(:params) do
393             {
394               config_cluster: false,
395               erlang_cookie: 'TESTCOOKIE'
396             }
397           end
398
399           it 'contains the rabbitmq_erlang_cookie' do
400             is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
401           end
402         end
403
404         describe 'without erlang_cookie and without config_cluster' do
405           let(:params) do
406             {
407               config_cluster: false
408             }
409           end
410
411           it 'contains the rabbitmq_erlang_cookie' do
412             is_expected.not_to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
413           end
414         end
415
416         describe 'and sets appropriate configuration' do
417           let(:params) do
418             {
419               config_cluster: true,
420               cluster_nodes: ['hare-1', 'hare-2'],
421               cluster_node_type: 'ram',
422               erlang_cookie: 'ORIGINAL',
423               wipe_db_on_cookie_change: true
424             }
425           end
426
427           it 'for cluster_nodes' do
428             is_expected.to contain_file('rabbitmq.config').with('content' => %r{cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram})
429           end
430         end
431       end
432
433       describe 'rabbitmq-env configuration' do
434         context 'with default params' do
435           it 'sets environment variables' do
436             is_expected.to contain_file('rabbitmq-env.config'). \
437               with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc})
438           end
439         end
440
441         context 'with environment_variables set' do
442           let(:params) do
443             { environment_variables: {
444               'NODE_IP_ADDRESS' => '1.1.1.1',
445               'NODE_PORT'          => '5656',
446               'NODENAME'           => 'HOSTNAME',
447               'SERVICENAME'        => 'RabbitMQ',
448               'CONSOLE_LOG'        => 'RabbitMQ.debug',
449               'CTL_ERL_ARGS'       => 'verbose',
450               'SERVER_ERL_ARGS'    => 'v',
451               'SERVER_START_ARGS'  => 'debug'
452             } }
453           end
454
455           it 'sets environment variables' do
456             is_expected.to contain_file('rabbitmq-env.config'). \
457               with_content(%r{NODE_IP_ADDRESS=1.1.1.1}). \
458               with_content(%r{NODE_PORT=5656}). \
459               with_content(%r{NODENAME=HOSTNAME}). \
460               with_content(%r{SERVICENAME=RabbitMQ}). \
461               with_content(%r{CONSOLE_LOG=RabbitMQ.debug}). \
462               with_content(%r{CTL_ERL_ARGS=verbose}). \
463               with_content(%r{SERVER_ERL_ARGS=v}). \
464               with_content(%r{SERVER_START_ARGS=debug})
465           end
466         end
467       end
468
469       context 'delete_guest_user' do
470         describe 'should do nothing by default' do
471           it { is_expected.not_to contain_rabbitmq_user('guest') }
472         end
473
474         describe 'delete user when delete_guest_user set' do
475           let(:params) { { delete_guest_user: true } }
476
477           it 'removes the user' do
478             is_expected.to contain_rabbitmq_user('guest').with(
479               'ensure'   => 'absent',
480               'provider' => 'rabbitmqctl'
481             )
482           end
483         end
484       end
485
486       context 'configuration setting' do
487         describe 'node_ip_address when set' do
488           let(:params) { { node_ip_address: '172.0.0.1' } }
489
490           it 'sets NODE_IP_ADDRESS to specified value' do
491             is_expected.to contain_file('rabbitmq-env.config').
492               with_content(%r{NODE_IP_ADDRESS=172\.0\.0\.1})
493           end
494         end
495
496         describe 'stomp by default' do
497           it 'does not specify stomp parameters in rabbitmq.config' do
498             is_expected.to contain_file('rabbitmq.config').without('content' => %r{stomp})
499           end
500         end
501         describe 'stomp when set' do
502           let(:params) { { config_stomp: true, stomp_port: 5679 } }
503
504           it 'specifies stomp port in rabbitmq.config' do
505             is_expected.to contain_file('rabbitmq.config').with('content' => %r{rabbitmq_stomp.*tcp_listeners, \[5679\]}m)
506           end
507         end
508         describe 'stomp when set ssl port w/o ssl enabled' do
509           let(:params) { { config_stomp: true, stomp_port: 5679, ssl: false, ssl_stomp_port: 5680 } }
510
511           it 'does not configure ssl_listeners in rabbitmq.config' do
512             is_expected.to contain_file('rabbitmq.config').without('content' => %r{rabbitmq_stomp.*ssl_listeners, \[5680\]}m)
513           end
514         end
515         describe 'stomp when set with ssl' do
516           let(:params) { { config_stomp: true, stomp_port: 5679, ssl: true, ssl_stomp_port: 5680 } }
517
518           it 'specifies stomp port and ssl stomp port in rabbitmq.config' do
519             is_expected.to contain_file('rabbitmq.config').with('content' => %r{rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]}m)
520           end
521         end
522       end
523
524       describe 'configuring ldap authentication' do
525         let :params do
526           { config_stomp: true,
527             ldap_auth: true,
528             ldap_server: 'ldap.example.com',
529             ldap_user_dn_pattern: 'ou=users,dc=example,dc=com',
530             ldap_other_bind: 'as_user',
531             ldap_use_ssl: false,
532             ldap_port: 389,
533             ldap_log: true,
534             ldap_config_variables: { 'foo' => 'bar' } }
535         end
536
537         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
538
539         it 'contains ldap parameters' do
540           verify_contents(catalogue, 'rabbitmq.config',
541                           ['[', '  {rabbit, [', '    {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', '  ]}',
542                            '  {rabbitmq_auth_backend_ldap, [', '    {other_bind, as_user},',
543                            '    {servers, ["ldap.example.com"]},',
544                            '    {user_dn_pattern, "ou=users,dc=example,dc=com"},', '    {use_ssl, false},',
545                            '    {port, 389},', '    {foo, bar},', '    {log, true}'])
546         end
547       end
548
549       describe 'configuring ldap authentication' do
550         let :params do
551           { config_stomp: false,
552             ldap_auth: true,
553             ldap_server: 'ldap.example.com',
554             ldap_user_dn_pattern: 'ou=users,dc=example,dc=com',
555             ldap_other_bind: 'as_user',
556             ldap_use_ssl: false,
557             ldap_port: 389,
558             ldap_log: true,
559             ldap_config_variables: { 'foo' => 'bar' } }
560         end
561
562         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
563
564         it 'contains ldap parameters' do
565           verify_contents(catalogue, 'rabbitmq.config',
566                           ['[', '  {rabbit, [', '    {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', '  ]}',
567                            '  {rabbitmq_auth_backend_ldap, [', '    {other_bind, as_user},',
568                            '    {servers, ["ldap.example.com"]},',
569                            '    {user_dn_pattern, "ou=users,dc=example,dc=com"},', '    {use_ssl, false},',
570                            '    {port, 389},', '    {foo, bar},', '    {log, true}'])
571         end
572       end
573
574       describe 'configuring ldap authentication' do
575         let :params do
576           { config_stomp: false,
577             ldap_auth: true,
578             ldap_server: 'ldap.example.com',
579             ldap_other_bind: 'as_user',
580             ldap_use_ssl: false,
581             ldap_port: 389,
582             ldap_log: true,
583             ldap_config_variables: { 'foo' => 'bar' } }
584         end
585
586         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
587
588         it 'does not set user_dn_pattern when none is specified' 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                            '    {use_ssl, false},',
594                            '    {port, 389},', '    {foo, bar},', '    {log, true}'])
595           content = catalogue.resource('file', 'rabbitmq.config').send(:parameters)[:content]
596           expect(content).not_to include 'user_dn_pattern'
597         end
598       end
599
600       describe 'configuring auth_backends' do
601         let :params do
602           { auth_backends: ['{baz, foo}', 'bar'] }
603         end
604
605         it 'contains auth_backends' do
606           verify_contents(catalogue, 'rabbitmq.config',
607                           ['    {auth_backends, [{baz, foo}, bar]},'])
608         end
609       end
610
611       describe 'auth_backends overrides ldap_auth' do
612         let :params do
613           { auth_backends: ['{baz, foo}', 'bar'],
614             ldap_auth: true }
615         end
616
617         it 'contains auth_backends' do
618           verify_contents(catalogue, 'rabbitmq.config',
619                           ['    {auth_backends, [{baz, foo}, bar]},'])
620         end
621       end
622
623       describe 'configuring shovel plugin' do
624         let :params do
625           {
626             config_shovel: true
627           }
628         end
629
630         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel') }
631
632         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel_management') }
633
634         describe 'with admin_enable false' do
635           let :params do
636             {
637               config_shovel: true,
638               admin_enable: false
639             }
640           end
641
642           it { is_expected.not_to contain_rabbitmq_plugin('rabbitmq_shovel_management') }
643         end
644
645         describe 'with static shovels' do
646           let :params do
647             {
648               config_shovel: true,
649               config_shovel_statics: {
650                 'shovel_first' => '{sources,[{broker,"amqp://"}]},
651         {destinations,[{broker,"amqp://site1.example.com"}]},
652         {queue,<<"source_one">>}',
653                 'shovel_second' => '{sources,[{broker,"amqp://"}]},
654         {destinations,[{broker,"amqp://site2.example.com"}]},
655         {queue,<<"source_two">>}'
656               }
657             }
658           end
659
660           it 'generates correct configuration' do
661             verify_contents(catalogue, 'rabbitmq.config', [
662                               '  {rabbitmq_shovel,',
663                               '    [{shovels,[',
664                               '      {shovel_first,[{sources,[{broker,"amqp://"}]},',
665                               '        {destinations,[{broker,"amqp://site1.example.com"}]},',
666                               '        {queue,<<"source_one">>}]},',
667                               '      {shovel_second,[{sources,[{broker,"amqp://"}]},',
668                               '        {destinations,[{broker,"amqp://site2.example.com"}]},',
669                               '        {queue,<<"source_two">>}]}',
670                               '    ]}]}'
671                             ])
672           end
673         end
674       end
675
676       describe 'configuring shovel plugin' do
677         let :params do
678           {
679             config_shovel: true
680           }
681         end
682
683         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel') }
684
685         it { is_expected.to contain_rabbitmq_plugin('rabbitmq_shovel_management') }
686
687         describe 'with admin_enable false' do
688           let :params do
689             {
690               config_shovel: true,
691               admin_enable: false
692             }
693           end
694
695           it { is_expected.not_to contain_rabbitmq_plugin('rabbitmq_shovel_management') }
696         end
697
698         describe 'with static shovels' do
699           let :params do
700             {
701               config_shovel: true,
702               config_shovel_statics: {
703                 'shovel_first' => '{sources,[{broker,"amqp://"}]},
704         {destinations,[{broker,"amqp://site1.example.com"}]},
705         {queue,<<"source_one">>}',
706                 'shovel_second' => '{sources,[{broker,"amqp://"}]},
707         {destinations,[{broker,"amqp://site2.example.com"}]},
708         {queue,<<"source_two">>}'
709               }
710             }
711           end
712
713           it 'generates correct configuration' do
714             verify_contents(catalogue, 'rabbitmq.config', [
715                               '  {rabbitmq_shovel,',
716                               '    [{shovels,[',
717                               '      {shovel_first,[{sources,[{broker,"amqp://"}]},',
718                               '        {destinations,[{broker,"amqp://site1.example.com"}]},',
719                               '        {queue,<<"source_one">>}]},',
720                               '      {shovel_second,[{sources,[{broker,"amqp://"}]},',
721                               '        {destinations,[{broker,"amqp://site2.example.com"}]},',
722                               '        {queue,<<"source_two">>}]}',
723                               '    ]}]}'
724                             ])
725           end
726         end
727       end
728
729       describe 'default_user and default_pass set' do
730         let(:params) { { default_user: 'foo', default_pass: 'bar' } }
731
732         it 'sets default_user and default_pass to specified values' do
733           is_expected.to contain_file('rabbitmq.config').with('content' => %r{default_user, <<"foo">>.*default_pass, <<"bar">>}m)
734         end
735       end
736
737       describe 'interfaces option with no ssl' do
738         let(:params) do
739           { interface: '0.0.0.0' }
740         end
741
742         it 'sets ssl options to specified values' do
743           is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\{"0.0.0.0", 5672\}\]})
744         end
745       end
746
747       describe 'ssl options and mangament_ssl false' do
748         let(:params) do
749           { ssl: true,
750             ssl_port: 3141,
751             ssl_cacert: '/path/to/cacert',
752             ssl_cert: '/path/to/cert',
753             ssl_key: '/path/to/key',
754             ssl_secure_renegotiate: true,
755             ssl_reuse_sessions: true,
756             ssl_honor_cipher_order: true,
757             ssl_dhfile: :undef,
758             management_ssl: false,
759             management_port: 13_142 }
760         end
761
762         it 'sets ssl options to specified values' do
763           is_expected.to contain_file('rabbitmq.config').with_content(
764             %r{ssl_listeners, \[3141\]}
765           )
766           is_expected.to contain_file('rabbitmq.config').with_content(
767             %r{ssl_options, \[}
768           )
769           is_expected.to contain_file('rabbitmq.config').with_content(
770             %r{cacertfile,"/path/to/cacert"}
771           )
772           is_expected.to contain_file('rabbitmq.config').with_content(
773             %r{certfile,"/path/to/cert"}
774           )
775           is_expected.to contain_file('rabbitmq.config').with_content(
776             %r{keyfile,"/path/to/key"}
777           )
778           is_expected.to contain_file('rabbitmq.config').with_content(
779             %r{secure_renegotiate,true}
780           )
781           is_expected.to contain_file('rabbitmq.config').with_content(
782             %r{reuse_sessions,true}
783           )
784           is_expected.to contain_file('rabbitmq.config').with_content(
785             %r{honor_cipher_order,true}
786           )
787           is_expected.to contain_file('rabbitmq.config').without_content(
788             %r{dhfile,}
789           )
790         end
791         it 'sets non ssl port for management port' do
792           is_expected.to contain_file('rabbitmq.config').with_content(
793             %r{port, 13142}
794           )
795           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
796             %r{port\s=\s13142}
797           )
798         end
799       end
800
801       describe 'ssl options and mangament_ssl true' do
802         let(:params) do
803           { ssl: true,
804             ssl_port: 3141,
805             ssl_cacert: '/path/to/cacert',
806             ssl_cert: '/path/to/cert',
807             ssl_key: '/path/to/key',
808             ssl_secure_renegotiate: true,
809             ssl_reuse_sessions: true,
810             ssl_honor_cipher_order: true,
811             ssl_dhfile: :undef,
812
813             management_ssl: true,
814             ssl_management_port: 13_141 }
815         end
816
817         it 'sets ssl options to specified values' do
818           is_expected.to contain_file('rabbitmq.config').with_content(
819             %r{ssl_listeners, \[3141\]}
820           )
821           is_expected.to contain_file('rabbitmq.config').with_content(
822             %r{ssl_opts, }
823           )
824           is_expected.to contain_file('rabbitmq.config').with_content(
825             %r{ssl_options, \[}
826           )
827           is_expected.to contain_file('rabbitmq.config').with_content(
828             %r{cacertfile,"/path/to/cacert"}
829           )
830           is_expected.to contain_file('rabbitmq.config').with_content(
831             %r{certfile,"/path/to/cert"}
832           )
833           is_expected.to contain_file('rabbitmq.config').with_content(
834             %r{keyfile,"/path/to/key"}
835           )
836           is_expected.to contain_file('rabbitmq.config').with_content(
837             %r{secure_renegotiate,true}
838           )
839           is_expected.to contain_file('rabbitmq.config').with_content(
840             %r{reuse_sessions,true}
841           )
842           is_expected.to contain_file('rabbitmq.config').with_content(
843             %r{honor_cipher_order,true}
844           )
845           is_expected.to contain_file('rabbitmq.config').without_content(
846             %r{dhfile,}
847           )
848         end
849         it 'sets ssl managment port to specified values' do
850           is_expected.to contain_file('rabbitmq.config').with_content(
851             %r{port, 13141}
852           )
853         end
854         it 'sets ssl options in the rabbitmqadmin.conf' do
855           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
856             %r{ssl_ca_cert_file\s=\s/path/to/cacert}
857           )
858           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
859             %r{ssl_cert_file\s=\s/path/to/cert}
860           )
861           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
862             %r{ssl_key_file\s=\s/path/to/key}
863           )
864           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
865             %r{hostname\s=\s}
866           )
867           is_expected.to contain_file('rabbitmqadmin.conf').with_content(
868             %r{port\s=\s13141}
869           )
870         end
871       end
872
873       describe 'ssl options' do
874         let(:params) do
875           { ssl: true,
876             ssl_port: 3141,
877             ssl_cacert: '/path/to/cacert',
878             ssl_cert: '/path/to/cert',
879             ssl_key: '/path/to/key',
880             ssl_secure_renegotiate: true,
881             ssl_reuse_sessions: true,
882             ssl_honor_cipher_order: true,
883             ssl_dhfile: :undef }
884         end
885
886         it 'sets ssl options to specified values' do
887           is_expected.to contain_file('rabbitmq.config').with_content(
888             %r{ssl_listeners, \[3141\]}
889           )
890           is_expected.to contain_file('rabbitmq.config').with_content(
891             %r{ssl_options, \[}
892           )
893           is_expected.to contain_file('rabbitmq.config').with_content(
894             %r{cacertfile,"/path/to/cacert"}
895           )
896           is_expected.to contain_file('rabbitmq.config').with_content(
897             %r{certfile,"/path/to/cert"}
898           )
899           is_expected.to contain_file('rabbitmq.config').with_content(
900             %r{keyfile,"/path/to/key"}
901           )
902           is_expected.to contain_file('rabbitmq.config').with_content(
903             %r{secure_renegotiate,true}
904           )
905           is_expected.to contain_file('rabbitmq.config').with_content(
906             %r{reuse_sessions,true}
907           )
908           is_expected.to contain_file('rabbitmq.config').with_content(
909             %r{honor_cipher_order,true}
910           )
911           is_expected.to contain_file('rabbitmq.config').without_content(
912             %r{dhfile,}
913           )
914         end
915       end
916
917       describe 'ssl options with ssl_interfaces' do
918         let(:params) do
919           { ssl: true,
920             ssl_port: 3141,
921             ssl_interface: '0.0.0.0',
922             ssl_cacert: '/path/to/cacert',
923             ssl_cert: '/path/to/cert',
924             ssl_key: '/path/to/key' }
925         end
926
927         it 'sets ssl options to specified values' do
928           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]})
929           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
930           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
931           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
932         end
933       end
934
935       describe 'ssl options with ssl_only' do
936         let(:params) do
937           { ssl: true,
938             ssl_only: true,
939             ssl_port: 3141,
940             ssl_cacert: '/path/to/cacert',
941             ssl_cert: '/path/to/cert',
942             ssl_key: '/path/to/key' }
943         end
944
945         it 'sets ssl options to specified values' do
946           is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]})
947           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]})
948           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[})
949           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
950           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
951           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
952         end
953         it 'does not set TCP listener environment defaults' do
954           is_expected.to contain_file('rabbitmq-env.config'). \
955             without_content(%r{NODE_PORT=}). \
956             without_content(%r{NODE_IP_ADDRESS=})
957         end
958       end
959
960       describe 'ssl options with ssl_only and ssl_interfaces' do
961         let(:params) do
962           { ssl: true,
963             ssl_only: true,
964             ssl_port: 3141,
965             ssl_interface: '0.0.0.0',
966             ssl_cacert: '/path/to/cacert',
967             ssl_cert: '/path/to/cert',
968             ssl_key: '/path/to/key' }
969         end
970
971         it 'sets ssl options to specified values' do
972           is_expected.to contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]})
973           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[\{"0.0.0.0", 3141\}\]})
974           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
975           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
976           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
977         end
978       end
979
980       describe 'ssl options with specific ssl versions' do
981         let(:params) do
982           { ssl: true,
983             ssl_port: 3141,
984             ssl_cacert: '/path/to/cacert',
985             ssl_cert: '/path/to/cert',
986             ssl_key: '/path/to/key',
987             ssl_versions: ['tlsv1.2', 'tlsv1.1'] }
988         end
989
990         it 'sets ssl options to specified values' do
991           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]})
992           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_options, \[})
993           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile,"/path/to/cacert"})
994           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
995           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
996           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, \[\{versions, \['tlsv1.1', 'tlsv1.2'\]\}\]})
997           is_expected.to contain_file('rabbitmq.config').with_content(%r{versions, \['tlsv1.1', 'tlsv1.2'\]})
998         end
999       end
1000
1001       describe 'ssl options with ssl_versions and not ssl' do
1002         let(:params) do
1003           { ssl: false,
1004             ssl_port: 3141,
1005             ssl_cacert: '/path/to/cacert',
1006             ssl_cert: '/path/to/cert',
1007             ssl_key: '/path/to/key',
1008             ssl_versions: ['tlsv1.2', 'tlsv1.1'] }
1009         end
1010
1011         it 'fails' do
1012           expect { catalogue }.to raise_error(Puppet::Error, %r{\$ssl_versions requires that \$ssl => true})
1013         end
1014       end
1015
1016       describe 'ssl options with ssl ciphers' do
1017         let(:params) do
1018           { ssl: true,
1019             ssl_port: 3141,
1020             ssl_cacert: '/path/to/cacert',
1021             ssl_cert: '/path/to/cert',
1022             ssl_key: '/path/to/key',
1023             ssl_ciphers: ['ecdhe_rsa,aes_256_cbc,sha', 'dhe_rsa,aes_256_cbc,sha'] }
1024         end
1025
1026         it 'sets ssl ciphers to specified values' do
1027           is_expected.to contain_file('rabbitmq.config').with_content(%r{ciphers,\[[[:space:]]+{dhe_rsa,aes_256_cbc,sha},[[:space:]]+{ecdhe_rsa,aes_256_cbc,sha}[[:space:]]+\]})
1028         end
1029       end
1030
1031       describe 'ssl admin options with specific ssl versions' do
1032         let(:params) do
1033           { ssl: true,
1034             ssl_management_port: 5926,
1035             ssl_cacert: '/path/to/cacert',
1036             ssl_cert: '/path/to/cert',
1037             ssl_key: '/path/to/key',
1038             ssl_versions: ['tlsv1.2', 'tlsv1.1'],
1039             admin_enable: true }
1040         end
1041
1042         it 'sets admin ssl opts to specified values' do
1043           is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
1044           is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[})
1045           is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 5926\}})
1046           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\}})
1047           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[})
1048           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},})
1049           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
1050           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}})
1051           is_expected.to contain_file('rabbitmq.config').with_content(%r{,\{versions, \['tlsv1.1', 'tlsv1.2'\]\}})
1052         end
1053       end
1054
1055       describe 'ssl with ssl_dhfile' do
1056         let(:params) do
1057           { ssl: true,
1058             ssl_interface: '0.0.0.0',
1059             ssl_dhfile: '/etc/pki/tls/dh-params.pem' }
1060         end
1061
1062         it { is_expected.to contain_file('rabbitmq.config').with_content(%r{dhfile, "/etc/pki/tls/dh-params\.pem}) }
1063       end
1064
1065       describe 'ssl with ssl_dhfile unset' do
1066         let(:params) do
1067           { ssl: true,
1068             ssl_interface: '0.0.0.0',
1069             ssl_dhfile: :undef }
1070         end
1071
1072         it { is_expected.to contain_file('rabbitmq.config').without_content(%r{dhfile,}) }
1073       end
1074
1075       describe 'ssl with ssl_secure_renegotiate false' do
1076         let(:params) do
1077           { ssl: true,
1078             ssl_interface: '0.0.0.0',
1079             ssl_secure_renegotiate: false }
1080         end
1081
1082         it { is_expected.to contain_file('rabbitmq.config').with_content(%r{secure_renegotiate,false}) }
1083       end
1084
1085       describe 'ssl with ssl_reuse_sessions false' do
1086         let(:params) do
1087           { ssl: true,
1088             ssl_interface: '0.0.0.0',
1089             ssl_reuse_sessions: false }
1090         end
1091
1092         it { is_expected.to contain_file('rabbitmq.config').with_content(%r{reuse_sessions,false}) }
1093       end
1094
1095       describe 'ssl with ssl_honor_cipher_order false' do
1096         let(:params) do
1097           { ssl: true,
1098             ssl_interface: '0.0.0.0',
1099             ssl_honor_cipher_order: false }
1100         end
1101
1102         it { is_expected.to contain_file('rabbitmq.config').with_content(%r{honor_cipher_order,false}) }
1103       end
1104
1105       describe 'ssl admin options' do
1106         let(:params) do
1107           { ssl: true,
1108             ssl_management_port: 3141,
1109             ssl_cacert: '/path/to/cacert',
1110             ssl_cert: '/path/to/cert',
1111             ssl_key: '/path/to/key',
1112             ssl_management_verify: 'verify_peer',
1113             ssl_management_fail_if_no_peer_cert: true,
1114             admin_enable: true }
1115         end
1116
1117         it 'sets rabbitmq_management ssl options to specified values' do
1118           is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
1119           is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[})
1120           is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
1121           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\}})
1122           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[})
1123           is_expected.to contain_file('rabbitmq.config').with_content(%r{verify,verify_peer\},})
1124           is_expected.to contain_file('rabbitmq.config').with_content(%r{fail_if_no_peer_cert,true\}})
1125           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},})
1126           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
1127           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}})
1128         end
1129       end
1130
1131       describe 'admin without ssl' do
1132         let(:params) do
1133           { ssl: false,
1134             management_port: 3141,
1135             admin_enable: true }
1136         end
1137
1138         it 'sets rabbitmq_management options to specified values' do
1139           is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
1140           is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[})
1141           is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
1142         end
1143       end
1144
1145       describe 'ssl admin options' do
1146         let(:params) do
1147           { ssl: true,
1148             ssl_management_port: 3141,
1149             ssl_cacert: '/path/to/cacert',
1150             ssl_cert: '/path/to/cert',
1151             ssl_key: '/path/to/key',
1152             admin_enable: true }
1153         end
1154
1155         it 'sets rabbitmq_management ssl options to specified values' do
1156           is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
1157           is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[})
1158           is_expected.to contain_file('rabbitmq.config').with_content(%r{port, 3141\},})
1159           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl, true\},})
1160           is_expected.to contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[})
1161           is_expected.to contain_file('rabbitmq.config').with_content(%r{cacertfile, "/path/to/cacert"\},})
1162           is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
1163           is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}})
1164         end
1165       end
1166
1167       describe 'admin without ssl' do
1168         let(:params) do
1169           { ssl: false,
1170             management_port: 3141,
1171             admin_enable: true }
1172         end
1173
1174         it 'sets rabbitmq_management options to specified values' do
1175           is_expected.to contain_file('rabbitmq.config'). \
1176             with_content(%r{\{rabbitmq_management, \[}). \
1177             with_content(%r{\{listener, \[}). \
1178             with_content(%r{\{port, 3141\}})
1179         end
1180       end
1181
1182       describe 'ipv6 enabled' do
1183         let(:params) { { ipv6: true } }
1184
1185         it 'enables resolver inet6 in inetrc' do
1186           is_expected.to contain_file('rabbitmq-inetrc').with_content(%r{{inet6, true}.})
1187         end
1188
1189         context 'without other erl args' do
1190           it 'enables inet6 distribution' do
1191             is_expected.to contain_file('rabbitmq-env.config'). \
1192               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="-proto_dist inet6_tcp"$}). \
1193               with_content(%r{^RABBITMQ_CTL_ERL_ARGS="-proto_dist inet6_tcp"$})
1194           end
1195         end
1196
1197         context 'with other quoted erl args' do
1198           let(:params) do
1199             { ipv6: true,
1200               environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => '"some quoted args"',
1201                                        'RABBITMQ_CTL_ERL_ARGS'    => '"other quoted args"' } }
1202           end
1203
1204           it 'enables inet6 distribution and quote properly' do
1205             is_expected.to contain_file('rabbitmq-env.config'). \
1206               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="some quoted args -proto_dist inet6_tcp"$}). \
1207               with_content(%r{^RABBITMQ_CTL_ERL_ARGS="other quoted args -proto_dist inet6_tcp"$})
1208           end
1209         end
1210
1211         context 'with other unquoted erl args' do
1212           let(:params) do
1213             { ipv6: true,
1214               environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => 'foo',
1215                                        'RABBITMQ_CTL_ERL_ARGS'    => 'bar' } }
1216           end
1217
1218           it 'enables inet6 distribution and quote properly' do
1219             is_expected.to contain_file('rabbitmq-env.config'). \
1220               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="foo -proto_dist inet6_tcp"$}). \
1221               with_content(%r{^RABBITMQ_CTL_ERL_ARGS="bar -proto_dist inet6_tcp"$})
1222           end
1223         end
1224
1225         context 'with SSL and without other erl args' do
1226           let(:params) do
1227             { ipv6: true,
1228               ssl_erl_dist: true }
1229           end
1230
1231           it 'enables inet6 distribution' do
1232             is_expected.to contain_file('rabbitmq-env.config'). \
1233               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS=" -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin -proto_dist inet6_tls"$}). \
1234               with_content(%r{^RABBITMQ_CTL_ERL_ARGS=" -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin -proto_dist inet6_tls"$})
1235           end
1236         end
1237
1238         context 'with SSL and other quoted erl args' do
1239           let(:params) do
1240             { ipv6: true,
1241               ssl_erl_dist: true,
1242               environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => '"some quoted args"',
1243                                        'RABBITMQ_CTL_ERL_ARGS'    => '"other quoted args"' } }
1244           end
1245
1246           it 'enables inet6 distribution and quote properly' do
1247             is_expected.to contain_file('rabbitmq-env.config'). \
1248               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="some quoted args -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin  -proto_dist inet6_tls"$}). \
1249               with_content(%r{^RABBITMQ_CTL_ERL_ARGS="other quoted args -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin  -proto_dist inet6_tls"$})
1250           end
1251         end
1252
1253         context 'with SSL and with other unquoted erl args' do
1254           let(:params) do
1255             { ipv6: true,
1256               ssl_erl_dist: true,
1257               environment_variables: { 'RABBITMQ_SERVER_ERL_ARGS' => 'foo',
1258                                        'RABBITMQ_CTL_ERL_ARGS'    => 'bar' } }
1259           end
1260
1261           it 'enables inet6 distribution and quote properly' do
1262             is_expected.to contain_file('rabbitmq-env.config'). \
1263               with_content(%r{^RABBITMQ_SERVER_ERL_ARGS="foo -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin  -proto_dist inet6_tls"$}). \
1264               with_content(%r{^RABBITMQ_CTL_ERL_ARGS="bar -pa /usr/lib64/erlang/lib/ssl-7.3.3.1/ebin  -proto_dist inet6_tls"$})
1265           end
1266         end
1267       end
1268
1269       describe 'config_variables options' do
1270         let(:params) do
1271           { config_variables: {
1272             'hipe_compile' => true,
1273             'vm_memory_high_watermark'      => 0.4,
1274             'frame_max'                     => 131_072,
1275             'collect_statistics'            => 'none',
1276             'auth_mechanisms'               => "['PLAIN', 'AMQPLAIN']"
1277           } }
1278         end
1279
1280         it 'sets environment variables' do
1281           is_expected.to contain_file('rabbitmq.config'). \
1282             with_content(%r{\{hipe_compile, true\}}). \
1283             with_content(%r{\{vm_memory_high_watermark, 0.4\}}). \
1284             with_content(%r{\{frame_max, 131072\}}). \
1285             with_content(%r{\{collect_statistics, none\}}). \
1286             with_content(%r{\{auth_mechanisms, \['PLAIN', 'AMQPLAIN'\]\}})
1287         end
1288       end
1289
1290       describe 'config_kernel_variables options' do
1291         let(:params) do
1292           { config_kernel_variables: {
1293             'inet_dist_listen_min' => 9100,
1294             'inet_dist_listen_max' => 9105
1295           } }
1296         end
1297
1298         it 'sets config variables' do
1299           is_expected.to contain_file('rabbitmq.config'). \
1300             with_content(%r{\{inet_dist_listen_min, 9100\}}). \
1301             with_content(%r{\{inet_dist_listen_max, 9105\}})
1302         end
1303       end
1304
1305       describe 'config_management_variables' do
1306         let(:params) do
1307           { config_management_variables: {
1308             'rates_mode' => 'none'
1309           } }
1310         end
1311
1312         it 'sets config variables' do
1313           is_expected.to contain_file('rabbitmq.config'). \
1314             with_content(%r{\{rates_mode, none\}})
1315         end
1316       end
1317
1318       describe 'tcp_keepalive enabled' do
1319         let(:params) { { tcp_keepalive: true } }
1320
1321         it 'sets tcp_listen_options keepalive true' do
1322           is_expected.to contain_file('rabbitmq.config'). \
1323             with_content(%r{\{keepalive,     true\}})
1324         end
1325       end
1326
1327       describe 'tcp_keepalive disabled (default)' do
1328         it 'does not set tcp_listen_options' do
1329           is_expected.to contain_file('rabbitmq.config'). \
1330             without_content(%r{\{keepalive,     true\}})
1331         end
1332       end
1333
1334       describe 'tcp_backlog with default value' do
1335         it 'sets tcp_listen_options backlog to 128' do
1336           is_expected.to contain_file('rabbitmq.config'). \
1337             with_content(%r{\{backlog,       128\}})
1338         end
1339       end
1340
1341       describe 'tcp_backlog with non-default value' do
1342         let(:params) do
1343           { tcp_backlog: 256 }
1344         end
1345
1346         it 'sets tcp_listen_options backlog to 256' do
1347           is_expected.to contain_file('rabbitmq.config'). \
1348             with_content(%r{\{backlog,       256\}})
1349         end
1350       end
1351
1352       describe 'tcp_sndbuf with default value' do
1353         it 'does not set tcp_listen_options sndbuf' do
1354           is_expected.to contain_file('rabbitmq.config'). \
1355             without_content(%r{sndbuf})
1356         end
1357       end
1358
1359       describe 'tcp_sndbuf with non-default value' do
1360         let(:params) do
1361           { tcp_sndbuf: 128 }
1362         end
1363
1364         it 'sets tcp_listen_options sndbuf to 128' do
1365           is_expected.to contain_file('rabbitmq.config'). \
1366             with_content(%r{\{sndbuf,       128\}})
1367         end
1368       end
1369
1370       describe 'tcp_recbuf with default value' do
1371         it 'does not set tcp_listen_options recbuf' do
1372           is_expected.to contain_file('rabbitmq.config'). \
1373             without_content(%r{recbuf})
1374         end
1375       end
1376
1377       describe 'tcp_recbuf with non-default value' do
1378         let(:params) do
1379           { tcp_recbuf: 128 }
1380         end
1381
1382         it 'sets tcp_listen_options recbuf to 128' do
1383           is_expected.to contain_file('rabbitmq.config'). \
1384             with_content(%r{\{recbuf,       128\}})
1385         end
1386       end
1387
1388       describe 'rabbitmq-heartbeat options' do
1389         let(:params) { { heartbeat: 60 } }
1390
1391         it 'sets heartbeat paramter in config file' do
1392           is_expected.to contain_file('rabbitmq.config'). \
1393             with_content(%r{\{heartbeat, 60\}})
1394         end
1395       end
1396
1397       context 'delete_guest_user' do
1398         describe 'should do nothing by default' do
1399           it { is_expected.not_to contain_rabbitmq_user('guest') }
1400         end
1401
1402         describe 'delete user when delete_guest_user set' do
1403           let(:params) { { delete_guest_user: true } }
1404
1405           it 'removes the user' do
1406             is_expected.to contain_rabbitmq_user('guest').with(
1407               'ensure'   => 'absent',
1408               'provider' => 'rabbitmqctl'
1409             )
1410           end
1411         end
1412       end
1413
1414       ##
1415       ## rabbitmq::service
1416       ##
1417       describe 'service with default params' do
1418         it {
1419           is_expected.to contain_service('rabbitmq-server').with(
1420             'ensure'     => 'running',
1421             'enable'     => 'true',
1422             'hasstatus'  => 'true',
1423             'hasrestart' => 'true'
1424           )
1425         }
1426       end
1427
1428       describe 'service with ensure stopped' do
1429         let :params do
1430           { service_ensure: 'stopped' }
1431         end
1432
1433         it {
1434           is_expected.to contain_service('rabbitmq-server').with(
1435             'ensure'    => 'stopped',
1436             'enable'    => false
1437           )
1438         }
1439       end
1440
1441       describe 'service with service_manage equal to false' do
1442         let :params do
1443           { service_manage: false }
1444         end
1445
1446         it { is_expected.not_to contain_service('rabbitmq-server') }
1447       end
1448     end
1449   end
1450 end