test.bats 67 KB

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