-
-
Notifications
You must be signed in to change notification settings - Fork 883
/
resource_server_spec.rb
1733 lines (1588 loc) · 69.4 KB
/
resource_server_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
require 'spec_helper'
describe 'nginx::resource::server' do
on_supported_os.each do |os, facts|
context "on #{os} with Facter #{facts[:facterversion]} and Puppet #{facts[:puppetversion]}" do
let(:facts) do
facts
end
let :title do
'www.rspec.example.com'
end
let :default_params do
{
www_root: '/',
ipv6_enable: true,
listen_unix_socket_enable: true,
fastcgi_index: 'index.php'
}
end
let :pre_condition do
[
'include nginx'
]
end
describe 'os-independent items' do
describe 'basic assumptions' do
let(:params) { default_params }
it { is_expected.to contain_class('nginx') }
it do
is_expected.to contain_concat("/etc/nginx/sites-available/#{title}.conf").with('owner' => 'root',
'group' => 'root',
'mode' => '0644')
end
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{access_log\s+/var/log/nginx/www\.rspec\.example\.com\.access\.log;}) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{error_log\s+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
it { is_expected.to contain_nginx__resource__location("#{title}-default") }
it { is_expected.not_to contain_file('/etc/nginx/fastcgi.conf') }
it do
is_expected.to contain_file("#{title}.conf symlink").with('ensure' => 'link',
'path' => "/etc/nginx/sites-enabled/#{title}.conf",
'target' => "/etc/nginx/sites-available/#{title}.conf")
end
end
describe 'with $confd_only enabled' do
let(:pre_condition) { 'class { "nginx": confd_only => true }' }
let(:params) { default_params }
it { is_expected.to contain_class('nginx') }
it do
is_expected.to contain_concat("/etc/nginx/conf.d/#{title}.conf").with('owner' => 'root',
'group' => 'root',
'mode' => '0644')
is_expected.not_to contain_file('/etc/nginx/sites-enabled')
is_expected.not_to contain_file('/etc/nginx/sites-available')
end
end
describe 'with both $rewrite_www_to_non_www and $rewrite_non_www_to_www enabled' do
let(:params) do
default_params.merge(rewrite_non_www_to_www: true, rewrite_www_to_non_www: true)
end
it do
is_expected.to compile.and_raise_error(
%r{You must not set both \$rewrite_www_to_non_www and \$rewrite_non_www_to_www to true}
)
end
end
describe 'server_header template content' do
[
{
title: 'should contain access and error logs directives inside the www rewrite',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{\s+return\s+301\s+http://rspec\.example\.com\$request_uri;\n
\s+access_log\s+/var/log/nginx/www.rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/www.rspec.example.com.error.log;\n}x
},
{
title: 'should not contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
value: false,
notmatch: %r{
^
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+http://rspec\.example\.com\$request_uri;
}x
},
{
title: 'should contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{
^
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+http://rspec\.example\.com\$request_uri;
}x
},
{
title: 'should set the IPv4 listen IP',
attr: 'listen_ip',
value: '127.0.0.1',
match: %r{\s+listen\s+127.0.0.1:80;}
},
{
title: 'should set the IPv4 listen port',
attr: 'listen_port',
value: 45,
match: %r{\s+listen\s+\*:45;}
},
{
title: 'should set the IPv4 listen options',
attr: 'listen_options',
value: 'spdy default',
match: %r{\s+listen\s+\*:80 spdy default;}
},
{
title: 'should enable IPv6',
attr: 'ipv6_enable',
value: true,
match: %r{\s+listen\s+\[::\]:80 default ipv6only=on;}
},
{
title: 'should not enable IPv6',
attr: 'ipv6_enable',
value: false,
notmatch: %r{\slisten \[::\]:80 default ipv6only=on;}
},
{
title: 'should set the IPv6 listen IP',
attr: 'ipv6_listen_ip',
value: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
match: %r{\s+listen\s+\[2001:0db8:85a3:0000:0000:8a2e:0370:7334\]:80 default ipv6only=on;}
},
{
title: 'should set the IPv6 listen port',
attr: 'ipv6_listen_port',
value: 45,
match: %r{\s+listen\s+\[::\]:45 default ipv6only=on;}
},
{
title: 'should set the IPv6 listen options',
attr: 'ipv6_listen_options',
value: 'spdy',
match: %r{\s+listen\s+\[::\]:80 spdy;}
},
{
title: 'should enable listening on unix socket',
attr: 'listen_unix_socket_enable',
value: true,
match: %r{\s+listen\s+unix:/var/run/nginx\.sock;}
},
{
title: 'should not enable listening on unix socket',
attr: 'listen_unix_socket_enable',
value: false,
notmatch: %r{\s+listen\s+unix:/var/run/nginx\.sock;}
},
{
title: 'should set the listen unix socket',
attr: 'listen_unix_socket',
value: '/var/run/puppet_nginx.sock',
match: %r{\s+listen\s+unix:/var/run/puppet_nginx\.sock;}
},
{
title: 'should set the listen unix socket options',
attr: 'listen_unix_socket_options',
value: 'spdy',
match: %r{\s+listen\s+unix:/var/run/nginx\.sock spdy;}
},
{
title: 'should set servername(s)',
attr: 'server_name',
value: ['www.foo.com', 'foo.com'],
match: %r{\s+server_name\s+www.foo.com foo.com;}
},
{
title: 'should rewrite www servername to non-www',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{\s+server_name\s+rspec.example.com;}
},
{
title: 'should not rewrite www servername to non-www',
attr: 'rewrite_www_to_non_www',
value: false,
match: %r{\s+server_name\s+www.rspec.example.com;}
},
{
title: 'should not set absolute_redirect',
attr: 'absolute_redirect',
value: :undef,
notmatch: %r{absolute_redirect}
},
{
title: 'should set absolute_redirect off',
attr: 'absolute_redirect',
value: 'off',
match: ' absolute_redirect off;'
},
{
title: 'should set auth_basic',
attr: 'auth_basic',
value: 'value',
match: %r{\s+auth_basic\s+"value";}
},
{
title: 'should set auth_basic_user_file',
attr: 'auth_basic_user_file',
value: 'value',
match: %r{\s+auth_basic_user_file\s+value;}
},
{
title: 'should set auth_request',
attr: 'auth_request',
value: 'value',
match: %r{\s+auth_request\s+value;}
},
{
title: 'should set the client_body_timeout',
attr: 'client_body_timeout',
value: 'value',
match: %r{^\s+client_body_timeout\s+value;}
},
{
title: 'should set the client_header_timeout',
attr: 'client_header_timeout',
value: 'value',
match: %r{^\s+client_header_timeout\s+value;}
},
{
title: 'should set the gzip_types',
attr: 'gzip_types',
value: 'value',
match: %r{^\s+gzip_types\s+value;}
},
{
title: 'should not set the gzip_static',
attr: 'gzip_static',
value: :undef,
notmatch: 'gzip_static'
},
{
title: 'should set the gzip_static',
attr: 'gzip_static',
value: 'on',
match: %r{^\s+gzip_static\s+on;}
},
{
title: 'should contain raw_prepend directives',
attr: 'raw_prepend',
value: [
'if (a) {',
' b;',
'}'
],
match: %r{^\s+if \(a\) \{\n\s++b;\n\s+\}}
},
{
title: 'should contain ordered prepended directives',
attr: 'server_cfg_prepend',
value: { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
match: [
' allow test value 3;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;'
]
},
{
title: 'should set root',
attr: 'use_default_location',
value: false,
match: ' root /;'
},
{
title: 'should not set root',
attr: 'use_default_location',
value: true,
notmatch: %r{ root /;}
},
{
title: 'should force https (SSL) redirect',
attr: 'ssl_redirect',
value: true,
match: %r{ return 301 https://\$host\$request_uri;}
},
{
title: 'should not force https (SSL) redirect',
attr: 'ssl_redirect',
value: false,
notmatch: %r{\s*return\s+301}
},
{
title: 'should set access_log',
attr: 'access_log',
value: '/path/to/access.log',
match: ' access_log /path/to/access.log;'
},
{
title: 'should set multiple access_log directives',
attr: 'access_log',
value: ['/path/to/log/1', 'syslog:server=localhost'],
match: [
' access_log /path/to/log/1;',
' access_log syslog:server=localhost;'
]
},
{
title: 'should set access_log off',
attr: 'access_log',
value: 'off',
match: ' access_log off;'
},
{
title: 'should set access_log to syslog',
attr: 'access_log',
value: 'syslog:server=localhost',
match: ' access_log syslog:server=localhost;'
},
{
title: 'should set format_log custom_format',
attr: 'format_log',
value: 'custom',
match: ' access_log /var/log/nginx/www.rspec.example.com.access.log custom;'
},
{
title: 'should not include access_log in server when set to absent',
attr: 'access_log',
value: 'absent',
notmatch: 'access_log'
},
{
title: 'should set error_log',
attr: 'error_log',
value: '/path/to/error.log',
match: ' error_log /path/to/error.log;'
},
{
title: 'should allow multiple error_log directives',
attr: 'error_log',
value: ['/path/to/error.log', 'syslog:server=localhost'],
match: [
' error_log /path/to/error.log;',
' error_log syslog:server=localhost;'
]
},
{
title: 'should set error_log severity level',
attr: 'error_log_severity',
value: 'warn',
match: ' error_log /var/log/nginx/www.rspec.example.com.error.log warn;'
},
{
title: 'should not set error_log severity level',
attr: 'error_log_severity',
value: :undef,
match: ' error_log /var/log/nginx/www.rspec.example.com.error.log;'
},
{
title: 'should not include error_log in server when set to absent',
attr: 'error_log',
value: 'absent',
notmatch: 'error_log'
},
{
title: 'should set error_pages',
attr: 'error_pages',
value: { '503' => '/foo.html' },
match: ' error_page 503 /foo.html;'
},
{
title: 'should set index_file(s)',
attr: 'index_files',
value: %w[name1 name2],
match: %r{\s*index\s+name1\s+name2;}
},
{
title: 'should not set index_file(s)',
attr: 'index_files',
value: [],
notmatch: %r{\s+index\s+}
},
{
title: 'should set autoindex',
attr: 'autoindex',
value: 'on',
match: ' autoindex on;'
},
{
title: 'should set autoindex_exact_size',
attr: 'autoindex_exact_size',
value: 'on',
match: ' autoindex_exact_size on;'
},
{
title: 'should set reset_timedout_connection',
attr: 'reset_timedout_connection',
value: 'on',
match: %r{^\s+reset_timedout_connection\s+on;}
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-header").with_content(item) }
else
lines = catalogue.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
end
end
end
end
context 'with a naked domain title over http' do
let(:title) { 'rspec.example.com' }
[
{
title: 'should contain access and error logs directives inside the non-www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+return\s+301\s+http://www.rspec\.example\.com\$request_uri;\n
\s+access_log\s+/var/log/nginx/rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/rspec.example.com.error.log;\n}x
},
{
title: 'should not contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
value: false,
notmatch: %r{
^
\s+server_name\s+rspec\.example\.com;\n
\s+return\s+301\s+http://www\.rspec\.example\.com\$request_uri;
}x
},
{
title: 'should contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{
^
\s+server_name\s+rspec\.example\.com;\n
\s+return\s+301\s+http://www\.rspec\.example\.com\$request_uri;
}x
},
{
title: 'should rewrite non-www servername to www',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+server_name\s+www.rspec.example.com;}
},
{
title: 'should not rewrite non-www servername to www',
attr: 'rewrite_non_www_to_www',
value: false,
notmatch: %r{\s+server_name\s+www.rspec.example.com;}
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }
it { is_expected.to contain_concat__fragment("#{title}-header") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-header").with_content(item) }
else
lines = catalogue.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment("#{title}-header").without_content(item)
end
end
end
end
end
context 'with a naked domain title over https' do
let(:title) { 'rspec.example.com' }
[
{
title: 'should contain access and error logs directives inside the non-www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+return\s+301\s+https://www.rspec\.example\.com\$request_uri;\n
\s+access_log\s+/var/log/nginx/ssl-rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/ssl-rspec.example.com.error.log;\n}x
},
{
title: 'should not contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
value: false,
notmatch: %r{
^
\s+server_name\s+rspec\.example\.com;\n
\s+return\s+301\s+https://www\.rspec\.example\.com\$request_uri;
}x
},
{
title: 'should contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{
^
\s+server_name\s+rspec\.example\.com;\n
\s+return\s+301\s+https://www\.rspec\.example\.com\$request_uri;
}x
},
{
title: 'should rewrite non-www servername to www',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+server_name\s+www.rspec.example.com;}
},
{
title: 'should not rewrite non-www servername to www',
attr: 'rewrite_non_www_to_www',
value: false,
notmatch: %r{\s+server_name\s+www.rspec.example.com;}
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value], ssl: true, ssl_cert: '/tmp/dummy.crt', ssl_key: '/tmp/dummy.key', listen_port: 443) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(item) }
else
lines = catalogue.resource('concat::fragment', "#{title}-ssl-header").send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment("#{title}-ssl-header").without_content(item)
end
end
end
end
end
end
describe 'server_footer template content' do
[
{
title: 'should not contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
value: false,
notmatch: %r{
^
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
}x
},
{
title: 'should contain include directives',
attr: 'include_files',
value: ['/file1', '/file2'],
match: [
%r{^\s+include\s+/file1;},
%r{^\s+include\s+/file2;}
]
},
{
title: 'should contain ordered appended directives',
attr: 'server_cfg_append',
value: { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
match: [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2a;',
' test2 test value 2b;'
]
},
{
title: 'should contain raw_append directives',
attr: 'raw_append',
value: [
'if (a) {',
' b;',
'}'
],
match: %r{^\s+if \(a\) \{\n\s++b;\n\s+\}}
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-footer").with_content(item) }
else
lines = catalogue.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment("#{title}-footer").without_content(item)
end
end
end
end
end
context 'with a naked domain title' do
[
{
title: 'should not contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
value: false,
notmatch: %r{
^
\s+server_name\s+rspec\.example\.com;\n
\s+return\s+301\s+https://www\.rspec\.example\.com\$request_uri;
}x
}
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let(:params) { default_params.merge(param[:attr].to_sym => param[:value]) }
it { is_expected.to contain_concat__fragment("#{title}-footer") }
it param[:title] do
matches = Array(param[:match])
if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_concat__fragment("#{title}-footer").with_content(item) }
else
lines = catalogue.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end
Array(param[:notmatch]).each do |item|
is_expected.to contain_concat__fragment("#{title}-footer").without_content(item)
end
end
end
end
end
describe 'server_ssl_header template content' do
context 'with ssl' do
let :params do
default_params.merge(
ssl: true,
ssl_key: '/tmp/dummy.key',
ssl_cert: '/tmp/dummy.crt'
)
end
context 'without a value for the nginx_version fact do' do
let :facts do
facts[:nginx_version] ? facts.delete(:nginx_version) : facts
end
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{listen \*:443 ssl;}) }
end
context 'with fact nginx_version=1.14.1' do
let(:facts) { facts.merge(nginx_version: '1.14.1') }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ ssl on;}) }
end
context 'with fact nginx_version=1.15.1' do
let(:facts) { facts.merge(nginx_version: '1.15.1') }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").without_content(%r{ ssl on;}) }
end
context 'http2 on with fact nginx_version=1.25.1' do
let(:facts) { facts.merge(nginx_version: '1.25.1') }
let :params do
default_params.merge(
http2: 'on',
ssl: true,
ssl_key: '/tmp/dummy.key',
ssl_cert: '/tmp/dummy.crt'
)
end
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{^\s+http2\s+on;}) }
end
context 'with fact nginx_version=1.25.1' do
let(:facts) { facts.merge(nginx_version: '1.25.1') }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{^\s+http2\s+off;}) }
end
context 'with ssl cert and key definitions' do
let(:pre_condition) do
<<-PUPPET
file { ['/tmp/dummy.key', '/tmp/dummy.crt']: }
include nginx
PUPPET
end
it { is_expected.to contain_file('/tmp/dummy.key').with_path('/tmp/dummy.key') }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").that_requires(['File[/tmp/dummy.key]', 'File[/tmp/dummy.crt]']) }
end
end
[
{
title: 'should not contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
value: false,
notmatch: %r{
^
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
}x
},
{
title: 'should contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{
^
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
}x
},
{
title: 'should set the IPv4 listen IP',
attr: 'listen_ip',
value: '127.0.0.1',
match: %r{\s+listen\s+127.0.0.1:443 ssl;}
},
{
title: 'should set the IPv4 SSL listen port',
attr: 'ssl_port',
value: 45,
match: %r{\s+listen\s+\*:45 ssl;}
},
{
title: 'should set SPDY',
attr: 'spdy',
value: 'on',
match: %r{\s+listen\s+\*:443 ssl spdy;}
},
{
title: 'should not set SPDY',
attr: 'spdy',
value: 'off',
match: %r{\s+listen\s+\*:443 ssl;}
},
{
title: 'should set HTTP2',
attr: 'http2',
value: 'on',
match: %r{\s+listen\s+\*:443 ssl http2;}
},
{
title: 'should not set HTTP2',
attr: 'http2',
value: 'off',
match: %r{\s+listen\s+\*:443 ssl;}
},
{
title: 'should set the IPv4 listen options',
attr: 'listen_options',
value: 'default',
match: %r{\s+listen\s+\*:443 ssl default;}
},
{
title: 'should enable IPv6',
attr: 'ipv6_enable',
value: true,
match: %r{\s+listen\s+\[::\]:443 ssl default ipv6only=on;}
},
{
title: 'should disable IPv6',
attr: 'ipv6_enable',
value: false,
notmatch: %r{ listen \[::\]:443 ssl default ipv6only=on;}
},
{
title: 'should set the IPv6 listen IP',
attr: 'ipv6_listen_ip',
value: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
match: %r{\s+listen\s+\[2001:0db8:85a3:0000:0000:8a2e:0370:7334\]:443 ssl default ipv6only=on;}
},
{
title: 'should set the IPv6 listen port',
attr: 'ssl_port',
value: 45,
match: %r{\s+listen\s+\[::\]:45 ssl default ipv6only=on;}
},
{
title: 'should set the IPv6 listen options',
attr: 'ipv6_listen_options',
value: 'spdy default',
match: %r{\s+listen\s+\[::\]:443 ssl spdy default;}
},
{
title: 'should set servername(s)',
attr: 'server_name',
value: ['www.foo.com', 'foo.com'],
match: %r{\s+server_name\s+www.foo.com foo.com;}
},
{
title: 'should rewrite www servername to non-www',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{\s+server_name\s+rspec.example.com;}
},
{
title: 'should not rewrite www servername to non-www',
attr: 'rewrite_www_to_non_www',
value: false,
match: %r{\s+server_name\s+www.rspec.example.com;}
},
{
title: 'should set the SSL buffer size',
attr: 'ssl_buffer_size',
value: '4k',
match: ' ssl_buffer_size 4k;'
},
{
title: 'should set the SSL client certificate file',
attr: 'ssl_client_cert',
value: '/tmp/client_certificate',
match: %r{\s+ssl_client_certificate\s+/tmp/client_certificate;}
},
{
title: 'should set the SSL CRL file',
attr: 'ssl_crl',
value: '/tmp/crl',
match: %r{\s+ssl_crl\s+/tmp/crl;}
},
{
title: 'should set the SSL DH parameters file',
attr: 'ssl_dhparam',
value: '/tmp/dhparam',
match: %r{\s+ssl_dhparam\s+/tmp/dhparam;}
},
{
title: 'should set ssl_ecdh_curve',
attr: 'ssl_ecdh_curve',
value: 'secp521r1',
match: %r{\s+ssl_ecdh_curve\s+secp521r1;}
},
{
title: 'should set the SSL stapling file',
attr: 'ssl_stapling_file',
value: '/tmp/stapling_file',
match: %r{\s+ssl_stapling_file\s+/tmp/stapling_file;}
},
{
title: 'should set the SSL trusted certificate file',
attr: 'ssl_trusted_cert',
value: '/tmp/trusted_certificate',
match: %r{\s+ssl_trusted_certificate\s+/tmp/trusted_certificate;}
},
{
title: 'should set ssl_verify_depth',
attr: 'ssl_verify_depth',
value: 2,
match: %r{^\s+ssl_verify_depth\s+2;}
},
{
title: 'should set the SSL cache',
attr: 'ssl_cache',
value: 'shared:SSL:1m',
match: %r{\s+ssl_session_cache\s+shared:SSL:1m;}
},
{
title: 'should set the SSL timeout',
attr: 'ssl_session_timeout',
value: '30m',
match: ' ssl_session_timeout 30m;'
},
{
title: 'should set the SSL protocols',
attr: 'ssl_protocols',
value: 'TLSv1',
match: %r{\s+ssl_protocols\s+TLSv1;}
},
{
title: 'should set the SSL ciphers',
attr: 'ssl_ciphers',
value: 'HIGH',
match: %r{\s+ssl_ciphers\s+HIGH;}
},
{
title: 'should set ssl_prefer_server_ciphers on',
attr: 'ssl_prefer_server_ciphers',
value: 'on',
match: %r{\s+ssl_prefer_server_ciphers\s+on;}
},
{
title: 'should set ssl_prefer_server_ciphers off',
attr: 'ssl_prefer_server_ciphers',
value: 'off',
match: %r{\s+ssl_prefer_server_ciphers\s+off;}
},
{
title: 'should not set absolute_redirect',
attr: 'absolute_redirect',
value: :undef,
notmatch: %r{absolute_redirect}
},
{
title: 'should set absolute_redirect off',
attr: 'absolute_redirect',
value: 'off',
match: ' absolute_redirect off;'
},
{
title: 'should set auth_basic',
attr: 'auth_basic',
value: 'value',
match: %r{\s+auth_basic\s+"value";}
},
{
title: 'should set auth_basic_user_file',
attr: 'auth_basic_user_file',
value: 'value',
match: %r{\s+auth_basic_user_file\s+"value";}
},
{
title: 'should set auth_request',
attr: 'auth_request',
value: 'value',
match: %r{\s+auth_request\s+value;}
},
{
title: 'should set the client_body_timeout',
attr: 'client_body_timeout',
value: 'value',
match: %r{^\s+client_body_timeout\s+value;}
},
{
title: 'should set the client_header_timeout',
attr: 'client_header_timeout',
value: 'value',
match: %r{^\s+client_header_timeout\s+value;}
},
{
title: 'should set the gzip_types',
attr: 'gzip_types',
value: 'value',
match: %r{^\s+gzip_types\s+value;}
},
{
title: 'should set access_log',
attr: 'access_log',
value: '/path/to/access.log',
match: ' access_log /path/to/access.log;'
},
{
title: 'should set multiple access_log directives',
attr: 'access_log',
value: ['/path/to/log/1', 'syslog:server=localhost'],
match: [
' access_log /path/to/log/1;',
' access_log syslog:server=localhost;'
]
},
{
title: 'should set access_log off',
attr: 'access_log',
value: 'off',
match: ' access_log off;'
},
{
title: 'should not include access_log in server when set to absent',