test.bats 50 KB

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