test.bats 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. #!/usr/bin/env bats
  2. load 'test_helper/bats-support/load'
  3. load 'test_helper/bats-assert/load'
  4. load 'test_helper/bats-file/load'
  5. function random() {
  6. head /dev/urandom | tr -dc 0-9 | head -c$1
  7. }
  8. function setup() {
  9. # echo "# Setup_file" > &3
  10. if [ $BATS_TEST_NUMBER = 1 ]; then
  11. echo 'user=test-5285' > /tmp/hestia-test-env.sh
  12. echo 'userbk=testbk-5285' >> /tmp/hestia-test-env.sh
  13. echo 'userpass1=test-5285' >> /tmp/hestia-test-env.sh
  14. echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
  15. echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
  16. echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
  17. fi
  18. source /tmp/hestia-test-env.sh
  19. source $HESTIA/func/main.sh
  20. source $HESTIA/conf/hestia.conf
  21. source $HESTIA/func/ip.sh
  22. }
  23. function validate_web_domain() {
  24. local user=$1
  25. local domain=$2
  26. local webproof=$3
  27. local webpath=${4}
  28. refute [ -z "$user" ]
  29. refute [ -z "$domain" ]
  30. refute [ -z "$webproof" ]
  31. source $HESTIA/func/ip.sh
  32. run v-list-web-domain $user $domain
  33. assert_success
  34. USER_DATA=$HESTIA/data/users/$user
  35. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  36. SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
  37. domain_ip=$(get_real_ip "$domain_ip")
  38. if [ ! -z $webpath ]; then
  39. assert_file_exist $HOMEDIR/$user/web/$domain/public_html/$webpath
  40. fi
  41. # Test HTTP
  42. run curl --location --silent --show-error --insecure --resolve "${domain}:80:${domain_ip}" "http://${domain}/${webpath}"
  43. assert_success
  44. assert_output --partial "$webproof"
  45. # Test HTTPS
  46. if [ "$SSL" = "yes" ]; then
  47. run v-list-web-domain-ssl $user $domain
  48. assert_success
  49. run curl --location --silent --show-error --insecure --resolve "${domain}:443:${domain_ip}" "https://${domain}/${webpath}"
  50. assert_success
  51. assert_output --partial "$webproof"
  52. fi
  53. }
  54. function validate_mail_domain() {
  55. local user=$1
  56. local domain=$2
  57. refute [ -z "$user" ]
  58. refute [ -z "$domain" ]
  59. run v-list-mail-domain $user $domain
  60. assert_success
  61. assert_dir_exist $HOMEDIR/$user/mail/$domain
  62. assert_dir_exist $HOMEDIR/$user/conf/mail/$domain
  63. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/aliases
  64. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antispam
  65. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antivirus
  66. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/fwd_only
  67. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/ip
  68. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/passwd
  69. }
  70. function validate_webmail_domain() {
  71. local user=$1
  72. local domain=$2
  73. local webproof=$3
  74. local webpath=${4}
  75. refute [ -z "$user" ]
  76. refute [ -z "$domain" ]
  77. refute [ -z "$webproof" ]
  78. source $HESTIA/func/ip.sh
  79. USER_DATA=$HESTIA/data/users/$user
  80. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  81. SSL=$(get_object_value 'mail' 'DOMAIN' "$domain" '$SSL')
  82. domain_ip=$(get_real_ip "$domain_ip")
  83. if [ ! -z "$webpath" ]; then
  84. assert_file_exist /var/lib/roundcube/$webpath
  85. fi
  86. # Test HTTP
  87. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
  88. assert_success
  89. assert_output --partial "$webproof"
  90. # Test HTTP
  91. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
  92. assert_success
  93. assert_output --partial "$webproof"
  94. # Test HTTPS
  95. if [ "$SSL" = "yes" ]; then
  96. run v-list-mail-domain-ssl $user $domain
  97. assert_success
  98. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:443:${domain_ip}" "https://webmail.${domain}/${webpath}"
  99. assert_success
  100. assert_output --partial "$webproof"
  101. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:443:${domain_ip}" "https://mail.${domain}/${webpath}"
  102. assert_success
  103. assert_output --partial "$webproof"
  104. fi
  105. }
  106. #----------------------------------------------------------#
  107. # MAIN #
  108. #----------------------------------------------------------#
  109. @test "Add new userXXX" {
  110. skip
  111. run v-add-user $user $user $user@hestiacp.com default "Super Test"
  112. assert_success
  113. refute_output
  114. }
  115. #----------------------------------------------------------#
  116. # IP #
  117. #----------------------------------------------------------#
  118. @test "Check reverse Dns validation" {
  119. # 1. PTR record for a IP should return a hostname(reverse) which in turn must resolve to the same IP addr(forward). (Full circle)
  120. # `-> not implemented in `is_ip_rdns_valid` yet and also not tested here
  121. # 2. Reject rPTR records that match generic dynamic IP pool patterns
  122. local ip="54.200.1.22"
  123. local rdns="ec2-54-200-1-22.us-west-2.compute.amazonaws.com"
  124. run is_ip_rdns_valid "$ip"
  125. assert_failure
  126. refute_output
  127. local rdns="ec2.54.200.1.22.us-west-2.compute.amazonaws.com"
  128. run is_ip_rdns_valid "$ip"
  129. assert_failure
  130. refute_output
  131. local rdns="ec2-22-1-200-54.us-west-2.compute.amazonaws.com"
  132. run is_ip_rdns_valid "$ip"
  133. assert_failure
  134. refute_output
  135. local rdns="ec2.22.1.200.54.us-west-2.compute.amazonaws.com"
  136. run is_ip_rdns_valid "$ip"
  137. assert_failure
  138. refute_output
  139. local rdns="ec2-200-54-1-22.us-west-2.compute.amazonaws.com"
  140. run is_ip_rdns_valid "$ip"
  141. assert_failure
  142. refute_output
  143. local rdns="panel-22.mydomain.tld"
  144. run is_ip_rdns_valid "$ip"
  145. assert_success
  146. assert_output "$rdns"
  147. local rdns="mail.mydomain.tld"
  148. run is_ip_rdns_valid "$ip"
  149. assert_success
  150. assert_output "$rdns"
  151. local rdns="mydomain.tld"
  152. run is_ip_rdns_valid "$ip"
  153. assert_success
  154. assert_output "$rdns"
  155. }
  156. #----------------------------------------------------------#
  157. # User #
  158. #----------------------------------------------------------#
  159. @test "Add new user" {
  160. run v-add-user $user $user $user@hestiacp.com default "Super Test"
  161. assert_success
  162. refute_output
  163. }
  164. @test "Change user password" {
  165. run v-change-user-password "$user" t3st-p4ssw0rd
  166. assert_success
  167. refute_output
  168. }
  169. @test "Change user email" {
  170. run v-change-user-contact "$user" tester@hestiacp.com
  171. assert_success
  172. refute_output
  173. }
  174. @test "Change user contact invalid email " {
  175. run v-change-user-contact "$user" testerhestiacp.com
  176. assert_failure $E_INVALID
  177. assert_output --partial 'Error: invalid email format'
  178. }
  179. @test "Change user name" {
  180. run v-change-user-name "$user" "New name"
  181. assert_success
  182. refute_output
  183. }
  184. @test "Change user shell" {
  185. run v-change-user-shell $user bash
  186. assert_success
  187. refute_output
  188. }
  189. @test "Change user invalid shell" {
  190. run v-change-user-shell $user bashinvalid
  191. assert_failure $E_INVALID
  192. assert_output --partial 'shell bashinvalid is not valid'
  193. }
  194. @test "Change user default ns" {
  195. run v-change-user-ns $user ns0.com ns1.com ns2.com ns3.com
  196. assert_success
  197. refute_output
  198. run v-list-user-ns "$user" plain
  199. assert_success
  200. assert_output --partial 'ns0.com'
  201. }
  202. #----------------------------------------------------------#
  203. # Cron #
  204. #----------------------------------------------------------#
  205. @test "Cron: Add cron job" {
  206. run v-add-cron-job $user 1 1 1 1 1 echo
  207. assert_success
  208. refute_output
  209. }
  210. @test "Cron: Suspend cron job" {
  211. run v-suspend-cron-job $user 1
  212. assert_success
  213. refute_output
  214. }
  215. @test "Cron: Unsuspend cron job" {
  216. run v-unsuspend-cron-job $user 1
  217. assert_success
  218. refute_output
  219. }
  220. @test "Cron: Delete cron job" {
  221. run v-delete-cron-job $user 1
  222. assert_success
  223. refute_output
  224. }
  225. @test "Cron: Add cron job (duplicate)" {
  226. run v-add-cron-job $user 1 1 1 1 1 echo 1
  227. assert_success
  228. refute_output
  229. run v-add-cron-job $user 1 1 1 1 1 echo 1
  230. assert_failure $E_EXISTS
  231. assert_output --partial 'JOB=1 is already exists'
  232. }
  233. @test "Cron: Second cron job" {
  234. run v-add-cron-job $user 2 2 2 2 2 echo 2
  235. assert_success
  236. refute_output
  237. }
  238. @test "Cron: Two cron jobs must be listed" {
  239. run v-list-cron-jobs $user csv
  240. assert_success
  241. assert_line --partial '1,1,1,1,1,"echo",no'
  242. assert_line --partial '2,2,2,2,2,"echo",no'
  243. }
  244. @test "Cron: rebuild" {
  245. run v-rebuild-cron-jobs $user
  246. assert_success
  247. refute_output
  248. }
  249. #----------------------------------------------------------#
  250. # IP #
  251. #----------------------------------------------------------#
  252. @test "Ip: Add new ip on first interface" {
  253. interface=$(v-list-sys-interfaces plain | head -n 1)
  254. run ip link show dev $interface
  255. assert_success
  256. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  257. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  258. # Save initial state
  259. echo "interface=${interface}" >> /tmp/hestia-test-env.sh
  260. [ -f "$a2_rpaf" ] && file_hash1=$(cat $a2_rpaf |md5sum |cut -d" " -f1) && echo "a2_rpaf_hash='${file_hash1}'" >> /tmp/hestia-test-env.sh
  261. [ -f "$a2_remoteip" ] && file_hash2=$(cat $a2_remoteip |md5sum |cut -d" " -f1) && echo "a2_remoteip_hash='${file_hash2}'" >> /tmp/hestia-test-env.sh
  262. local ip="198.18.0.12"
  263. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  264. assert_success
  265. refute_output
  266. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  267. assert_file_exist $HESTIA/data/ips/$ip
  268. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  269. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  270. if [ -n "$PROXY_SYSTEM" ]; then
  271. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  272. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  273. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  274. fi
  275. }
  276. @test "Ip: Add ip (duplicate)" {
  277. run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
  278. assert_failure $E_EXISTS
  279. }
  280. @test "Ip: Add extra ip" {
  281. local ip="198.18.0.121"
  282. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  283. assert_success
  284. refute_output
  285. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  286. assert_file_exist $HESTIA/data/ips/$ip
  287. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  288. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  289. if [ -n "$PROXY_SYSTEM" ]; then
  290. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  291. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  292. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  293. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  294. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  295. fi
  296. }
  297. @test "Ip: Delete ips" {
  298. local ip="198.18.0.12"
  299. run v-delete-sys-ip $ip
  300. assert_success
  301. refute_output
  302. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  303. assert_file_not_exist $HESTIA/data/ips/$ip
  304. ip="198.18.0.121"
  305. run v-delete-sys-ip $ip
  306. assert_success
  307. refute_output
  308. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  309. assert_file_not_exist $HESTIA/data/ips/$ip
  310. if [ -n "$PROXY_SYSTEM" ]; then
  311. assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  312. fi
  313. # remoteip and rpaf config hashes must match the initial one
  314. if [ ! -z "$a2_rpaf_hash" ]; then
  315. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  316. file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
  317. assert_equal "$file_hash" "$a2_rpaf_hash"
  318. fi
  319. if [ ! -z "$a2_remoteip_hash" ]; then
  320. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  321. file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
  322. assert_equal "$file_hash" "$a2_remoteip_hash"
  323. fi
  324. }
  325. @test "Ip: Add IP for rest of the test" {
  326. local ip="198.18.0.125"
  327. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  328. assert_success
  329. refute_output
  330. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  331. assert_file_exist $HESTIA/data/ips/$ip
  332. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  333. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  334. if [ -n "$PROXY_SYSTEM" ]; then
  335. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  336. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  337. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  338. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  339. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  340. fi
  341. }
  342. #----------------------------------------------------------#
  343. # WEB #
  344. #----------------------------------------------------------#
  345. @test "WEB: Add web domain" {
  346. run v-add-web-domain $user $domain 198.18.0.125
  347. assert_success
  348. refute_output
  349. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  350. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  351. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  352. }
  353. @test "WEB: Add web domain (duplicate)" {
  354. run v-add-web-domain $user $domain 198.18.0.125
  355. assert_failure $E_EXISTS
  356. }
  357. @test "WEB: Add web domain alias" {
  358. run v-add-web-domain-alias $user $domain v3.$domain
  359. assert_success
  360. refute_output
  361. }
  362. @test "WEB: Add web domain alias (duplicate)" {
  363. run v-add-web-domain-alias $user $domain v3.$domain
  364. assert_failure $E_EXISTS
  365. }
  366. @test "WEB: Add web domain stats" {
  367. run v-add-web-domain-stats $user $domain awstats
  368. assert_success
  369. refute_output
  370. }
  371. @test "WEB: Add web domain stats user" {
  372. skip
  373. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  374. assert_success
  375. refute_output
  376. }
  377. @test "WEB: Suspend web domain" {
  378. run v-suspend-web-domain $user $domain
  379. assert_success
  380. refute_output
  381. validate_web_domain $user $domain 'This site is currently suspended'
  382. }
  383. @test "WEB: Unsuspend web domain" {
  384. run v-unsuspend-web-domain $user $domain
  385. assert_success
  386. refute_output
  387. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  388. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  389. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  390. }
  391. @test "WEB: Add ssl" {
  392. cp -f $HESTIA/ssl/certificate.crt /tmp/$domain.crt
  393. cp -f $HESTIA/ssl/certificate.key /tmp/$domain.key
  394. run v-add-web-domain-ssl $user $domain /tmp
  395. assert_success
  396. refute_output
  397. }
  398. @test "WEB: Rebuild web domain" {
  399. run v-rebuild-web-domains $user
  400. assert_success
  401. refute_output
  402. }
  403. #----------------------------------------------------------#
  404. # MULTIPHP #
  405. #----------------------------------------------------------#
  406. @test "Multiphp: Default php Backend version" {
  407. def_phpver=$(multiphp_default_version)
  408. multi_domain="multiphp.${domain}"
  409. run v-add-web-domain $user $multi_domain 198.18.0.125
  410. assert_success
  411. refute_output
  412. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  413. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  414. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  415. }
  416. @test "Multiphp: Change backend version - PHP v5.6" {
  417. test_phpver='5.6'
  418. multi_domain="multiphp.${domain}"
  419. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  420. skip "PHP ${test_phpver} not installed"
  421. fi
  422. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  423. assert_success
  424. refute_output
  425. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  426. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  427. # A single php-fpm pool config file must be present
  428. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  429. assert_equal "$num_fpm_config_files" '1'
  430. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  431. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  432. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  433. }
  434. @test "Multiphp: Change backend version - PHP v7.0" {
  435. test_phpver='7.0'
  436. multi_domain="multiphp.${domain}"
  437. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  438. skip "PHP ${test_phpver} not installed"
  439. fi
  440. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  441. assert_success
  442. refute_output
  443. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  444. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  445. # A single php-fpm pool config file must be present
  446. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  447. assert_equal "$num_fpm_config_files" '1'
  448. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  449. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  450. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  451. }
  452. @test "Multiphp: Change backend version - PHP v7.1" {
  453. test_phpver='7.1'
  454. multi_domain="multiphp.${domain}"
  455. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  456. skip "PHP ${test_phpver} not installed"
  457. fi
  458. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  459. assert_success
  460. refute_output
  461. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  462. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  463. # A single php-fpm pool config file must be present
  464. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  465. assert_equal "$num_fpm_config_files" '1'
  466. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  467. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  468. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  469. }
  470. @test "Multiphp: Change backend version - PHP v7.2" {
  471. test_phpver='7.2'
  472. multi_domain="multiphp.${domain}"
  473. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  474. skip "PHP ${test_phpver} not installed"
  475. fi
  476. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  477. assert_success
  478. refute_output
  479. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  480. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  481. # A single php-fpm pool config file must be present
  482. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  483. assert_equal "$num_fpm_config_files" '1'
  484. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  485. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  486. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  487. }
  488. @test "Multiphp: Change backend version - PHP v7.3" {
  489. test_phpver='7.3'
  490. multi_domain="multiphp.${domain}"
  491. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  492. skip "PHP ${test_phpver} not installed"
  493. fi
  494. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  495. assert_success
  496. refute_output
  497. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  498. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  499. # A single php-fpm pool config file must be present
  500. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  501. assert_equal "$num_fpm_config_files" '1'
  502. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  503. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  504. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  505. }
  506. @test "Multiphp: Change backend version - PHP v7.4" {
  507. test_phpver='7.4'
  508. multi_domain="multiphp.${domain}"
  509. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  510. skip "PHP ${test_phpver} not installed"
  511. fi
  512. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  513. assert_success
  514. refute_output
  515. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  516. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  517. # A single php-fpm pool config file must be present
  518. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  519. assert_equal "$num_fpm_config_files" '1'
  520. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  521. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  522. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  523. }
  524. @test "Multiphp: Change backend version - PHP v8.0" {
  525. test_phpver='8.0'
  526. multi_domain="multiphp.${domain}"
  527. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  528. skip "PHP ${test_phpver} not installed"
  529. fi
  530. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  531. assert_success
  532. refute_output
  533. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  534. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  535. # A single php-fpm pool config file must be present
  536. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  537. assert_equal "$num_fpm_config_files" '1'
  538. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  539. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  540. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  541. }
  542. @test "Multiphp: Cleanup" {
  543. multi_domain="multiphp.${domain}"
  544. run v-delete-web-domain $user $multi_domain 'yes'
  545. assert_success
  546. refute_output
  547. # No php-fpm pool config file must be present
  548. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  549. assert_equal "$num_fpm_config_files" '0'
  550. }
  551. #----------------------------------------------------------#
  552. # DNS #
  553. #----------------------------------------------------------#
  554. @test "DNS: Add domain" {
  555. run v-add-dns-domain $user $domain 198.18.0.125
  556. assert_success
  557. refute_output
  558. }
  559. @test "DNS: Add domain (duplicate)" {
  560. run v-add-dns-domain $user $domain 198.18.0.125
  561. assert_failure $E_EXISTS
  562. }
  563. @test "DNS: Add domain record" {
  564. run v-add-dns-record $user $domain test A 198.18.0.125 20
  565. assert_success
  566. refute_output
  567. }
  568. @test "DNS: Delete domain record" {
  569. run v-delete-dns-record $user $domain 20
  570. assert_success
  571. refute_output
  572. }
  573. @test "DNS: Delete missing domain record" {
  574. run v-delete-dns-record $user $domain 20
  575. assert_failure $E_NOTEXIST
  576. }
  577. @test "DNS: Change domain expire date" {
  578. run v-change-dns-domain-exp $user $domain 2020-01-01
  579. assert_success
  580. refute_output
  581. }
  582. @test "DNS: Change domain ip" {
  583. run v-change-dns-domain-ip $user $domain 127.0.0.1
  584. assert_success
  585. refute_output
  586. }
  587. @test "DNS: Suspend domain" {
  588. run v-suspend-dns-domain $user $domain
  589. assert_success
  590. refute_output
  591. }
  592. @test "DNS: Unsuspend domain" {
  593. run v-unsuspend-dns-domain $user $domain
  594. assert_success
  595. refute_output
  596. }
  597. @test "DNS: Rebuild" {
  598. run v-rebuild-dns-domains $user
  599. assert_success
  600. refute_output
  601. }
  602. #----------------------------------------------------------#
  603. # MAIL #
  604. #----------------------------------------------------------#
  605. @test "MAIL: Add domain" {
  606. run v-add-mail-domain $user $domain
  607. assert_success
  608. refute_output
  609. validate_mail_domain $user $domain
  610. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  611. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  612. # rm /var/lib/roundcube/check_server.php
  613. }
  614. @test "MAIL: Add domain (duplicate)" {
  615. run v-add-mail-domain $user $domain
  616. assert_failure $E_EXISTS
  617. }
  618. @test "MAIL: Add account" {
  619. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  620. assert_success
  621. refute_output
  622. }
  623. @test "MAIL: Add account (duplicate)" {
  624. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  625. assert_failure $E_EXISTS
  626. }
  627. @test "MAIL: Delete account" {
  628. run v-delete-mail-account $user $domain test
  629. assert_success
  630. refute_output
  631. }
  632. @test "MAIL: Delete missing account" {
  633. run v-delete-mail-account $user $domain test
  634. assert_failure $E_NOTEXIST
  635. }
  636. #----------------------------------------------------------#
  637. # DB #
  638. #----------------------------------------------------------#
  639. #----------------------------------------------------------#
  640. # Backup / Restore #
  641. #----------------------------------------------------------#
  642. #Test backup
  643. # Hestia v1.1.1 archive contains:
  644. # user: hestia111
  645. # web:
  646. # - test.hestia.com (+SSL self-signed)
  647. # dns:
  648. # - test.hestia.com
  649. # mail:
  650. # - test.hestia.com
  651. # mail acc:
  652. # - testaccount@test.hestia.com
  653. # db:
  654. # - hestia111_db
  655. # cron:
  656. # - 1: /bin/true
  657. #
  658. # Vesta 0.9.8-23 archive contains:
  659. # user: vesta09823
  660. # web:
  661. # - vesta09823.tld (+SSL self-signed)
  662. # dns:
  663. # - vesta09823.tld
  664. # mail:
  665. # - vesta09823.tld
  666. # mail acc:
  667. # - testaccount@vesta09823.tld
  668. # db:
  669. # - vesta09823_db
  670. # cron:
  671. # - 1: /bin/true
  672. #
  673. # Testing Hestia backups
  674. @test "Restore[1]: Hestia archive for a non-existing user" {
  675. if [ -d "$HOMEDIR/$userbk" ]; then
  676. run v-delete-user $userbk
  677. assert_success
  678. refute_output
  679. fi
  680. mkdir -p /backup
  681. local archive_name="hestia111.2020-03-26"
  682. run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
  683. assert_success
  684. run v-restore-user $userbk "${archive_name}.tar"
  685. assert_success
  686. rm "/backup/${archive_name}.tar"
  687. }
  688. @test "Restore[1]: From Hestia [WEB]" {
  689. local domain="test.hestia.com"
  690. validate_web_domain $userbk $domain 'Hello Hestia'
  691. }
  692. @test "Restore[1]: From Hestia [DNS]" {
  693. local domain="test.hestia.com"
  694. run v-list-dns-domain $userbk $domain
  695. assert_success
  696. run nslookup $domain 127.0.0.1
  697. assert_success
  698. }
  699. @test "Restore[1]: From Hestia [MAIL]" {
  700. local domain="test.hestia.com"
  701. run v-list-mail-domain $userbk $domain
  702. assert_success
  703. }
  704. @test "Restore[1]: From Hestia [MAIL-Account]" {
  705. local domain="test.hestia.com"
  706. run v-list-mail-account $userbk $domain testaccount
  707. assert_success
  708. }
  709. @test "Restore[1]: From Hestia [DB]" {
  710. run v-list-database $userbk "${userbk}_db"
  711. assert_success
  712. }
  713. @test "Restore[1]: From Hestia [CRON]" {
  714. run v-list-cron-job $userbk 1
  715. assert_success
  716. }
  717. @test "Restore[1]: From Hestia Cleanup" {
  718. run v-delete-user $userbk
  719. assert_success
  720. refute_output
  721. }
  722. @test "Restore[2]: Hestia archive over a existing user" {
  723. if [ -d "$HOMEDIR/$userbk" ]; then
  724. run v-delete-user $userbk
  725. assert_success
  726. refute_output
  727. fi
  728. if [ ! -d "$HOMEDIR/$userbk" ]; then
  729. run v-add-user $userbk $userbk test@hestia.com
  730. assert_success
  731. fi
  732. mkdir -p /backup
  733. local archive_name="hestia111.2020-03-26"
  734. run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
  735. assert_success
  736. run v-restore-user $userbk "${archive_name}.tar"
  737. assert_success
  738. rm "/backup/${archive_name}.tar"
  739. }
  740. @test "Restore[2]: From Hestia [WEB]" {
  741. local domain="test.hestia.com"
  742. validate_web_domain $userbk "${domain}" 'Hello Hestia'
  743. }
  744. @test "Restore[2]: From Hestia [DNS]" {
  745. local domain="test.hestia.com"
  746. run v-list-dns-domain $userbk $domain
  747. assert_success
  748. run nslookup $domain 127.0.0.1
  749. assert_success
  750. }
  751. @test "Restore[2]: From Hestia [MAIL]" {
  752. local domain="test.hestia.com"
  753. run v-list-mail-domain $userbk $domain
  754. assert_success
  755. }
  756. @test "Restore[2]: From Hestia [MAIL-Account]" {
  757. local domain="test.hestia.com"
  758. run v-list-mail-account $userbk $domain testaccount
  759. assert_success
  760. }
  761. @test "Restore[2]: From Hestia [DB]" {
  762. run v-list-database $userbk "${userbk}_db"
  763. assert_success
  764. }
  765. @test "Restore[2]: From Hestia [CRON]" {
  766. run v-list-cron-job $userbk 1
  767. assert_success
  768. }
  769. @test "Restore[2]: From Hestia Cleanup" {
  770. run v-delete-user $userbk
  771. assert_success
  772. refute_output
  773. }
  774. # Testing Vesta Backups
  775. @test "Restore[1]: Vesta archive for a non-existing user" {
  776. if [ -d "$HOMEDIR/$userbk" ]; then
  777. run v-delete-user $userbk
  778. assert_success
  779. refute_output
  780. fi
  781. mkdir -p /backup
  782. local archive_name="vesta09823.2018-10-18"
  783. run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
  784. assert_success
  785. run v-restore-user $userbk "${archive_name}.tar"
  786. assert_success
  787. rm "/backup/${archive_name}.tar"
  788. }
  789. @test "Restore[1]: From Vesta [WEB]" {
  790. local domain="vesta09823.tld"
  791. validate_web_domain $userbk $domain 'Hello Vesta'
  792. }
  793. @test "Restore[1]: From Vesta [DNS]" {
  794. local domain="vesta09823.tld"
  795. run v-list-dns-domain $userbk $domain
  796. assert_success
  797. run nslookup $domain 127.0.0.1
  798. assert_success
  799. }
  800. @test "Restore[1]: From Vesta [MAIL]" {
  801. local domain="vesta09823.tld"
  802. run v-list-mail-domain $userbk $domain
  803. assert_success
  804. }
  805. @test "Restore[1]: From Vesta [MAIL-Account]" {
  806. local domain="vesta09823.tld"
  807. run v-list-mail-account $userbk $domain testaccount
  808. assert_success
  809. }
  810. @test "Restore[1]: From Vesta [DB]" {
  811. run v-list-database $userbk "${userbk}_db"
  812. assert_success
  813. }
  814. @test "Restore[1]: From Vesta [CRON]" {
  815. run v-list-cron-job $userbk 1
  816. assert_success
  817. }
  818. @test "Restore[1]: From Vesta Cleanup" {
  819. run v-delete-user $userbk
  820. assert_success
  821. refute_output
  822. }
  823. @test "Restore[2]: Vesta archive over a existing user" {
  824. if [ -d "$HOMEDIR/$userbk" ]; then
  825. run v-delete-user $userbk
  826. assert_success
  827. refute_output
  828. fi
  829. if [ ! -d "$HOMEDIR/$userbk" ]; then
  830. run v-add-user $userbk $userbk test@hestia.com
  831. assert_success
  832. fi
  833. mkdir -p /backup
  834. local archive_name="vesta09823.2018-10-18"
  835. run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache "https://hestiacp.com/testing/data/${archive_name}.tar" -O "/backup/${archive_name}.tar"
  836. assert_success
  837. run v-restore-user $userbk "${archive_name}.tar"
  838. assert_success
  839. rm "/backup/${archive_name}.tar"
  840. }
  841. @test "Restore[2]: From Vesta [WEB]" {
  842. local domain="vesta09823.tld"
  843. validate_web_domain $userbk "${domain}" 'Hello Vesta'
  844. }
  845. @test "Restore[2]: From Vesta [DNS]" {
  846. local domain="vesta09823.tld"
  847. run v-list-dns-domain $userbk $domain
  848. assert_success
  849. run nslookup $domain 127.0.0.1
  850. assert_success
  851. }
  852. @test "Restore[2]: From Vesta [MAIL]" {
  853. local domain="vesta09823.tld"
  854. run v-list-mail-domain $userbk $domain
  855. assert_success
  856. }
  857. @test "Restore[2]: From Vesta [MAIL-Account]" {
  858. local domain="vesta09823.tld"
  859. run v-list-mail-account $userbk $domain testaccount
  860. assert_success
  861. }
  862. @test "Restore[2]: From Vesta [DB]" {
  863. run v-list-database $userbk "${userbk}_db"
  864. assert_success
  865. }
  866. @test "Restore[2]: From Vesta [CRON]" {
  867. run v-list-cron-job $userbk 1
  868. assert_success
  869. }
  870. @test "Restore[2]: From Vesta Cleanup" {
  871. run v-delete-user $userbk
  872. assert_success
  873. refute_output
  874. }
  875. #----------------------------------------------------------#
  876. # CLEANUP #
  877. #----------------------------------------------------------#
  878. @test "Mail: Delete domain" {
  879. # skip
  880. run v-delete-mail-domain $user $domain
  881. assert_success
  882. refute_output
  883. }
  884. @test "DNS: Delete domain" {
  885. # skip
  886. run v-delete-dns-domain $user $domain
  887. assert_success
  888. refute_output
  889. }
  890. @test "WEB: Delete domain" {
  891. # skip
  892. run v-delete-web-domain $user $domain
  893. assert_success
  894. refute_output
  895. }
  896. @test "Delete user" {
  897. # skip
  898. run v-delete-user $user
  899. assert_success
  900. refute_output
  901. }
  902. @test "Ip: Delete the test IP" {
  903. # skip
  904. run v-delete-sys-ip 198.18.0.125
  905. assert_success
  906. refute_output
  907. }
  908. @test 'assert()' {
  909. touch '/var/log/test.log'
  910. assert [ -e '/var/log/test.log' ]
  911. }