test.bats 46 KB

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