test.bats 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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 stats" {
  402. run v-add-web-domain-stats $user $domain awstats
  403. assert_success
  404. refute_output
  405. }
  406. @test "WEB: Add web domain stats user" {
  407. skip
  408. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  409. assert_success
  410. refute_output
  411. }
  412. @test "WEB: Suspend web domain" {
  413. run v-suspend-web-domain $user $domain
  414. assert_success
  415. refute_output
  416. validate_web_domain $user $domain 'This site is currently suspended'
  417. }
  418. @test "WEB: Unsuspend web domain" {
  419. run v-unsuspend-web-domain $user $domain
  420. assert_success
  421. refute_output
  422. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  423. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  424. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  425. }
  426. @test "WEB: Add ssl" {
  427. cp -f $HESTIA/ssl/certificate.crt /tmp/$domain.crt
  428. cp -f $HESTIA/ssl/certificate.key /tmp/$domain.key
  429. run v-add-web-domain-ssl $user $domain /tmp
  430. assert_success
  431. refute_output
  432. }
  433. @test "WEB: Rebuild web domain" {
  434. run v-rebuild-web-domains $user
  435. assert_success
  436. refute_output
  437. }
  438. #----------------------------------------------------------#
  439. # MULTIPHP #
  440. #----------------------------------------------------------#
  441. @test "Multiphp: Default php Backend version" {
  442. def_phpver=$(multiphp_default_version)
  443. multi_domain="multiphp.${domain}"
  444. run v-add-web-domain $user $multi_domain 198.18.0.125
  445. assert_success
  446. refute_output
  447. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  448. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  449. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  450. }
  451. @test "Multiphp: Change backend version - PHP v5.6" {
  452. test_phpver='5.6'
  453. multi_domain="multiphp.${domain}"
  454. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  455. skip "PHP ${test_phpver} not installed"
  456. fi
  457. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  458. assert_success
  459. refute_output
  460. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  461. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  462. # A single php-fpm pool config file must be present
  463. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  464. assert_equal "$num_fpm_config_files" '1'
  465. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  466. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  467. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  468. }
  469. @test "Multiphp: Change backend version - PHP v7.0" {
  470. test_phpver='7.0'
  471. multi_domain="multiphp.${domain}"
  472. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  473. skip "PHP ${test_phpver} not installed"
  474. fi
  475. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  476. assert_success
  477. refute_output
  478. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  479. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  480. # A single php-fpm pool config file must be present
  481. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  482. assert_equal "$num_fpm_config_files" '1'
  483. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  484. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  485. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  486. }
  487. @test "Multiphp: Change backend version - PHP v7.1" {
  488. test_phpver='7.1'
  489. multi_domain="multiphp.${domain}"
  490. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  491. skip "PHP ${test_phpver} not installed"
  492. fi
  493. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  494. assert_success
  495. refute_output
  496. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  497. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  498. # A single php-fpm pool config file must be present
  499. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  500. assert_equal "$num_fpm_config_files" '1'
  501. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  502. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  503. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  504. }
  505. @test "Multiphp: Change backend version - PHP v7.2" {
  506. test_phpver='7.2'
  507. multi_domain="multiphp.${domain}"
  508. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  509. skip "PHP ${test_phpver} not installed"
  510. fi
  511. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  512. assert_success
  513. refute_output
  514. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  515. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  516. # A single php-fpm pool config file must be present
  517. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  518. assert_equal "$num_fpm_config_files" '1'
  519. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  520. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  521. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  522. }
  523. @test "Multiphp: Change backend version - PHP v7.3" {
  524. test_phpver='7.3'
  525. multi_domain="multiphp.${domain}"
  526. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  527. skip "PHP ${test_phpver} not installed"
  528. fi
  529. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  530. assert_success
  531. refute_output
  532. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  533. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  534. # A single php-fpm pool config file must be present
  535. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  536. assert_equal "$num_fpm_config_files" '1'
  537. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  538. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  539. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  540. }
  541. @test "Multiphp: Change backend version - PHP v7.4" {
  542. test_phpver='7.4'
  543. multi_domain="multiphp.${domain}"
  544. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  545. skip "PHP ${test_phpver} not installed"
  546. fi
  547. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  548. assert_success
  549. refute_output
  550. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  551. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  552. # A single php-fpm pool config file must be present
  553. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  554. assert_equal "$num_fpm_config_files" '1'
  555. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  556. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  557. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  558. }
  559. @test "Multiphp: Change backend version - PHP v8.0" {
  560. test_phpver='8.0'
  561. multi_domain="multiphp.${domain}"
  562. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  563. skip "PHP ${test_phpver} not installed"
  564. fi
  565. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  566. assert_success
  567. refute_output
  568. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  569. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  570. # A single php-fpm pool config file must be present
  571. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  572. assert_equal "$num_fpm_config_files" '1'
  573. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  574. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  575. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  576. }
  577. @test "Multiphp: Cleanup" {
  578. multi_domain="multiphp.${domain}"
  579. run v-delete-web-domain $user $multi_domain 'yes'
  580. assert_success
  581. refute_output
  582. # No php-fpm pool config file must be present
  583. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  584. assert_equal "$num_fpm_config_files" '0'
  585. }
  586. #----------------------------------------------------------#
  587. # CUSTOM DOCROOT #
  588. #----------------------------------------------------------#
  589. @test "Docroot: Self Subfolder" {
  590. docroot1_domain="docroot1.${domain}"
  591. run v-add-web-domain $user $docroot1_domain 198.18.0.125
  592. assert_success
  593. refute_output
  594. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
  595. assert_success
  596. refute_output
  597. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
  598. assert_success
  599. refute_output
  600. echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  601. validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
  602. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  603. }
  604. @test "Docroot: Other domain subfolder" {
  605. docroot1_domain="docroot1.${domain}"
  606. docroot2_domain="docroot2.${domain}"
  607. run v-add-web-domain $user $docroot2_domain 198.18.0.125
  608. assert_success
  609. refute_output
  610. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
  611. assert_success
  612. refute_output
  613. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
  614. assert_success
  615. refute_output
  616. echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  617. validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
  618. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  619. }
  620. @test "Docroot: Other domain root folder" {
  621. docroot1_domain="docroot1.${domain}"
  622. docroot2_domain="docroot2.${domain}"
  623. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
  624. assert_success
  625. refute_output
  626. echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  627. validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
  628. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  629. }
  630. @test "Docroot: Reset" {
  631. docroot1_domain="docroot1.${domain}"
  632. run v-change-web-domain-docroot $user "$docroot1_domain" "default"
  633. assert_success
  634. refute_output
  635. echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  636. validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
  637. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  638. }
  639. @test "Docroot: Cleanup" {
  640. docroot1_domain="docroot1.${domain}"
  641. docroot2_domain="docroot2.${domain}"
  642. run v-delete-web-domain $user $docroot1_domain
  643. assert_success
  644. refute_output
  645. run v-delete-web-domain $user $docroot2_domain
  646. assert_success
  647. refute_output
  648. }
  649. #----------------------------------------------------------#
  650. # DNS #
  651. #----------------------------------------------------------#
  652. @test "DNS: Add domain" {
  653. run v-add-dns-domain $user $domain 198.18.0.125
  654. assert_success
  655. refute_output
  656. }
  657. @test "DNS: Add domain (duplicate)" {
  658. run v-add-dns-domain $user $domain 198.18.0.125
  659. assert_failure $E_EXISTS
  660. }
  661. @test "DNS: Add domain record" {
  662. run v-add-dns-record $user $domain test A 198.18.0.125 20
  663. assert_success
  664. refute_output
  665. }
  666. @test "DNS: Delete domain record" {
  667. run v-delete-dns-record $user $domain 20
  668. assert_success
  669. refute_output
  670. }
  671. @test "DNS: Delete missing domain record" {
  672. run v-delete-dns-record $user $domain 20
  673. assert_failure $E_NOTEXIST
  674. }
  675. @test "DNS: Change domain expire date" {
  676. run v-change-dns-domain-exp $user $domain 2020-01-01
  677. assert_success
  678. refute_output
  679. }
  680. @test "DNS: Change domain ip" {
  681. run v-change-dns-domain-ip $user $domain 127.0.0.1
  682. assert_success
  683. refute_output
  684. }
  685. @test "DNS: Suspend domain" {
  686. run v-suspend-dns-domain $user $domain
  687. assert_success
  688. refute_output
  689. }
  690. @test "DNS: Unsuspend domain" {
  691. run v-unsuspend-dns-domain $user $domain
  692. assert_success
  693. refute_output
  694. }
  695. @test "DNS: Rebuild" {
  696. run v-rebuild-dns-domains $user
  697. assert_success
  698. refute_output
  699. }
  700. #----------------------------------------------------------#
  701. # MAIL #
  702. #----------------------------------------------------------#
  703. @test "MAIL: Add domain" {
  704. run v-add-mail-domain $user $domain
  705. assert_success
  706. refute_output
  707. validate_mail_domain $user $domain
  708. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  709. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  710. # rm /var/lib/roundcube/check_server.php
  711. }
  712. @test "MAIL: Add domain (duplicate)" {
  713. run v-add-mail-domain $user $domain
  714. assert_failure $E_EXISTS
  715. }
  716. @test "MAIL: Add account" {
  717. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  718. assert_success
  719. refute_output
  720. }
  721. @test "MAIL: Add account (duplicate)" {
  722. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  723. assert_failure $E_EXISTS
  724. }
  725. @test "MAIL: Delete account" {
  726. run v-delete-mail-account $user $domain test
  727. assert_success
  728. refute_output
  729. }
  730. @test "MAIL: Delete missing account" {
  731. run v-delete-mail-account $user $domain test
  732. assert_failure $E_NOTEXIST
  733. }
  734. #----------------------------------------------------------#
  735. # DB #
  736. #----------------------------------------------------------#
  737. @test "DB: Add database (mysql)" {
  738. run v-add-database $user database dbuser 1234 mysql
  739. assert_success
  740. refute_output
  741. # validate_database database_name database_user password
  742. validate_database $database $dbuser 1234
  743. }
  744. @test "DB: Add Database (mysql) (Duplicate)" {
  745. run v-add-database $user database dbuser 1234 mysql
  746. assert_failure $E_EXISTS
  747. }
  748. @test "DB: Rebuild Database (mysql)" {
  749. run v-rebuild-database $user $database
  750. assert_success
  751. refute_output
  752. }
  753. @test "DB: Change database user password (mysql)" {
  754. run v-change-database-password $user $database 123456
  755. assert_success
  756. refute_output
  757. validate_database $database $dbuser 123456
  758. }
  759. @test "DB: Change database user (mysql)" {
  760. run v-change-database-user $user $database database
  761. assert_success
  762. refute_output
  763. validate_database $database $database 123456
  764. }
  765. @test "DB: Suspend database" {
  766. run v-suspend-database $user $database
  767. assert_success
  768. refute_output
  769. }
  770. @test "DB: Unsuspend database" {
  771. run v-unsuspend-database $user $database
  772. assert_success
  773. refute_output
  774. }
  775. @test "DB: Delete database" {
  776. run v-delete-database $user $database
  777. assert_success
  778. refute_output
  779. }
  780. @test "DB: Delete missing database" {
  781. run v-delete-database $user $database
  782. assert_failure $E_NOTEXIST
  783. }
  784. #----------------------------------------------------------#
  785. # Backup / Restore #
  786. #----------------------------------------------------------#
  787. #Test backup
  788. # Hestia v1.1.1 archive contains:
  789. # user: hestia111
  790. # web:
  791. # - test.hestia.com (+SSL self-signed)
  792. # dns:
  793. # - test.hestia.com
  794. # mail:
  795. # - test.hestia.com
  796. # mail acc:
  797. # - testaccount@test.hestia.com
  798. # db:
  799. # - hestia111_db
  800. # cron:
  801. # - 1: /bin/true
  802. # Hestia 1.3.1 archive contains (As zstd format)
  803. # user: hestia131
  804. # web:
  805. # - test.hestia.com (+SSL self-signed)
  806. # dns:
  807. # - test.hestia.com
  808. # mail:
  809. # - test.hestia.com
  810. # mail acc:
  811. # - testaccount@test.hestia.com
  812. # db:
  813. # - hestia131_db
  814. # cron:
  815. # - 1: /bin/true
  816. # Vesta 0.9.8-23 archive contains:
  817. # user: vesta09823
  818. # web:
  819. # - vesta09823.tld (+SSL self-signed)
  820. # dns:
  821. # - vesta09823.tld
  822. # mail:
  823. # - vesta09823.tld
  824. # mail acc:
  825. # - testaccount@vesta09823.tld
  826. # db:
  827. # - vesta09823_db
  828. # cron:
  829. # - 1: /bin/true
  830. #
  831. # Testing Hestia backups
  832. @test "Restore[1]: Hestia archive for a non-existing user" {
  833. if [ -d "$HOMEDIR/$userbk" ]; then
  834. run v-delete-user $userbk
  835. assert_success
  836. refute_output
  837. fi
  838. mkdir -p /backup
  839. local archive_name="hestia111.2020-03-26"
  840. 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"
  841. assert_success
  842. run v-restore-user $userbk "${archive_name}.tar"
  843. assert_success
  844. rm "/backup/${archive_name}.tar"
  845. }
  846. @test "Restore[1]: From Hestia [WEB]" {
  847. local domain="test.hestia.com"
  848. validate_web_domain $userbk $domain 'Hello Hestia'
  849. }
  850. @test "Restore[1]: From Hestia [DNS]" {
  851. local domain="test.hestia.com"
  852. run v-list-dns-domain $userbk $domain
  853. assert_success
  854. run nslookup $domain 127.0.0.1
  855. assert_success
  856. }
  857. @test "Restore[1]: From Hestia [MAIL]" {
  858. local domain="test.hestia.com"
  859. run v-list-mail-domain $userbk $domain
  860. assert_success
  861. }
  862. @test "Restore[1]: From Hestia [MAIL-Account]" {
  863. local domain="test.hestia.com"
  864. run v-list-mail-account $userbk $domain testaccount
  865. assert_success
  866. }
  867. @test "Restore[1]: From Hestia [DB]" {
  868. run v-list-database $userbk "${userbk}_db"
  869. assert_success
  870. }
  871. @test "Restore[1]: From Hestia [CRON]" {
  872. run v-list-cron-job $userbk 1
  873. assert_success
  874. }
  875. @test "Restore[1]: From Hestia Cleanup" {
  876. run v-delete-user $userbk
  877. assert_success
  878. refute_output
  879. }
  880. @test "Restore[2]: Hestia archive over a existing user" {
  881. if [ -d "$HOMEDIR/$userbk" ]; then
  882. run v-delete-user $userbk
  883. assert_success
  884. refute_output
  885. fi
  886. if [ ! -d "$HOMEDIR/$userbk" ]; then
  887. run v-add-user $userbk $userbk test@hestia.com
  888. assert_success
  889. fi
  890. mkdir -p /backup
  891. local archive_name="hestia111.2020-03-26"
  892. 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"
  893. assert_success
  894. run v-restore-user $userbk "${archive_name}.tar"
  895. assert_success
  896. rm "/backup/${archive_name}.tar"
  897. }
  898. @test "Restore[2]: From Hestia [WEB]" {
  899. local domain="test.hestia.com"
  900. validate_web_domain $userbk "${domain}" 'Hello Hestia'
  901. }
  902. @test "Restore[2]: From Hestia [DNS]" {
  903. local domain="test.hestia.com"
  904. run v-list-dns-domain $userbk $domain
  905. assert_success
  906. run nslookup $domain 127.0.0.1
  907. assert_success
  908. }
  909. @test "Restore[2]: From Hestia [MAIL]" {
  910. local domain="test.hestia.com"
  911. run v-list-mail-domain $userbk $domain
  912. assert_success
  913. }
  914. @test "Restore[2]: From Hestia [MAIL-Account]" {
  915. local domain="test.hestia.com"
  916. run v-list-mail-account $userbk $domain testaccount
  917. assert_success
  918. }
  919. @test "Restore[2]: From Hestia [DB]" {
  920. run v-list-database $userbk "${userbk}_db"
  921. assert_success
  922. }
  923. @test "Restore[2]: From Hestia [CRON]" {
  924. run v-list-cron-job $userbk 1
  925. assert_success
  926. }
  927. @test "Restore[2]: From Hestia Cleanup" {
  928. run v-delete-user $userbk
  929. assert_success
  930. refute_output
  931. }
  932. @test "Restore[3]: Hestia (zstd) archive for a non-existing user" {
  933. if [ -d "$HOMEDIR/$userbk" ]; then
  934. run v-delete-user $userbk
  935. assert_success
  936. refute_output
  937. fi
  938. mkdir -p /backup
  939. local archive_name="hestia131.2020-12-12"
  940. 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"
  941. assert_success
  942. run v-restore-user $userbk "${archive_name}.tar"
  943. assert_success
  944. rm "/backup/${archive_name}.tar"
  945. }
  946. @test "Restore[3]: From Hestia [WEB]" {
  947. local domain="test.hestia.com"
  948. validate_web_domain $userbk $domain 'Hello Hestia'
  949. }
  950. @test "Restore[3]: From Hestia [DNS]" {
  951. local domain="test.hestia.com"
  952. run v-list-dns-domain $userbk $domain
  953. assert_success
  954. run nslookup $domain 127.0.0.1
  955. assert_success
  956. }
  957. @test "Restore[3]: From Hestia [MAIL]" {
  958. local domain="test.hestia.com"
  959. run v-list-mail-domain $userbk $domain
  960. assert_success
  961. }
  962. @test "Restore[3]: From Hestia [MAIL-Account]" {
  963. local domain="test.hestia.com"
  964. run v-list-mail-account $userbk $domain testaccount
  965. assert_success
  966. }
  967. @test "Restore[3]: From Hestia [DB]" {
  968. run v-list-database $userbk "${userbk}_db"
  969. assert_success
  970. }
  971. @test "Restore[3]: From Hestia [CRON]" {
  972. run v-list-cron-job $userbk 1
  973. assert_success
  974. }
  975. @test "Restore[3]: From Hestia Cleanup" {
  976. run v-delete-user $userbk
  977. assert_success
  978. refute_output
  979. }
  980. @test "Restore[4]: Hestia (zstd) archive for a existing user" {
  981. if [ -d "$HOMEDIR/$userbk" ]; then
  982. run v-delete-user $userbk
  983. assert_success
  984. refute_output
  985. fi
  986. if [ ! -d "$HOMEDIR/$userbk" ]; then
  987. run v-add-user $userbk $userbk test@hestia.com
  988. assert_success
  989. fi
  990. mkdir -p /backup
  991. local archive_name="hestia131.2020-12-12"
  992. 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"
  993. assert_success
  994. run v-restore-user $userbk "${archive_name}.tar"
  995. assert_success
  996. rm "/backup/${archive_name}.tar"
  997. }
  998. @test "Restore[4]: From Hestia [WEB]" {
  999. local domain="test.hestia.com"
  1000. validate_web_domain $userbk $domain 'Hello Hestia'
  1001. }
  1002. @test "Restore[4]: From Hestia [DNS]" {
  1003. local domain="test.hestia.com"
  1004. run v-list-dns-domain $userbk $domain
  1005. assert_success
  1006. run nslookup $domain 127.0.0.1
  1007. assert_success
  1008. }
  1009. @test "Restore[4]: From Hestia [MAIL]" {
  1010. local domain="test.hestia.com"
  1011. run v-list-mail-domain $userbk $domain
  1012. assert_success
  1013. }
  1014. @test "Restore[4]: From Hestia [MAIL-Account]" {
  1015. local domain="test.hestia.com"
  1016. run v-list-mail-account $userbk $domain testaccount
  1017. assert_success
  1018. }
  1019. @test "Restore[4]: From Hestia [DB]" {
  1020. run v-list-database $userbk "${userbk}_db"
  1021. assert_success
  1022. }
  1023. @test "Restore[4]: From Hestia [CRON]" {
  1024. run v-list-cron-job $userbk 1
  1025. assert_success
  1026. }
  1027. @test "Restore[4]: From Hestia Cleanup" {
  1028. run v-delete-user $userbk
  1029. assert_success
  1030. refute_output
  1031. }
  1032. # Testing Vesta Backups
  1033. @test "Restore[1]: Vesta archive for a non-existing user" {
  1034. if [ -d "$HOMEDIR/$userbk" ]; then
  1035. run v-delete-user $userbk
  1036. assert_success
  1037. refute_output
  1038. fi
  1039. mkdir -p /backup
  1040. local archive_name="vesta09823.2018-10-18"
  1041. 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"
  1042. assert_success
  1043. run v-restore-user $userbk "${archive_name}.tar"
  1044. assert_success
  1045. rm "/backup/${archive_name}.tar"
  1046. }
  1047. @test "Restore[1]: From Vesta [WEB]" {
  1048. local domain="vesta09823.tld"
  1049. validate_web_domain $userbk $domain 'Hello Vesta'
  1050. }
  1051. @test "Restore[1]: From Vesta [DNS]" {
  1052. local domain="vesta09823.tld"
  1053. run v-list-dns-domain $userbk $domain
  1054. assert_success
  1055. run nslookup $domain 127.0.0.1
  1056. assert_success
  1057. }
  1058. @test "Restore[1]: From Vesta [MAIL]" {
  1059. local domain="vesta09823.tld"
  1060. run v-list-mail-domain $userbk $domain
  1061. assert_success
  1062. }
  1063. @test "Restore[1]: From Vesta [MAIL-Account]" {
  1064. local domain="vesta09823.tld"
  1065. run v-list-mail-account $userbk $domain testaccount
  1066. assert_success
  1067. }
  1068. @test "Restore[1]: From Vesta [DB]" {
  1069. run v-list-database $userbk "${userbk}_db"
  1070. assert_success
  1071. }
  1072. @test "Restore[1]: From Vesta [CRON]" {
  1073. run v-list-cron-job $userbk 1
  1074. assert_success
  1075. }
  1076. @test "Restore[1]: From Vesta Cleanup" {
  1077. run v-delete-user $userbk
  1078. assert_success
  1079. refute_output
  1080. }
  1081. @test "Restore[2]: Vesta archive over a existing user" {
  1082. if [ -d "$HOMEDIR/$userbk" ]; then
  1083. run v-delete-user $userbk
  1084. assert_success
  1085. refute_output
  1086. fi
  1087. if [ ! -d "$HOMEDIR/$userbk" ]; then
  1088. run v-add-user $userbk $userbk test@hestia.com
  1089. assert_success
  1090. fi
  1091. mkdir -p /backup
  1092. local archive_name="vesta09823.2018-10-18"
  1093. 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"
  1094. assert_success
  1095. run v-restore-user $userbk "${archive_name}.tar"
  1096. assert_success
  1097. rm "/backup/${archive_name}.tar"
  1098. }
  1099. @test "Restore[2]: From Vesta [WEB]" {
  1100. local domain="vesta09823.tld"
  1101. validate_web_domain $userbk "${domain}" 'Hello Vesta'
  1102. }
  1103. @test "Restore[2]: From Vesta [DNS]" {
  1104. local domain="vesta09823.tld"
  1105. run v-list-dns-domain $userbk $domain
  1106. assert_success
  1107. run nslookup $domain 127.0.0.1
  1108. assert_success
  1109. }
  1110. @test "Restore[2]: From Vesta [MAIL]" {
  1111. local domain="vesta09823.tld"
  1112. run v-list-mail-domain $userbk $domain
  1113. assert_success
  1114. }
  1115. @test "Restore[2]: From Vesta [MAIL-Account]" {
  1116. local domain="vesta09823.tld"
  1117. run v-list-mail-account $userbk $domain testaccount
  1118. assert_success
  1119. }
  1120. @test "Restore[2]: From Vesta [DB]" {
  1121. run v-list-database $userbk "${userbk}_db"
  1122. assert_success
  1123. }
  1124. @test "Restore[2]: From Vesta [CRON]" {
  1125. run v-list-cron-job $userbk 1
  1126. assert_success
  1127. }
  1128. @test "Restore[2]: From Vesta Cleanup" {
  1129. run v-delete-user $userbk
  1130. assert_success
  1131. refute_output
  1132. }
  1133. #----------------------------------------------------------#
  1134. # CLEANUP #
  1135. #----------------------------------------------------------#
  1136. @test "Mail: Delete domain" {
  1137. # skip
  1138. run v-delete-mail-domain $user $domain
  1139. assert_success
  1140. refute_output
  1141. }
  1142. @test "DNS: Delete domain" {
  1143. # skip
  1144. run v-delete-dns-domain $user $domain
  1145. assert_success
  1146. refute_output
  1147. }
  1148. @test "WEB: Delete domain" {
  1149. # skip
  1150. run v-delete-web-domain $user $domain
  1151. assert_success
  1152. refute_output
  1153. }
  1154. @test "Delete user" {
  1155. # skip
  1156. run v-delete-user $user
  1157. assert_success
  1158. refute_output
  1159. }
  1160. @test "Ip: Delete the test IP" {
  1161. # skip
  1162. run v-delete-sys-ip 198.18.0.125
  1163. assert_success
  1164. refute_output
  1165. }
  1166. @test 'assert()' {
  1167. touch '/var/log/test.log'
  1168. assert [ -e '/var/log/test.log' ]
  1169. }