test.bats 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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. echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
  18. echo 'dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
  19. fi
  20. source /tmp/hestia-test-env.sh
  21. source $HESTIA/func/main.sh
  22. source $HESTIA/conf/hestia.conf
  23. source $HESTIA/func/ip.sh
  24. }
  25. function validate_web_domain() {
  26. local user=$1
  27. local domain=$2
  28. local webproof=$3
  29. local webpath=${4}
  30. refute [ -z "$user" ]
  31. refute [ -z "$domain" ]
  32. refute [ -z "$webproof" ]
  33. source $HESTIA/func/ip.sh
  34. run v-list-web-domain $user $domain
  35. assert_success
  36. USER_DATA=$HESTIA/data/users/$user
  37. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  38. SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
  39. domain_ip=$(get_real_ip "$domain_ip")
  40. if [ ! -z $webpath ]; then
  41. domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
  42. if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
  43. assert_file_exist "${domain_docroot}/${webpath}"
  44. else
  45. assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
  46. fi
  47. fi
  48. # Test HTTP
  49. run curl --location --silent --show-error --insecure --resolve "${domain}:80:${domain_ip}" "http://${domain}/${webpath}"
  50. assert_success
  51. assert_output --partial "$webproof"
  52. # Test HTTPS
  53. if [ "$SSL" = "yes" ]; then
  54. run v-list-web-domain-ssl $user $domain
  55. assert_success
  56. run curl --location --silent --show-error --insecure --resolve "${domain}:443:${domain_ip}" "https://${domain}/${webpath}"
  57. assert_success
  58. assert_output --partial "$webproof"
  59. fi
  60. }
  61. function validate_mail_domain() {
  62. local user=$1
  63. local domain=$2
  64. refute [ -z "$user" ]
  65. refute [ -z "$domain" ]
  66. run v-list-mail-domain $user $domain
  67. assert_success
  68. assert_dir_exist $HOMEDIR/$user/mail/$domain
  69. assert_dir_exist $HOMEDIR/$user/conf/mail/$domain
  70. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/aliases
  71. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antispam
  72. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antivirus
  73. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/fwd_only
  74. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/ip
  75. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/passwd
  76. }
  77. function validate_webmail_domain() {
  78. local user=$1
  79. local domain=$2
  80. local webproof=$3
  81. local webpath=${4}
  82. refute [ -z "$user" ]
  83. refute [ -z "$domain" ]
  84. refute [ -z "$webproof" ]
  85. source $HESTIA/func/ip.sh
  86. USER_DATA=$HESTIA/data/users/$user
  87. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  88. SSL=$(get_object_value 'mail' 'DOMAIN' "$domain" '$SSL')
  89. domain_ip=$(get_real_ip "$domain_ip")
  90. if [ ! -z "$webpath" ]; then
  91. assert_file_exist /var/lib/roundcube/$webpath
  92. fi
  93. # Test HTTP
  94. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
  95. assert_success
  96. assert_output --partial "$webproof"
  97. # Test HTTP
  98. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
  99. assert_success
  100. assert_output --partial "$webproof"
  101. # Test HTTPS
  102. if [ "$SSL" = "yes" ]; then
  103. run v-list-mail-domain-ssl $user $domain
  104. assert_success
  105. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:443:${domain_ip}" "https://webmail.${domain}/${webpath}"
  106. assert_success
  107. assert_output --partial "$webproof"
  108. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:443:${domain_ip}" "https://mail.${domain}/${webpath}"
  109. assert_success
  110. assert_output --partial "$webproof"
  111. fi
  112. }
  113. function validate_database(){
  114. local database=$1
  115. local dbuser=$2
  116. local password=$3
  117. host_str=$(grep "HOST='localhost'" $HESTIA/conf/mysql.conf)
  118. parse_object_kv_list "$host_str"
  119. if [ -z $PORT ]; then PORT=3306; fi
  120. refute [ -z "$HOST" ]
  121. refute [ -z "$PORT" ]
  122. refute [ -z "$database" ]
  123. refute [ -z "$dbuser" ]
  124. refute [ -z "$password" ]
  125. # Create an connection to verify correct username / password has been set correctly
  126. tmpfile=$(mktemp /tmp/mysql.XXXXXX)
  127. echo "[client]">$tmpfile
  128. echo "host='$HOST'" >> $tmpfile
  129. echo "user='$dbuser'" >> $tmpfile
  130. echo "password='$password'" >> $tmpfile
  131. echo "port='$PORT'" >> $tmpfile
  132. chmod 600 $tmpfile
  133. sql_tmp=$(mktemp /tmp/query.XXXXXX)
  134. echo "show databases;" > $sql_tmp
  135. run mysql --defaults-file=$tmpfile < "$sql_tmp"
  136. assert_success
  137. assert_output --partial "$database"
  138. rm -f "$sql_tmp"
  139. rm -f "$tmpfile"
  140. }
  141. #----------------------------------------------------------#
  142. # MAIN #
  143. #----------------------------------------------------------#
  144. @test "Add new userXXX" {
  145. skip
  146. run v-add-user $user $user $user@hestiacp.com default "Super Test"
  147. assert_success
  148. refute_output
  149. }
  150. #----------------------------------------------------------#
  151. # IP #
  152. #----------------------------------------------------------#
  153. @test "Check reverse Dns validation" {
  154. # 1. PTR record for a IP should return a hostname(reverse) which in turn must resolve to the same IP addr(forward). (Full circle)
  155. # `-> not implemented in `is_ip_rdns_valid` yet and also not tested here
  156. # 2. Reject rPTR records that match generic dynamic IP pool patterns
  157. local ip="54.200.1.22"
  158. local rdns="ec2-54-200-1-22.us-west-2.compute.amazonaws.com"
  159. run is_ip_rdns_valid "$ip"
  160. assert_failure
  161. refute_output
  162. local rdns="ec2.54.200.1.22.us-west-2.compute.amazonaws.com"
  163. run is_ip_rdns_valid "$ip"
  164. assert_failure
  165. refute_output
  166. local rdns="ec2-22-1-200-54.us-west-2.compute.amazonaws.com"
  167. run is_ip_rdns_valid "$ip"
  168. assert_failure
  169. refute_output
  170. local rdns="ec2.22.1.200.54.us-west-2.compute.amazonaws.com"
  171. run is_ip_rdns_valid "$ip"
  172. assert_failure
  173. refute_output
  174. local rdns="ec2-200-54-1-22.us-west-2.compute.amazonaws.com"
  175. run is_ip_rdns_valid "$ip"
  176. assert_failure
  177. refute_output
  178. local rdns="panel-22.mydomain.tld"
  179. run is_ip_rdns_valid "$ip"
  180. assert_success
  181. assert_output "$rdns"
  182. local rdns="mail.mydomain.tld"
  183. run is_ip_rdns_valid "$ip"
  184. assert_success
  185. assert_output "$rdns"
  186. local rdns="mydomain.tld"
  187. run is_ip_rdns_valid "$ip"
  188. assert_success
  189. assert_output "$rdns"
  190. }
  191. #----------------------------------------------------------#
  192. # User #
  193. #----------------------------------------------------------#
  194. @test "Add new user" {
  195. run v-add-user $user $user $user@hestiacp.com default "Super Test"
  196. assert_success
  197. refute_output
  198. }
  199. @test "Change user password" {
  200. run v-change-user-password "$user" t3st-p4ssw0rd
  201. assert_success
  202. refute_output
  203. }
  204. @test "Change user email" {
  205. run v-change-user-contact "$user" tester@hestiacp.com
  206. assert_success
  207. refute_output
  208. }
  209. @test "Change user contact invalid email " {
  210. run v-change-user-contact "$user" testerhestiacp.com
  211. assert_failure $E_INVALID
  212. assert_output --partial 'Error: invalid email format'
  213. }
  214. @test "Change user name" {
  215. run v-change-user-name "$user" "New name"
  216. assert_success
  217. refute_output
  218. }
  219. @test "Change user shell" {
  220. run v-change-user-shell $user bash
  221. assert_success
  222. refute_output
  223. }
  224. @test "Change user invalid shell" {
  225. run v-change-user-shell $user bashinvalid
  226. assert_failure $E_INVALID
  227. assert_output --partial 'shell bashinvalid is not valid'
  228. }
  229. @test "Change user default ns" {
  230. run v-change-user-ns $user ns0.com ns1.com ns2.com ns3.com
  231. assert_success
  232. refute_output
  233. run v-list-user-ns "$user" plain
  234. assert_success
  235. assert_output --partial 'ns0.com'
  236. }
  237. #----------------------------------------------------------#
  238. # Cron #
  239. #----------------------------------------------------------#
  240. @test "Cron: Add cron job" {
  241. run v-add-cron-job $user 1 1 1 1 1 echo
  242. assert_success
  243. refute_output
  244. }
  245. @test "Cron: Suspend cron job" {
  246. run v-suspend-cron-job $user 1
  247. assert_success
  248. refute_output
  249. }
  250. @test "Cron: Unsuspend cron job" {
  251. run v-unsuspend-cron-job $user 1
  252. assert_success
  253. refute_output
  254. }
  255. @test "Cron: Delete cron job" {
  256. run v-delete-cron-job $user 1
  257. assert_success
  258. refute_output
  259. }
  260. @test "Cron: Add cron job (duplicate)" {
  261. run v-add-cron-job $user 1 1 1 1 1 echo 1
  262. assert_success
  263. refute_output
  264. run v-add-cron-job $user 1 1 1 1 1 echo 1
  265. assert_failure $E_EXISTS
  266. assert_output --partial 'JOB=1 is already exists'
  267. }
  268. @test "Cron: Second cron job" {
  269. run v-add-cron-job $user 2 2 2 2 2 echo 2
  270. assert_success
  271. refute_output
  272. }
  273. @test "Cron: Two cron jobs must be listed" {
  274. run v-list-cron-jobs $user csv
  275. assert_success
  276. assert_line --partial '1,1,1,1,1,"echo",no'
  277. assert_line --partial '2,2,2,2,2,"echo",no'
  278. }
  279. @test "Cron: rebuild" {
  280. run v-rebuild-cron-jobs $user
  281. assert_success
  282. refute_output
  283. }
  284. #----------------------------------------------------------#
  285. # IP #
  286. #----------------------------------------------------------#
  287. @test "Ip: Add new ip on first interface" {
  288. interface=$(v-list-sys-interfaces plain | head -n 1)
  289. run ip link show dev $interface
  290. assert_success
  291. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  292. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  293. # Save initial state
  294. echo "interface=${interface}" >> /tmp/hestia-test-env.sh
  295. [ -f "$a2_rpaf" ] && file_hash1=$(cat $a2_rpaf |md5sum |cut -d" " -f1) && echo "a2_rpaf_hash='${file_hash1}'" >> /tmp/hestia-test-env.sh
  296. [ -f "$a2_remoteip" ] && file_hash2=$(cat $a2_remoteip |md5sum |cut -d" " -f1) && echo "a2_remoteip_hash='${file_hash2}'" >> /tmp/hestia-test-env.sh
  297. local ip="198.18.0.12"
  298. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  299. assert_success
  300. refute_output
  301. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  302. assert_file_exist $HESTIA/data/ips/$ip
  303. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  304. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  305. if [ -n "$PROXY_SYSTEM" ]; then
  306. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  307. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  308. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  309. fi
  310. }
  311. @test "Ip: Add ip (duplicate)" {
  312. run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
  313. assert_failure $E_EXISTS
  314. }
  315. @test "Ip: Add extra ip" {
  316. local ip="198.18.0.121"
  317. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  318. assert_success
  319. refute_output
  320. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  321. assert_file_exist $HESTIA/data/ips/$ip
  322. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  323. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  324. if [ -n "$PROXY_SYSTEM" ]; then
  325. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  326. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  327. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  328. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  329. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  330. fi
  331. }
  332. @test "Ip: Delete ips" {
  333. local ip="198.18.0.12"
  334. run v-delete-sys-ip $ip
  335. assert_success
  336. refute_output
  337. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  338. assert_file_not_exist $HESTIA/data/ips/$ip
  339. ip="198.18.0.121"
  340. run v-delete-sys-ip $ip
  341. assert_success
  342. refute_output
  343. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  344. assert_file_not_exist $HESTIA/data/ips/$ip
  345. if [ -n "$PROXY_SYSTEM" ]; then
  346. assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  347. fi
  348. # remoteip and rpaf config hashes must match the initial one
  349. if [ ! -z "$a2_rpaf_hash" ]; then
  350. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  351. file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
  352. assert_equal "$file_hash" "$a2_rpaf_hash"
  353. fi
  354. if [ ! -z "$a2_remoteip_hash" ]; then
  355. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  356. file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
  357. assert_equal "$file_hash" "$a2_remoteip_hash"
  358. fi
  359. }
  360. @test "Ip: Add IP for rest of the test" {
  361. local ip="198.18.0.125"
  362. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  363. assert_success
  364. refute_output
  365. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  366. assert_file_exist $HESTIA/data/ips/$ip
  367. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  368. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  369. if [ -n "$PROXY_SYSTEM" ]; then
  370. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  371. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  372. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  373. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  374. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  375. fi
  376. }
  377. #----------------------------------------------------------#
  378. # WEB #
  379. #----------------------------------------------------------#
  380. @test "WEB: Add web domain" {
  381. run v-add-web-domain $user $domain 198.18.0.125
  382. assert_success
  383. refute_output
  384. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  385. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  386. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  387. }
  388. @test "WEB: Add web domain (duplicate)" {
  389. run v-add-web-domain $user $domain 198.18.0.125
  390. assert_failure $E_EXISTS
  391. }
  392. @test "WEB: Add web domain alias" {
  393. run v-add-web-domain-alias $user $domain v3.$domain
  394. assert_success
  395. refute_output
  396. }
  397. @test "WEB: Add web domain alias (duplicate)" {
  398. run v-add-web-domain-alias $user $domain v3.$domain
  399. assert_failure $E_EXISTS
  400. }
  401. @test "WEB: Add web domain wildcard alias" {
  402. run v-add-web-domain-alias $user $domain "*.$domain"
  403. assert_success
  404. refute_output
  405. }
  406. @test "WEB: Add web domain stats" {
  407. run v-add-web-domain-stats $user $domain awstats
  408. assert_success
  409. refute_output
  410. }
  411. @test "WEB: Add web domain stats user" {
  412. skip
  413. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  414. assert_success
  415. refute_output
  416. }
  417. @test "WEB: Suspend web domain" {
  418. run v-suspend-web-domain $user $domain
  419. assert_success
  420. refute_output
  421. validate_web_domain $user $domain 'This site is currently suspended'
  422. }
  423. @test "WEB: Unsuspend web domain" {
  424. run v-unsuspend-web-domain $user $domain
  425. assert_success
  426. refute_output
  427. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  428. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  429. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  430. }
  431. @test "WEB: Add ssl" {
  432. cp -f $HESTIA/ssl/certificate.crt /tmp/$domain.crt
  433. cp -f $HESTIA/ssl/certificate.key /tmp/$domain.key
  434. run v-add-web-domain-ssl $user $domain /tmp
  435. assert_success
  436. refute_output
  437. }
  438. @test "WEB: Rebuild web domain" {
  439. run v-rebuild-web-domains $user
  440. assert_success
  441. refute_output
  442. }
  443. #----------------------------------------------------------#
  444. # MULTIPHP #
  445. #----------------------------------------------------------#
  446. @test "Multiphp: Default php Backend version" {
  447. def_phpver=$(multiphp_default_version)
  448. multi_domain="multiphp.${domain}"
  449. run v-add-web-domain $user $multi_domain 198.18.0.125
  450. assert_success
  451. refute_output
  452. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  453. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  454. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  455. }
  456. @test "Multiphp: Change backend version - PHP v5.6" {
  457. test_phpver='5.6'
  458. multi_domain="multiphp.${domain}"
  459. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  460. skip "PHP ${test_phpver} not installed"
  461. fi
  462. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  463. assert_success
  464. refute_output
  465. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  466. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  467. # A single php-fpm pool config file must be present
  468. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  469. assert_equal "$num_fpm_config_files" '1'
  470. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  471. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  472. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  473. }
  474. @test "Multiphp: Change backend version - PHP v7.0" {
  475. test_phpver='7.0'
  476. multi_domain="multiphp.${domain}"
  477. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  478. skip "PHP ${test_phpver} not installed"
  479. fi
  480. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  481. assert_success
  482. refute_output
  483. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  484. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  485. # A single php-fpm pool config file must be present
  486. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  487. assert_equal "$num_fpm_config_files" '1'
  488. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  489. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  490. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  491. }
  492. @test "Multiphp: Change backend version - PHP v7.1" {
  493. test_phpver='7.1'
  494. multi_domain="multiphp.${domain}"
  495. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  496. skip "PHP ${test_phpver} not installed"
  497. fi
  498. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  499. assert_success
  500. refute_output
  501. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  502. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  503. # A single php-fpm pool config file must be present
  504. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  505. assert_equal "$num_fpm_config_files" '1'
  506. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  507. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  508. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  509. }
  510. @test "Multiphp: Change backend version - PHP v7.2" {
  511. test_phpver='7.2'
  512. multi_domain="multiphp.${domain}"
  513. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  514. skip "PHP ${test_phpver} not installed"
  515. fi
  516. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  517. assert_success
  518. refute_output
  519. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  520. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  521. # A single php-fpm pool config file must be present
  522. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  523. assert_equal "$num_fpm_config_files" '1'
  524. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  525. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  526. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  527. }
  528. @test "Multiphp: Change backend version - PHP v7.3" {
  529. test_phpver='7.3'
  530. multi_domain="multiphp.${domain}"
  531. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  532. skip "PHP ${test_phpver} not installed"
  533. fi
  534. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  535. assert_success
  536. refute_output
  537. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  538. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  539. # A single php-fpm pool config file must be present
  540. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  541. assert_equal "$num_fpm_config_files" '1'
  542. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  543. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  544. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  545. }
  546. @test "Multiphp: Change backend version - PHP v7.4" {
  547. test_phpver='7.4'
  548. multi_domain="multiphp.${domain}"
  549. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  550. skip "PHP ${test_phpver} not installed"
  551. fi
  552. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  553. assert_success
  554. refute_output
  555. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  556. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  557. # A single php-fpm pool config file must be present
  558. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  559. assert_equal "$num_fpm_config_files" '1'
  560. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  561. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  562. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  563. }
  564. @test "Multiphp: Change backend version - PHP v8.0" {
  565. test_phpver='8.0'
  566. multi_domain="multiphp.${domain}"
  567. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  568. skip "PHP ${test_phpver} not installed"
  569. fi
  570. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  571. assert_success
  572. refute_output
  573. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  574. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  575. # A single php-fpm pool config file must be present
  576. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  577. assert_equal "$num_fpm_config_files" '1'
  578. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  579. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  580. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  581. }
  582. @test "Multiphp: Cleanup" {
  583. multi_domain="multiphp.${domain}"
  584. run v-delete-web-domain $user $multi_domain 'yes'
  585. assert_success
  586. refute_output
  587. # No php-fpm pool config file must be present
  588. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  589. assert_equal "$num_fpm_config_files" '0'
  590. }
  591. #----------------------------------------------------------#
  592. # CUSTOM DOCROOT #
  593. #----------------------------------------------------------#
  594. @test "Docroot: Self Subfolder" {
  595. docroot1_domain="docroot1.${domain}"
  596. run v-add-web-domain $user $docroot1_domain 198.18.0.125
  597. assert_success
  598. refute_output
  599. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
  600. assert_success
  601. refute_output
  602. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
  603. assert_success
  604. refute_output
  605. echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  606. validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
  607. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  608. }
  609. @test "Docroot: Other domain subfolder" {
  610. docroot1_domain="docroot1.${domain}"
  611. docroot2_domain="docroot2.${domain}"
  612. run v-add-web-domain $user $docroot2_domain 198.18.0.125
  613. assert_success
  614. refute_output
  615. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
  616. assert_success
  617. refute_output
  618. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
  619. assert_success
  620. refute_output
  621. echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  622. validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
  623. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  624. }
  625. @test "Docroot: Other domain root folder" {
  626. docroot1_domain="docroot1.${domain}"
  627. docroot2_domain="docroot2.${domain}"
  628. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
  629. assert_success
  630. refute_output
  631. echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  632. validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
  633. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  634. }
  635. @test "Docroot: Reset" {
  636. docroot1_domain="docroot1.${domain}"
  637. run v-change-web-domain-docroot $user "$docroot1_domain" "default"
  638. assert_success
  639. refute_output
  640. echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  641. validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
  642. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  643. }
  644. @test "Docroot: Cleanup" {
  645. docroot1_domain="docroot1.${domain}"
  646. docroot2_domain="docroot2.${domain}"
  647. run v-delete-web-domain $user $docroot1_domain
  648. assert_success
  649. refute_output
  650. run v-delete-web-domain $user $docroot2_domain
  651. assert_success
  652. refute_output
  653. }
  654. #----------------------------------------------------------#
  655. # DNS #
  656. #----------------------------------------------------------#
  657. @test "DNS: Add domain" {
  658. run v-add-dns-domain $user $domain 198.18.0.125
  659. assert_success
  660. refute_output
  661. }
  662. @test "DNS: Add domain (duplicate)" {
  663. run v-add-dns-domain $user $domain 198.18.0.125
  664. assert_failure $E_EXISTS
  665. }
  666. @test "DNS: Add domain record" {
  667. run v-add-dns-record $user $domain test A 198.18.0.125 20
  668. assert_success
  669. refute_output
  670. }
  671. @test "DNS: Delete domain record" {
  672. run v-delete-dns-record $user $domain 20
  673. assert_success
  674. refute_output
  675. }
  676. @test "DNS: Delete missing domain record" {
  677. run v-delete-dns-record $user $domain 20
  678. assert_failure $E_NOTEXIST
  679. }
  680. @test "DNS: Change domain expire date" {
  681. run v-change-dns-domain-exp $user $domain 2020-01-01
  682. assert_success
  683. refute_output
  684. }
  685. @test "DNS: Change domain ip" {
  686. run v-change-dns-domain-ip $user $domain 127.0.0.1
  687. assert_success
  688. refute_output
  689. }
  690. @test "DNS: Suspend domain" {
  691. run v-suspend-dns-domain $user $domain
  692. assert_success
  693. refute_output
  694. }
  695. @test "DNS: Unsuspend domain" {
  696. run v-unsuspend-dns-domain $user $domain
  697. assert_success
  698. refute_output
  699. }
  700. @test "DNS: Rebuild" {
  701. run v-rebuild-dns-domains $user
  702. assert_success
  703. refute_output
  704. }
  705. #----------------------------------------------------------#
  706. # MAIL #
  707. #----------------------------------------------------------#
  708. @test "MAIL: Add domain" {
  709. run v-add-mail-domain $user $domain
  710. assert_success
  711. refute_output
  712. validate_mail_domain $user $domain
  713. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  714. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  715. # rm /var/lib/roundcube/check_server.php
  716. }
  717. @test "MAIL: Add domain (duplicate)" {
  718. run v-add-mail-domain $user $domain
  719. assert_failure $E_EXISTS
  720. }
  721. @test "MAIL: Add account" {
  722. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  723. assert_success
  724. refute_output
  725. }
  726. @test "MAIL: Add account (duplicate)" {
  727. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  728. assert_failure $E_EXISTS
  729. }
  730. @test "MAIL: Delete account" {
  731. run v-delete-mail-account $user $domain test
  732. assert_success
  733. refute_output
  734. }
  735. @test "MAIL: Delete missing account" {
  736. run v-delete-mail-account $user $domain test
  737. assert_failure $E_NOTEXIST
  738. }
  739. #----------------------------------------------------------#
  740. # DB #
  741. #----------------------------------------------------------#
  742. @test "DB: Add database (mysql)" {
  743. run v-add-database $user database dbuser 1234 mysql
  744. assert_success
  745. refute_output
  746. # validate_database database_name database_user password
  747. validate_database $database $dbuser 1234
  748. }
  749. @test "DB: Add Database (mysql) (Duplicate)" {
  750. run v-add-database $user database dbuser 1234 mysql
  751. assert_failure $E_EXISTS
  752. }
  753. @test "DB: Rebuild Database (mysql)" {
  754. run v-rebuild-database $user $database
  755. assert_success
  756. refute_output
  757. }
  758. @test "DB: Change database user password (mysql)" {
  759. run v-change-database-password $user $database 123456
  760. assert_success
  761. refute_output
  762. validate_database $database $dbuser 123456
  763. }
  764. @test "DB: Change database user (mysql)" {
  765. run v-change-database-user $user $database database
  766. assert_success
  767. refute_output
  768. validate_database $database $database 123456
  769. }
  770. @test "DB: Suspend database" {
  771. run v-suspend-database $user $database
  772. assert_success
  773. refute_output
  774. }
  775. @test "DB: Unsuspend database" {
  776. run v-unsuspend-database $user $database
  777. assert_success
  778. refute_output
  779. }
  780. @test "DB: Delete database" {
  781. run v-delete-database $user $database
  782. assert_success
  783. refute_output
  784. }
  785. @test "DB: Delete missing database" {
  786. run v-delete-database $user $database
  787. assert_failure $E_NOTEXIST
  788. }
  789. #----------------------------------------------------------#
  790. # Backup / Restore #
  791. #----------------------------------------------------------#
  792. #Test backup
  793. # Hestia v1.1.1 archive contains:
  794. # user: hestia111
  795. # web:
  796. # - test.hestia.com (+SSL self-signed)
  797. # dns:
  798. # - test.hestia.com
  799. # mail:
  800. # - test.hestia.com
  801. # mail acc:
  802. # - testaccount@test.hestia.com
  803. # db:
  804. # - hestia111_db
  805. # cron:
  806. # - 1: /bin/true
  807. # Hestia 1.3.1 archive contains (As zstd format)
  808. # user: hestia131
  809. # web:
  810. # - test.hestia.com (+SSL self-signed)
  811. # dns:
  812. # - test.hestia.com
  813. # mail:
  814. # - test.hestia.com
  815. # mail acc:
  816. # - testaccount@test.hestia.com
  817. # db:
  818. # - hestia131_db
  819. # cron:
  820. # - 1: /bin/true
  821. # Vesta 0.9.8-23 archive contains:
  822. # user: vesta09823
  823. # web:
  824. # - vesta09823.tld (+SSL self-signed)
  825. # dns:
  826. # - vesta09823.tld
  827. # mail:
  828. # - vesta09823.tld
  829. # mail acc:
  830. # - testaccount@vesta09823.tld
  831. # db:
  832. # - vesta09823_db
  833. # cron:
  834. # - 1: /bin/true
  835. #
  836. # Testing Hestia backups
  837. @test "Restore[1]: Hestia archive for a non-existing user" {
  838. if [ -d "$HOMEDIR/$userbk" ]; then
  839. run v-delete-user $userbk
  840. assert_success
  841. refute_output
  842. fi
  843. mkdir -p /backup
  844. local archive_name="hestia111.2020-03-26"
  845. 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"
  846. assert_success
  847. run v-restore-user $userbk "${archive_name}.tar"
  848. assert_success
  849. rm "/backup/${archive_name}.tar"
  850. }
  851. @test "Restore[1]: From Hestia [WEB]" {
  852. local domain="test.hestia.com"
  853. validate_web_domain $userbk $domain 'Hello Hestia'
  854. }
  855. @test "Restore[1]: From Hestia [DNS]" {
  856. local domain="test.hestia.com"
  857. run v-list-dns-domain $userbk $domain
  858. assert_success
  859. run nslookup $domain 127.0.0.1
  860. assert_success
  861. }
  862. @test "Restore[1]: From Hestia [MAIL]" {
  863. local domain="test.hestia.com"
  864. run v-list-mail-domain $userbk $domain
  865. assert_success
  866. }
  867. @test "Restore[1]: From Hestia [MAIL-Account]" {
  868. local domain="test.hestia.com"
  869. run v-list-mail-account $userbk $domain testaccount
  870. assert_success
  871. }
  872. @test "Restore[1]: From Hestia [DB]" {
  873. run v-list-database $userbk "${userbk}_db"
  874. assert_success
  875. }
  876. @test "Restore[1]: From Hestia [CRON]" {
  877. run v-list-cron-job $userbk 1
  878. assert_success
  879. }
  880. @test "Restore[1]: From Hestia Cleanup" {
  881. run v-delete-user $userbk
  882. assert_success
  883. refute_output
  884. }
  885. @test "Restore[2]: Hestia archive over a existing user" {
  886. if [ -d "$HOMEDIR/$userbk" ]; then
  887. run v-delete-user $userbk
  888. assert_success
  889. refute_output
  890. fi
  891. if [ ! -d "$HOMEDIR/$userbk" ]; then
  892. run v-add-user $userbk $userbk test@hestia.com
  893. assert_success
  894. fi
  895. mkdir -p /backup
  896. local archive_name="hestia111.2020-03-26"
  897. 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"
  898. assert_success
  899. run v-restore-user $userbk "${archive_name}.tar"
  900. assert_success
  901. rm "/backup/${archive_name}.tar"
  902. }
  903. @test "Restore[2]: From Hestia [WEB]" {
  904. local domain="test.hestia.com"
  905. validate_web_domain $userbk "${domain}" 'Hello Hestia'
  906. }
  907. @test "Restore[2]: From Hestia [DNS]" {
  908. local domain="test.hestia.com"
  909. run v-list-dns-domain $userbk $domain
  910. assert_success
  911. run nslookup $domain 127.0.0.1
  912. assert_success
  913. }
  914. @test "Restore[2]: From Hestia [MAIL]" {
  915. local domain="test.hestia.com"
  916. run v-list-mail-domain $userbk $domain
  917. assert_success
  918. }
  919. @test "Restore[2]: From Hestia [MAIL-Account]" {
  920. local domain="test.hestia.com"
  921. run v-list-mail-account $userbk $domain testaccount
  922. assert_success
  923. }
  924. @test "Restore[2]: From Hestia [DB]" {
  925. run v-list-database $userbk "${userbk}_db"
  926. assert_success
  927. }
  928. @test "Restore[2]: From Hestia [CRON]" {
  929. run v-list-cron-job $userbk 1
  930. assert_success
  931. }
  932. @test "Restore[2]: From Hestia Cleanup" {
  933. run v-delete-user $userbk
  934. assert_success
  935. refute_output
  936. }
  937. @test "Restore[3]: Hestia (zstd) archive for a non-existing user" {
  938. if [ -d "$HOMEDIR/$userbk" ]; then
  939. run v-delete-user $userbk
  940. assert_success
  941. refute_output
  942. fi
  943. mkdir -p /backup
  944. local archive_name="hestia131.2020-12-12"
  945. 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"
  946. assert_success
  947. run v-restore-user $userbk "${archive_name}.tar"
  948. assert_success
  949. rm "/backup/${archive_name}.tar"
  950. }
  951. @test "Restore[3]: From Hestia [WEB]" {
  952. local domain="test.hestia.com"
  953. validate_web_domain $userbk $domain 'Hello Hestia'
  954. }
  955. @test "Restore[3]: From Hestia [DNS]" {
  956. local domain="test.hestia.com"
  957. run v-list-dns-domain $userbk $domain
  958. assert_success
  959. run nslookup $domain 127.0.0.1
  960. assert_success
  961. }
  962. @test "Restore[3]: From Hestia [MAIL]" {
  963. local domain="test.hestia.com"
  964. run v-list-mail-domain $userbk $domain
  965. assert_success
  966. }
  967. @test "Restore[3]: From Hestia [MAIL-Account]" {
  968. local domain="test.hestia.com"
  969. run v-list-mail-account $userbk $domain testaccount
  970. assert_success
  971. }
  972. @test "Restore[3]: From Hestia [DB]" {
  973. run v-list-database $userbk "${userbk}_db"
  974. assert_success
  975. }
  976. @test "Restore[3]: From Hestia [CRON]" {
  977. run v-list-cron-job $userbk 1
  978. assert_success
  979. }
  980. @test "Restore[3]: From Hestia Cleanup" {
  981. run v-delete-user $userbk
  982. assert_success
  983. refute_output
  984. }
  985. @test "Restore[4]: Hestia (zstd) archive for a existing user" {
  986. if [ -d "$HOMEDIR/$userbk" ]; then
  987. run v-delete-user $userbk
  988. assert_success
  989. refute_output
  990. fi
  991. if [ ! -d "$HOMEDIR/$userbk" ]; then
  992. run v-add-user $userbk $userbk test@hestia.com
  993. assert_success
  994. fi
  995. mkdir -p /backup
  996. local archive_name="hestia131.2020-12-12"
  997. 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"
  998. assert_success
  999. run v-restore-user $userbk "${archive_name}.tar"
  1000. assert_success
  1001. rm "/backup/${archive_name}.tar"
  1002. }
  1003. @test "Restore[4]: From Hestia [WEB]" {
  1004. local domain="test.hestia.com"
  1005. validate_web_domain $userbk $domain 'Hello Hestia'
  1006. }
  1007. @test "Restore[4]: From Hestia [DNS]" {
  1008. local domain="test.hestia.com"
  1009. run v-list-dns-domain $userbk $domain
  1010. assert_success
  1011. run nslookup $domain 127.0.0.1
  1012. assert_success
  1013. }
  1014. @test "Restore[4]: From Hestia [MAIL]" {
  1015. local domain="test.hestia.com"
  1016. run v-list-mail-domain $userbk $domain
  1017. assert_success
  1018. }
  1019. @test "Restore[4]: From Hestia [MAIL-Account]" {
  1020. local domain="test.hestia.com"
  1021. run v-list-mail-account $userbk $domain testaccount
  1022. assert_success
  1023. }
  1024. @test "Restore[4]: From Hestia [DB]" {
  1025. run v-list-database $userbk "${userbk}_db"
  1026. assert_success
  1027. }
  1028. @test "Restore[4]: From Hestia [CRON]" {
  1029. run v-list-cron-job $userbk 1
  1030. assert_success
  1031. }
  1032. @test "Restore[4]: From Hestia Cleanup" {
  1033. run v-delete-user $userbk
  1034. assert_success
  1035. refute_output
  1036. }
  1037. # Testing Vesta Backups
  1038. @test "Restore[1]: Vesta archive for a non-existing user" {
  1039. if [ -d "$HOMEDIR/$userbk" ]; then
  1040. run v-delete-user $userbk
  1041. assert_success
  1042. refute_output
  1043. fi
  1044. mkdir -p /backup
  1045. local archive_name="vesta09823.2018-10-18"
  1046. 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"
  1047. assert_success
  1048. run v-restore-user $userbk "${archive_name}.tar"
  1049. assert_success
  1050. rm "/backup/${archive_name}.tar"
  1051. }
  1052. @test "Restore[1]: From Vesta [WEB]" {
  1053. local domain="vesta09823.tld"
  1054. validate_web_domain $userbk $domain 'Hello Vesta'
  1055. }
  1056. @test "Restore[1]: From Vesta [DNS]" {
  1057. local domain="vesta09823.tld"
  1058. run v-list-dns-domain $userbk $domain
  1059. assert_success
  1060. run nslookup $domain 127.0.0.1
  1061. assert_success
  1062. }
  1063. @test "Restore[1]: From Vesta [MAIL]" {
  1064. local domain="vesta09823.tld"
  1065. run v-list-mail-domain $userbk $domain
  1066. assert_success
  1067. }
  1068. @test "Restore[1]: From Vesta [MAIL-Account]" {
  1069. local domain="vesta09823.tld"
  1070. run v-list-mail-account $userbk $domain testaccount
  1071. assert_success
  1072. }
  1073. @test "Restore[1]: From Vesta [DB]" {
  1074. run v-list-database $userbk "${userbk}_db"
  1075. assert_success
  1076. }
  1077. @test "Restore[1]: From Vesta [CRON]" {
  1078. run v-list-cron-job $userbk 1
  1079. assert_success
  1080. }
  1081. @test "Restore[1]: From Vesta Cleanup" {
  1082. run v-delete-user $userbk
  1083. assert_success
  1084. refute_output
  1085. }
  1086. @test "Restore[2]: Vesta archive over a existing user" {
  1087. if [ -d "$HOMEDIR/$userbk" ]; then
  1088. run v-delete-user $userbk
  1089. assert_success
  1090. refute_output
  1091. fi
  1092. if [ ! -d "$HOMEDIR/$userbk" ]; then
  1093. run v-add-user $userbk $userbk test@hestia.com
  1094. assert_success
  1095. fi
  1096. mkdir -p /backup
  1097. local archive_name="vesta09823.2018-10-18"
  1098. 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"
  1099. assert_success
  1100. run v-restore-user $userbk "${archive_name}.tar"
  1101. assert_success
  1102. rm "/backup/${archive_name}.tar"
  1103. }
  1104. @test "Restore[2]: From Vesta [WEB]" {
  1105. local domain="vesta09823.tld"
  1106. validate_web_domain $userbk "${domain}" 'Hello Vesta'
  1107. }
  1108. @test "Restore[2]: From Vesta [DNS]" {
  1109. local domain="vesta09823.tld"
  1110. run v-list-dns-domain $userbk $domain
  1111. assert_success
  1112. run nslookup $domain 127.0.0.1
  1113. assert_success
  1114. }
  1115. @test "Restore[2]: From Vesta [MAIL]" {
  1116. local domain="vesta09823.tld"
  1117. run v-list-mail-domain $userbk $domain
  1118. assert_success
  1119. }
  1120. @test "Restore[2]: From Vesta [MAIL-Account]" {
  1121. local domain="vesta09823.tld"
  1122. run v-list-mail-account $userbk $domain testaccount
  1123. assert_success
  1124. }
  1125. @test "Restore[2]: From Vesta [DB]" {
  1126. run v-list-database $userbk "${userbk}_db"
  1127. assert_success
  1128. }
  1129. @test "Restore[2]: From Vesta [CRON]" {
  1130. run v-list-cron-job $userbk 1
  1131. assert_success
  1132. }
  1133. @test "Restore[2]: From Vesta Cleanup" {
  1134. run v-delete-user $userbk
  1135. assert_success
  1136. refute_output
  1137. }
  1138. #----------------------------------------------------------#
  1139. # CLEANUP #
  1140. #----------------------------------------------------------#
  1141. @test "Mail: Delete domain" {
  1142. # skip
  1143. run v-delete-mail-domain $user $domain
  1144. assert_success
  1145. refute_output
  1146. }
  1147. @test "DNS: Delete domain" {
  1148. # skip
  1149. run v-delete-dns-domain $user $domain
  1150. assert_success
  1151. refute_output
  1152. }
  1153. @test "WEB: Delete domain" {
  1154. # skip
  1155. run v-delete-web-domain $user $domain
  1156. assert_success
  1157. refute_output
  1158. }
  1159. @test "Delete user" {
  1160. # skip
  1161. run v-delete-user $user
  1162. assert_success
  1163. refute_output
  1164. }
  1165. @test "Ip: Delete the test IP" {
  1166. # skip
  1167. run v-delete-sys-ip 198.18.0.125
  1168. assert_success
  1169. refute_output
  1170. }
  1171. @test 'assert()' {
  1172. touch '/var/log/test.log'
  1173. assert [ -e '/var/log/test.log' ]
  1174. }