test.bats 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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 "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 "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 "Change user password" {
  259. run v-change-user-password "$user" t3st-p4ssw0rd
  260. assert_success
  261. refute_output
  262. }
  263. @test "Change user email" {
  264. run v-change-user-contact "$user" tester@hestiacp.com
  265. assert_success
  266. refute_output
  267. }
  268. @test "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 "Change user name" {
  274. run v-change-user-name "$user" "New name"
  275. assert_success
  276. refute_output
  277. }
  278. @test "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 "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 "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 "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 "Change user language" {
  306. run v-change-user-language $user "nl"
  307. assert_success
  308. refute_output
  309. }
  310. @test "Change user language (Does not exists)" {
  311. run v-change-user-language $user "aa"
  312. assert_failure $E_NOTEXIST
  313. }
  314. @test "Change user sort order" {
  315. run v-change-user-sort-order $user "name"
  316. assert_success
  317. refute_output
  318. }
  319. @test "Change user theme" {
  320. run v-change-user-theme $user "flat"
  321. assert_success
  322. refute_output
  323. }
  324. @test "Change user theme (Does not exists)" {
  325. run v-change-user-theme $user "aa"
  326. assert_failure $E_NOTEXIST
  327. }
  328. @test "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 "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 "Add user notification" {
  338. run v-add-user-notification $user "Test message" "Message"
  339. assert_success
  340. refute_output
  341. }
  342. @test "Acknowledge user notification" {
  343. run v-acknowledge-user-notification $user 1
  344. assert_success
  345. refute_output
  346. }
  347. @test "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 "Delete user notification" {
  353. run v-delete-user-notification admin 1
  354. assert_success
  355. refute_output
  356. }
  357. #----------------------------------------------------------#
  358. # Cron #
  359. #----------------------------------------------------------#
  360. @test "Cron: Add cron job" {
  361. run v-add-cron-job $user 1 1 1 1 1 echo
  362. assert_success
  363. refute_output
  364. }
  365. @test "Cron: Suspend cron job" {
  366. run v-suspend-cron-job $user 1
  367. assert_success
  368. refute_output
  369. }
  370. @test "Cron: Unsuspend cron job" {
  371. run v-unsuspend-cron-job $user 1
  372. assert_success
  373. refute_output
  374. }
  375. @test "Cron: Delete cron job" {
  376. run v-delete-cron-job $user 1
  377. assert_success
  378. refute_output
  379. }
  380. @test "Cron: Add cron job (duplicate)" {
  381. run v-add-cron-job $user 1 1 1 1 1 echo 1
  382. assert_success
  383. refute_output
  384. run v-add-cron-job $user 1 1 1 1 1 echo 1
  385. assert_failure $E_EXISTS
  386. assert_output --partial 'JOB=1 already exists'
  387. }
  388. @test "Cron: Second cron job" {
  389. run v-add-cron-job $user 2 2 2 2 2 echo 2
  390. assert_success
  391. refute_output
  392. }
  393. @test "Cron: Two cron jobs must be listed" {
  394. run v-list-cron-jobs $user csv
  395. assert_success
  396. assert_line --partial '1,1,1,1,1,"echo",no'
  397. assert_line --partial '2,2,2,2,2,"echo",no'
  398. }
  399. @test "Cron: rebuild" {
  400. run v-rebuild-cron-jobs $user
  401. assert_success
  402. refute_output
  403. }
  404. #----------------------------------------------------------#
  405. # IP #
  406. #----------------------------------------------------------#
  407. @test "Ip: Add new ip on first interface" {
  408. interface=$(v-list-sys-interfaces plain | head -n 1)
  409. run ip link show dev $interface
  410. assert_success
  411. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  412. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  413. # Save initial state
  414. echo "interface=${interface}" >> /tmp/hestia-test-env.sh
  415. [ -f "$a2_rpaf" ] && file_hash1=$(cat $a2_rpaf |md5sum |cut -d" " -f1) && echo "a2_rpaf_hash='${file_hash1}'" >> /tmp/hestia-test-env.sh
  416. [ -f "$a2_remoteip" ] && file_hash2=$(cat $a2_remoteip |md5sum |cut -d" " -f1) && echo "a2_remoteip_hash='${file_hash2}'" >> /tmp/hestia-test-env.sh
  417. local ip="198.18.0.12"
  418. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  419. assert_success
  420. refute_output
  421. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  422. assert_file_exist $HESTIA/data/ips/$ip
  423. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  424. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  425. if [ -n "$PROXY_SYSTEM" ]; then
  426. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  427. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  428. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  429. fi
  430. }
  431. @test "Ip: Add ip (duplicate)" {
  432. run v-add-sys-ip 198.18.0.12 255.255.255.255 $interface $user
  433. assert_failure $E_EXISTS
  434. }
  435. @test "Ip: Add extra ip" {
  436. local ip="198.18.0.121"
  437. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  438. assert_success
  439. refute_output
  440. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  441. assert_file_exist $HESTIA/data/ips/$ip
  442. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  443. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  444. if [ -n "$PROXY_SYSTEM" ]; then
  445. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  446. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  447. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  448. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  449. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  450. fi
  451. }
  452. @test "Ip: Delete ips" {
  453. local ip="198.18.0.12"
  454. run v-delete-sys-ip $ip
  455. assert_success
  456. refute_output
  457. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  458. assert_file_not_exist $HESTIA/data/ips/$ip
  459. ip="198.18.0.121"
  460. run v-delete-sys-ip $ip
  461. assert_success
  462. refute_output
  463. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  464. assert_file_not_exist $HESTIA/data/ips/$ip
  465. if [ -n "$PROXY_SYSTEM" ]; then
  466. assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  467. fi
  468. # remoteip and rpaf config hashes must match the initial one
  469. if [ ! -z "$a2_rpaf_hash" ]; then
  470. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  471. file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
  472. assert_equal "$file_hash" "$a2_rpaf_hash"
  473. fi
  474. if [ ! -z "$a2_remoteip_hash" ]; then
  475. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  476. file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
  477. assert_equal "$file_hash" "$a2_remoteip_hash"
  478. fi
  479. }
  480. @test "Ip: Add IP for rest of the test" {
  481. local ip="198.18.0.125"
  482. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  483. assert_success
  484. refute_output
  485. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  486. assert_file_exist $HESTIA/data/ips/$ip
  487. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  488. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  489. if [ -n "$PROXY_SYSTEM" ]; then
  490. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  491. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  492. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  493. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  494. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  495. fi
  496. }
  497. #----------------------------------------------------------#
  498. # WEB #
  499. #----------------------------------------------------------#
  500. @test "WEB: Add web domain" {
  501. run v-add-web-domain $user $domain 198.18.0.125
  502. assert_success
  503. refute_output
  504. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  505. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  506. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  507. }
  508. @test "WEB: Add web domain (duplicate)" {
  509. run v-add-web-domain $user $domain 198.18.0.125
  510. assert_failure $E_EXISTS
  511. }
  512. @test "WEB: Add web domain alias" {
  513. run v-add-web-domain-alias $user $domain v3.$domain
  514. assert_success
  515. refute_output
  516. }
  517. @test "WEB: Add web domain alias (duplicate)" {
  518. run v-add-web-domain-alias $user $domain v3.$domain
  519. assert_failure $E_EXISTS
  520. }
  521. @test "WEB: Add web domain wildcard alias" {
  522. run v-add-web-domain-alias $user $domain "*.$domain"
  523. assert_success
  524. refute_output
  525. }
  526. @test "WEB: Delete web domain wildcard alias" {
  527. run v-delete-web-domain-alias $user $domain "*.$domain"
  528. assert_success
  529. refute_output
  530. }
  531. @test "WEB: Add web domain stats" {
  532. run v-add-web-domain-stats $user $domain awstats
  533. assert_success
  534. refute_output
  535. }
  536. @test "WEB: Add web domain stats user" {
  537. skip
  538. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  539. assert_success
  540. refute_output
  541. }
  542. @test "WEB: Suspend web domain" {
  543. run v-suspend-web-domain $user $domain
  544. assert_success
  545. refute_output
  546. validate_web_domain $user $domain 'This site is currently suspended'
  547. }
  548. @test "WEB: Unsuspend web domain" {
  549. run v-unsuspend-web-domain $user $domain
  550. assert_success
  551. refute_output
  552. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  553. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  554. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  555. }
  556. @test "WEB: Add redirect to www.domain.com" {
  557. run v-add-web-domain-redirect $user $domain www.$domain 301
  558. assert_success
  559. refute_output
  560. run validate_headers_domain $user $domain "301"
  561. }
  562. @test "WEB: Delete redirect to www.domain.com" {
  563. run v-delete-web-domain-redirect $user $domain
  564. assert_success
  565. refute_output
  566. }
  567. @test "WEB: Enable Fast CGI Cache" {
  568. if [ "$WEB_SYSTEM" != "nginx" ]; then
  569. skip "FastCGI cache is not supported"
  570. fi
  571. run v-add-fastcgi-cache $user $domain '1m' yes
  572. assert_success
  573. refute_output
  574. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  575. run validate_headers_domain $user $domain "Miss"
  576. run validate_headers_domain $user $domain "Hit"
  577. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  578. }
  579. @test "WEB: Disable Fast CGI Cache" {
  580. if [ "$WEB_SYSTEM" != "nginx" ]; then
  581. skip "FastCGI cache is not supported"
  582. fi
  583. run v-delete-fastcgi-cache $user $domain '1m' yes
  584. assert_success
  585. refute_output
  586. }
  587. @test "WEB: Generate Self signed certificate" {
  588. ssl=$(v-generate-ssl-cert "$domain" "info@$domain" US CA "Orange County" HestiaCP IT "mail.$domain" | tail -n1 | awk '{print $2}')
  589. echo $ssl;
  590. mv $ssl/$domain.crt /tmp/$domain.crt
  591. mv $ssl/$domain.key /tmp/$domain.key
  592. }
  593. @test "WEB: Add ssl" {
  594. # Use self signed certificates during last test
  595. run v-add-web-domain-ssl $user $domain /tmp
  596. assert_success
  597. refute_output
  598. }
  599. @test "WEB: Rebuild web domain" {
  600. run v-rebuild-web-domains $user
  601. assert_success
  602. refute_output
  603. }
  604. #----------------------------------------------------------#
  605. # IDN #
  606. #----------------------------------------------------------#
  607. @test "WEB: Add IDN domain UTF idn-tést.eu" {
  608. run v-add-web-domain $user idn-tést.eu 198.18.0.125
  609. assert_success
  610. refute_output
  611. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  612. validate_web_domain $user idn-tést.eu 'Hestia Test:12' 'php-test.php'
  613. rm $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  614. }
  615. @test "WEB: Add IDN domain ASCII idn-tést.eu" {
  616. # Expected to fail due to utf exists
  617. run v-add-web-domain $user $( idn -a idn-tést.eu) 198.18.0.125
  618. assert_failure $E_EXISTS
  619. }
  620. @test "WEB: Generate Self signed certificate ASCII idn-tést.eu" {
  621. 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"
  622. assert_success
  623. }
  624. @test "WEB: Delete IDN domain idn-tést.eu" {
  625. run v-delete-web-domain $user idn-tést.eu
  626. assert_success
  627. refute_output
  628. }
  629. @test "WEB: Add IDN domain UTF bløst.рф" {
  630. run v-add-web-domain $user bløst.рф 198.18.0.125
  631. assert_success
  632. refute_output
  633. }
  634. @test "WEB: Generate Self signed certificate ASCII bløst.рф" {
  635. 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"
  636. assert_success
  637. }
  638. @test "WEB: Delete IDN domain bløst.рф" {
  639. run v-delete-web-domain $user bløst.рф
  640. assert_success
  641. refute_output
  642. }
  643. #----------------------------------------------------------#
  644. # MULTIPHP #
  645. #----------------------------------------------------------#
  646. @test "Multiphp: Default php Backend version" {
  647. def_phpver=$(multiphp_default_version)
  648. multi_domain="multiphp.${domain}"
  649. run v-add-web-domain $user $multi_domain 198.18.0.125
  650. assert_success
  651. refute_output
  652. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  653. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  654. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  655. }
  656. @test "Multiphp: Change backend version - PHP v5.6" {
  657. test_phpver='5.6'
  658. multi_domain="multiphp.${domain}"
  659. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  660. skip "PHP ${test_phpver} not installed"
  661. fi
  662. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  663. assert_success
  664. refute_output
  665. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  666. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  667. # A single php-fpm pool config file must be present
  668. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  669. assert_equal "$num_fpm_config_files" '1'
  670. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  671. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  672. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  673. }
  674. @test "Multiphp: Change backend version - PHP v7.0" {
  675. test_phpver='7.0'
  676. multi_domain="multiphp.${domain}"
  677. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  678. skip "PHP ${test_phpver} not installed"
  679. fi
  680. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  681. assert_success
  682. refute_output
  683. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  684. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  685. # A single php-fpm pool config file must be present
  686. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  687. assert_equal "$num_fpm_config_files" '1'
  688. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  689. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  690. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  691. }
  692. @test "Multiphp: Change backend version - PHP v7.1" {
  693. test_phpver='7.1'
  694. multi_domain="multiphp.${domain}"
  695. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  696. skip "PHP ${test_phpver} not installed"
  697. fi
  698. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  699. assert_success
  700. refute_output
  701. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  702. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  703. # A single php-fpm pool config file must be present
  704. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  705. assert_equal "$num_fpm_config_files" '1'
  706. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  707. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  708. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  709. }
  710. @test "Multiphp: Change backend version - PHP v7.2" {
  711. test_phpver='7.2'
  712. multi_domain="multiphp.${domain}"
  713. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  714. skip "PHP ${test_phpver} not installed"
  715. fi
  716. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  717. assert_success
  718. refute_output
  719. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  720. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  721. # A single php-fpm pool config file must be present
  722. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  723. assert_equal "$num_fpm_config_files" '1'
  724. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  725. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  726. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  727. }
  728. @test "Multiphp: Change backend version - PHP v7.3" {
  729. test_phpver='7.3'
  730. multi_domain="multiphp.${domain}"
  731. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  732. skip "PHP ${test_phpver} not installed"
  733. fi
  734. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  735. assert_success
  736. refute_output
  737. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  738. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  739. # A single php-fpm pool config file must be present
  740. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  741. assert_equal "$num_fpm_config_files" '1'
  742. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  743. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  744. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  745. }
  746. @test "Multiphp: Change backend version - PHP v7.4" {
  747. test_phpver='7.4'
  748. multi_domain="multiphp.${domain}"
  749. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  750. skip "PHP ${test_phpver} not installed"
  751. fi
  752. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  753. assert_success
  754. refute_output
  755. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  756. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  757. # A single php-fpm pool config file must be present
  758. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  759. assert_equal "$num_fpm_config_files" '1'
  760. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  761. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  762. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  763. }
  764. @test "Multiphp: Change backend version - PHP v8.0" {
  765. test_phpver='8.0'
  766. multi_domain="multiphp.${domain}"
  767. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  768. skip "PHP ${test_phpver} not installed"
  769. fi
  770. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  771. assert_success
  772. refute_output
  773. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  774. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  775. # A single php-fpm pool config file must be present
  776. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  777. assert_equal "$num_fpm_config_files" '1'
  778. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  779. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  780. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  781. }
  782. @test "Multiphp: Change backend version - PHP v8.1" {
  783. test_phpver='8.1'
  784. multi_domain="multiphp.${domain}"
  785. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  786. skip "PHP ${test_phpver} not installed"
  787. fi
  788. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_1' 'yes'
  789. assert_success
  790. refute_output
  791. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  792. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  793. # A single php-fpm pool config file must be present
  794. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  795. assert_equal "$num_fpm_config_files" '1'
  796. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  797. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  798. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  799. }
  800. @test "Multiphp: Cleanup" {
  801. multi_domain="multiphp.${domain}"
  802. run v-delete-web-domain $user $multi_domain 'yes'
  803. assert_success
  804. refute_output
  805. # No php-fpm pool config file must be present
  806. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  807. assert_equal "$num_fpm_config_files" '0'
  808. }
  809. #----------------------------------------------------------#
  810. # CUSTOM DOCROOT #
  811. #----------------------------------------------------------#
  812. @test "Docroot: Self Subfolder" {
  813. docroot1_domain="docroot1.${domain}"
  814. run v-add-web-domain $user $docroot1_domain 198.18.0.125
  815. assert_success
  816. refute_output
  817. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
  818. assert_success
  819. refute_output
  820. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
  821. assert_success
  822. refute_output
  823. echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  824. validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
  825. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  826. }
  827. @test "Docroot: Other domain subfolder" {
  828. docroot1_domain="docroot1.${domain}"
  829. docroot2_domain="docroot2.${domain}"
  830. run v-add-web-domain $user $docroot2_domain 198.18.0.125
  831. assert_success
  832. refute_output
  833. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
  834. assert_success
  835. refute_output
  836. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
  837. assert_success
  838. refute_output
  839. echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  840. validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
  841. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  842. }
  843. @test "Docroot: Other domain root folder" {
  844. docroot1_domain="docroot1.${domain}"
  845. docroot2_domain="docroot2.${domain}"
  846. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
  847. assert_success
  848. refute_output
  849. echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  850. validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
  851. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  852. }
  853. @test "Docroot: Reset" {
  854. docroot1_domain="docroot1.${domain}"
  855. run v-change-web-domain-docroot $user "$docroot1_domain" "default"
  856. assert_success
  857. refute_output
  858. echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  859. validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
  860. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  861. }
  862. @test "Docroot: Cleanup" {
  863. docroot1_domain="docroot1.${domain}"
  864. docroot2_domain="docroot2.${domain}"
  865. run v-delete-web-domain $user $docroot1_domain
  866. assert_success
  867. refute_output
  868. run v-delete-web-domain $user $docroot2_domain
  869. assert_success
  870. refute_output
  871. }
  872. #----------------------------------------------------------#
  873. # DNS #
  874. #----------------------------------------------------------#
  875. @test "DNS: Add domain" {
  876. run v-add-dns-domain $user $domain 198.18.0.125
  877. assert_success
  878. refute_output
  879. }
  880. @test "DNS: Add domain (duplicate)" {
  881. run v-add-dns-domain $user $domain 198.18.0.125
  882. assert_failure $E_EXISTS
  883. }
  884. @test "DNS: Add domain record" {
  885. run v-add-dns-record $user $domain test A 198.18.0.125 20
  886. assert_success
  887. refute_output
  888. }
  889. @test "DNS: Change DNS record" {
  890. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  891. assert_success
  892. refute_output
  893. }
  894. @test "DNS: Change DNS record (no update)" {
  895. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  896. assert_failure $E_EXSIST
  897. }
  898. @test "DNS: Change DNS record id" {
  899. run v-change-dns-record-id $user $domain 20 21
  900. assert_success
  901. refute_output
  902. # Change back
  903. run v-change-dns-record-id $user $domain 21 20
  904. }
  905. @test "DNS: Change DNS record id (no update)" {
  906. run v-change-dns-record-id $user $domain 20 20
  907. assert_failure $E_EXSIST
  908. }
  909. @test "DNS: Delete domain record" {
  910. run v-delete-dns-record $user $domain 20
  911. assert_success
  912. refute_output
  913. }
  914. @test "DNS: Delete missing domain record" {
  915. run v-delete-dns-record $user $domain 20
  916. assert_failure $E_NOTEXIST
  917. }
  918. @test "DNS: Change domain expire date" {
  919. run v-change-dns-domain-exp $user $domain 2020-01-01
  920. assert_success
  921. refute_output
  922. }
  923. @test "DNS: Change domain ip" {
  924. run v-change-dns-domain-ip $user $domain 127.0.0.1
  925. assert_success
  926. refute_output
  927. }
  928. @test "DNS: Suspend domain" {
  929. run v-suspend-dns-domain $user $domain
  930. assert_success
  931. refute_output
  932. }
  933. @test "DNS: Unsuspend domain" {
  934. run v-unsuspend-dns-domain $user $domain
  935. assert_success
  936. refute_output
  937. }
  938. @test "DNS: Rebuild" {
  939. run v-rebuild-dns-domains $user
  940. assert_success
  941. refute_output
  942. }
  943. #----------------------------------------------------------#
  944. # MAIL #
  945. #----------------------------------------------------------#
  946. @test "MAIL: Add domain" {
  947. run v-add-mail-domain $user $domain
  948. assert_success
  949. refute_output
  950. validate_mail_domain $user $domain
  951. }
  952. @test "MAIL: Add mail domain webmail client (Roundcube)" {
  953. run v-add-mail-domain-webmail $user $domain "roundcube" "yes"
  954. assert_success
  955. refute_output
  956. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  957. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  958. # rm /var/lib/roundcube/check_server.php
  959. }
  960. @test "Mail: Add SSL to mail domain" {
  961. # Use generated certificates during WEB Generate Self signed certificate
  962. run v-add-mail-domain-ssl $user $domain /tmp
  963. assert_success
  964. refute_output
  965. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  966. }
  967. @test "MAIL: Add mail domain webmail client (Rainloop)" {
  968. if [ -z "$(echo $WEBMAIL_SYSTEM | grep -w "rainloop")" ]; then
  969. skip "Webmail client Rainloop not installed"
  970. fi
  971. run v-add-mail-domain-webmail $user $domain "rainloop" "yes"
  972. assert_success
  973. refute_output
  974. validate_mail_domain $user $domain
  975. validate_webmail_domain $user $domain 'RainLoop Webmail'
  976. }
  977. @test "MAIL: Disable webmail client" {
  978. run v-add-mail-domain-webmail $user $domain "disabled" "yes"
  979. assert_success
  980. refute_output
  981. validate_mail_domain $user $domain
  982. validate_webmail_domain $user $domain 'Success!'
  983. }
  984. @test "MAIL: Add domain (duplicate)" {
  985. run v-add-mail-domain $user $domain
  986. assert_failure $E_EXISTS
  987. }
  988. @test "MAIL: Add account" {
  989. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  990. assert_success
  991. refute_output
  992. }
  993. @test "MAIL: Add account (duplicate)" {
  994. run v-add-mail-account $user $domain test t3st-p4ssw0rd
  995. assert_failure $E_EXISTS
  996. }
  997. @test "MAIL: Delete account" {
  998. run v-delete-mail-account $user $domain test
  999. assert_success
  1000. refute_output
  1001. }
  1002. @test "MAIL: Delete missing account" {
  1003. run v-delete-mail-account $user $domain test
  1004. assert_failure $E_NOTEXIST
  1005. }
  1006. @test "MAIL: Rebuild mail domain" {
  1007. run v-rebuild-mail-domains $user
  1008. assert_success
  1009. refute_output
  1010. }
  1011. #----------------------------------------------------------#
  1012. # Limit possibilities adding different owner domain #
  1013. #----------------------------------------------------------#
  1014. @test "Allow Users: User can't add user.user2.com " {
  1015. # Case: admin company.ltd
  1016. # users should not be allowed to add user.company.ltd
  1017. run v-add-user $user2 $user2 $user@hestiacp.com default "Super Test"
  1018. assert_success
  1019. refute_output
  1020. run v-add-web-domain $user2 $rootdomain
  1021. assert_success
  1022. refute_output
  1023. run v-add-web-domain $user $subdomain
  1024. assert_failure $E_EXISTS
  1025. }
  1026. @test "Allow Users: User can't add user.user2.com as alias" {
  1027. run v-add-web-domain-alias $user $domain $subdomain
  1028. assert_failure $E_EXISTS
  1029. }
  1030. @test "Allow Users: User can't add user.user2.com as mail domain" {
  1031. run v-add-mail-domain $user $subdomain
  1032. assert_failure $E_EXISTS
  1033. }
  1034. @test "Allow Users: User can't add user.user2.com as dns domain" {
  1035. run v-add-dns-domain $user $subdomain 198.18.0.125
  1036. assert_failure $E_EXISTS
  1037. }
  1038. @test "Allow Users: Set Allow users" {
  1039. # Allow user to yes allows
  1040. # Case: admin company.ltd
  1041. # users are allowed to add user.company.ltd
  1042. run v-add-web-domain-allow-users $user2 $rootdomain
  1043. assert_success
  1044. refute_output
  1045. }
  1046. @test "Allow Users: User can add user.user2.com" {
  1047. run v-add-web-domain $user $subdomain
  1048. assert_success
  1049. refute_output
  1050. }
  1051. @test "Allow Users: User can add user.user2.com as alias" {
  1052. run v-delete-web-domain $user $subdomain
  1053. assert_success
  1054. refute_output
  1055. run v-add-web-domain-alias $user $domain $subdomain
  1056. assert_success
  1057. refute_output
  1058. }
  1059. @test "Allow Users: User can add user.user2.com as mail domain" {
  1060. run v-add-mail-domain $user $subdomain
  1061. assert_success
  1062. refute_output
  1063. }
  1064. @test "Allow Users: User can add user.user2.com as dns domain" {
  1065. run v-add-dns-domain $user $subdomain 198.18.0.125
  1066. assert_success
  1067. refute_output
  1068. }
  1069. @test "Allow Users: Cleanup tests" {
  1070. run v-delete-dns-domain $user $subdomain
  1071. assert_success
  1072. refute_output
  1073. run v-delete-mail-domain $user $subdomain
  1074. assert_success
  1075. refute_output
  1076. }
  1077. @test "Allow Users: Set Allow users no" {
  1078. run v-delete-web-domain-alias $user $domain $subdomain
  1079. assert_success
  1080. refute_output
  1081. run v-delete-web-domain-allow-users $user2 $rootdomain
  1082. assert_success
  1083. refute_output
  1084. }
  1085. @test "Allow Users: User can't add user.user2.com again" {
  1086. run v-add-web-domain $user $subdomain
  1087. assert_failure $E_EXISTS
  1088. }
  1089. @test "Allow Users: user2 can add user.user2.com again" {
  1090. run v-add-web-domain $user2 $subdomain
  1091. assert_success
  1092. refute_output
  1093. }
  1094. @test "Allow Users: Delete user2" {
  1095. run v-delete-user $user2
  1096. assert_success
  1097. refute_output
  1098. }
  1099. #----------------------------------------------------------#
  1100. # DB #
  1101. #----------------------------------------------------------#
  1102. @test "MYSQL: Add database" {
  1103. run v-add-database $user database dbuser 1234 mysql
  1104. assert_success
  1105. refute_output
  1106. # validate_database mysql database_name database_user password
  1107. validate_database mysql $database $dbuser 1234
  1108. }
  1109. @test "MYSQL: Add Database (Duplicate)" {
  1110. run v-add-database $user database dbuser 1234 mysql
  1111. assert_failure $E_EXISTS
  1112. }
  1113. @test "MYSQL: Rebuild Database" {
  1114. run v-rebuild-database $user $database
  1115. assert_success
  1116. refute_output
  1117. }
  1118. @test "MYSQL: Change database user password" {
  1119. run v-change-database-password $user $database 123456
  1120. assert_success
  1121. refute_output
  1122. validate_database mysql $database $dbuser 123456
  1123. }
  1124. @test "MYSQL: Change database user" {
  1125. run v-change-database-user $user $database database
  1126. assert_success
  1127. refute_output
  1128. validate_database mysql $database $database 123456
  1129. }
  1130. @test "MYSQL: Suspend database" {
  1131. run v-suspend-database $user $database
  1132. assert_success
  1133. refute_output
  1134. }
  1135. @test "MYSQL: Unsuspend database" {
  1136. run v-unsuspend-database $user $database
  1137. assert_success
  1138. refute_output
  1139. }
  1140. @test "MYSQL: Delete database" {
  1141. run v-delete-database $user $database
  1142. assert_success
  1143. refute_output
  1144. }
  1145. @test "MYSQL: Delete missing database" {
  1146. run v-delete-database $user $database
  1147. assert_failure $E_NOTEXIST
  1148. }
  1149. @test "PGSQL: Add database invalid user" {
  1150. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1151. skip "PostGreSQL is not installed"
  1152. fi
  1153. run v-add-database "$user" "database" "dbuser" "1234ABCD" "pgsql"
  1154. assert_failure $E_INVALID
  1155. }
  1156. @test "PGSQL: Add database" {
  1157. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1158. skip "PostGreSQL is not installed"
  1159. fi
  1160. run v-add-user $pguser $pguser $user@hestiacp.com default "Super Test"
  1161. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1162. assert_success
  1163. refute_output
  1164. validate_database pgsql $pgdatabase $pgdbuser "1234ABCD"
  1165. }
  1166. @test "PGSQL: Add Database (Duplicate)" {
  1167. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1168. skip "PostGreSQL is not installed"
  1169. fi
  1170. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1171. assert_failure $E_EXISTS
  1172. }
  1173. @test "PGSQL: Rebuild Database" {
  1174. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1175. skip "PostGreSQL is not installed"
  1176. fi
  1177. run v-rebuild-database $pguser $pgdatabase
  1178. assert_success
  1179. refute_output
  1180. }
  1181. @test "PGSQL: Change database user password" {
  1182. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1183. skip "PostGreSQL is not installed"
  1184. fi
  1185. run v-change-database-password $pguser $pgdatabase "123456"
  1186. assert_success
  1187. refute_output
  1188. validate_database pgsql $pgdatabase $pgdbuser "123456"
  1189. }
  1190. @test "PGSQL: Suspend database" {
  1191. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1192. skip "PostGreSQL is not installed"
  1193. fi
  1194. run v-suspend-database $pguser $pgdatabase
  1195. assert_success
  1196. refute_output
  1197. }
  1198. @test "PGSQL: Unsuspend database" {
  1199. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1200. skip "PostGreSQL is not installed"
  1201. fi
  1202. run v-unsuspend-database $pguser $pgdatabase
  1203. assert_success
  1204. refute_output
  1205. }
  1206. @test "PGSQL: Change database user" {
  1207. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1208. skip "PostGreSQL is not installed"
  1209. fi
  1210. skip
  1211. run v-change-database-user $pguser $pgdatabase database
  1212. assert_success
  1213. refute_output
  1214. validate_database pgsql $pgdatabase $pgdatabase 123456
  1215. }
  1216. @test "PGSQL: Delete database" {
  1217. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1218. skip "PostGreSQL is not installed"
  1219. fi
  1220. run v-delete-database $pguser $pgdatabase
  1221. assert_success
  1222. refute_output
  1223. }
  1224. @test "PGSQL: Delete missing database" {
  1225. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1226. skip "PostGreSQL is not installed"
  1227. fi
  1228. run v-delete-database $pguser $pgdatabase
  1229. assert_failure $E_NOTEXIST
  1230. run v-delete-user $pguser
  1231. }
  1232. #----------------------------------------------------------#
  1233. # System #
  1234. #----------------------------------------------------------#
  1235. @test "System: Set/Enable SMTP account for internal mail" {
  1236. run v-add-sys-smtp $domain 587 STARTTLS info@$domain 1234-test noreply@$domain
  1237. assert_success
  1238. refute_output
  1239. }
  1240. @test "System: Disable SMTP account for internal mail" {
  1241. run v-delete-sys-smtp
  1242. assert_success
  1243. refute_output
  1244. }
  1245. @test "System: Set/Enable SMTP relay" {
  1246. run v-add-sys-smtp-relay $domain info@$domain 1234-test 587
  1247. assert_success
  1248. refute_output
  1249. assert_file_exist /etc/exim4/smtp_relay.conf
  1250. }
  1251. @test "System: Delete SMTP relay" {
  1252. run v-delete-sys-smtp-relay
  1253. assert_success
  1254. refute_output
  1255. assert_file_not_exist /etc/exim4/smtp_relay.conf
  1256. }
  1257. #----------------------------------------------------------#
  1258. # Firewall #
  1259. #----------------------------------------------------------#
  1260. @test "Firewall: Add ip to banlist" {
  1261. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1262. assert_success
  1263. refute_output
  1264. check_ip_banned '1.2.3.4' 'HESTIA'
  1265. }
  1266. @test "Firewall: Delete ip to banlist" {
  1267. run v-delete-firewall-ban '1.2.3.4' 'HESTIA'
  1268. assert_success
  1269. refute_output
  1270. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1271. }
  1272. @test "Firewall: Add ip to banlist for ALL" {
  1273. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1274. assert_success
  1275. refute_output
  1276. run v-add-firewall-ban '1.2.3.4' 'MAIL'
  1277. assert_success
  1278. refute_output
  1279. check_ip_banned '1.2.3.4' 'HESTIA'
  1280. }
  1281. @test "Firewall: Delete ip to banlist CHAIN = ALL" {
  1282. run v-delete-firewall-ban '1.2.3.4' 'ALL'
  1283. assert_success
  1284. refute_output
  1285. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1286. }
  1287. @test "Test Whitelist Fail2ban" {
  1288. echo "1.2.3.4" >> $HESTIA/data/firewall/excludes.conf
  1289. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1290. rm $HESTIA/data/firewall/excludes.conf
  1291. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1292. }
  1293. @test "Test create ipset" {
  1294. run v-add-firewall-ipset "blacklist" "script:/usr/local/hestia/install/deb/firewall/ipset/blacklist.sh" v4 yes
  1295. assert_success
  1296. refute_output
  1297. }
  1298. @test "Create firewall with Ipset" {
  1299. run v-add-firewall-rule 'DROP' 'ipset:blacklist' '8083,22' 'TCP' 'Test'
  1300. assert_success
  1301. refute_output
  1302. }
  1303. @test "List firewall rules" {
  1304. run v-list-firewall csv
  1305. assert_success
  1306. assert_line --partial '11,DROP,TCP,8083,22,ipset:blacklist'
  1307. }
  1308. @test "Delete firewall with Ipset" {
  1309. run v-delete-firewall-rule '11'
  1310. assert_success
  1311. refute_output
  1312. }
  1313. @test "Test delete ipset" {
  1314. run v-delete-firewall-ipset "blacklist"
  1315. assert_success
  1316. refute_output
  1317. }
  1318. #----------------------------------------------------------#
  1319. # PACKAGE #
  1320. #----------------------------------------------------------#
  1321. @test "Package: Create new Package" {
  1322. cp $HESTIA/data/packages/default.pkg /tmp/package
  1323. run v-add-user-package /tmp/package hestiatest
  1324. assert_success
  1325. refute_output
  1326. }
  1327. @test "Package: Assign user to new Package" {
  1328. run v-change-user-package $user hestiatest
  1329. assert_success
  1330. refute_output
  1331. }
  1332. @test "Package: Create new package (Duplicate)" {
  1333. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1334. run v-add-user-package /tmp/package hestiatest
  1335. assert_failure $E_EXISTS
  1336. }
  1337. @test "Package: Update new Package" {
  1338. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1339. run v-add-user-package /tmp/package hestiatest yes
  1340. assert_success
  1341. refute_output
  1342. }
  1343. @test "Package: Update package of user" {
  1344. run v-change-user-package $user hestiatest
  1345. assert_success
  1346. refute_output
  1347. run grep "BANDWIDTH='100'" $HESTIA/data/users/$user/user.conf
  1348. assert_success
  1349. assert_output --partial "100"
  1350. }
  1351. @test "Package: Copy package Not Exists" {
  1352. run v-copy-user-package hestiadoesnotexists hestiatest2
  1353. assert_failure $E_NOTEXIST
  1354. }
  1355. @test "Package: Copy package" {
  1356. run v-copy-user-package hestiatest hestiatest2
  1357. assert_success
  1358. refute_output
  1359. }
  1360. @test "Package: Copy package Exists" {
  1361. run v-copy-user-package hestiatest hestiatest2
  1362. assert_failure $E_EXISTS
  1363. }
  1364. @test "Package: Delete package" {
  1365. run v-delete-user-package hestiatest
  1366. run v-delete-user-package hestiatest2
  1367. rm /tmp/package
  1368. assert_success
  1369. refute_output
  1370. run grep "BANDWIDTH='unlimited'" $HESTIA/data/users/$user/user.conf
  1371. assert_success
  1372. assert_output --partial "unlimited"
  1373. }
  1374. #----------------------------------------------------------#
  1375. # Backup user #
  1376. #----------------------------------------------------------#
  1377. @test "Backup user" {
  1378. run v-backup-user $user
  1379. assert_success
  1380. }
  1381. @test "List Backups" {
  1382. run v-list-user-backups $user plain
  1383. assert_success
  1384. assert_output --partial "$user"
  1385. }
  1386. @test "Delete backups" {
  1387. run v-delete-user-backup $user $(v-list-user-backups $user plain | cut -f1)
  1388. assert_success
  1389. run rm /backup/$user.log
  1390. }
  1391. #----------------------------------------------------------#
  1392. # CLEANUP #
  1393. #----------------------------------------------------------#
  1394. @test "Mail: Delete domain" {
  1395. run v-delete-mail-domain $user $domain
  1396. assert_success
  1397. refute_output
  1398. }
  1399. @test "DNS: Delete domain" {
  1400. run v-delete-dns-domain $user $domain
  1401. assert_success
  1402. refute_output
  1403. }
  1404. @test "WEB: Delete domain" {
  1405. run v-delete-web-domain $user $domain
  1406. assert_success
  1407. refute_output
  1408. }
  1409. @test "Delete user" {
  1410. run v-delete-user $user
  1411. assert_success
  1412. refute_output
  1413. }
  1414. @test "Ip: Delete the test IP" {
  1415. run v-delete-sys-ip 198.18.0.125
  1416. assert_success
  1417. refute_output
  1418. }
  1419. @test 'assert()' {
  1420. touch '/var/log/test.log'
  1421. assert [ -e '/var/log/test.log' ]
  1422. }