test.bats 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. #----------------------------------------------------------#
  543. # DNS #
  544. #----------------------------------------------------------#
  545. @test "DNS: Add domain" {
  546. run v-add-dns-domain $user $domain 198.18.0.125
  547. assert_success
  548. refute_output
  549. }
  550. @test "DNS: Add domain (duplicate)" {
  551. run v-add-dns-domain $user $domain 198.18.0.125
  552. assert_failure $E_EXISTS
  553. }
  554. @test "DNS: Add domain record" {
  555. run v-add-dns-record $user $domain test A 198.18.0.125 20
  556. assert_success
  557. refute_output
  558. }
  559. @test "DNS: Delete domain record" {
  560. run v-delete-dns-record $user $domain 20
  561. assert_success
  562. refute_output
  563. }
  564. @test "DNS: Delete missing domain record" {
  565. run v-delete-dns-record $user $domain 20
  566. assert_failure $E_NOTEXIST
  567. }
  568. @test "DNS: Change domain expire date" {
  569. run v-change-dns-domain-exp $user $domain 2020-01-01
  570. assert_success
  571. refute_output
  572. }
  573. @test "DNS: Change domain ip" {
  574. run v-change-dns-domain-ip $user $domain 127.0.0.1
  575. assert_success
  576. refute_output
  577. }
  578. @test "DNS: Suspend domain" {
  579. run v-suspend-dns-domain $user $domain
  580. assert_success
  581. refute_output
  582. }
  583. @test "DNS: Unsuspend domain" {
  584. run v-unsuspend-dns-domain $user $domain
  585. assert_success
  586. refute_output
  587. }
  588. @test "DNS: Rebuild" {
  589. run v-rebuild-dns-domains $user
  590. assert_success
  591. refute_output
  592. }
  593. #----------------------------------------------------------#
  594. # MAIL #
  595. #----------------------------------------------------------#
  596. @test "MAIL: Add domain" {
  597. run v-add-mail-domain $user $domain
  598. assert_success
  599. refute_output
  600. validate_mail_domain $user $domain
  601. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  602. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  603. # rm /var/lib/roundcube/check_server.php
  604. }
  605. @test "MAIL: Add domain (duplicate)" {
  606. run v-add-mail-domain $user $domain
  607. assert_failure $E_EXISTS
  608. }
  609. @test "MAIL: Add account" {
  610. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  611. assert_success
  612. refute_output
  613. }
  614. @test "MAIL: Add account (duplicate)" {
  615. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  616. assert_failure $E_EXISTS
  617. }
  618. @test "MAIL: Delete account" {
  619. run v-delete-mail-account $user $domain test
  620. assert_success
  621. refute_output
  622. }
  623. @test "MAIL: Delete missing account" {
  624. run v-delete-mail-account $user $domain test
  625. assert_failure $E_NOTEXIST
  626. }
  627. #----------------------------------------------------------#
  628. # DB #
  629. #----------------------------------------------------------#
  630. #----------------------------------------------------------#
  631. # Backup / Restore #
  632. #----------------------------------------------------------#
  633. #Test backup
  634. # Hestia v1.1.1 archive contains:
  635. # user: hestia111
  636. # web:
  637. # - test.hestia.com (+SSL self-signed)
  638. # dns:
  639. # - test.hestia.com
  640. # mail:
  641. # - test.hestia.com
  642. # mail acc:
  643. # - testaccount@test.hestia.com
  644. # db:
  645. # - hestia111_db
  646. # cron:
  647. # - 1: /bin/true
  648. #
  649. # Vesta 0.9.8-23 archive contains:
  650. # user: vesta09823
  651. # web:
  652. # - vesta09823.tld (+SSL self-signed)
  653. # dns:
  654. # - vesta09823.tld
  655. # mail:
  656. # - vesta09823.tld
  657. # mail acc:
  658. # - testaccount@vesta09823.tld
  659. # db:
  660. # - vesta09823_db
  661. # cron:
  662. # - 1: /bin/true
  663. #
  664. # Testing Hestia backups
  665. @test "Restore[1]: Hestia archive for a non-existing user" {
  666. if [ -d "$HOMEDIR/$userbk" ]; then
  667. run v-delete-user $userbk
  668. assert_success
  669. refute_output
  670. fi
  671. mkdir -p /backup
  672. local archive_name="hestia111.2020-03-26"
  673. 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"
  674. assert_success
  675. run v-restore-user $userbk "${archive_name}.tar"
  676. assert_success
  677. rm "/backup/${archive_name}.tar"
  678. }
  679. @test "Restore[1]: From Hestia [WEB]" {
  680. local domain="test.hestia.com"
  681. validate_web_domain $userbk $domain 'Hello Hestia'
  682. }
  683. @test "Restore[1]: From Hestia [DNS]" {
  684. local domain="test.hestia.com"
  685. run v-list-dns-domain $userbk $domain
  686. assert_success
  687. run nslookup $domain 127.0.0.1
  688. assert_success
  689. }
  690. @test "Restore[1]: From Hestia [MAIL]" {
  691. local domain="test.hestia.com"
  692. run v-list-mail-domain $userbk $domain
  693. assert_success
  694. }
  695. @test "Restore[1]: From Hestia [MAIL-Account]" {
  696. local domain="test.hestia.com"
  697. run v-list-mail-account $userbk $domain testaccount
  698. assert_success
  699. }
  700. @test "Restore[1]: From Hestia [DB]" {
  701. run v-list-database $userbk "${userbk}_db"
  702. assert_success
  703. }
  704. @test "Restore[1]: From Hestia [CRON]" {
  705. run v-list-cron-job $userbk 1
  706. assert_success
  707. }
  708. @test "Restore[1]: From Hestia Cleanup" {
  709. run v-delete-user $userbk
  710. assert_success
  711. refute_output
  712. }
  713. @test "Restore[2]: Hestia archive over a existing user" {
  714. if [ -d "$HOMEDIR/$userbk" ]; then
  715. run v-delete-user $userbk
  716. assert_success
  717. refute_output
  718. fi
  719. if [ ! -d "$HOMEDIR/$userbk" ]; then
  720. run v-add-user $userbk $userbk test@hestia.com
  721. assert_success
  722. fi
  723. mkdir -p /backup
  724. local archive_name="hestia111.2020-03-26"
  725. 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"
  726. assert_success
  727. run v-restore-user $userbk "${archive_name}.tar"
  728. assert_success
  729. rm "/backup/${archive_name}.tar"
  730. }
  731. @test "Restore[2]: From Hestia [WEB]" {
  732. local domain="test.hestia.com"
  733. validate_web_domain $userbk "${domain}" 'Hello Hestia'
  734. }
  735. @test "Restore[2]: From Hestia [DNS]" {
  736. local domain="test.hestia.com"
  737. run v-list-dns-domain $userbk $domain
  738. assert_success
  739. run nslookup $domain 127.0.0.1
  740. assert_success
  741. }
  742. @test "Restore[2]: From Hestia [MAIL]" {
  743. local domain="test.hestia.com"
  744. run v-list-mail-domain $userbk $domain
  745. assert_success
  746. }
  747. @test "Restore[2]: From Hestia [MAIL-Account]" {
  748. local domain="test.hestia.com"
  749. run v-list-mail-account $userbk $domain testaccount
  750. assert_success
  751. }
  752. @test "Restore[2]: From Hestia [DB]" {
  753. run v-list-database $userbk "${userbk}_db"
  754. assert_success
  755. }
  756. @test "Restore[2]: From Hestia [CRON]" {
  757. run v-list-cron-job $userbk 1
  758. assert_success
  759. }
  760. @test "Restore[2]: From Hestia Cleanup" {
  761. run v-delete-user $userbk
  762. assert_success
  763. refute_output
  764. }
  765. # Testing Vesta Backups
  766. @test "Restore[1]: Vesta archive for a non-existing user" {
  767. if [ -d "$HOMEDIR/$userbk" ]; then
  768. run v-delete-user $userbk
  769. assert_success
  770. refute_output
  771. fi
  772. mkdir -p /backup
  773. local archive_name="vesta09823.2018-10-18"
  774. 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"
  775. assert_success
  776. run v-restore-user $userbk "${archive_name}.tar"
  777. assert_success
  778. rm "/backup/${archive_name}.tar"
  779. }
  780. @test "Restore[1]: From Vesta [WEB]" {
  781. local domain="vesta09823.tld"
  782. validate_web_domain $userbk $domain 'Hello Vesta'
  783. }
  784. @test "Restore[1]: From Vesta [DNS]" {
  785. local domain="vesta09823.tld"
  786. run v-list-dns-domain $userbk $domain
  787. assert_success
  788. run nslookup $domain 127.0.0.1
  789. assert_success
  790. }
  791. @test "Restore[1]: From Vesta [MAIL]" {
  792. local domain="vesta09823.tld"
  793. run v-list-mail-domain $userbk $domain
  794. assert_success
  795. }
  796. @test "Restore[1]: From Vesta [MAIL-Account]" {
  797. local domain="vesta09823.tld"
  798. run v-list-mail-account $userbk $domain testaccount
  799. assert_success
  800. }
  801. @test "Restore[1]: From Vesta [DB]" {
  802. run v-list-database $userbk "${userbk}_db"
  803. assert_success
  804. }
  805. @test "Restore[1]: From Vesta [CRON]" {
  806. run v-list-cron-job $userbk 1
  807. assert_success
  808. }
  809. @test "Restore[1]: From Vesta Cleanup" {
  810. run v-delete-user $userbk
  811. assert_success
  812. refute_output
  813. }
  814. @test "Restore[2]: Vesta archive over a existing user" {
  815. if [ -d "$HOMEDIR/$userbk" ]; then
  816. run v-delete-user $userbk
  817. assert_success
  818. refute_output
  819. fi
  820. if [ ! -d "$HOMEDIR/$userbk" ]; then
  821. run v-add-user $userbk $userbk test@hestia.com
  822. assert_success
  823. fi
  824. mkdir -p /backup
  825. local archive_name="vesta09823.2018-10-18"
  826. 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"
  827. assert_success
  828. run v-restore-user $userbk "${archive_name}.tar"
  829. assert_success
  830. rm "/backup/${archive_name}.tar"
  831. }
  832. @test "Restore[2]: From Vesta [WEB]" {
  833. local domain="vesta09823.tld"
  834. validate_web_domain $userbk "${domain}" 'Hello Vesta'
  835. }
  836. @test "Restore[2]: From Vesta [DNS]" {
  837. local domain="vesta09823.tld"
  838. run v-list-dns-domain $userbk $domain
  839. assert_success
  840. run nslookup $domain 127.0.0.1
  841. assert_success
  842. }
  843. @test "Restore[2]: From Vesta [MAIL]" {
  844. local domain="vesta09823.tld"
  845. run v-list-mail-domain $userbk $domain
  846. assert_success
  847. }
  848. @test "Restore[2]: From Vesta [MAIL-Account]" {
  849. local domain="vesta09823.tld"
  850. run v-list-mail-account $userbk $domain testaccount
  851. assert_success
  852. }
  853. @test "Restore[2]: From Vesta [DB]" {
  854. run v-list-database $userbk "${userbk}_db"
  855. assert_success
  856. }
  857. @test "Restore[2]: From Vesta [CRON]" {
  858. run v-list-cron-job $userbk 1
  859. assert_success
  860. }
  861. @test "Restore[2]: From Vesta Cleanup" {
  862. run v-delete-user $userbk
  863. assert_success
  864. refute_output
  865. }
  866. #----------------------------------------------------------#
  867. # CLEANUP #
  868. #----------------------------------------------------------#
  869. @test "Mail: Delete domain" {
  870. # skip
  871. run v-delete-mail-domain $user $domain
  872. assert_success
  873. refute_output
  874. }
  875. @test "DNS: Delete domain" {
  876. # skip
  877. run v-delete-dns-domain $user $domain
  878. assert_success
  879. refute_output
  880. }
  881. @test "WEB: Delete domain" {
  882. # skip
  883. run v-delete-web-domain $user $domain
  884. assert_success
  885. refute_output
  886. }
  887. @test "Delete user" {
  888. # skip
  889. run v-delete-user $user
  890. assert_success
  891. refute_output
  892. }
  893. @test "Ip: Delete the test IP" {
  894. # skip
  895. run v-delete-sys-ip 198.18.0.125
  896. assert_success
  897. refute_output
  898. }
  899. @test 'assert()' {
  900. touch '/var/log/test.log'
  901. assert [ -e '/var/log/test.log' ]
  902. }