forked from puppetlabs/puppetlabs-apache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvhost_spec.rb
More file actions
1110 lines (1087 loc) · 41.2 KB
/
Copy pathvhost_spec.rb
File metadata and controls
1110 lines (1087 loc) · 41.2 KB
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
require 'spec_helper'
describe 'apache::vhost', :type => :define do
let :pre_condition do
'class { "apache": default_vhost => false, }'
end
let :title do
'rspec.example.com'
end
let :default_params do
{
:docroot => '/rspec/docroot',
:port => '84',
}
end
describe 'os-dependent items' do
context "on RedHat based systems" do
let :default_facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :params do default_params end
let :facts do default_facts end
it { should include_class("apache") }
it { should include_class("apache::params") }
end
context "on Debian based systems" do
let :default_facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
let :params do default_params end
let :facts do default_facts end
it { should include_class("apache") }
it { should include_class("apache::params") }
it { should contain_file("25-rspec.example.com.conf").with(
:ensure => 'present',
:path => '/etc/apache2/sites-available/25-rspec.example.com.conf'
) }
it { should contain_file("25-rspec.example.com.conf symlink").with(
:ensure => 'link',
:path => '/etc/apache2/sites-enabled/25-rspec.example.com.conf',
:target => '/etc/apache2/sites-available/25-rspec.example.com.conf'
) }
end
context "on FreeBSD systems" do
let :default_facts do
{
:osfamily => 'FreeBSD',
:operatingsystemrelease => '9',
:concat_basedir => '/dne',
}
end
let :params do default_params end
let :facts do default_facts end
it { should include_class("apache") }
it { should include_class("apache::params") }
it { should contain_file("25-rspec.example.com.conf").with(
:ensure => 'present',
:path => '/usr/local/etc/apache22/Vhosts/25-rspec.example.com.conf'
) }
end
end
describe 'os-independent items' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end
describe 'basic assumptions' do
let :params do default_params end
it { should include_class("apache") }
it { should include_class("apache::params") }
it { should contain_apache__listen(params[:port]) }
it { should contain_apache__namevirtualhost("*:#{params[:port]}") }
end
# All match and notmatch should be a list of regexs and exact match strings
context ".conf content" do
[
{
:title => 'should contain docroot',
:attr => 'docroot',
:value => '/not/default',
:match => [/^ DocumentRoot \/not\/default$/,/ <Directory \/not\/default>/],
},
{
:title => 'should set a port',
:attr => 'port',
:value => '8080',
:match => [/^<VirtualHost \*:8080>$/],
},
{
:title => 'should set an ip',
:attr => 'ip',
:value => '10.0.0.1',
:match => [/^<VirtualHost 10\.0\.0\.1:84>$/],
},
{
:title => 'should set a serveradmin',
:attr => 'serveradmin',
:value => 'test@test.com',
:match => [/^ ServerAdmin test@test.com$/],
},
{
:title => 'should enable ssl',
:attr => 'ssl',
:value => true,
:match => [/^ SSLEngine on$/],
},
{
:title => 'should set a servername',
:attr => 'servername',
:value => 'param.test',
:match => [/^ ServerName param.test$/],
},
{
:title => 'should accept server aliases',
:attr => 'serveraliases',
:value => ['one.com','two.com'],
:match => [
/^ ServerAlias one\.com$/,
/^ ServerAlias two\.com$/
],
},
{
:title => 'should accept setenv',
:attr => 'setenv',
:value => ['TEST1 one','TEST2 two'],
:match => [
/^ SetEnv TEST1 one$/,
/^ SetEnv TEST2 two$/
],
},
{
:title => 'should accept setenvif',
:attr => 'setenvif',
## These are bugged in rspec-puppet; the $1 is droped
#:value => ['Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'],
#:match => [' SetEnvIf Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'],
:value => ['Host "^test\.com$" VHOST_ACCESS=test'],
:match => [/^ SetEnvIf Host "\^test\\.com\$" VHOST_ACCESS=test$/],
},
{
:title => 'should accept options',
:attr => 'options',
:value => ['Fake','Options'],
:match => [/^ Options Fake Options$/],
},
{
:title => 'should accept overrides',
:attr => 'override',
:value => ['Fake', 'Override'],
:match => [/^ AllowOverride Fake Override$/],
},
{
:title => 'should accept logroot',
:attr => 'logroot',
:value => '/fake/log',
:match => [/CustomLog \/fake\/log\//,/ErrorLog \/fake\/log\//],
},
{
:title => 'should accept log_level',
:attr => 'log_level',
:value => 'info',
:match => [/LogLevel info/],
},
{
:title => 'should accept pipe destination for access log',
:attr => 'access_log_pipe',
:value => '| /bin/fake/logging',
:match => [/CustomLog "| \/bin\/fake\/logging" combined$/],
},
{
:title => 'should accept pipe destination for error log',
:attr => 'error_log_pipe',
:value => '| /bin/fake/logging',
:match => [/ErrorLog "| \/bin\/fake\/logging" combined$/],
},
{
:title => 'should accept syslog destination for access log',
:attr => 'access_log_syslog',
:value => 'syslog:local1',
:match => [/CustomLog syslog:local1 combined$/],
},
{
:title => 'should accept syslog destination for error log',
:attr => 'error_log_syslog',
:value => 'syslog',
:match => [/ErrorLog syslog$/],
},
{
:title => 'should accept custom format for access logs',
:attr => 'access_log_format',
:value => '%h %{X-Forwarded-For}i %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\" \"Host: %{Host}i\" %T %D',
:match => [/CustomLog \/var\/log\/.+_access\.log "%h %\{X-Forwarded-For\}i %l %u %t \\"%r\\" %s %b \\"%\{Referer\}i\\" \\"%\{User-agent\}i\\" \\"Host: %\{Host\}i\\" %T %D"$/],
},
{
:title => 'should contain access logs',
:attr => 'access_log',
:value => true,
:match => [/CustomLog \/var\/log\/.+_access\.log combined$/],
},
{
:title => 'should not contain access logs',
:attr => 'access_log',
:value => false,
:notmatch => [/CustomLog \/var\/log\/.+_access\.log combined$/],
},
{
:title => 'should contain error logs',
:attr => 'error_log',
:value => true,
:match => [/ErrorLog.+$/],
},
{
:title => 'should not contain error logs',
:attr => 'error_log',
:value => false,
:notmatch => [/ErrorLog.+$/],
},
{
:title => 'should set ErrorDocument 503',
:attr => 'error_documents',
:value => [ { 'error_code' => '503', 'document' => '"Go away, the backend is broken."'}],
:match => [/^ ErrorDocument 503 "Go away, the backend is broken."$/],
},
{
:title => 'should set ErrorDocuments 503 407',
:attr => 'error_documents',
:value => [
{ 'error_code' => '503', 'document' => '/service-unavail'},
{ 'error_code' => '407', 'document' => 'https://example.com/proxy/login'},
],
:match => [
/^ ErrorDocument 503 \/service-unavail$/,
/^ ErrorDocument 407 https:\/\/example\.com\/proxy\/login$/,
],
},
{
:title => 'should set ErrorDocument 503 in directory',
:attr => 'directories',
:value => { 'path' => '/srv/www', 'error_documents' => [{ 'error_code' => '503', 'document' => '"Go away, the backend is broken."'}] },
:match => [/^ ErrorDocument 503 "Go away, the backend is broken."$/],
},
{
:title => 'should set ErrorDocuments 503 407 in directory',
:attr => 'directories',
:value => { 'path' => '/srv/www', 'error_documents' =>
[
{ 'error_code' => '503', 'document' => '/service-unavail'},
{ 'error_code' => '407', 'document' => 'https://example.com/proxy/login'},
]},
:match => [
/^ ErrorDocument 503 \/service-unavail$/,
/^ ErrorDocument 407 https:\/\/example\.com\/proxy\/login$/,
],
},
{
:title => 'should accept a scriptalias',
:attr => 'scriptalias',
:value => '/usr/scripts',
:match => [
/^ ScriptAlias \/cgi-bin\/ \/usr\/scripts$/,
],
},
{
:title => 'should accept a single scriptaliases',
:attr => 'scriptaliases',
:value => { 'alias' => '/blah/', 'path' => '/usr/scripts' },
:match => [
/^ ScriptAlias \/blah\/ \/usr\/scripts$/,
],
:nomatch => [/ScriptAlias \/cgi\-bin\//],
},
{
:title => 'should accept multiple scriptaliases',
:attr => 'scriptaliases',
:value => [ { 'alias' => '/blah', 'path' => '/usr/scripts' }, { 'alias' => '/blah2', 'path' => '/usr/scripts' } ],
:match => [
/^ ScriptAlias \/blah \/usr\/scripts$/,
/^ ScriptAlias \/blah2 \/usr\/scripts$/,
],
:nomatch => [/ScriptAlias \/cgi\-bin\//],
},
{
:title => 'should accept multiple scriptaliases with and without trailing slashes',
:attr => 'scriptaliases',
:value => [ { 'alias' => '/blah', 'path' => '/usr/scripts' }, { 'alias' => '/blah2/', 'path' => '/usr/scripts2/' } ],
:match => [
/^ ScriptAlias \/blah \/usr\/scripts$/,
/^ ScriptAlias \/blah2\/ \/usr\/scripts2\/$/,
],
:nomatch => [/ScriptAlias \/cgi\-bin\//],
},
{
:title => 'should accept a ScriptAliasMatch directive',
:attr => 'scriptaliases',
## XXX As mentioned above, rspec-puppet drops constructs like $1.
## Thus, these tests don't work as they should. As a workaround we
## use FOO instead of $1 here.
:value => [ { 'aliasmatch' => '^/cgi-bin(.*)', 'path' => '/usr/local/apache/cgi-binFOO' } ],
:match => [
/^ ScriptAliasMatch \^\/cgi-bin\(\.\*\) \/usr\/local\/apache\/cgi-binFOO$/
],
},
{
:title => 'should accept multiple ScriptAliasMatch directives',
:attr => 'scriptaliases',
## XXX As mentioned above, rspec-puppet drops constructs like $1.
## Thus, these tests don't work as they should. As a workaround we
## use FOO instead of $1 here.
:value => [
{ 'aliasmatch' => '^/cgi-bin(.*)', 'path' => '/usr/local/apache/cgi-binFOO' },
{ 'aliasmatch' => '"(?x)^/git/(.*/(HEAD|info/refs|objects/(info/[^/]+|[0-9a-f]{2}/[0-9a-f]{38}|pack/pack-[0-9a-f]{40}\.(pack|idx))|git-(upload|receive)-pack))"', 'path' => '/var/www/bin/gitolite-suexec-wrapper/FOO' },
],
:match => [
/^ ScriptAliasMatch \^\/cgi-bin\(\.\*\) \/usr\/local\/apache\/cgi-binFOO$/,
/^ ScriptAliasMatch "\(\?x\)\^\/git\/\(\.\*\/\(HEAD\|info\/refs\|objects\/\(info\/\[\^\/\]\+\|\[0-9a-f\]\{2\}\/\[0-9a-f\]\{38\}\|pack\/pack-\[0-9a-f\]\{40\}\\\.\(pack\|idx\)\)\|git-\(upload\|receive\)-pack\)\)" \/var\/www\/bin\/gitolite-suexec-wrapper\/FOO$/,
],
},
{
:title => 'should accept mixed ScriptAlias and ScriptAliasMatch directives',
:attr => 'scriptaliases',
## XXX As mentioned above, rspec-puppet drops constructs like $1.
## Thus, these tests don't work as they should. As a workaround we
## use FOO instead of $1 here.
:value => [
{ 'aliasmatch' => '"(?x)^/git/(.*/(HEAD|info/refs|objects/(info/[^/]+|[0-9a-f]{2}/[0-9a-f]{38}|pack/pack-[0-9a-f]{40}\.(pack|idx))|git-(upload|receive)-pack))"', 'path' => '/var/www/bin/gitolite-suexec-wrapper/FOO' },
{ 'alias' => '/git', 'path' => '/var/www/gitweb/index.cgi' },
{ 'aliasmatch' => '^/cgi-bin(.*)', 'path' => '/usr/local/apache/cgi-binFOO' },
{ 'alias' => '/trac', 'path' => '/etc/apache2/trac.fcgi' },
],
:match => [
/^ ScriptAliasMatch "\(\?x\)\^\/git\/\(\.\*\/\(HEAD\|info\/refs\|objects\/\(info\/\[\^\/\]\+\|\[0-9a-f\]\{2\}\/\[0-9a-f\]\{38\}\|pack\/pack-\[0-9a-f\]\{40\}\\\.\(pack\|idx\)\)\|git-\(upload\|receive\)-pack\)\)" \/var\/www\/bin\/gitolite-suexec-wrapper\/FOO$/,
/^ ScriptAlias \/git \/var\/www\/gitweb\/index\.cgi$/,
/^ ScriptAliasMatch \^\/cgi-bin\(\.\*\) \/usr\/local\/apache\/cgi-binFOO$/,
/^ ScriptAlias \/trac \/etc\/apache2\/trac.fcgi$/,
],
},
{
:title => 'should accept proxy destinations',
:attr => 'proxy_dest',
:value => 'http://fake.com',
:match => [
/^ ProxyPass \/ http:\/\/fake.com\/$/,
/^ <Location \/>$/,
/^ ProxyPassReverse \/$/,
/^ <\/Location>$/,
],
:notmatch => [/ProxyPass .+!$/],
},
{
:title => 'should accept proxy_pass hash',
:attr => 'proxy_pass',
:value => { 'path' => '/path-a', 'url' => 'http://fake.com/a' },
:match => [
/^ ProxyPass \/path-a http:\/\/fake.com\/a$/,
/^ <Location \/path-a>$/,
/^ ProxyPassReverse \/$/,
/^ <\/Location>$/,
],
:notmatch => [/ProxyPass .+!$/],
},
{
:title => 'should accept proxy_pass array of hash',
:attr => 'proxy_pass',
:value => [
{ 'path' => '/path-a/', 'url' => 'http://fake.com/a/' },
{ 'path' => '/path-b', 'url' => 'http://fake.com/b' },
],
:match => [
/^ ProxyPass \/path-a\/ http:\/\/fake.com\/a\/$/,
/^ <Location \/path-a\/>$/,
/^ ProxyPassReverse \/$/,
/^ <\/Location>$/,
/^ ProxyPass \/path-b http:\/\/fake.com\/b$/,
/^ <Location \/path-b>$/,
/^ ProxyPassReverse \/$/,
/^ <\/Location>$/,
],
:notmatch => [/ProxyPass .+!$/],
},
{
:title => 'should enable rack',
:attr => 'rack_base_uris',
:value => ['/rack1','/rack2'],
:match => [
/^ RackBaseURI \/rack1$/,
/^ RackBaseURI \/rack2$/,
],
},
{
:title => 'should accept request headers',
:attr => 'request_headers',
:value => ['append something', 'unset something_else'],
:match => [
/^ RequestHeader append something$/,
/^ RequestHeader unset something_else$/,
],
},
{
:title => 'should accept rewrite rules',
:attr => 'rewrite_rule',
:value => 'not a real rule',
:match => [/^ RewriteRule not a real rule$/],
},
{
:title => 'should accept rewrite rules',
:attr => 'rewrites',
:value => [{'rewrite_rule' => ['not a real rule']}],
:match => [/^ RewriteRule not a real rule$/],
},
{
:title => 'should accept rewrite comment',
:attr => 'rewrites',
:value => [{'comment' => 'rewrite comment', 'rewrite_rule' => ['not a real rule']}],
:match => [/^ #rewrite comment/],
},
{
:title => 'should accept rewrite conditions',
:attr => 'rewrites',
:value => [{'comment' => 'redirect IE', 'rewrite_cond' => ['%{HTTP_USER_AGENT} ^MSIE'], 'rewrite_rule' => ['^index\.html$ welcome.html'],}],
:match => [
/^ #redirect IE$/,
/^ RewriteCond %{HTTP_USER_AGENT} \^MSIE$/,
/^ RewriteRule \^index\\\.html\$ welcome.html$/,
],
},
{
:title => 'should accept multiple rewrites',
:attr => 'rewrites',
:value => [
{'rewrite_rule' => ['not a real rule']},
{'rewrite_rule' => ['not a real rule two']},
],
:match => [
/^ RewriteRule not a real rule$/,
/^ RewriteRule not a real rule two$/,
],
},
{
:title => 'should block scm',
:attr => 'block',
:value => 'scm',
:match => [/^ <DirectoryMatch \.\*\\\.\(svn\|git\|bzr\)\/\.\*>$/],
},
{
:title => 'should accept a custom fragment',
:attr => 'custom_fragment',
:value => " Some custom fragment line\n That spans multiple lines",
:match => [
/^ Some custom fragment line$/,
/^ That spans multiple lines$/,
/^<\/VirtualHost>$/,
],
},
{
:title => 'should accept an array of alias hashes',
:attr => 'aliases',
:value => [ { 'alias' => '/', 'path' => '/var/www'} ],
:match => [/^ Alias \/ \/var\/www$/],
},
{
:title => 'should accept an alias hash',
:attr => 'aliases',
:value => { 'alias' => '/', 'path' => '/var/www'},
:match => [/^ Alias \/ \/var\/www$/],
},
{
:title => 'should accept multiple aliases',
:attr => 'aliases',
:value => [
{ 'alias' => '/', 'path' => '/var/www'},
{ 'alias' => '/cgi-bin', 'path' => '/var/www/cgi-bin'},
{ 'alias' => '/css', 'path' => '/opt/someapp/css'},
],
:match => [
/^ Alias \/ \/var\/www$/,
/^ Alias \/cgi-bin \/var\/www\/cgi-bin$/,
/^ Alias \/css \/opt\/someapp\/css$/,
],
},
{
:title => 'should accept an aliasmatch hash',
:attr => 'aliases',
## XXX As mentioned above, rspec-puppet drops the $1. Thus, these
# tests don't work.
#:value => { 'aliasmatch' => '^/image/(.*).gif', 'path' => '/files/gifs/$1.gif' },
#:match => [/^ AliasMatch \^\/image\/\(\.\*\)\.gif \/files\/gifs\/\$1\.gif$/],
},
{
:title => 'should accept a array of alias and aliasmatch hashes mixed',
:attr => 'aliases',
## XXX As mentioned above, rspec-puppet drops the $1. Thus, these
# tests don't work.
#:value => [
# { 'alias' => '/css', 'path' => '/files/css' },
# { 'aliasmatch' => '^/image/(.*).gif', 'path' => '/files/gifs/$1.gif' },
# { 'aliasmatch' => '^/image/(.*).jpg', 'path' => '/files/jpgs/$1.jpg' },
# { 'alias' => '/image', 'path' => '/files/images' },
#],
#:match => [
# /^ Alias \/css \/files\/css$/,
# /^ AliasMatch \^\/image\/\(.\*\)\.gif \/files\/gifs\/\$1\.gif$/,
# /^ AliasMatch \^\/image\/\(.\*\)\.jpg \/files\/jpgs\/\$1\.jpg$/,
# /^ Alias \/image \/files\/images$/
#],
},
{
:title => 'should accept multiple additional includes',
:attr => 'additional_includes',
:value => [
'/tmp/proxy_group_a',
'/tmp/proxy_group_b',
'/tmp/proxy_group_c',
],
:match => [
/^ Include \/tmp\/proxy_group_a$/,
/^ Include \/tmp\/proxy_group_b$/,
/^ Include \/tmp\/proxy_group_c$/,
],
},
{
:title => 'should accept a suPHP_Engine',
:attr => 'suphp_engine',
:value => 'on',
:match => [/^ suPHP_Engine on$/],
},
{
:title => 'should accept a wsgi script alias',
:attr => 'wsgi_script_aliases',
:value => { '/' => '/var/www/myapp.wsgi'},
:match => [/^ WSGIScriptAlias \/ \/var\/www\/myapp.wsgi$/],
},
{
:title => 'should accept multiple wsgi aliases',
:attr => 'wsgi_script_aliases',
:value => {
'/wiki' => '/usr/local/wsgi/scripts/mywiki.wsgi',
'/blog' => '/usr/local/wsgi/scripts/myblog.wsgi',
'/' => '/usr/local/wsgi/scripts/myapp.wsgi',
},
:match => [
/^ WSGIScriptAlias \/wiki \/usr\/local\/wsgi\/scripts\/mywiki.wsgi$/,
/^ WSGIScriptAlias \/blog \/usr\/local\/wsgi\/scripts\/myblog.wsgi$/,
/^ WSGIScriptAlias \/ \/usr\/local\/wsgi\/scripts\/myapp.wsgi$/,
],
},
{
:title => 'should accept a directory',
:attr => 'directories',
:value => { 'path' => '/opt/app' },
:notmatch => [' <Directory /rspec/docroot>'],
:match => [
/^ <Directory \/opt\/app>$/,
/^ AllowOverride None$/,
/^ Order allow,deny$/,
/^ Allow from all$/,
/^ <\/Directory>$/,
],
},
{
:title => 'should accept directory directives hash',
:attr => 'directories',
:value => {
'path' => '/opt/app',
'headers' => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
'allow' => 'from rspec.org',
'allow_override' => 'Lol',
'deny' => 'from google.com',
'options' => '-MultiViews',
'order' => 'deny,yned',
'passenger_enabled' => 'onf',
},
:match => [
/^ <Directory \/opt\/app>$/,
/^ Header Set X-Robots-Tag "noindex, noarchive, nosnippet"$/,
/^ Allow from rspec.org$/,
/^ AllowOverride Lol$/,
/^ Deny from google.com$/,
/^ Options -MultiViews$/,
/^ Order deny,yned$/,
/^ PassengerEnabled onf$/,
/^ <\/Directory>$/,
],
},
{
:title => 'should accept directory directives with arrays and hashes',
:attr => 'directories',
:value => [
{
'path' => '/opt/app1',
'allow' => 'from rspec.org',
'allow_override' => ['AuthConfig','Indexes'],
'deny' => 'from google.com',
'options' => ['-MultiViews','+MultiViews'],
'order' => ['deny','yned'],
'passenger_enabled' => 'onf',
},
{
'path' => '/opt/app2',
'addhandlers' => {
'handler' => 'cgi-script',
'extensions' => '.cgi',
},
},
],
:match => [
/^ <Directory \/opt\/app1>$/,
/^ Allow from rspec.org$/,
/^ AllowOverride AuthConfig Indexes$/,
/^ Deny from google.com$/,
/^ Options -MultiViews \+MultiViews$/,
/^ Order deny,yned$/,
/^ PassengerEnabled onf$/,
/^ <\/Directory>$/,
/^ <Directory \/opt\/app2>$/,
/^ AllowOverride None$/,
/^ Order allow,deny$/,
/^ Allow from all$/,
/^ AddHandler cgi-script .cgi$/,
/^ <\/Directory>$/,
],
},
{
:title => 'should accept multiple directories',
:attr => 'directories',
:value => [
{ 'path' => '/opt/app' },
{ 'path' => '/var/www' },
{ 'path' => '/rspec/docroot'}
],
:match => [
/^ <Directory \/opt\/app>$/,
/^ <Directory \/var\/www>$/,
/^ <Directory \/rspec\/docroot>$/,
],
},
{
:title => 'should accept location for provider',
:attr => 'directories',
:value => {
'path' => '/',
'provider' => 'location',
},
:notmatch => [' AllowOverride None'],
:match => [
/^ <Location \/>$/,
/^ Order allow,deny$/,
/^ Allow from all$/,
/^ <\/Location>$/,
],
},
{
:title => 'should accept files for provider',
:attr => 'directories',
:value => {
'path' => 'index.html',
'provider' => 'files',
},
:notmatch => [' AllowOverride None'],
:match => [
/^ <Files index.html>$/,
/^ Order allow,deny$/,
/^ Allow from all$/,
/^ <\/Files>$/,
],
},
{
:title => 'should contain virtual_docroot',
:attr => 'virtual_docroot',
:value => '/not/default',
:match => [
/^ VirtualDocumentRoot \/not\/default$/,
],
},
].each do |param|
describe "when #{param[:attr]} is #{param[:value]}" do
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_file("25-#{title}.conf").with_mode('0644') }
if param[:match]
it "#{param[:title]}: matches" do
param[:match].each do |match|
should contain_file("25-#{title}.conf").with_content( match )
end
end
end
if param[:notmatch]
it "#{param[:title]}: notmatches" do
param[:notmatch].each do |notmatch|
should_not contain_file("25-#{title}.conf").with_content( notmatch )
end
end
end
end
end
end
context ".conf content with SSL" do
[
{
:title => 'should accept setting SSLCertificateFile',
:attr => 'ssl_cert',
:value => '/path/to/cert.pem',
:match => [/^ SSLCertificateFile \/path\/to\/cert\.pem$/],
},
{
:title => 'should accept setting SSLCertificateKeyFile',
:attr => 'ssl_key',
:value => '/path/to/cert.pem',
:match => [/^ SSLCertificateKeyFile \/path\/to\/cert\.pem$/],
},
{
:title => 'should accept setting SSLCertificateChainFile',
:attr => 'ssl_chain',
:value => '/path/to/cert.pem',
:match => [/^ SSLCertificateChainFile \/path\/to\/cert\.pem$/],
},
{
:title => 'should accept setting SSLCertificatePath',
:attr => 'ssl_certs_dir',
:value => '/path/to/certs',
:match => [/^ SSLCACertificatePath \/path\/to\/certs$/],
},
{
:title => 'should accept setting SSLCertificateFile',
:attr => 'ssl_ca',
:value => '/path/to/ca.pem',
:match => [/^ SSLCACertificateFile \/path\/to\/ca\.pem$/],
},
{
:title => 'should accept setting SSLRevocationPath',
:attr => 'ssl_crl_path',
:value => '/path/to/crl',
:match => [/^ SSLCARevocationPath \/path\/to\/crl$/],
},
{
:title => 'should accept setting SSLRevocationFile',
:attr => 'ssl_crl',
:value => '/path/to/crl.pem',
:match => [/^ SSLCARevocationFile \/path\/to\/crl\.pem$/],
},
{
:title => 'should accept setting SSLProxyEngine',
:attr => 'ssl_proxyengine',
:value => true,
:match => [/^ SSLProxyEngine On$/],
},
{
:title => 'should accept setting SSLProtocol',
:attr => 'ssl_protocol',
:value => 'all -SSLv2',
:match => [/^ SSLProtocol all -SSLv2$/],
},
{
:title => 'should accept setting SSLCipherSuite',
:attr => 'ssl_cipher',
:value => 'RC4-SHA:HIGH:!ADH:!SSLv2',
:match => [/^ SSLCipherSuite RC4-SHA:HIGH:!ADH:!SSLv2$/],
},
{
:title => 'should accept setting SSLHonorCipherOrder',
:attr => 'ssl_honorcipherorder',
:value => 'On',
:match => [/^ SSLHonorCipherOrder On$/],
},
{
:title => 'should accept setting SSLVerifyClient',
:attr => 'ssl_verify_client',
:value => 'optional',
:match => [/^ SSLVerifyClient optional$/],
},
{
:title => 'should accept setting SSLVerifyDepth',
:attr => 'ssl_verify_depth',
:value => '1',
:match => [/^ SSLVerifyDepth 1$/],
},
{
:title => 'should accept setting SSLOptions with a string',
:attr => 'ssl_options',
:value => '+ExportCertData',
:match => [/^ SSLOptions \+ExportCertData$/],
},
{
:title => 'should accept setting SSLOptions with an array',
:attr => 'ssl_options',
:value => ['+StrictRequire','+ExportCertData'],
:match => [/^ SSLOptions \+StrictRequire \+ExportCertData/],
},
{
:title => 'should accept setting SSLOptions with a string in directories',
:attr => 'directories',
:value => { 'path' => '/srv/www', 'ssl_options' => '+ExportCertData'},
:match => [/^ SSLOptions \+ExportCertData$/],
},
{
:title => 'should accept setting SSLOptions with an array in directories',
:attr => 'directories',
:value => { 'path' => '/srv/www', 'ssl_options' => ['-StdEnvVars','+ExportCertData']},
:match => [/^ SSLOptions -StdEnvVars \+ExportCertData/],
},
].each do |param|
describe "when #{param[:attr]} is #{param[:value]} with SSL" do
let :params do
default_params.merge( {
param[:attr].to_sym => param[:value],
:ssl => true,
} )
end
it { should contain_file("25-#{title}.conf").with_mode('0644') }
if param[:match]
it "#{param[:title]}: matches" do
param[:match].each do |match|
should contain_file("25-#{title}.conf").with_content( match )
end
end
end
if param[:notmatch]
it "#{param[:title]}: notmatches" do
param[:notmatch].each do |notmatch|
should_not contain_file("25-#{title}.conf").with_content( notmatch )
end
end
end
end
end
end
context 'attribute resources' do
describe 'when access_log_file and access_log_pipe are specified' do
let :params do default_params.merge({
:access_log_file => 'fake.log',
:access_log_pipe => '| /bin/fake',
}) end
it 'should cause a failure' do
expect { subject }.to raise_error(Puppet::Error, /'access_log_file' and 'access_log_pipe' cannot be defined at the same time/)
end
end
describe 'when error_log_file and error_log_pipe are specified' do
let :params do default_params.merge({
:error_log_file => 'fake.log',
:error_log_pipe => '| /bin/fake',
}) end
it 'should cause a failure' do
expect { subject }.to raise_error(Puppet::Error, /'error_log_file' and 'error_log_pipe' cannot be defined at the same time/)
end
end
describe 'when docroot owner is specified' do
let :params do default_params.merge({
:docroot_owner => 'testuser',
:docroot_group => 'testgroup',
}) end
it 'should set vhost ownership' do
should contain_file(params[:docroot]).with({
:ensure => :directory,
:owner => 'testuser',
:group => 'testgroup',
})
end
end
describe 'when wsgi_daemon_process and wsgi_daemon_process_options are specified' do
let :params do default_params.merge({
:wsgi_daemon_process => 'example.org',
:wsgi_daemon_process_options => { 'processes' => '2', 'threads' => '15' },
}) end
it 'should set wsgi_daemon_process_options' do
should contain_file("25-#{title}.conf").with_content(
/^ WSGIDaemonProcess example.org processes=2 threads=15$/
)
end
end
describe 'when rewrites are specified' do
let :params do default_params.merge({
:rewrites => [
{
'comment' => 'test rewrites',
'rewrite_cond' => ['%{HTTP_USER_AGENT} ^Lynx/ [OR]', '%{HTTP_USER_AGENT} ^Mozilla/[12]'],
'rewrite_rule' => ['^index\.html$ welcome.html', '^index\.cgi$ index.php'],
}
]
}) end
it 'should set RewriteConds and RewriteRules' do
should contain_file("25-#{title}.conf").with_content(
/^ #test rewrites$/
)
should contain_file("25-#{title}.conf").with_content(
/^ RewriteCond %\{HTTP_USER_AGENT\} \^Lynx\/ \[OR\]$/
)
should contain_file("25-#{title}.conf").with_content(
/^ RewriteCond %\{HTTP_USER_AGENT\} \^Mozilla\/\[12\]$/
)
should contain_file("25-#{title}.conf").with_content(
/^ RewriteRule \^index\\.html\$ welcome.html$/
)
should contain_file("25-#{title}.conf").with_content(
/^ RewriteRule \^index\\.cgi\$ index.php$/
)
end
end
describe 'when rewrite_rule and rewrite_cond are specified' do
let :params do default_params.merge({
:rewrite_cond => '%{HTTPS} off',
:rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}',
}) end
it 'should set RewriteCond' do
should contain_file("25-#{title}.conf").with_content(
/^ RewriteCond %\{HTTPS\} off$/
)
end
end
describe 'when suphp_engine is on and suphp_configpath is specified' do
let :params do default_params.merge({
:suphp_engine => 'on',
:suphp_configpath => '/etc/php5/apache2',
}) end
it 'should set suphp_configpath' do
should contain_file("25-#{title}.conf").with_content(
/^ suPHP_ConfigPath \/etc\/php5\/apache2$/
)
end
end
describe 'when suphp_engine is on and suphp_addhandler is specified' do
let :params do default_params.merge({
:suphp_engine => 'on',
:suphp_addhandler => 'x-httpd-php',
}) end
it 'should set suphp_addhandler' do
should contain_file("25-#{title}.conf").with_content(
/^ suPHP_AddHandler x-httpd-php/
)
end
end
describe 'when suphp_engine is on and suphp { user & group } is specified' do
let :params do default_params.merge({
:suphp_engine => 'on',
:directories => { 'path' => '/srv/www',
'suphp' => { 'user' => 'myappuser', 'group' => 'myappgroup' },
}
}) end
it 'should set suphp_UserGroup' do
should contain_file("25-#{title}.conf").with_content(
/^ suPHP_UserGroup myappuser myappgroup/
)
end
end
describe 'priority/default settings' do
describe 'when neither priority/default is specified' do
let :params do default_params end
it { should contain_file("25-#{title}.conf").with_path(
/25-#{title}.conf/
) }
end
describe 'when both priority/default_vhost is specified' do
let :params do
default_params.merge({
:priority => 15,
:default_vhost => true,
})
end
it { should contain_file("15-#{title}.conf").with_path(
/15-#{title}.conf/
) }
end
describe 'when only priority is specified' do
let :params do
default_params.merge({ :priority => 14, })
end
it { should contain_file("14-#{title}.conf").with_path(
/14-#{title}.conf/
) }
end
describe 'when only default is specified' do
let :params do
default_params.merge({ :default_vhost => true, })
end
it { should contain_file("10-#{title}.conf").with_path(
/10-#{title}.conf/
) }
end
end