test.bats 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  1. #!/usr/bin/env bats
  2. if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
  3. . /etc/profile.d/hestia.sh
  4. fi
  5. load 'test_helper/bats-support/load'
  6. load 'test_helper/bats-assert/load'
  7. load 'test_helper/bats-file/load'
  8. function random() {
  9. head /dev/urandom | tr -dc 0-9 | head -c$1
  10. }
  11. function setup() {
  12. # echo "# Setup_file" > &3
  13. if [ $BATS_TEST_NUMBER = 1 ]; then
  14. echo 'user=test-5285' > /tmp/hestia-test-env.sh
  15. echo 'user2=test-5286' >> /tmp/hestia-test-env.sh
  16. echo 'userbk=testbk-5285' >> /tmp/hestia-test-env.sh
  17. echo 'userpass1=test-5285' >> /tmp/hestia-test-env.sh
  18. echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
  19. echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
  20. echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
  21. echo 'domainuk=test-5285.hestiacp.com.uk' >> /tmp/hestia-test-env.sh
  22. echo 'rootdomain=testhestiacp.com' >> /tmp/hestia-test-env.sh
  23. echo 'subdomain=cdn.testhestiacp.com' >> /tmp/hestia-test-env.sh
  24. echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
  25. echo 'dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
  26. echo 'pguser=test5290' >> /tmp/hestia-test-env.sh
  27. echo 'pgdatabase=test5290_database' >> /tmp/hestia-test-env.sh
  28. echo 'pgdbuser=test5290_dbuser' >> /tmp/hestia-test-env.sh
  29. fi
  30. source /tmp/hestia-test-env.sh
  31. source $HESTIA/func/main.sh
  32. source $HESTIA/conf/hestia.conf
  33. source $HESTIA/func/ip.sh
  34. }
  35. function validate_web_domain() {
  36. local user=$1
  37. local domain=$2
  38. local webproof=$3
  39. local webpath=${4}
  40. refute [ -z "$user" ]
  41. refute [ -z "$domain" ]
  42. refute [ -z "$webproof" ]
  43. source $HESTIA/func/ip.sh
  44. run v-list-web-domain $user $domain
  45. assert_success
  46. USER_DATA=$HESTIA/data/users/$user
  47. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  48. SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
  49. domain_ip=$(get_real_ip "$domain_ip")
  50. if [ ! -z $webpath ]; then
  51. domain_docroot=$(get_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT')
  52. if [ -n "$domain_docroot" ] && [ -d "$domain_docroot" ]; then
  53. assert_file_exist "${domain_docroot}/${webpath}"
  54. else
  55. assert_file_exist "${HOMEDIR}/${user}/web/${domain}/public_html/${webpath}"
  56. fi
  57. fi
  58. # Test HTTP
  59. # Curl hates UTF domains so convert them to ascci.
  60. domain_idn=$(idn -a $domain)
  61. run curl --location --silent --show-error --insecure --resolve "${domain_idn}:80:${domain_ip}" "http://${domain_idn}/${webpath}"
  62. assert_success
  63. assert_output --partial "$webproof"
  64. # Test HTTPS
  65. if [ "$SSL" = "yes" ]; then
  66. run v-list-web-domain-ssl $user $domain
  67. assert_success
  68. run curl --location --silent --show-error --insecure --resolve "${domain_idn}:443:${domain_ip}" "https://${domain_idn}/${webpath}"
  69. assert_success
  70. assert_output --partial "$webproof"
  71. fi
  72. }
  73. function validate_headers_domain() {
  74. local user=$1
  75. local domain=$2
  76. local webproof=$3
  77. refute [ -z "$user" ]
  78. refute [ -z "$domain" ]
  79. refute [ -z "$webproof" ]
  80. source $HESTIA/func/ip.sh
  81. run v-list-web-domain $user $domain
  82. assert_success
  83. USER_DATA=$HESTIA/data/users/$user
  84. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  85. SSL=$(get_object_value 'web' 'DOMAIN' "$domain" '$SSL')
  86. domain_ip=$(get_real_ip "$domain_ip")
  87. # Test HTTP with code redirect for some reasons due to 301 redirect it fails
  88. curl -i --resolve "${domain}:80:${domain_ip}" "http://${domain}"
  89. assert_success
  90. assert_output --partial "$webproof"
  91. }
  92. function validate_mail_domain() {
  93. local user=$1
  94. local domain=$2
  95. refute [ -z "$user" ]
  96. refute [ -z "$domain" ]
  97. run v-list-mail-domain $user $domain
  98. assert_success
  99. assert_dir_exist $HOMEDIR/$user/mail/$domain
  100. assert_dir_exist $HOMEDIR/$user/conf/mail/$domain
  101. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/aliases
  102. if [ -n "$ANTISPAM_SYSTEM" ]; then
  103. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antispam
  104. fi
  105. if [ -n "$ANTIVIRUS_SYSTEM" ]; then
  106. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/antivirus
  107. fi
  108. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/fwd_only
  109. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/ip
  110. assert_file_exist $HOMEDIR/$user/conf/mail/$domain/passwd
  111. }
  112. function validate_webmail_domain() {
  113. local user=$1
  114. local domain=$2
  115. local webproof=$3
  116. local webpath=${4}
  117. refute [ -z "$user" ]
  118. refute [ -z "$domain" ]
  119. refute [ -z "$webproof" ]
  120. source $HESTIA/func/ip.sh
  121. USER_DATA=$HESTIA/data/users/$user
  122. local domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
  123. SSL=$(get_object_value 'mail' 'DOMAIN' "$domain" '$SSL')
  124. domain_ip=$(get_real_ip "$domain_ip")
  125. if [ ! -z "$webpath" ]; then
  126. assert_file_exist /var/lib/roundcube/$webpath
  127. fi
  128. if [ "$SSL" = "no" ]; then
  129. # Test HTTP
  130. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
  131. assert_success
  132. assert_output --partial "$webproof"
  133. # Test HTTP
  134. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
  135. assert_success
  136. assert_output --partial "$webproof"
  137. fi
  138. # Test HTTPS
  139. if [ "$SSL" = "yes" ]; then
  140. # Test HTTP with 301 redirect for some reasons due to 301 redirect it fails
  141. run curl --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
  142. assert_success
  143. assert_output --partial "301 Moved Permanently"
  144. # Test HTTP with 301 redirect for some reasons due to 301 redirect it fails
  145. run curl --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
  146. assert_success
  147. assert_output --partial "301 Moved Permanently"
  148. run v-list-mail-domain-ssl $user $domain
  149. assert_success
  150. run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:443:${domain_ip}" "https://webmail.${domain}/${webpath}"
  151. assert_success
  152. assert_output --partial "$webproof"
  153. run curl --location --silent --show-error --insecure --resolve "mail.${domain}:443:${domain_ip}" "https://mail.${domain}/${webpath}"
  154. assert_success
  155. assert_output --partial "$webproof"
  156. fi
  157. }
  158. function validate_database(){
  159. local type=$1
  160. local database=$2
  161. local dbuser=$3
  162. local password=$4
  163. host_str=$(grep "HOST='localhost'" $HESTIA/conf/$type.conf)
  164. parse_object_kv_list "$host_str"
  165. if [ -z $PORT ]; then PORT=3306; fi
  166. refute [ -z "$HOST" ]
  167. refute [ -z "$PORT" ]
  168. refute [ -z "$database" ]
  169. refute [ -z "$dbuser" ]
  170. refute [ -z "$password" ]
  171. if [ "$type" = "mysql" ]; then
  172. # Create an connection to verify correct username / password has been set correctly
  173. tmpfile=$(mktemp /tmp/mysql.XXXXXX)
  174. echo "[client]">$tmpfile
  175. echo "host='$HOST'" >> $tmpfile
  176. echo "user='$dbuser'" >> $tmpfile
  177. echo "password='$password'" >> $tmpfile
  178. echo "port='$PORT'" >> $tmpfile
  179. chmod 600 $tmpfile
  180. sql_tmp=$(mktemp /tmp/query.XXXXXX)
  181. echo "show databases;" > $sql_tmp
  182. run mysql --defaults-file=$tmpfile < "$sql_tmp"
  183. assert_success
  184. assert_output --partial "$database"
  185. rm -f "$sql_tmp"
  186. rm -f "$tmpfile"
  187. else
  188. echo "*:*:*:$dbuser:$password" > /root/.pgpass
  189. chmod 600 /root/.pgpass
  190. run export PGPASSWORD="$password" | psql -h $HOST -U "$dbuser" -p $PORT -d "$database" --no-password -c "\l"
  191. assert_success
  192. rm /root/.pgpass
  193. fi
  194. }
  195. function check_ip_banned(){
  196. local ip=$1
  197. local chain=$2
  198. run grep "IP='$ip' CHAIN='$chain'" $HESTIA/data/firewall/banlist.conf
  199. assert_success
  200. assert_output --partial "$ip"
  201. }
  202. function check_ip_not_banned(){
  203. local ip=$1
  204. local chain=$2
  205. run grep "IP='$ip' CHAIN='$chain'" $HESTIA/data/firewall/banlist.conf
  206. assert_failure E_ARGS
  207. refute_output
  208. }
  209. #----------------------------------------------------------#
  210. # IP #
  211. #----------------------------------------------------------#
  212. @test "RDNS: Check reverse Dns validation" {
  213. # 1. PTR record for a IP should return a hostname(reverse) which in turn must resolve to the same IP addr(forward). (Full circle)
  214. # `-> not implemented in `is_ip_rdns_valid` yet and also not tested here
  215. # 2. Reject rPTR records that match generic dynamic IP pool patterns
  216. local ip="54.200.1.22"
  217. local rdns="ec2-54-200-1-22.us-west-2.compute.amazonaws.com"
  218. run is_ip_rdns_valid "$ip"
  219. assert_failure
  220. refute_output
  221. local rdns="ec2.54.200.1.22.us-west-2.compute.amazonaws.com"
  222. run is_ip_rdns_valid "$ip"
  223. assert_failure
  224. refute_output
  225. local rdns="ec2-22-1-200-54.us-west-2.compute.amazonaws.com"
  226. run is_ip_rdns_valid "$ip"
  227. assert_failure
  228. refute_output
  229. local rdns="ec2.22.1.200.54.us-west-2.compute.amazonaws.com"
  230. run is_ip_rdns_valid "$ip"
  231. assert_failure
  232. refute_output
  233. local rdns="ec2-200-54-1-22.us-west-2.compute.amazonaws.com"
  234. run is_ip_rdns_valid "$ip"
  235. assert_failure
  236. refute_output
  237. local rdns="panel-22.mydomain.tld"
  238. run is_ip_rdns_valid "$ip"
  239. assert_success
  240. assert_output "$rdns"
  241. local rdns="mail.mydomain.tld"
  242. run is_ip_rdns_valid "$ip"
  243. assert_success
  244. assert_output "$rdns"
  245. local rdns="mydomain.tld"
  246. run is_ip_rdns_valid "$ip"
  247. assert_success
  248. assert_output "$rdns"
  249. }
  250. #----------------------------------------------------------#
  251. # User #
  252. #----------------------------------------------------------#
  253. @test "User: Add new user" {
  254. run v-add-user $user $user $user@hestiacp.com default "Super Test"
  255. assert_success
  256. refute_output
  257. }
  258. @test "User: Change user password" {
  259. run v-change-user-password "$user" "$userpass2"
  260. assert_success
  261. refute_output
  262. }
  263. @test "User: Change user email" {
  264. run v-change-user-contact "$user" tester@hestiacp.com
  265. assert_success
  266. refute_output
  267. }
  268. @test "User: Change user contact invalid email " {
  269. run v-change-user-contact "$user" testerhestiacp.com
  270. assert_failure $E_INVALID
  271. assert_output --partial 'Error: invalid email format'
  272. }
  273. @test "User: Change user name" {
  274. run v-change-user-name "$user" "New name"
  275. assert_success
  276. refute_output
  277. }
  278. @test "User: Change user shell" {
  279. run v-change-user-shell $user bash
  280. assert_success
  281. refute_output
  282. run stat -c '%U' /home/$user
  283. assert_output --partial "$user"
  284. }
  285. @test "User: Change user invalid shell" {
  286. run v-change-user-shell $user bashinvalid
  287. assert_failure $E_INVALID
  288. assert_output --partial 'shell bashinvalid is not valid'
  289. }
  290. @test "User: Change user nologin" {
  291. run v-change-user-shell $user nologin
  292. assert_success
  293. refute_output
  294. run stat -c '%U' /home/$user
  295. assert_output --partial 'root'
  296. }
  297. @test "User: Change user default ns" {
  298. run v-change-user-ns $user ns0.com ns1.com ns2.com ns3.com
  299. assert_success
  300. refute_output
  301. run v-list-user-ns "$user" plain
  302. assert_success
  303. assert_output --partial 'ns0.com'
  304. }
  305. @test "User: Change user language" {
  306. run v-change-user-language $user "nl"
  307. assert_success
  308. refute_output
  309. }
  310. @test "User: Change user language (Does not exists)" {
  311. run v-change-user-language $user "aa"
  312. assert_failure $E_NOTEXIST
  313. }
  314. @test "User: Change user sort order" {
  315. run v-change-user-sort-order $user "name"
  316. assert_success
  317. refute_output
  318. }
  319. @test "User: Change user theme" {
  320. run v-change-user-theme $user "flat"
  321. assert_success
  322. refute_output
  323. }
  324. @test "User: Change user theme (Does not exists)" {
  325. run v-change-user-theme $user "aa"
  326. assert_failure $E_NOTEXIST
  327. }
  328. @test "User: Change user login ip" {
  329. run v-change-user-config-value $user "LOGIN_USE_IPLIST" "1.2.3.4,1.2.3.5"
  330. assert_success
  331. refute_output
  332. }
  333. @test "User: Change user login ip (Failed)" {
  334. run v-change-user-config-value $user "LOGIN_USE_IPLIST" "'; echo 'jaap'; echo '"
  335. assert_failure $E_INVALID
  336. }
  337. @test "User: Add user notification" {
  338. run v-add-user-notification $user "Test message" "Message"
  339. assert_success
  340. refute_output
  341. }
  342. @test "User: Acknowledge user notification" {
  343. run v-acknowledge-user-notification $user 1
  344. assert_success
  345. refute_output
  346. }
  347. @test "User: List user notification" {
  348. run v-list-user-notifications $user csv
  349. assert_success
  350. assert_output --partial "1,\"Test message\",\"Message\",yes"
  351. }
  352. @test "User: Delete user notification" {
  353. run v-delete-user-notification admin 1
  354. assert_success
  355. refute_output
  356. }
  357. @test "User: Get User salt ipv4" {
  358. run v-get-user-salt $user 192.168.2.10
  359. assert_success
  360. }
  361. @test "User: Get User salt ipv4 invalid" {
  362. run v-get-user-salt $user 192.168.992.10
  363. assert_failure $E_INVALID
  364. }
  365. @test "User: Get User salt ipv6" {
  366. run v-get-user-salt $user "21DA:D3:0:2F3B:2AA:FF:FE28:9C5A"
  367. assert_success
  368. }
  369. @test "User: Get User salt ipv6 not exists" {
  370. run v-get-user-salt "notexists" "21DA:D3:0:2F3B:2AA:FF:FE28:9C5B"
  371. assert_failure $E_PASSWORD
  372. }
  373. @test "User: Get User salt ipv6 invalid" {
  374. run v-get-user-salt "$user" "21DA:D3:0:2F3B:ZZZ:FF:FE28:9C5B"
  375. assert_failure $E_INVALID
  376. }
  377. @test "User: Check user password" {
  378. run v-check-user-password $user "$userpass2" 192.168.2.10 'no'
  379. assert_success
  380. }
  381. @test "User: Check user password Incorrect password" {
  382. run v-check-user-password $user "$userpass1" 192.168.2.10 'no'
  383. assert_failure $E_PASSWORD
  384. }
  385. @test "User: Check user hash ipv4" {
  386. hash=$(v-check-user-password $user "$userpass2" 192.168.2.10 'yes');
  387. run v-check-user-hash $user $hash 192.168.2.10
  388. assert_success
  389. }
  390. @test "User: Check user hash ipv6" {
  391. hash=$(v-check-user-password $user "$userpass2" 21DA:D3:0:2F3B:2AA:FF:FE28:9C5A 'yes');
  392. run v-check-user-hash $user $hash 21DA:D3:0:2F3B:2AA:FF:FE28:9C5A
  393. assert_success
  394. }
  395. @test "User: Check user hash ipv6 incorrect" {
  396. run v-check-user-hash $user 'jafawefaweijawe' 21DA:D3:0:2F3B:2AA:FF:FE28:9C5A
  397. assert_failure $E_PASSWORD
  398. }
  399. #----------------------------------------------------------#
  400. # Cron #
  401. #----------------------------------------------------------#
  402. @test "Cron: Add cron job" {
  403. run v-add-cron-job $user 1 1 1 1 1 echo
  404. assert_success
  405. refute_output
  406. }
  407. @test "Cron: Suspend cron job" {
  408. run v-suspend-cron-job $user 1
  409. assert_success
  410. refute_output
  411. }
  412. @test "Cron: Unsuspend cron job" {
  413. run v-unsuspend-cron-job $user 1
  414. assert_success
  415. refute_output
  416. }
  417. @test "Cron: Delete cron job" {
  418. run v-delete-cron-job $user 1
  419. assert_success
  420. refute_output
  421. }
  422. @test "Cron: Add cron job (duplicate)" {
  423. run v-add-cron-job $user 1 1 1 1 1 echo 1
  424. assert_success
  425. refute_output
  426. run v-add-cron-job $user 1 1 1 1 1 echo 1
  427. assert_failure $E_EXISTS
  428. assert_output --partial 'JOB=1 already exists'
  429. }
  430. @test "Cron: Second cron job" {
  431. run v-add-cron-job $user 2 2 2 2 2 echo 2
  432. assert_success
  433. refute_output
  434. }
  435. @test "Cron: Two cron jobs must be listed" {
  436. run v-list-cron-jobs $user csv
  437. assert_success
  438. assert_line --partial '1,1,1,1,1,"echo",no'
  439. assert_line --partial '2,2,2,2,2,"echo",no'
  440. }
  441. @test "Cron: rebuild" {
  442. run v-rebuild-cron-jobs $user
  443. assert_success
  444. refute_output
  445. }
  446. #----------------------------------------------------------#
  447. # IP #
  448. #----------------------------------------------------------#
  449. @test "Ip: Add new ip on first interface" {
  450. interface=$(v-list-sys-interfaces plain | head -n 1)
  451. run ip link show dev $interface
  452. assert_success
  453. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  454. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  455. # Save initial state
  456. echo "interface=${interface}" >> /tmp/hestia-test-env.sh
  457. [ -f "$a2_rpaf" ] && file_hash1=$(cat $a2_rpaf |md5sum |cut -d" " -f1) && echo "a2_rpaf_hash='${file_hash1}'" >> /tmp/hestia-test-env.sh
  458. [ -f "$a2_remoteip" ] && file_hash2=$(cat $a2_remoteip |md5sum |cut -d" " -f1) && echo "a2_remoteip_hash='${file_hash2}'" >> /tmp/hestia-test-env.sh
  459. local ip="198.18.0.12"
  460. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  461. assert_success
  462. refute_output
  463. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  464. assert_file_exist $HESTIA/data/ips/$ip
  465. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  466. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  467. if [ -n "$PROXY_SYSTEM" ]; then
  468. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  469. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  470. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  471. fi
  472. }
  473. @test "Ip: Add ip (duplicate)" {
  474. run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
  475. assert_failure $E_EXISTS
  476. }
  477. @test "Ip: Add extra ip" {
  478. local ip="198.18.0.121"
  479. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  480. assert_success
  481. refute_output
  482. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  483. assert_file_exist $HESTIA/data/ips/$ip
  484. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  485. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  486. if [ -n "$PROXY_SYSTEM" ]; then
  487. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  488. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  489. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  490. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  491. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  492. fi
  493. }
  494. @test "Ip: Delete ips" {
  495. local ip="198.18.0.12"
  496. run v-delete-sys-ip $ip
  497. assert_success
  498. refute_output
  499. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  500. assert_file_not_exist $HESTIA/data/ips/$ip
  501. ip="198.18.0.121"
  502. run v-delete-sys-ip $ip
  503. assert_success
  504. refute_output
  505. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  506. assert_file_not_exist $HESTIA/data/ips/$ip
  507. if [ -n "$PROXY_SYSTEM" ]; then
  508. assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  509. fi
  510. # remoteip and rpaf config hashes must match the initial one
  511. if [ ! -z "$a2_rpaf_hash" ]; then
  512. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  513. file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
  514. assert_equal "$file_hash" "$a2_rpaf_hash"
  515. fi
  516. if [ ! -z "$a2_remoteip_hash" ]; then
  517. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  518. file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
  519. assert_equal "$file_hash" "$a2_remoteip_hash"
  520. fi
  521. }
  522. @test "Ip: Add IP for rest of the test" {
  523. local ip="198.18.0.125"
  524. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  525. assert_success
  526. refute_output
  527. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  528. assert_file_exist $HESTIA/data/ips/$ip
  529. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  530. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  531. if [ -n "$PROXY_SYSTEM" ]; then
  532. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  533. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  534. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  535. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  536. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  537. fi
  538. }
  539. #----------------------------------------------------------#
  540. # WEB #
  541. #----------------------------------------------------------#
  542. @test "WEB: Add web domain" {
  543. run v-add-web-domain $user $domain 198.18.0.125
  544. assert_success
  545. refute_output
  546. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  547. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  548. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  549. }
  550. @test "WEB: Add web domain (duplicate)" {
  551. run v-add-web-domain $user $domain 198.18.0.125
  552. assert_failure $E_EXISTS
  553. }
  554. @test "WEB: Add web domain alias" {
  555. run v-add-web-domain-alias $user $domain v3.$domain
  556. assert_success
  557. refute_output
  558. }
  559. @test "WEB: Add web domain alias (duplicate)" {
  560. run v-add-web-domain-alias $user $domain v3.$domain
  561. assert_failure $E_EXISTS
  562. }
  563. @test "WEB: Add web domain wildcard alias" {
  564. run v-add-web-domain-alias $user $domain "*.$domain"
  565. assert_success
  566. refute_output
  567. }
  568. @test "WEB: Delete web domain wildcard alias" {
  569. run v-delete-web-domain-alias $user $domain "*.$domain"
  570. assert_success
  571. refute_output
  572. }
  573. @test "WEB: Add web domain stats" {
  574. run v-add-web-domain-stats $user $domain awstats
  575. assert_success
  576. refute_output
  577. }
  578. @test "WEB: Add web domain stats user" {
  579. skip
  580. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  581. assert_success
  582. refute_output
  583. }
  584. @test "WEB: Suspend web domain" {
  585. run v-suspend-web-domain $user $domain
  586. assert_success
  587. refute_output
  588. validate_web_domain $user $domain 'This site is currently suspended'
  589. }
  590. @test "WEB: Unsuspend web domain" {
  591. run v-unsuspend-web-domain $user $domain
  592. assert_success
  593. refute_output
  594. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  595. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  596. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  597. }
  598. @test "WEB: Add redirect to www.domain.com" {
  599. run v-add-web-domain-redirect $user $domain www.$domain 301
  600. assert_success
  601. refute_output
  602. run validate_headers_domain $user $domain "301"
  603. }
  604. @test "WEB: Delete redirect to www.domain.com" {
  605. run v-delete-web-domain-redirect $user $domain
  606. assert_success
  607. refute_output
  608. }
  609. @test "WEB: Enable Fast CGI Cache" {
  610. if [ "$WEB_SYSTEM" != "nginx" ]; then
  611. skip "FastCGI cache is not supported"
  612. fi
  613. run v-add-fastcgi-cache $user $domain '1m' yes
  614. assert_success
  615. refute_output
  616. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  617. run validate_headers_domain $user $domain "Miss"
  618. run validate_headers_domain $user $domain "Hit"
  619. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  620. }
  621. @test "WEB: Disable Fast CGI Cache" {
  622. if [ "$WEB_SYSTEM" != "nginx" ]; then
  623. skip "FastCGI cache is not supported"
  624. fi
  625. run v-delete-fastcgi-cache $user $domain '1m' yes
  626. assert_success
  627. refute_output
  628. }
  629. @test "WEB: Generate Self signed certificate" {
  630. ssl=$(v-generate-ssl-cert "$domain" "info@$domain" US CA "Orange County" HestiaCP IT "mail.$domain" | tail -n1 | awk '{print $2}')
  631. echo $ssl;
  632. mv $ssl/$domain.crt /tmp/$domain.crt
  633. mv $ssl/$domain.key /tmp/$domain.key
  634. }
  635. @test "WEB: Add ssl" {
  636. # Use self signed certificates during last test
  637. run v-add-web-domain-ssl $user $domain /tmp
  638. assert_success
  639. refute_output
  640. }
  641. @test "WEB: Rebuild web domain" {
  642. run v-rebuild-web-domains $user
  643. assert_success
  644. refute_output
  645. }
  646. #----------------------------------------------------------#
  647. # IDN #
  648. #----------------------------------------------------------#
  649. @test "WEB: Add IDN domain UTF idn-tést.eu" {
  650. run v-add-web-domain $user idn-tést.eu 198.18.0.125
  651. assert_success
  652. refute_output
  653. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  654. validate_web_domain $user idn-tést.eu 'Hestia Test:12' 'php-test.php'
  655. rm $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  656. }
  657. @test "WEB: Add IDN domain ASCII idn-tést.eu" {
  658. # Expected to fail due to utf exists
  659. run v-add-web-domain $user $( idn -a idn-tést.eu) 198.18.0.125
  660. assert_failure $E_EXISTS
  661. }
  662. @test "WEB: Generate Self signed certificate ASCII idn-tést.eu" {
  663. run v-generate-ssl-cert "xn--idn-tst-fya.eu" "info@xn--idn-tst-fya.eu" US CA "Orange County" HestiaCP IT "mail.xn--idn-tst-fya.eu"
  664. assert_success
  665. }
  666. @test "WEB: Delete IDN domain idn-tést.eu" {
  667. run v-delete-web-domain $user idn-tést.eu
  668. assert_success
  669. refute_output
  670. }
  671. @test "WEB: Add IDN domain UTF bløst.рф" {
  672. run v-add-web-domain $user bløst.рф 198.18.0.125
  673. assert_success
  674. refute_output
  675. }
  676. @test "WEB: Generate Self signed certificate ASCII bløst.рф" {
  677. run v-generate-ssl-cert "xn--blst-hra.xn--p1ai" "info@xn--blst-hra.xn--p1ai" US CA "Orange County" HestiaCP IT "mail.xn--blst-hra.xn--p1ai"
  678. assert_success
  679. }
  680. @test "WEB: Delete IDN domain bløst.рф" {
  681. run v-delete-web-domain $user bløst.рф
  682. assert_success
  683. refute_output
  684. }
  685. #----------------------------------------------------------#
  686. # MULTIPHP #
  687. #----------------------------------------------------------#
  688. @test "Multiphp: Default php Backend version" {
  689. def_phpver=$(multiphp_default_version)
  690. multi_domain="multiphp.${domain}"
  691. run v-add-web-domain $user $multi_domain 198.18.0.125
  692. assert_success
  693. refute_output
  694. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  695. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  696. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  697. }
  698. @test "Multiphp: Change backend version - PHP v5.6" {
  699. test_phpver='5.6'
  700. multi_domain="multiphp.${domain}"
  701. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  702. skip "PHP ${test_phpver} not installed"
  703. fi
  704. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  705. assert_success
  706. refute_output
  707. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  708. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  709. # A single php-fpm pool config file must be present
  710. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  711. assert_equal "$num_fpm_config_files" '1'
  712. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  713. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  714. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  715. }
  716. @test "Multiphp: Change backend version - PHP v7.0" {
  717. test_phpver='7.0'
  718. multi_domain="multiphp.${domain}"
  719. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  720. skip "PHP ${test_phpver} not installed"
  721. fi
  722. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  723. assert_success
  724. refute_output
  725. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  726. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  727. # A single php-fpm pool config file must be present
  728. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  729. assert_equal "$num_fpm_config_files" '1'
  730. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  731. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  732. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  733. }
  734. @test "Multiphp: Change backend version - PHP v7.1" {
  735. test_phpver='7.1'
  736. multi_domain="multiphp.${domain}"
  737. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  738. skip "PHP ${test_phpver} not installed"
  739. fi
  740. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  741. assert_success
  742. refute_output
  743. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  744. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  745. # A single php-fpm pool config file must be present
  746. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  747. assert_equal "$num_fpm_config_files" '1'
  748. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  749. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  750. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  751. }
  752. @test "Multiphp: Change backend version - PHP v7.2" {
  753. test_phpver='7.2'
  754. multi_domain="multiphp.${domain}"
  755. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  756. skip "PHP ${test_phpver} not installed"
  757. fi
  758. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  759. assert_success
  760. refute_output
  761. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  762. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  763. # A single php-fpm pool config file must be present
  764. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  765. assert_equal "$num_fpm_config_files" '1'
  766. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  767. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  768. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  769. }
  770. @test "Multiphp: Change backend version - PHP v7.3" {
  771. test_phpver='7.3'
  772. multi_domain="multiphp.${domain}"
  773. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  774. skip "PHP ${test_phpver} not installed"
  775. fi
  776. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  777. assert_success
  778. refute_output
  779. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  780. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  781. # A single php-fpm pool config file must be present
  782. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  783. assert_equal "$num_fpm_config_files" '1'
  784. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  785. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  786. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  787. }
  788. @test "Multiphp: Change backend version - PHP v7.4" {
  789. test_phpver='7.4'
  790. multi_domain="multiphp.${domain}"
  791. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  792. skip "PHP ${test_phpver} not installed"
  793. fi
  794. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  795. assert_success
  796. refute_output
  797. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  798. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  799. # A single php-fpm pool config file must be present
  800. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  801. assert_equal "$num_fpm_config_files" '1'
  802. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  803. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  804. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  805. }
  806. @test "Multiphp: Change backend version - PHP v8.0" {
  807. test_phpver='8.0'
  808. multi_domain="multiphp.${domain}"
  809. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  810. skip "PHP ${test_phpver} not installed"
  811. fi
  812. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  813. assert_success
  814. refute_output
  815. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  816. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  817. # A single php-fpm pool config file must be present
  818. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  819. assert_equal "$num_fpm_config_files" '1'
  820. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  821. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  822. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  823. }
  824. @test "Multiphp: Change backend version - PHP v8.1" {
  825. test_phpver='8.1'
  826. multi_domain="multiphp.${domain}"
  827. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  828. skip "PHP ${test_phpver} not installed"
  829. fi
  830. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_1' 'yes'
  831. assert_success
  832. refute_output
  833. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  834. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  835. # A single php-fpm pool config file must be present
  836. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  837. assert_equal "$num_fpm_config_files" '1'
  838. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  839. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  840. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  841. }
  842. @test "Multiphp: Cleanup" {
  843. multi_domain="multiphp.${domain}"
  844. run v-delete-web-domain $user $multi_domain 'yes'
  845. assert_success
  846. refute_output
  847. # No php-fpm pool config file must be present
  848. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  849. assert_equal "$num_fpm_config_files" '0'
  850. }
  851. #----------------------------------------------------------#
  852. # CUSTOM DOCROOT #
  853. #----------------------------------------------------------#
  854. @test "Docroot: Self Subfolder" {
  855. docroot1_domain="docroot1.${domain}"
  856. run v-add-web-domain $user $docroot1_domain 198.18.0.125
  857. assert_success
  858. refute_output
  859. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
  860. assert_success
  861. refute_output
  862. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
  863. assert_success
  864. refute_output
  865. echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  866. validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
  867. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  868. }
  869. @test "Docroot: Other domain subfolder" {
  870. docroot1_domain="docroot1.${domain}"
  871. docroot2_domain="docroot2.${domain}"
  872. run v-add-web-domain $user $docroot2_domain 198.18.0.125
  873. assert_success
  874. refute_output
  875. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
  876. assert_success
  877. refute_output
  878. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
  879. assert_success
  880. refute_output
  881. echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  882. validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
  883. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  884. }
  885. @test "Docroot: Other domain root folder" {
  886. docroot1_domain="docroot1.${domain}"
  887. docroot2_domain="docroot2.${domain}"
  888. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
  889. assert_success
  890. refute_output
  891. echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  892. validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
  893. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  894. }
  895. @test "Docroot: Reset" {
  896. docroot1_domain="docroot1.${domain}"
  897. run v-change-web-domain-docroot $user "$docroot1_domain" "default"
  898. assert_success
  899. refute_output
  900. echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  901. validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
  902. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  903. }
  904. @test "Docroot: Cleanup" {
  905. docroot1_domain="docroot1.${domain}"
  906. docroot2_domain="docroot2.${domain}"
  907. run v-delete-web-domain $user $docroot1_domain
  908. assert_success
  909. refute_output
  910. run v-delete-web-domain $user $docroot2_domain
  911. assert_success
  912. refute_output
  913. }
  914. #----------------------------------------------------------#
  915. # DNS #
  916. #----------------------------------------------------------#
  917. @test "DNS: Add domain" {
  918. run v-add-dns-domain $user $domain 198.18.0.125
  919. assert_success
  920. refute_output
  921. }
  922. @test "DNS: Add domain (duplicate)" {
  923. run v-add-dns-domain $user $domain 198.18.0.125
  924. assert_failure $E_EXISTS
  925. }
  926. @test "DNS: Add domain record" {
  927. run v-add-dns-record $user $domain test A 198.18.0.125 20
  928. assert_success
  929. refute_output
  930. }
  931. @test "DNS: Add domain record *.domain.com" {
  932. run v-add-dns-record $user $domain '*' A 198.18.0.125 '' 30
  933. assert_success
  934. refute_output
  935. }
  936. @test "DNS: Change DNS record" {
  937. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  938. assert_success
  939. refute_output
  940. }
  941. @test "DNS: Change DNS record (no update)" {
  942. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  943. assert_failure $E_EXSIST
  944. }
  945. @test "DNS: Change DNS record id" {
  946. run v-change-dns-record-id $user $domain 20 21
  947. assert_success
  948. refute_output
  949. # Change back
  950. run v-change-dns-record-id $user $domain 21 20
  951. }
  952. @test "DNS: Change DNS record id (no update)" {
  953. run v-change-dns-record-id $user $domain 20 20
  954. assert_failure $E_EXSIST
  955. }
  956. @test "DNS: Delete domain record" {
  957. run v-delete-dns-record $user $domain 20
  958. assert_success
  959. refute_output
  960. }
  961. @test "DNS: Delete missing domain record" {
  962. run v-delete-dns-record $user $domain 20
  963. assert_failure $E_NOTEXIST
  964. }
  965. @test "DNS: Change domain expire date" {
  966. run v-change-dns-domain-exp $user $domain 2020-01-01
  967. assert_success
  968. refute_output
  969. }
  970. @test "DNS: Add domain record MX" {
  971. run v-add-dns-record $user $domain '@' MX mx.hestiacp.com '' 50
  972. assert_success
  973. refute_output
  974. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  975. run v-change-dns-record $user $domain 50 '@' MX mx.hestia.com
  976. assert_success
  977. refute_output
  978. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  979. run v-delete-dns-record $user $domain 50
  980. assert_success
  981. refute_output
  982. }
  983. @test "DNS: Add domain record NS" {
  984. run v-delete-dns-record $user $domain 50
  985. run v-add-dns-record $user $domain '@' NS mx.hestiacp.com '' 50
  986. assert_success
  987. refute_output
  988. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  989. run v-change-dns-record $user $domain 50 '@' NS mx.hestia.com
  990. assert_success
  991. refute_output
  992. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  993. run v-delete-dns-record $user $domain 50
  994. assert_success
  995. refute_output
  996. }
  997. @test "DNS: Add domain record SRV" {
  998. run v-delete-dns-record $user $domain 50
  999. run v-add-dns-record $user $domain '_test_domain' SRV mx.hestiacp.com '' 50
  1000. assert_success
  1001. refute_output
  1002. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1003. run v-change-dns-record $user $domain 50 '_test.domain' SRV mx.hestia.com
  1004. assert_success
  1005. refute_output
  1006. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1007. run v-delete-dns-record $user $domain 50
  1008. assert_success
  1009. refute_output
  1010. }
  1011. @test "DNS: Add domain record CNAME" {
  1012. run v-delete-dns-record $user $domain 50
  1013. run v-add-dns-record $user $domain 'mail' CNAME mx.hestiacp.com '' 50
  1014. assert_success
  1015. refute_output
  1016. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1017. run v-change-dns-record $user $domain 50 'mail' CNAME mx.hestia.com
  1018. assert_success
  1019. refute_output
  1020. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1021. run v-delete-dns-record $user $domain 50
  1022. assert_success
  1023. refute_output
  1024. }
  1025. @test "DNS: Check txt dns records type1" {
  1026. [ -z "$DNS_SYSTEM" ] && skip
  1027. run v-delete-dns-record $user $domain 50
  1028. record1_in='v=DMARC1; p=quarantine; pct=100'
  1029. record2_in='v=DMARC1; p=quarantine; pct=90'
  1030. record1_out='"v=DMARC1; p=quarantine; pct=100"'
  1031. record2_in='"v=DMARC1; p=quarantine; pct=90"'
  1032. # Test Create
  1033. run v-add-dns-record $user $domain 'test-long-txt' 'TXT' "$record1_in" '' 50
  1034. assert_success
  1035. refute_output
  1036. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record1_out"
  1037. # Test Edit
  1038. run v-change-dns-record $user $domain 50 'test-long-txt' 'TXT' "$record2_in"
  1039. assert_success
  1040. refute_output
  1041. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record2_out"
  1042. # Test Cleanup
  1043. run v-delete-dns-record $user $domain 50
  1044. assert_success
  1045. refute_output
  1046. }
  1047. @test "DNS: Check txt dns records type2" {
  1048. [ -z "$DNS_SYSTEM" ] && skip
  1049. run v-delete-dns-record $user $domain 50
  1050. record3_in='k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4gVrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQAB'
  1051. record3_out='"k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4g""VrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQAB"'
  1052. record4_in='k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4gVrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQA4'
  1053. record4_out='"k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4g""VrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQA4"'
  1054. # Test Create
  1055. run v-add-dns-record $user $domain 'test-long-txt' 'TXT' "$record3_in" '' 50
  1056. assert_success
  1057. refute_output
  1058. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record3_out"
  1059. # Test Edit
  1060. run v-change-dns-record $user $domain 50 'test-long-txt' 'TXT' "$record4_in"
  1061. assert_success
  1062. refute_output
  1063. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record4_out"
  1064. # Test Cleanup
  1065. run v-delete-dns-record $user $domain 50
  1066. assert_success
  1067. refute_output
  1068. }
  1069. @test "DNS: Change domain ip" {
  1070. run v-change-dns-domain-ip $user $domain 127.0.0.1
  1071. assert_success
  1072. refute_output
  1073. }
  1074. @test "DNS: Suspend domain" {
  1075. run v-suspend-dns-domain $user $domain
  1076. assert_success
  1077. refute_output
  1078. }
  1079. @test "DNS: Unsuspend domain" {
  1080. run v-unsuspend-dns-domain $user $domain
  1081. assert_success
  1082. refute_output
  1083. }
  1084. @test "DNS: Rebuild" {
  1085. run v-rebuild-dns-domains $user
  1086. assert_success
  1087. refute_output
  1088. }
  1089. #----------------------------------------------------------#
  1090. # MAIL #
  1091. #----------------------------------------------------------#
  1092. @test "MAIL: Add domain" {
  1093. run v-add-mail-domain $user $domain
  1094. assert_success
  1095. refute_output
  1096. validate_mail_domain $user $domain
  1097. }
  1098. @test "MAIL: Add mail domain webmail client (Roundcube)" {
  1099. run v-add-mail-domain-webmail $user $domain "roundcube" "yes"
  1100. assert_success
  1101. refute_output
  1102. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  1103. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  1104. # rm /var/lib/roundcube/check_server.php
  1105. }
  1106. @test "Mail: Add SSL to mail domain" {
  1107. # Use generated certificates during WEB Generate Self signed certificate
  1108. run v-add-mail-domain-ssl $user $domain /tmp
  1109. assert_success
  1110. refute_output
  1111. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  1112. }
  1113. @test "MAIL: Add mail domain webmail client (Rainloop)" {
  1114. if [ -z "$(echo $WEBMAIL_SYSTEM | grep -w "rainloop")" ]; then
  1115. skip "Webmail client Rainloop not installed"
  1116. fi
  1117. run v-add-mail-domain-webmail $user $domain "rainloop" "yes"
  1118. assert_success
  1119. refute_output
  1120. validate_mail_domain $user $domain
  1121. validate_webmail_domain $user $domain 'RainLoop Webmail'
  1122. }
  1123. @test "MAIL: Disable webmail client" {
  1124. run v-add-mail-domain-webmail $user $domain "disabled" "yes"
  1125. assert_success
  1126. refute_output
  1127. validate_mail_domain $user $domain
  1128. validate_webmail_domain $user $domain 'Success!'
  1129. }
  1130. @test "MAIL: Add domain (duplicate)" {
  1131. run v-add-mail-domain $user $domain
  1132. assert_failure $E_EXISTS
  1133. }
  1134. @test "MAIL: Add account" {
  1135. run v-add-mail-account $user $domain test "$userpass2"
  1136. assert_success
  1137. refute_output
  1138. }
  1139. @test "MAIL: Add account (duplicate)" {
  1140. run v-add-mail-account $user $domain test "$userpass2"
  1141. assert_failure $E_EXISTS
  1142. }
  1143. @test "MAIL: Delete account" {
  1144. run v-delete-mail-account $user $domain test
  1145. assert_success
  1146. refute_output
  1147. }
  1148. @test "MAIL: Delete missing account" {
  1149. run v-delete-mail-account $user $domain test
  1150. assert_failure $E_NOTEXIST
  1151. }
  1152. @test "MAIL: Rebuild mail domain" {
  1153. run v-rebuild-mail-domains $user
  1154. assert_success
  1155. refute_output
  1156. }
  1157. #----------------------------------------------------------#
  1158. # Limit possibilities adding different owner domain #
  1159. #----------------------------------------------------------#
  1160. @test "Allow Users: User can't add user.user2.com " {
  1161. # Case: admin company.ltd
  1162. # users should not be allowed to add user.company.ltd
  1163. run v-add-user $user2 $user2 $user@hestiacp.com default "Super Test"
  1164. assert_success
  1165. refute_output
  1166. run v-add-web-domain $user2 $rootdomain
  1167. assert_success
  1168. refute_output
  1169. run v-add-web-domain $user $subdomain
  1170. assert_failure $E_EXISTS
  1171. }
  1172. @test "Allow Users: User can't add user.user2.com as alias" {
  1173. run v-add-web-domain-alias $user $domain $subdomain
  1174. assert_failure $E_EXISTS
  1175. }
  1176. @test "Allow Users: User can't add user.user2.com as mail domain" {
  1177. run v-add-mail-domain $user $subdomain
  1178. assert_failure $E_EXISTS
  1179. }
  1180. @test "Allow Users: User can't add user.user2.com as dns domain" {
  1181. run v-add-dns-domain $user $subdomain 198.18.0.125
  1182. assert_failure $E_EXISTS
  1183. }
  1184. @test "Allow Users: Set Allow users" {
  1185. # Allow user to yes allows
  1186. # Case: admin company.ltd
  1187. # users are allowed to add user.company.ltd
  1188. run v-add-web-domain-allow-users $user2 $rootdomain
  1189. assert_success
  1190. refute_output
  1191. }
  1192. @test "Allow Users: User can add user.user2.com" {
  1193. run v-add-web-domain $user $subdomain
  1194. assert_success
  1195. refute_output
  1196. }
  1197. @test "Allow Users: User can add user.user2.com as alias" {
  1198. run v-delete-web-domain $user $subdomain
  1199. assert_success
  1200. refute_output
  1201. run v-add-web-domain-alias $user $domain $subdomain
  1202. assert_success
  1203. refute_output
  1204. }
  1205. @test "Allow Users: User can add user.user2.com as mail domain" {
  1206. run v-add-mail-domain $user $subdomain
  1207. assert_success
  1208. refute_output
  1209. }
  1210. @test "Allow Users: User can add user.user2.com as dns domain" {
  1211. run v-add-dns-domain $user $subdomain 198.18.0.125
  1212. assert_success
  1213. refute_output
  1214. }
  1215. @test "Allow Users: Cleanup tests" {
  1216. run v-delete-dns-domain $user $subdomain
  1217. assert_success
  1218. refute_output
  1219. run v-delete-mail-domain $user $subdomain
  1220. assert_success
  1221. refute_output
  1222. }
  1223. @test "Allow Users: Set Allow users no" {
  1224. run v-delete-web-domain-alias $user $domain $subdomain
  1225. assert_success
  1226. refute_output
  1227. run v-delete-web-domain-allow-users $user2 $rootdomain
  1228. assert_success
  1229. refute_output
  1230. }
  1231. @test "Allow Users: User can't add user.user2.com again" {
  1232. run v-add-web-domain $user $subdomain
  1233. assert_failure $E_EXISTS
  1234. }
  1235. @test "Allow Users: user2 can add user.user2.com again" {
  1236. run v-add-web-domain $user2 $subdomain
  1237. assert_success
  1238. refute_output
  1239. }
  1240. @test "Allow Users: Delete user2" {
  1241. run v-delete-user $user2
  1242. assert_success
  1243. refute_output
  1244. }
  1245. #----------------------------------------------------------#
  1246. # DB #
  1247. #----------------------------------------------------------#
  1248. @test "MYSQL: Add database" {
  1249. run v-add-database $user database dbuser 1234 mysql
  1250. assert_success
  1251. refute_output
  1252. # validate_database mysql database_name database_user password
  1253. validate_database mysql $database $dbuser 1234
  1254. }
  1255. @test "MYSQL: Add Database (Duplicate)" {
  1256. run v-add-database $user database dbuser 1234 mysql
  1257. assert_failure $E_EXISTS
  1258. }
  1259. @test "MYSQL: Rebuild Database" {
  1260. run v-rebuild-database $user $database
  1261. assert_success
  1262. refute_output
  1263. }
  1264. @test "MYSQL: Change database user password" {
  1265. run v-change-database-password $user $database 123456
  1266. assert_success
  1267. refute_output
  1268. validate_database mysql $database $dbuser 123456
  1269. }
  1270. @test "MYSQL: Change database user" {
  1271. run v-change-database-user $user $database database
  1272. assert_success
  1273. refute_output
  1274. validate_database mysql $database $database 123456
  1275. }
  1276. @test "MYSQL: Suspend database" {
  1277. run v-suspend-database $user $database
  1278. assert_success
  1279. refute_output
  1280. }
  1281. @test "MYSQL: Unsuspend database" {
  1282. run v-unsuspend-database $user $database
  1283. assert_success
  1284. refute_output
  1285. }
  1286. @test "MYSQL: Delete database" {
  1287. run v-delete-database $user $database
  1288. assert_success
  1289. refute_output
  1290. }
  1291. @test "MYSQL: Delete missing database" {
  1292. run v-delete-database $user $database
  1293. assert_failure $E_NOTEXIST
  1294. }
  1295. @test "PGSQL: Add database invalid user" {
  1296. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1297. skip "PostGreSQL is not installed"
  1298. fi
  1299. run v-add-database "$user" "database" "dbuser" "1234ABCD" "pgsql"
  1300. assert_failure $E_INVALID
  1301. }
  1302. @test "PGSQL: Add database" {
  1303. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1304. skip "PostGreSQL is not installed"
  1305. fi
  1306. run v-add-user $pguser $pguser $user@hestiacp.com default "Super Test"
  1307. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1308. assert_success
  1309. refute_output
  1310. validate_database pgsql $pgdatabase $pgdbuser "1234ABCD"
  1311. }
  1312. @test "PGSQL: Add Database (Duplicate)" {
  1313. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1314. skip "PostGreSQL is not installed"
  1315. fi
  1316. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1317. assert_failure $E_EXISTS
  1318. }
  1319. @test "PGSQL: Rebuild Database" {
  1320. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1321. skip "PostGreSQL is not installed"
  1322. fi
  1323. run v-rebuild-database $pguser $pgdatabase
  1324. assert_success
  1325. refute_output
  1326. }
  1327. @test "PGSQL: Change database user password" {
  1328. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1329. skip "PostGreSQL is not installed"
  1330. fi
  1331. run v-change-database-password $pguser $pgdatabase "123456"
  1332. assert_success
  1333. refute_output
  1334. validate_database pgsql $pgdatabase $pgdbuser "123456"
  1335. }
  1336. @test "PGSQL: Suspend database" {
  1337. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1338. skip "PostGreSQL is not installed"
  1339. fi
  1340. run v-suspend-database $pguser $pgdatabase
  1341. assert_success
  1342. refute_output
  1343. }
  1344. @test "PGSQL: Unsuspend database" {
  1345. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1346. skip "PostGreSQL is not installed"
  1347. fi
  1348. run v-unsuspend-database $pguser $pgdatabase
  1349. assert_success
  1350. refute_output
  1351. }
  1352. @test "PGSQL: Change database user" {
  1353. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1354. skip "PostGreSQL is not installed"
  1355. fi
  1356. skip
  1357. run v-change-database-user $pguser $pgdatabase database
  1358. assert_success
  1359. refute_output
  1360. validate_database pgsql $pgdatabase $pgdatabase 123456
  1361. }
  1362. @test "PGSQL: Delete database" {
  1363. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1364. skip "PostGreSQL is not installed"
  1365. fi
  1366. run v-delete-database $pguser $pgdatabase
  1367. assert_success
  1368. refute_output
  1369. }
  1370. @test "PGSQL: Delete missing database" {
  1371. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1372. skip "PostGreSQL is not installed"
  1373. fi
  1374. run v-delete-database $pguser $pgdatabase
  1375. assert_failure $E_NOTEXIST
  1376. run v-delete-user $pguser
  1377. }
  1378. #----------------------------------------------------------#
  1379. # System #
  1380. #----------------------------------------------------------#
  1381. @test "System: Set/Enable SMTP account for internal mail" {
  1382. run v-add-sys-smtp $domain 587 STARTTLS info@$domain 1234-test noreply@$domain
  1383. assert_success
  1384. refute_output
  1385. }
  1386. @test "System: Disable SMTP account for internal mail" {
  1387. run v-delete-sys-smtp
  1388. assert_success
  1389. refute_output
  1390. }
  1391. @test "System: Set/Enable SMTP relay" {
  1392. run v-add-sys-smtp-relay $domain info@$domain 1234-test 587
  1393. assert_success
  1394. refute_output
  1395. assert_file_exist /etc/exim4/smtp_relay.conf
  1396. }
  1397. @test "System: Delete SMTP relay" {
  1398. run v-delete-sys-smtp-relay
  1399. assert_success
  1400. refute_output
  1401. assert_file_not_exist /etc/exim4/smtp_relay.conf
  1402. }
  1403. #----------------------------------------------------------#
  1404. # Firewall #
  1405. #----------------------------------------------------------#
  1406. @test "Firewall: Add ip to banlist" {
  1407. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1408. assert_success
  1409. refute_output
  1410. check_ip_banned '1.2.3.4' 'HESTIA'
  1411. }
  1412. @test "Firewall: Delete ip to banlist" {
  1413. run v-delete-firewall-ban '1.2.3.4' 'HESTIA'
  1414. assert_success
  1415. refute_output
  1416. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1417. }
  1418. @test "Firewall: Add ip to banlist for ALL" {
  1419. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1420. assert_success
  1421. refute_output
  1422. run v-add-firewall-ban '1.2.3.4' 'MAIL'
  1423. assert_success
  1424. refute_output
  1425. check_ip_banned '1.2.3.4' 'HESTIA'
  1426. }
  1427. @test "Firewall: Delete ip to banlist CHAIN = ALL" {
  1428. run v-delete-firewall-ban '1.2.3.4' 'ALL'
  1429. assert_success
  1430. refute_output
  1431. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1432. }
  1433. @test "Test Whitelist Fail2ban" {
  1434. echo "1.2.3.4" >> $HESTIA/data/firewall/excludes.conf
  1435. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1436. rm $HESTIA/data/firewall/excludes.conf
  1437. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1438. }
  1439. @test "Test create ipset" {
  1440. run v-add-firewall-ipset "blacklist" "script:/usr/local/hestia/install/deb/firewall/ipset/blacklist.sh" v4 yes
  1441. assert_success
  1442. refute_output
  1443. }
  1444. @test "Create firewall with Ipset" {
  1445. run v-add-firewall-rule 'DROP' 'ipset:blacklist' '8083,22' 'TCP' 'Test'
  1446. assert_success
  1447. refute_output
  1448. }
  1449. @test "List firewall rules" {
  1450. run v-list-firewall csv
  1451. assert_success
  1452. assert_line --partial '11,DROP,TCP,8083,22,ipset:blacklist'
  1453. }
  1454. @test "Delete firewall with Ipset" {
  1455. run v-delete-firewall-rule '11'
  1456. assert_success
  1457. refute_output
  1458. }
  1459. @test "Test delete ipset" {
  1460. run v-delete-firewall-ipset "blacklist"
  1461. assert_success
  1462. refute_output
  1463. }
  1464. #----------------------------------------------------------#
  1465. # PACKAGE #
  1466. #----------------------------------------------------------#
  1467. @test "Package: Create new Package" {
  1468. cp $HESTIA/data/packages/default.pkg /tmp/package
  1469. run v-add-user-package /tmp/package hestiatest
  1470. assert_success
  1471. refute_output
  1472. }
  1473. @test "Package: Assign user to new Package" {
  1474. run v-change-user-package $user hestiatest
  1475. assert_success
  1476. refute_output
  1477. }
  1478. @test "Package: Create new package (Duplicate)" {
  1479. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1480. run v-add-user-package /tmp/package hestiatest
  1481. assert_failure $E_EXISTS
  1482. }
  1483. @test "Package: Update new Package" {
  1484. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1485. run v-add-user-package /tmp/package hestiatest yes
  1486. assert_success
  1487. refute_output
  1488. }
  1489. @test "Package: Update package of user" {
  1490. run v-change-user-package $user hestiatest
  1491. assert_success
  1492. refute_output
  1493. run grep "BANDWIDTH='100'" $HESTIA/data/users/$user/user.conf
  1494. assert_success
  1495. assert_output --partial "100"
  1496. }
  1497. @test "Package: Copy package Not Exists" {
  1498. run v-copy-user-package hestiadoesnotexists hestiatest2
  1499. assert_failure $E_NOTEXIST
  1500. }
  1501. @test "Package: Copy package" {
  1502. run v-copy-user-package hestiatest hestiatest2
  1503. assert_success
  1504. refute_output
  1505. }
  1506. @test "Package: Copy package Exists" {
  1507. run v-copy-user-package hestiatest hestiatest2
  1508. assert_failure $E_EXISTS
  1509. }
  1510. @test "Package: Delete package" {
  1511. run v-delete-user-package hestiatest
  1512. run v-delete-user-package hestiatest2
  1513. rm /tmp/package
  1514. assert_success
  1515. refute_output
  1516. run grep "BANDWIDTH='unlimited'" $HESTIA/data/users/$user/user.conf
  1517. assert_success
  1518. assert_output --partial "unlimited"
  1519. }
  1520. #----------------------------------------------------------#
  1521. # Backup user #
  1522. #----------------------------------------------------------#
  1523. @test "Backup user" {
  1524. run v-backup-user $user
  1525. assert_success
  1526. }
  1527. @test "List Backups" {
  1528. run v-list-user-backups $user plain
  1529. assert_success
  1530. assert_output --partial "$user"
  1531. }
  1532. @test "Delete backups" {
  1533. run v-delete-user-backup $user $(v-list-user-backups $user plain | cut -f1)
  1534. assert_success
  1535. run rm /backup/$user.log
  1536. }
  1537. #----------------------------------------------------------#
  1538. # CLEANUP #
  1539. #----------------------------------------------------------#
  1540. @test "Mail: Delete domain" {
  1541. run v-delete-mail-domain $user $domain
  1542. assert_success
  1543. refute_output
  1544. }
  1545. @test "DNS: Delete domain" {
  1546. run v-delete-dns-domain $user $domain
  1547. assert_success
  1548. refute_output
  1549. }
  1550. @test "WEB: Delete domain" {
  1551. run v-delete-web-domain $user $domain
  1552. assert_success
  1553. refute_output
  1554. }
  1555. @test "Delete user" {
  1556. run v-delete-user $user
  1557. assert_success
  1558. refute_output
  1559. }
  1560. @test "Ip: Delete the test IP" {
  1561. run v-delete-sys-ip 198.18.0.125
  1562. assert_success
  1563. refute_output
  1564. }
  1565. @test 'assert()' {
  1566. touch '/var/log/test.log'
  1567. assert [ -e '/var/log/test.log' ]
  1568. }