test.bats 62 KB

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