forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bats
More file actions
executable file
·1617 lines (1268 loc) · 45.5 KB
/
test.bats
File metadata and controls
executable file
·1617 lines (1268 loc) · 45.5 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
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/bats-file/load'
function random() {
head /dev/urandom | tr -dc 0-9 | head -c$1
}
function setup() {
# echo "# Setup_file" > &3
if [ $BATS_TEST_NUMBER = 1 ]; then
echo 'user=test-5285' > /tmp/hestia-test-env.sh
echo 'user2=test-5286' >> /tmp/hestia-test-env.sh
echo 'userbk=testbk-5285' >> /tmp/hestia-test-env.sh
echo 'userpass1=test-5285' >> /tmp/hestia-test-env.sh
echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
echo 'rootdomain=testhestiacp.com' >> /tmp/hestia-test-env.sh
echo 'subdomain=cdn.testhestiacp.com' >> /tmp/hestia-test-env.sh
echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
echo 'dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
fi
source /tmp/hestia-test-env.sh
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf
source $HESTIA/func/ip.sh
}
function validate_web_domain() {
local user=$1
local domain=$2
local webproof=$3
local webpath=${4}
refute [ -z "$user" ]
refute [ -z "$domain" ]
refute [ -z "$webproof" ]
source $HESTIA/func/ip.sh
run v-list-web-domain $user $domain
assert_success
USER_DATA=$HESTIA/data/users/$user
local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
domain_ip=$(get_real_ip "$domain_ip")
if [ ! -z $webpath ]; then
domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
assert_file_exist "${domain_docroot}/${webpath}"
else
assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
fi
fi
# Test HTTP
run curl --location --silent --show-error --insecure --resolve "${domain}:80:${domain_ip}" "http://${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
# Test HTTPS
if [ "$SSL" = "yes" ]; then
run v-list-web-domain-ssl $user $domain
assert_success
run curl --location --silent --show-error --insecure --resolve "${domain}:443:${domain_ip}" "https://${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
fi
}
function validate_mail_domain() {
local user=$1
local domain=$2
refute [ -z "$user" ]
refute [ -z "$domain" ]
run v-list-mail-domain $user $domain
assert_success
assert_dir_exist $HOMEDIR/$user/mail/$domain
assert_dir_exist $HOMEDIR/$user/conf/mail/$domain
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/aliases
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antispam
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antivirus
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/fwd_only
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/ip
assert_file_exist $HOMEDIR/$user/conf/mail/$domain/passwd
}
function validate_webmail_domain() {
local user=$1
local domain=$2
local webproof=$3
local webpath=${4}
refute [ -z "$user" ]
refute [ -z "$domain" ]
refute [ -z "$webproof" ]
source $HESTIA/func/ip.sh
USER_DATA=$HESTIA/data/users/$user
local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
SSL=$(get_object_value 'mail' 'DOMAIN' "$domain" '$SSL')
domain_ip=$(get_real_ip "$domain_ip")
if [ ! -z "$webpath" ]; then
assert_file_exist /var/lib/roundcube/$webpath
fi
# Test HTTP
run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
# Test HTTP
run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
# Test HTTPS
if [ "$SSL" = "yes" ]; then
run v-list-mail-domain-ssl $user $domain
assert_success
run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:443:${domain_ip}" "https://webmail.${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
run curl --location --silent --show-error --insecure --resolve "mail.${domain}:443:${domain_ip}" "https://mail.${domain}/${webpath}"
assert_success
assert_output --partial "$webproof"
fi
}
function validate_database(){
local database=$1
local dbuser=$2
local password=$3
host_str=$(grep "HOST='localhost'" $HESTIA/conf/mysql.conf)
parse_object_kv_list "$host_str"
if [ -z $PORT ]; then PORT=3306; fi
refute [ -z "$HOST" ]
refute [ -z "$PORT" ]
refute [ -z "$database" ]
refute [ -z "$dbuser" ]
refute [ -z "$password" ]
# Create an connection to verify correct username / password has been set correctly
tmpfile=$(mktemp /tmp/mysql.XXXXXX)
echo "[client]">$tmpfile
echo "host='$HOST'" >> $tmpfile
echo "user='$dbuser'" >> $tmpfile
echo "password='$password'" >> $tmpfile
echo "port='$PORT'" >> $tmpfile
chmod 600 $tmpfile
sql_tmp=$(mktemp /tmp/query.XXXXXX)
echo "show databases;" > $sql_tmp
run mysql --defaults-file=$tmpfile < "$sql_tmp"
assert_success
assert_output --partial "$database"
rm -f "$sql_tmp"
rm -f "$tmpfile"
}
#----------------------------------------------------------#
# MAIN #
#----------------------------------------------------------#
@test "Add new userXXX" {
skip
run v-add-user $user $user $user@hestiacp.com default "Super Test"
assert_success
refute_output
}
#----------------------------------------------------------#
# IP #
#----------------------------------------------------------#
@test "Check reverse Dns validation" {
# 1. PTR record for a IP should return a hostname(reverse) which in turn must resolve to the same IP addr(forward). (Full circle)
# `-> not implemented in `is_ip_rdns_valid` yet and also not tested here
# 2. Reject rPTR records that match generic dynamic IP pool patterns
local ip="54.200.1.22"
local rdns="ec2-54-200-1-22.us-west-2.compute.amazonaws.com"
run is_ip_rdns_valid "$ip"
assert_failure
refute_output
local rdns="ec2.54.200.1.22.us-west-2.compute.amazonaws.com"
run is_ip_rdns_valid "$ip"
assert_failure
refute_output
local rdns="ec2-22-1-200-54.us-west-2.compute.amazonaws.com"
run is_ip_rdns_valid "$ip"
assert_failure
refute_output
local rdns="ec2.22.1.200.54.us-west-2.compute.amazonaws.com"
run is_ip_rdns_valid "$ip"
assert_failure
refute_output
local rdns="ec2-200-54-1-22.us-west-2.compute.amazonaws.com"
run is_ip_rdns_valid "$ip"
assert_failure
refute_output
local rdns="panel-22.mydomain.tld"
run is_ip_rdns_valid "$ip"
assert_success
assert_output "$rdns"
local rdns="mail.mydomain.tld"
run is_ip_rdns_valid "$ip"
assert_success
assert_output "$rdns"
local rdns="mydomain.tld"
run is_ip_rdns_valid "$ip"
assert_success
assert_output "$rdns"
}
#----------------------------------------------------------#
# User #
#----------------------------------------------------------#
@test "Add new user" {
run v-add-user $user $user $user@hestiacp.com default "Super Test"
assert_success
refute_output
}
@test "Change user password" {
run v-change-user-password "$user" t3st-p4ssw0rd
assert_success
refute_output
}
@test "Change user email" {
run v-change-user-contact "$user" tester@hestiacp.com
assert_success
refute_output
}
@test "Change user contact invalid email " {
run v-change-user-contact "$user" testerhestiacp.com
assert_failure $E_INVALID
assert_output --partial 'Error: invalid email format'
}
@test "Change user name" {
run v-change-user-name "$user" "New name"
assert_success
refute_output
}
@test "Change user shell" {
run v-change-user-shell $user bash
assert_success
refute_output
}
@test "Change user invalid shell" {
run v-change-user-shell $user bashinvalid
assert_failure $E_INVALID
assert_output --partial 'shell bashinvalid is not valid'
}
@test "Change user default ns" {
run v-change-user-ns $user ns0.com ns1.com ns2.com ns3.com
assert_success
refute_output
run v-list-user-ns "$user" plain
assert_success
assert_output --partial 'ns0.com'
}
#----------------------------------------------------------#
# Cron #
#----------------------------------------------------------#
@test "Cron: Add cron job" {
run v-add-cron-job $user 1 1 1 1 1 echo
assert_success
refute_output
}
@test "Cron: Suspend cron job" {
run v-suspend-cron-job $user 1
assert_success
refute_output
}
@test "Cron: Unsuspend cron job" {
run v-unsuspend-cron-job $user 1
assert_success
refute_output
}
@test "Cron: Delete cron job" {
run v-delete-cron-job $user 1
assert_success
refute_output
}
@test "Cron: Add cron job (duplicate)" {
run v-add-cron-job $user 1 1 1 1 1 echo 1
assert_success
refute_output
run v-add-cron-job $user 1 1 1 1 1 echo 1
assert_failure $E_EXISTS
assert_output --partial 'JOB=1 already exists'
}
@test "Cron: Second cron job" {
run v-add-cron-job $user 2 2 2 2 2 echo 2
assert_success
refute_output
}
@test "Cron: Two cron jobs must be listed" {
run v-list-cron-jobs $user csv
assert_success
assert_line --partial '1,1,1,1,1,"echo",no'
assert_line --partial '2,2,2,2,2,"echo",no'
}
@test "Cron: rebuild" {
run v-rebuild-cron-jobs $user
assert_success
refute_output
}
#----------------------------------------------------------#
# IP #
#----------------------------------------------------------#
@test "Ip: Add new ip on first interface" {
interface=$(v-list-sys-interfaces plain | head -n 1)
run ip link show dev $interface
assert_success
local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
# Save initial state
echo "interface=${interface}" >> /tmp/hestia-test-env.sh
[ -f "$a2_rpaf" ] && file_hash1=$(cat $a2_rpaf |md5sum |cut -d" " -f1) && echo "a2_rpaf_hash='${file_hash1}'" >> /tmp/hestia-test-env.sh
[ -f "$a2_remoteip" ] && file_hash2=$(cat $a2_remoteip |md5sum |cut -d" " -f1) && echo "a2_remoteip_hash='${file_hash2}'" >> /tmp/hestia-test-env.sh
local ip="198.18.0.12"
run v-add-sys-ip $ip 255.255.255.255 $interface $user
assert_success
refute_output
assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
assert_file_exist $HESTIA/data/ips/$ip
assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
if [ -n "$PROXY_SYSTEM" ]; then
assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
[ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
[ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
fi
}
@test "Ip: Add ip (duplicate)" {
run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
assert_failure $E_EXISTS
}
@test "Ip: Add extra ip" {
local ip="198.18.0.121"
run v-add-sys-ip $ip 255.255.255.255 $interface $user
assert_success
refute_output
assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
assert_file_exist $HESTIA/data/ips/$ip
assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
if [ -n "$PROXY_SYSTEM" ]; then
assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
[ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
[ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
fi
}
@test "Ip: Delete ips" {
local ip="198.18.0.12"
run v-delete-sys-ip $ip
assert_success
refute_output
assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
assert_file_not_exist $HESTIA/data/ips/$ip
ip="198.18.0.121"
run v-delete-sys-ip $ip
assert_success
refute_output
assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
assert_file_not_exist $HESTIA/data/ips/$ip
if [ -n "$PROXY_SYSTEM" ]; then
assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
fi
# remoteip and rpaf config hashes must match the initial one
if [ ! -z "$a2_rpaf_hash" ]; then
local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
assert_equal "$file_hash" "$a2_rpaf_hash"
fi
if [ ! -z "$a2_remoteip_hash" ]; then
local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
assert_equal "$file_hash" "$a2_remoteip_hash"
fi
}
@test "Ip: Add IP for rest of the test" {
local ip="198.18.0.125"
run v-add-sys-ip $ip 255.255.255.255 $interface $user
assert_success
refute_output
assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
assert_file_exist $HESTIA/data/ips/$ip
assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
if [ -n "$PROXY_SYSTEM" ]; then
assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
[ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
[ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
fi
}
#----------------------------------------------------------#
# WEB #
#----------------------------------------------------------#
@test "WEB: Add web domain" {
run v-add-web-domain $user $domain 198.18.0.125
assert_success
refute_output
echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
}
@test "WEB: Add web domain (duplicate)" {
run v-add-web-domain $user $domain 198.18.0.125
assert_failure $E_EXISTS
}
@test "WEB: Add web domain alias" {
run v-add-web-domain-alias $user $domain v3.$domain
assert_success
refute_output
}
@test "WEB: Add web domain alias (duplicate)" {
run v-add-web-domain-alias $user $domain v3.$domain
assert_failure $E_EXISTS
}
@test "WEB: Add web domain wildcard alias" {
run v-add-web-domain-alias $user $domain "*.$domain"
assert_success
refute_output
}
@test "WEB: Delete web domain wildcard alias" {
run v-delete-web-domain-alias $user $domain "*.$domain"
assert_success
refute_output
}
@test "WEB: Add web domain stats" {
run v-add-web-domain-stats $user $domain awstats
assert_success
refute_output
}
@test "WEB: Add web domain stats user" {
skip
run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
assert_success
refute_output
}
@test "WEB: Suspend web domain" {
run v-suspend-web-domain $user $domain
assert_success
refute_output
validate_web_domain $user $domain 'This site is currently suspended'
}
@test "WEB: Unsuspend web domain" {
run v-unsuspend-web-domain $user $domain
assert_success
refute_output
echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
}
@test "WEB: Add ssl" {
cp -f $HESTIA/ssl/certificate.crt /tmp/$domain.crt
cp -f $HESTIA/ssl/certificate.key /tmp/$domain.key
run v-add-web-domain-ssl $user $domain /tmp
assert_success
refute_output
}
@test "WEB: Rebuild web domain" {
run v-rebuild-web-domains $user
assert_success
refute_output
}
#----------------------------------------------------------#
# MULTIPHP #
#----------------------------------------------------------#
@test "Multiphp: Default php Backend version" {
def_phpver=$(multiphp_default_version)
multi_domain="multiphp.${domain}"
run v-add-web-domain $user $multi_domain 198.18.0.125
assert_success
refute_output
echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v5.6" {
test_phpver='5.6'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v7.0" {
test_phpver='7.0'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v7.1" {
test_phpver='7.1'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v7.2" {
test_phpver='7.2'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v7.3" {
test_phpver='7.3'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v7.4" {
test_phpver='7.4'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
}
@test "Multiphp: Change backend version - PHP v8.0" {
test_phpver='8.0'
multi_domain="multiphp.${domain}"
if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
skip "PHP ${test_phpver} not installed"
fi
run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
assert_success
refute_output
# Changing web backend will create a php-fpm pool config in the corresponding php folder
assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
# A single php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '1'
echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
}
@test "Multiphp: Cleanup" {
multi_domain="multiphp.${domain}"
run v-delete-web-domain $user $multi_domain 'yes'
assert_success
refute_output
# No php-fpm pool config file must be present
num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
assert_equal "$num_fpm_config_files" '0'
}
#----------------------------------------------------------#
# CUSTOM DOCROOT #
#----------------------------------------------------------#
@test "Docroot: Self Subfolder" {
docroot1_domain="docroot1.${domain}"
run v-add-web-domain $user $docroot1_domain 198.18.0.125
assert_success
refute_output
run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
assert_success
refute_output
run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
assert_success
refute_output
echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
}
@test "Docroot: Other domain subfolder" {
docroot1_domain="docroot1.${domain}"
docroot2_domain="docroot2.${domain}"
run v-add-web-domain $user $docroot2_domain 198.18.0.125
assert_success
refute_output
run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
assert_success
refute_output
run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
assert_success
refute_output
echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
}
@test "Docroot: Other domain root folder" {
docroot1_domain="docroot1.${domain}"
docroot2_domain="docroot2.${domain}"
run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
assert_success
refute_output
echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
}
@test "Docroot: Reset" {
docroot1_domain="docroot1.${domain}"
run v-change-web-domain-docroot $user "$docroot1_domain" "default"
assert_success
refute_output
echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
}
@test "Docroot: Cleanup" {
docroot1_domain="docroot1.${domain}"
docroot2_domain="docroot2.${domain}"
run v-delete-web-domain $user $docroot1_domain
assert_success
refute_output
run v-delete-web-domain $user $docroot2_domain
assert_success
refute_output
}
#----------------------------------------------------------#
# DNS #
#----------------------------------------------------------#
@test "DNS: Add domain" {
run v-add-dns-domain $user $domain 198.18.0.125
assert_success
refute_output
}
@test "DNS: Add domain (duplicate)" {
run v-add-dns-domain $user $domain 198.18.0.125
assert_failure $E_EXISTS
}
@test "DNS: Add domain record" {
run v-add-dns-record $user $domain test A 198.18.0.125 20
assert_success
refute_output
}
@test "DNS: Delete domain record" {
run v-delete-dns-record $user $domain 20
assert_success
refute_output
}
@test "DNS: Delete missing domain record" {
run v-delete-dns-record $user $domain 20
assert_failure $E_NOTEXIST
}
@test "DNS: Change domain expire date" {
run v-change-dns-domain-exp $user $domain 2020-01-01
assert_success
refute_output
}
@test "DNS: Change domain ip" {
run v-change-dns-domain-ip $user $domain 127.0.0.1
assert_success
refute_output
}
@test "DNS: Suspend domain" {
run v-suspend-dns-domain $user $domain
assert_success
refute_output
}
@test "DNS: Unsuspend domain" {
run v-unsuspend-dns-domain $user $domain
assert_success
refute_output
}
@test "DNS: Rebuild" {
run v-rebuild-dns-domains $user
assert_success
refute_output
}
#----------------------------------------------------------#
# MAIL #
#----------------------------------------------------------#
@test "MAIL: Add domain" {
run v-add-mail-domain $user $domain
assert_success
refute_output
validate_mail_domain $user $domain
# echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
# rm /var/lib/roundcube/check_server.php
}
@test "MAIL: Add domain (duplicate)" {
run v-add-mail-domain $user $domain
assert_failure $E_EXISTS
}
@test "MAIL: Add account" {
run v-add-mail-account $user $domain test t3st-p4ssw0rd
assert_success
refute_output
}
@test "MAIL: Add account (duplicate)" {
run v-add-mail-account $user $domain test t3st-p4ssw0rd
assert_failure $E_EXISTS
}
@test "MAIL: Delete account" {
run v-delete-mail-account $user $domain test
assert_success
refute_output
}
@test "MAIL: Delete missing account" {
run v-delete-mail-account $user $domain test
assert_failure $E_NOTEXIST
}
#----------------------------------------------------------#
# Limit possibilities adding different owner domain #
#----------------------------------------------------------#
@test "Allow Users: User can't add user.user2.com " {
# Case: admin company.ltd
# users should not be allowed to add user.company.ltd
run v-add-user $user2 $user2 $user@hestiacp.com default "Super Test"
assert_success
refute_output
run v-add-web-domain $user2 $rootdomain
assert_success
refute_output
run v-add-web-domain $user $subdomain
assert_failure $E_EXISTS
}
@test "Allow Users: User can't add user.user2.com as alias" {
run v-add-web-domain-alias $user $domain $subdomain
assert_failure $E_EXISTS
}
@test "Allow Users: User can't add user.user2.com as mail domain" {
run v-add-mail-domain $user $subdomain
assert_failure $E_EXISTS
}
@test "Allow Users: User can't add user.user2.com as dns domain" {
run v-add-dns-domain $user $subdomain 198.18.0.125
assert_failure $E_EXISTS
}
@test "Allow Users: Set Allow users" {
# Allow user to yes allows
# Case: admin company.ltd
# users are allowed to add user.company.ltd
run v-add-web-domain-allow-users $user2 $rootdomain
assert_success
refute_output
}
@test "Allow Users: User can add user.user2.com" {
run v-add-web-domain $user $subdomain
assert_success
refute_output
}