test.bats 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  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 [ $(lsb_release -s -i) = "Ubuntu" ]; 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 ip 198.18.0.12" {
  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. }
  573. @test "Ip: [Ubuntu] Netplan file changed" {
  574. # Skip if Debian
  575. if [ $(lsb_release -s -i) != "Ubuntu" ]; then
  576. skip
  577. fi
  578. ip="198.18.0.121"
  579. assert_file_exist /etc/netplan/60-hestia.yaml
  580. assert_file_contains /etc/netplan/60-hestia.yaml "$ip"
  581. }
  582. @test "Ip: Delete ip 198.18.0.121" {
  583. ip="198.18.0.121"
  584. run v-delete-sys-ip $ip
  585. assert_success
  586. refute_output
  587. assert_file_not_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  588. assert_file_not_exist $HESTIA/data/ips/$ip
  589. if [ -n "$PROXY_SYSTEM" ]; then
  590. assert_file_not_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  591. fi
  592. # remoteip and rpaf config hashes must match the initial one
  593. if [ ! -z "$a2_rpaf_hash" ]; then
  594. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  595. file_hash=$(cat $a2_rpaf |md5sum |cut -d" " -f1)
  596. assert_equal "$file_hash" "$a2_rpaf_hash"
  597. fi
  598. if [ ! -z "$a2_remoteip_hash" ]; then
  599. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  600. file_hash=$(cat $a2_remoteip |md5sum |cut -d" " -f1)
  601. assert_equal "$file_hash" "$a2_remoteip_hash"
  602. fi
  603. }
  604. @test "Ip: Add IP for rest of the test" {
  605. local ip="198.18.0.125"
  606. run v-add-sys-ip $ip 255.255.255.255 $interface $user
  607. assert_success
  608. refute_output
  609. assert_file_exist /etc/$WEB_SYSTEM/conf.d/$ip.conf
  610. assert_file_exist $HESTIA/data/ips/$ip
  611. assert_file_contains $HESTIA/data/ips/$ip "OWNER='$user'"
  612. assert_file_contains $HESTIA/data/ips/$ip "INTERFACE='$interface'"
  613. if [ -n "$PROXY_SYSTEM" ]; then
  614. assert_file_exist /etc/$PROXY_SYSTEM/conf.d/$ip.conf
  615. local a2_rpaf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
  616. [ -f "$a2_rpaf" ] && assert_file_contains "$a2_rpaf" "RPAFproxy_ips.*$ip\b"
  617. local a2_remoteip="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
  618. [ -f "$a2_remoteip" ] && assert_file_contains "$a2_remoteip" "RemoteIPInternalProxy $ip\$"
  619. fi
  620. }
  621. #----------------------------------------------------------#
  622. # WEB #
  623. #----------------------------------------------------------#
  624. @test "WEB: Add web domain" {
  625. run v-add-web-domain $user $domain 198.18.0.125
  626. assert_success
  627. refute_output
  628. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  629. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  630. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  631. }
  632. @test "WEB: Add web domain (duplicate)" {
  633. run v-add-web-domain $user $domain 198.18.0.125
  634. assert_failure $E_EXISTS
  635. }
  636. @test "WEB: Add web domain alias" {
  637. run v-add-web-domain-alias $user $domain v3.$domain
  638. assert_success
  639. refute_output
  640. }
  641. @test "WEB: Add web domain alias (duplicate)" {
  642. run v-add-web-domain-alias $user $domain v3.$domain
  643. assert_failure $E_EXISTS
  644. }
  645. @test "WEB: Add web domain wildcard alias" {
  646. run v-add-web-domain-alias $user $domain "*.$domain"
  647. assert_success
  648. refute_output
  649. }
  650. @test "WEB: Delete web domain wildcard alias" {
  651. run v-delete-web-domain-alias $user $domain "*.$domain"
  652. assert_success
  653. refute_output
  654. }
  655. @test "WEB: Add web domain stats" {
  656. run v-add-web-domain-stats $user $domain awstats
  657. assert_success
  658. refute_output
  659. }
  660. @test "WEB: Add web domain stats user" {
  661. skip
  662. run v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd
  663. assert_success
  664. refute_output
  665. }
  666. @test "WEB: Suspend web domain" {
  667. run v-suspend-web-domain $user $domain
  668. assert_success
  669. refute_output
  670. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  671. validate_web_domain $user $domain 'This site is currently suspended'
  672. validate_web_domain $user $domain 'This site is currently suspended' 'php-test.php'
  673. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  674. }
  675. @test "WEB: Unsuspend web domain" {
  676. run v-unsuspend-web-domain $user $domain
  677. assert_success
  678. refute_output
  679. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  680. validate_web_domain $user $domain 'Hestia Test:12' 'php-test.php'
  681. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  682. }
  683. @test "WEB: Add redirect to www.domain.com" {
  684. run v-add-web-domain-redirect $user $domain www.$domain 301
  685. assert_success
  686. refute_output
  687. run validate_headers_domain $user $domain "301"
  688. }
  689. @test "WEB: Delete redirect to www.domain.com" {
  690. run v-delete-web-domain-redirect $user $domain
  691. assert_success
  692. refute_output
  693. }
  694. @test "WEB: Enable Fast CGI Cache" {
  695. if [ "$WEB_SYSTEM" != "nginx" ]; then
  696. skip "FastCGI cache is not supported"
  697. fi
  698. run v-add-fastcgi-cache $user $domain '1m' yes
  699. assert_success
  700. refute_output
  701. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/$domain/public_html/php-test.php
  702. run validate_headers_domain $user $domain "Miss"
  703. run validate_headers_domain $user $domain "Hit"
  704. rm $HOMEDIR/$user/web/$domain/public_html/php-test.php
  705. }
  706. @test "WEB: Disable Fast CGI Cache" {
  707. if [ "$WEB_SYSTEM" != "nginx" ]; then
  708. skip "FastCGI cache is not supported"
  709. fi
  710. run v-delete-fastcgi-cache $user $domain yes
  711. assert_success
  712. refute_output
  713. }
  714. @test "WEB: Generate Self signed certificate" {
  715. ssl=$(v-generate-ssl-cert "$domain" "info@$domain" US CA "Orange County" HestiaCP IT "mail.$domain" | tail -n1 | awk '{print $2}')
  716. echo $ssl;
  717. mv $ssl/$domain.crt /tmp/$domain.crt
  718. mv $ssl/$domain.key /tmp/$domain.key
  719. }
  720. @test "WEB: Add ssl" {
  721. # Use self signed certificates during last test
  722. run v-add-web-domain-ssl $user $domain /tmp
  723. assert_success
  724. refute_output
  725. }
  726. @test "WEB: Rebuild web domain" {
  727. run v-rebuild-web-domains $user
  728. assert_success
  729. refute_output
  730. }
  731. #----------------------------------------------------------#
  732. # IDN #
  733. #----------------------------------------------------------#
  734. @test "WEB: Add IDN domain UTF idn-tést.eu" {
  735. run v-add-web-domain $user idn-tést.eu 198.18.0.125
  736. assert_success
  737. refute_output
  738. echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  739. validate_web_domain $user idn-tést.eu 'Hestia Test:12' 'php-test.php'
  740. rm $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
  741. }
  742. @test "WEB: Add IDN domain ASCII idn-tést.eu" {
  743. # Expected to fail due to utf exists
  744. run v-add-web-domain $user "xn--idn-tst-fya.eu" 198.18.0.125
  745. assert_failure $E_EXISTS
  746. }
  747. @test "WEB: Generate Self signed certificate ASCII idn-tést.eu" {
  748. 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"
  749. assert_success
  750. }
  751. @test "WEB: Delete IDN domain idn-tést.eu" {
  752. run v-delete-web-domain $user idn-tést.eu
  753. assert_success
  754. refute_output
  755. }
  756. @test "WEB: Add IDN domain UTF bløst.рф" {
  757. run v-add-web-domain $user bløst.рф 198.18.0.125
  758. assert_success
  759. refute_output
  760. }
  761. @test "WEB: Generate Self signed certificate ASCII bløst.рф" {
  762. 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"
  763. assert_success
  764. }
  765. @test "WEB: Delete IDN domain bløst.рф" {
  766. run v-delete-web-domain $user bløst.рф
  767. assert_success
  768. refute_output
  769. }
  770. #----------------------------------------------------------#
  771. # MULTIPHP #
  772. #----------------------------------------------------------#
  773. @test "Multiphp: Default php Backend version" {
  774. def_phpver=$(multiphp_default_version)
  775. multi_domain="multiphp.${domain}"
  776. run v-add-web-domain $user $multi_domain 198.18.0.125
  777. assert_success
  778. refute_output
  779. echo -e "<?php\necho PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  780. validate_web_domain $user $multi_domain "$def_phpver" 'php-test.php'
  781. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  782. }
  783. @test "Multiphp: Change backend version - PHP v5.6" {
  784. test_phpver='5.6'
  785. multi_domain="multiphp.${domain}"
  786. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  787. skip "PHP ${test_phpver} not installed"
  788. fi
  789. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-5_6' 'yes'
  790. assert_success
  791. refute_output
  792. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  793. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  794. # A single php-fpm pool config file must be present
  795. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  796. assert_equal "$num_fpm_config_files" '1'
  797. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  798. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  799. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  800. }
  801. @test "Multiphp: Change backend version - PHP v7.0" {
  802. test_phpver='7.0'
  803. multi_domain="multiphp.${domain}"
  804. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  805. skip "PHP ${test_phpver} not installed"
  806. fi
  807. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_0' 'yes'
  808. assert_success
  809. refute_output
  810. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  811. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  812. # A single php-fpm pool config file must be present
  813. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  814. assert_equal "$num_fpm_config_files" '1'
  815. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  816. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  817. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  818. }
  819. @test "Multiphp: Change backend version - PHP v7.1" {
  820. test_phpver='7.1'
  821. multi_domain="multiphp.${domain}"
  822. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  823. skip "PHP ${test_phpver} not installed"
  824. fi
  825. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_1' 'yes'
  826. assert_success
  827. refute_output
  828. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  829. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  830. # A single php-fpm pool config file must be present
  831. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  832. assert_equal "$num_fpm_config_files" '1'
  833. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  834. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  835. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  836. }
  837. @test "Multiphp: Change backend version - PHP v7.2" {
  838. test_phpver='7.2'
  839. multi_domain="multiphp.${domain}"
  840. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  841. skip "PHP ${test_phpver} not installed"
  842. fi
  843. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_2' 'yes'
  844. assert_success
  845. refute_output
  846. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  847. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  848. # A single php-fpm pool config file must be present
  849. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  850. assert_equal "$num_fpm_config_files" '1'
  851. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  852. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  853. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  854. }
  855. @test "Multiphp: Change backend version - PHP v7.3" {
  856. test_phpver='7.3'
  857. multi_domain="multiphp.${domain}"
  858. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  859. skip "PHP ${test_phpver} not installed"
  860. fi
  861. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_3' 'yes'
  862. assert_success
  863. refute_output
  864. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  865. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  866. # A single php-fpm pool config file must be present
  867. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  868. assert_equal "$num_fpm_config_files" '1'
  869. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  870. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  871. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  872. }
  873. @test "Multiphp: Change backend version - PHP v7.4" {
  874. test_phpver='7.4'
  875. multi_domain="multiphp.${domain}"
  876. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  877. skip "PHP ${test_phpver} not installed"
  878. fi
  879. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-7_4' 'yes'
  880. assert_success
  881. refute_output
  882. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  883. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  884. # A single php-fpm pool config file must be present
  885. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  886. assert_equal "$num_fpm_config_files" '1'
  887. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  888. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  889. rm "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  890. }
  891. @test "Multiphp: Change backend version - PHP v8.0" {
  892. test_phpver='8.0'
  893. multi_domain="multiphp.${domain}"
  894. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  895. skip "PHP ${test_phpver} not installed"
  896. fi
  897. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_0' 'yes'
  898. assert_success
  899. refute_output
  900. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  901. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  902. # A single php-fpm pool config file must be present
  903. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  904. assert_equal "$num_fpm_config_files" '1'
  905. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  906. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  907. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  908. }
  909. @test "Multiphp: Change backend version - PHP v8.1" {
  910. test_phpver='8.1'
  911. multi_domain="multiphp.${domain}"
  912. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  913. skip "PHP ${test_phpver} not installed"
  914. fi
  915. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_1' 'yes'
  916. assert_success
  917. refute_output
  918. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  919. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  920. # A single php-fpm pool config file must be present
  921. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  922. assert_equal "$num_fpm_config_files" '1'
  923. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  924. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  925. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  926. }
  927. @test "Multiphp: Change backend version - PHP v8.2" {
  928. test_phpver='8.2'
  929. multi_domain="multiphp.${domain}"
  930. if [ ! -d "/etc/php/${test_phpver}/fpm/pool.d/" ]; then
  931. skip "PHP ${test_phpver} not installed"
  932. fi
  933. run v-change-web-domain-backend-tpl $user $multi_domain 'PHP-8_2' 'yes'
  934. assert_success
  935. refute_output
  936. # Changing web backend will create a php-fpm pool config in the corresponding php folder
  937. assert_file_exist "/etc/php/${test_phpver}/fpm/pool.d/${multi_domain}.conf"
  938. # A single php-fpm pool config file must be present
  939. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  940. assert_equal "$num_fpm_config_files" '1'
  941. echo -e "<?php\necho 'hestia-multiphptest:'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" > "$HOMEDIR/$user/web/$multi_domain/public_html/php-test.php"
  942. validate_web_domain $user $multi_domain "hestia-multiphptest:$test_phpver" 'php-test.php'
  943. rm $HOMEDIR/$user/web/$multi_domain/public_html/php-test.php
  944. }
  945. @test "Multiphp: Cleanup" {
  946. multi_domain="multiphp.${domain}"
  947. run v-delete-web-domain $user $multi_domain 'yes'
  948. assert_success
  949. refute_output
  950. # No php-fpm pool config file must be present
  951. num_fpm_config_files="$(find -L /etc/php/ -name "${multi_domain}.conf" | wc -l)"
  952. assert_equal "$num_fpm_config_files" '0'
  953. }
  954. #----------------------------------------------------------#
  955. # CUSTOM DOCROOT #
  956. #----------------------------------------------------------#
  957. @test "Docroot: Self Subfolder" {
  958. docroot1_domain="docroot1.${domain}"
  959. run v-add-web-domain $user $docroot1_domain 198.18.0.125
  960. assert_success
  961. refute_output
  962. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/"
  963. assert_success
  964. refute_output
  965. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot1_domain" "/public"
  966. assert_success
  967. refute_output
  968. echo -e '<?php\necho "self-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  969. validate_web_domain $user $docroot1_domain "self-sub-${docroot1_domain}" 'php-test.php'
  970. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/public/php-test.php"
  971. }
  972. @test "Docroot: Other domain subfolder" {
  973. docroot1_domain="docroot1.${domain}"
  974. docroot2_domain="docroot2.${domain}"
  975. run v-add-web-domain $user $docroot2_domain 198.18.0.125
  976. assert_success
  977. refute_output
  978. run v-add-fs-directory $user "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/"
  979. assert_success
  980. refute_output
  981. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain" "/public"
  982. assert_success
  983. refute_output
  984. echo -e '<?php\necho "doc2-sub-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  985. validate_web_domain $user $docroot1_domain "doc2-sub-${docroot1_domain}" 'php-test.php'
  986. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/public/php-test.php"
  987. }
  988. @test "Docroot: Other domain root folder" {
  989. docroot1_domain="docroot1.${domain}"
  990. docroot2_domain="docroot2.${domain}"
  991. run v-change-web-domain-docroot $user "$docroot1_domain" "$docroot2_domain"
  992. assert_success
  993. refute_output
  994. echo -e '<?php\necho "doc2-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  995. validate_web_domain $user $docroot1_domain "doc2-root-${docroot1_domain}" 'php-test.php'
  996. rm "$HOMEDIR/$user/web/$docroot2_domain/public_html/php-test.php"
  997. }
  998. @test "Docroot: Reset" {
  999. docroot1_domain="docroot1.${domain}"
  1000. run v-change-web-domain-docroot $user "$docroot1_domain" "default"
  1001. assert_success
  1002. refute_output
  1003. echo -e '<?php\necho "doc1-root-".$_SERVER["HTTP_HOST"];' > "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  1004. validate_web_domain $user $docroot1_domain "doc1-root-${docroot1_domain}" 'php-test.php'
  1005. rm "$HOMEDIR/$user/web/$docroot1_domain/public_html/php-test.php"
  1006. }
  1007. @test "Docroot: Cleanup" {
  1008. docroot1_domain="docroot1.${domain}"
  1009. docroot2_domain="docroot2.${domain}"
  1010. run v-delete-web-domain $user $docroot1_domain
  1011. assert_success
  1012. refute_output
  1013. run v-delete-web-domain $user $docroot2_domain
  1014. assert_success
  1015. refute_output
  1016. }
  1017. #----------------------------------------------------------#
  1018. # DNS #
  1019. #----------------------------------------------------------#
  1020. @test "DNS: Add domain" {
  1021. run v-add-dns-domain $user $domain 198.18.0.125
  1022. assert_success
  1023. refute_output
  1024. }
  1025. @test "DNS: Add domain (duplicate)" {
  1026. run v-add-dns-domain $user $domain 198.18.0.125
  1027. assert_failure $E_EXISTS
  1028. }
  1029. @test "DNS: Add domain record" {
  1030. run v-add-dns-record $user $domain test A 198.18.0.125 '' 20
  1031. assert_success
  1032. refute_output
  1033. }
  1034. @test "DNS: Add domain record *.domain.com" {
  1035. run v-add-dns-record $user $domain '*' A 198.18.0.125 '' 30
  1036. assert_success
  1037. refute_output
  1038. }
  1039. @test "DNS: Add domain record *.domain.com with ID 0" {
  1040. run v-add-dns-record $user $domain '*' A 198.18.0.125 '' 0
  1041. assert_failure $E_INVALID
  1042. }
  1043. @test "DNS: Change DNS record" {
  1044. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  1045. assert_success
  1046. refute_output
  1047. }
  1048. @test "DNS: Change DNS record (no update)" {
  1049. run v-change-dns-record $user $domain 20 test A 198.18.0.125 "" "" 1500
  1050. assert_failure $E_EXSIST
  1051. }
  1052. @test "DNS: Change DNS record id" {
  1053. run v-change-dns-record-id $user $domain 20 21
  1054. assert_success
  1055. refute_output
  1056. # Change back
  1057. run v-change-dns-record-id $user $domain 21 20
  1058. }
  1059. @test "DNS: Change DNS record id (no update)" {
  1060. run v-change-dns-record-id $user $domain 20 20
  1061. assert_failure $E_EXSIST
  1062. }
  1063. @test "DNS: Delete domain record" {
  1064. run v-delete-dns-record $user $domain 20
  1065. assert_success
  1066. refute_output
  1067. }
  1068. @test "DNS: Delete missing domain record" {
  1069. run v-delete-dns-record $user $domain 20
  1070. assert_failure $E_NOTEXIST
  1071. }
  1072. @test "DNS: Change domain expire date" {
  1073. run v-change-dns-domain-exp $user $domain 2020-01-01
  1074. assert_success
  1075. refute_output
  1076. }
  1077. @test "DNS: Add domain record MX" {
  1078. run v-add-dns-record $user $domain '@' MX mx.hestiacp.com '' 50
  1079. assert_success
  1080. refute_output
  1081. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1082. run v-change-dns-record $user $domain 50 '@' MX mx.hestia.com
  1083. assert_success
  1084. refute_output
  1085. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1086. run v-delete-dns-record $user $domain 50
  1087. assert_success
  1088. refute_output
  1089. }
  1090. @test "DNS: Add domain record NS" {
  1091. run v-delete-dns-record $user $domain 50
  1092. run v-add-dns-record $user $domain '@' NS mx.hestiacp.com '' 50
  1093. assert_success
  1094. refute_output
  1095. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1096. run v-change-dns-record $user $domain 50 '@' NS mx.hestia.com
  1097. assert_success
  1098. refute_output
  1099. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1100. run v-delete-dns-record $user $domain 50
  1101. assert_success
  1102. refute_output
  1103. }
  1104. @test "DNS: Add domain record SRV" {
  1105. run v-delete-dns-record $user $domain 50
  1106. run v-add-dns-record $user $domain '_test_domain' SRV mx.hestiacp.com '' 50
  1107. assert_success
  1108. refute_output
  1109. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1110. run v-change-dns-record $user $domain 50 '_test.domain' SRV mx.hestia.com
  1111. assert_success
  1112. refute_output
  1113. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1114. run v-delete-dns-record $user $domain 50
  1115. assert_success
  1116. refute_output
  1117. }
  1118. @test "DNS: Add domain record CNAME" {
  1119. run v-delete-dns-record $user $domain 50
  1120. run v-add-dns-record $user $domain 'mail' CNAME mx.hestiacp.com '' 50
  1121. assert_success
  1122. refute_output
  1123. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestiacp.com."
  1124. run v-change-dns-record $user $domain 50 'mail' CNAME mx.hestia.com
  1125. assert_success
  1126. refute_output
  1127. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "mx.hestia.com."
  1128. run v-delete-dns-record $user $domain 50
  1129. assert_success
  1130. refute_output
  1131. }
  1132. @test "DNS: Check txt dns records type1" {
  1133. [ -z "$DNS_SYSTEM" ] && skip
  1134. run v-delete-dns-record $user $domain 50
  1135. record1_in='v=DMARC1; p=quarantine; pct=100'
  1136. record2_in='v=DMARC1; p=quarantine; pct=90'
  1137. record1_out='"v=DMARC1; p=quarantine; pct=100"'
  1138. record2_in='"v=DMARC1; p=quarantine; pct=90"'
  1139. # Test Create
  1140. run v-add-dns-record $user $domain 'test-long-txt' 'TXT' "$record1_in" '' 50
  1141. assert_success
  1142. refute_output
  1143. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record1_out"
  1144. # Test Edit
  1145. run v-change-dns-record $user $domain 50 'test-long-txt' 'TXT' "$record2_in"
  1146. assert_success
  1147. refute_output
  1148. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record2_out"
  1149. # Test Cleanup
  1150. run v-delete-dns-record $user $domain 50
  1151. assert_success
  1152. refute_output
  1153. }
  1154. @test "DNS: Check txt dns records type2" {
  1155. [ -z "$DNS_SYSTEM" ] && skip
  1156. run v-delete-dns-record $user $domain 50
  1157. record3_in='k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4gVrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQAB'
  1158. record3_out='"k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4g""VrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQAB"'
  1159. record4_in='k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4gVrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQA4'
  1160. record4_out='"k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4+VEVsoTbl6tYLJlhozqAGju3IgpSVdBAS5LMyzpHP8/L0/PlyVRJnm2xECjVk3DRqCmelyIvmraw1VtFz2aH6DRlDhHsZghj1DmGhwN+7NkwIb4hEvmytMVAz1WyiLH6Rm6Iemm/ZCt1RhrAMUYLxHA9mJgky76YCcf8/cX35xC+1vd4a5U6YofAZeVP9DBvVgQ8ung4g""VrOrQrXkU8QfVNAoXz5pfJo74GB7woIBFhZXsU6SKho7KnzT5inVCIOtWp7L5hyEnbySWQPHT2vAMCCAe2AY/Vv0N3HW14o8P3b4A6OU920wFB2kA7pkQNzO5OwH+HSttwG0PaIiQxYQIDAQA4"'
  1161. # Test Create
  1162. run v-add-dns-record $user $domain 'test-long-txt' 'TXT' "$record3_in" '' 50
  1163. assert_success
  1164. refute_output
  1165. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record3_out"
  1166. # Test Edit
  1167. run v-change-dns-record $user $domain 50 'test-long-txt' 'TXT' "$record4_in"
  1168. assert_success
  1169. refute_output
  1170. assert_file_contains "$HOMEDIR/$user/conf/dns/${domain}.db" "$record4_out"
  1171. # Test Cleanup
  1172. run v-delete-dns-record $user $domain 50
  1173. assert_success
  1174. refute_output
  1175. }
  1176. @test "DNS: Change domain ip" {
  1177. run v-change-dns-domain-ip $user $domain 127.0.0.1
  1178. assert_success
  1179. refute_output
  1180. }
  1181. @test "DNS: Suspend domain" {
  1182. run v-suspend-dns-domain $user $domain
  1183. assert_success
  1184. refute_output
  1185. }
  1186. @test "DNS: Unsuspend domain" {
  1187. run v-unsuspend-dns-domain $user $domain
  1188. assert_success
  1189. refute_output
  1190. }
  1191. @test "DNS: Rebuild" {
  1192. run v-rebuild-dns-domains $user
  1193. assert_success
  1194. refute_output
  1195. }
  1196. #----------------------------------------------------------#
  1197. # MAIL #
  1198. #----------------------------------------------------------#
  1199. @test "MAIL: Add domain" {
  1200. run v-add-mail-domain $user $domain
  1201. assert_success
  1202. refute_output
  1203. validate_mail_domain $user $domain
  1204. }
  1205. @test "MAIL: Add mail domain webmail client (Roundcube)" {
  1206. run v-add-mail-domain-webmail $user $domain "roundcube" "yes"
  1207. assert_success
  1208. refute_output
  1209. # echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
  1210. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  1211. # rm /var/lib/roundcube/check_server.php
  1212. }
  1213. @test "Mail: Add SSL to mail domain" {
  1214. # Use generated certificates during WEB Generate Self signed certificate
  1215. run v-add-mail-domain-ssl $user $domain /tmp
  1216. assert_success
  1217. refute_output
  1218. validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
  1219. }
  1220. @test "MAIL: Add mail domain webmail client (SnappyMail)" {
  1221. if [ -z "$(echo $WEBMAIL_SYSTEM | grep -w "snappymail")" ]; then
  1222. skip "Webmail client SnappyMail not installed"
  1223. fi
  1224. run v-add-mail-domain-webmail $user $domain "snappymail" "yes"
  1225. assert_success
  1226. refute_output
  1227. validate_mail_domain $user $domain
  1228. validate_webmail_domain $user $domain 'SnappyMail Webmail'
  1229. }
  1230. @test "MAIL: Disable webmail client" {
  1231. run v-add-mail-domain-webmail $user $domain "disabled" "yes"
  1232. assert_success
  1233. refute_output
  1234. validate_mail_domain $user $domain
  1235. validate_webmail_domain $user $domain 'Success!'
  1236. run v-add-mail-domain-webmail $user $domain "roundcube" "yes"
  1237. assert_success
  1238. refute_output
  1239. }
  1240. @test "MAIL: Add domain (duplicate)" {
  1241. run v-add-mail-domain $user $domain
  1242. assert_failure $E_EXISTS
  1243. }
  1244. @test "MAIL: Add account" {
  1245. run v-add-mail-account $user $domain test "$userpass2"
  1246. assert_success
  1247. assert_file_contains /etc/exim4/domains/$domain/limits "test@$domain"
  1248. refute_output
  1249. }
  1250. @test "MAIL: Add account (duplicate)" {
  1251. run v-add-mail-account $user $domain test "$userpass2"
  1252. assert_failure $E_EXISTS
  1253. }
  1254. @test "MAIL: Add account 2" {
  1255. run v-add-mail-account $user $domain random "$userpass2"
  1256. assert_success
  1257. assert_file_contains /etc/exim4/domains/$domain/limits "random@$domain"
  1258. refute_output
  1259. }
  1260. @test "MAIL: Add account alias" {
  1261. run v-add-mail-account-alias $user $domain test hestiacprocks
  1262. assert_success
  1263. assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacprocks@$domain"
  1264. refute_output
  1265. }
  1266. @test "MAIL: Add account alias 2" {
  1267. run v-add-mail-account-alias $user $domain test hestiacprocks2
  1268. assert_success
  1269. assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacprocks2@$domain"
  1270. refute_output
  1271. }
  1272. @test "MAIL: Add account alias 3" {
  1273. run v-add-mail-account-alias $user $domain test hestiacp
  1274. assert_success
  1275. assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacp@$domain"
  1276. refute_output
  1277. }
  1278. @test "MAIL: Add account 3" {
  1279. run v-add-mail-account $user $domain hestia "$userpass2"
  1280. assert_success
  1281. assert_file_contains /etc/exim4/domains/$domain/limits "hestia@$domain"
  1282. refute_output
  1283. }
  1284. @test "MAIL: Add account 4" {
  1285. run v-add-mail-account $user $domain hestiarocks3 "$userpass2"
  1286. assert_success
  1287. assert_file_contains /etc/exim4/domains/$domain/limits "hestiarocks3@$domain"
  1288. refute_output
  1289. }
  1290. @test "MAIL: Add account alias Invalid length" {
  1291. run v-add-mail-account-alias $user $domain test 'hestiacp-realy-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
  1292. assert_failure $E_INVALID
  1293. }
  1294. @test "MAIL: Add account alias Invalid" {
  1295. run v-add-mail-account-alias $user $domain test '-test'
  1296. assert_failure $E_INVALID
  1297. }
  1298. @test "MAIL: Add account alias Invalid 2" {
  1299. run v-add-mail-account-alias $user $domain test 'hestia@test'
  1300. assert_failure $E_INVALID
  1301. }
  1302. @test "MAIL: Add account alias (duplicate)" {
  1303. run v-add-mail-account-alias $user $domain test hestiacprocks
  1304. assert_failure $E_EXISTS
  1305. }
  1306. @test "MAIL: change mail account password" {
  1307. run curl -k -X POST -d "email=test@$domain&password=$userpass2&new=123456" https://localhost:8083/reset/mail/
  1308. assert_success
  1309. assert_output --partial "==ok=="
  1310. }
  1311. @test "MAIL: change mail account password (Incorrect PW)" {
  1312. run curl -k -X POST -d "email=test@$domain&password=$userpass2&new=123456" https://localhost:8083/reset/mail/
  1313. assert_success
  1314. assert_output --partial "error"
  1315. }
  1316. @test "MAIL: Change rate limit" {
  1317. run v-change-mail-account-rate-limit $user $domain test 10
  1318. assert_file_contains /etc/exim4/domains/$domain/limits "test@$domain:10"
  1319. }
  1320. @test "MAIL: Delete account" {
  1321. run v-delete-mail-account $user $domain test
  1322. assert_success
  1323. refute_output
  1324. }
  1325. @test "MAIL: Delete missing account" {
  1326. run v-delete-mail-account $user $domain test
  1327. assert_failure $E_NOTEXIST
  1328. }
  1329. @test "MAIL: Rebuild mail domain" {
  1330. run v-rebuild-mail-domains $user
  1331. assert_success
  1332. refute_output
  1333. }
  1334. @test "MAIL: Delete DKIM" {
  1335. run v-delete-mail-domain-dkim $user $domain
  1336. assert_success
  1337. refute_output
  1338. run grep "RECORD='_domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
  1339. assert_failure
  1340. refute_output
  1341. run grep "RECORD='mail._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
  1342. assert_failure
  1343. refute_output
  1344. }
  1345. @test "MAIL: Add DKIM" {
  1346. run v-add-mail-domain-dkim $user $domain
  1347. assert_success
  1348. refute_output
  1349. run grep "RECORD='_domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
  1350. assert_success
  1351. assert_output --partial "RECORD='_domainkey' TYPE='TXT'"
  1352. run grep "RECORD='mail._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
  1353. assert_success
  1354. assert_output --partial "RECORD='mail._domainkey' TYPE='TXT'"
  1355. }
  1356. @test "MAIL: Delete DKIM but preserve custom dkim records" {
  1357. run v-add-dns-record $user $domain 'k2._domainkey' 'TXT' 'v=DKIM1; k=rsa; p=123456'
  1358. assert_success
  1359. refute_output
  1360. run v-delete-mail-domain-dkim $user $domain
  1361. assert_success
  1362. refute_output
  1363. run grep "RECORD='k2._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
  1364. assert_success
  1365. assert_output --partial "RECORD='k2._domainkey' TYPE='TXT'"
  1366. }
  1367. #----------------------------------------------------------#
  1368. # Limit possibilities adding different owner domain #
  1369. #----------------------------------------------------------#
  1370. @test "Allow Users: User can't add user.user2.com " {
  1371. # Case: admin company.tld
  1372. # users should not be allowed to add user.company.tld
  1373. run v-add-user $user2 $user2 $user@hestiacp.com default "Super Test"
  1374. assert_success
  1375. refute_output
  1376. run v-add-web-domain $user2 $rootdomain
  1377. assert_success
  1378. refute_output
  1379. run v-add-web-domain $user $subdomain
  1380. assert_failure $E_EXISTS
  1381. }
  1382. @test "Allow Users: User can't add user.user2.com as alias" {
  1383. run v-add-web-domain-alias $user $domain $subdomain
  1384. assert_failure $E_EXISTS
  1385. }
  1386. @test "Allow Users: User can't add user.user2.com as mail domain" {
  1387. run v-add-mail-domain $user $subdomain
  1388. assert_failure $E_EXISTS
  1389. }
  1390. @test "Allow Users: User can't add user.user2.com as dns domain" {
  1391. run v-add-dns-domain $user $subdomain 198.18.0.125
  1392. assert_failure $E_EXISTS
  1393. }
  1394. @test "Allow Users: Set Allow users" {
  1395. # Allow user to yes allows
  1396. # Case: admin company.tld
  1397. # users are allowed to add user.company.tld
  1398. run v-add-web-domain-allow-users $user2 $rootdomain
  1399. assert_success
  1400. refute_output
  1401. }
  1402. @test "Allow Users: User can add user.user2.com" {
  1403. run v-add-web-domain $user $subdomain
  1404. assert_success
  1405. refute_output
  1406. }
  1407. @test "Allow Users: User can add user.user2.com as alias" {
  1408. run v-delete-web-domain $user $subdomain
  1409. assert_success
  1410. refute_output
  1411. run v-add-web-domain-alias $user $domain $subdomain
  1412. assert_success
  1413. refute_output
  1414. }
  1415. @test "Allow Users: User can add user.user2.com as mail domain" {
  1416. run v-add-mail-domain $user $subdomain
  1417. assert_success
  1418. refute_output
  1419. }
  1420. @test "Allow Users: User can add user.user2.com as dns domain" {
  1421. run v-add-dns-domain $user $subdomain 198.18.0.125
  1422. assert_success
  1423. refute_output
  1424. }
  1425. @test "Allow Users: Cleanup tests" {
  1426. run v-delete-dns-domain $user $subdomain
  1427. assert_success
  1428. refute_output
  1429. run v-delete-mail-domain $user $subdomain
  1430. assert_success
  1431. refute_output
  1432. }
  1433. @test "Allow Users: Set Allow users no" {
  1434. run v-delete-web-domain-alias $user $domain $subdomain
  1435. assert_success
  1436. refute_output
  1437. run v-delete-web-domain-allow-users $user2 $rootdomain
  1438. assert_success
  1439. refute_output
  1440. }
  1441. @test "Allow Users: User can't add user.user2.com again" {
  1442. run v-add-web-domain $user $subdomain
  1443. assert_failure $E_EXISTS
  1444. }
  1445. @test "Allow Users: user2 can add user.user2.com again" {
  1446. run v-add-web-domain $user2 $subdomain
  1447. assert_success
  1448. refute_output
  1449. }
  1450. #----------------------------------------------------------#
  1451. # DB #
  1452. #----------------------------------------------------------#
  1453. @test "MYSQL: Add database" {
  1454. run v-add-database $user database dbuser 1234 mysql
  1455. assert_success
  1456. refute_output
  1457. # validate_database mysql database_name database_user password
  1458. validate_database mysql $database $dbuser 1234
  1459. }
  1460. @test "MYSQL: Add Database (Duplicate)" {
  1461. run v-add-database $user database dbuser 1234 mysql
  1462. assert_failure $E_EXISTS
  1463. }
  1464. @test "MYSQL: Rebuild Database" {
  1465. run v-rebuild-database $user $database
  1466. assert_success
  1467. refute_output
  1468. }
  1469. @test "MYSQL: Change database user password" {
  1470. run v-change-database-password $user $database 123456
  1471. assert_success
  1472. refute_output
  1473. validate_database mysql $database $dbuser 123456
  1474. }
  1475. @test "MYSQL: Change database user" {
  1476. run v-change-database-user $user $database database
  1477. assert_success
  1478. refute_output
  1479. validate_database mysql $database $database 123456
  1480. }
  1481. @test "MYSQL: Suspend database" {
  1482. run v-suspend-database $user $database
  1483. assert_success
  1484. refute_output
  1485. }
  1486. @test "MYSQL: Unsuspend database" {
  1487. run v-unsuspend-database $user $database
  1488. assert_success
  1489. refute_output
  1490. }
  1491. @test "MYSQL: Delete database" {
  1492. run v-delete-database $user $database
  1493. assert_success
  1494. refute_output
  1495. }
  1496. @test "MYSQL: Delete missing database" {
  1497. run v-delete-database $user $database
  1498. assert_failure $E_NOTEXIST
  1499. }
  1500. @test "PGSQL: Add database invalid user" {
  1501. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1502. skip "PostGreSQL is not installed"
  1503. fi
  1504. run v-add-database "$user" "database" "dbuser" "1234ABCD" "pgsql"
  1505. assert_failure $E_INVALID
  1506. }
  1507. @test "PGSQL: Add database" {
  1508. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1509. skip "PostGreSQL is not installed"
  1510. fi
  1511. run v-add-user $pguser $pguser $user@hestiacp.com default "Super Test"
  1512. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1513. assert_success
  1514. refute_output
  1515. # validate_database pgsql $pgdatabase $pgdbuser "1234ABCD"
  1516. }
  1517. @test "PGSQL: Add Database (Duplicate)" {
  1518. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1519. skip "PostGreSQL is not installed"
  1520. fi
  1521. run v-add-database "$pguser" "database" "dbuser" "1234ABCD" "pgsql"
  1522. assert_failure $E_EXISTS
  1523. }
  1524. @test "PGSQL: Rebuild Database" {
  1525. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1526. skip "PostGreSQL is not installed"
  1527. fi
  1528. run v-rebuild-database $pguser $pgdatabase
  1529. assert_success
  1530. refute_output
  1531. }
  1532. @test "PGSQL: Change database user password" {
  1533. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1534. skip "PostGreSQL is not installed"
  1535. fi
  1536. run v-change-database-password $pguser $pgdatabase "123456"
  1537. assert_success
  1538. refute_output
  1539. # validate_database pgsql $pgdatabase $pgdbuser "123456"
  1540. }
  1541. @test "PGSQL: Suspend database" {
  1542. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1543. skip "PostGreSQL is not installed"
  1544. fi
  1545. run v-suspend-database $pguser $pgdatabase
  1546. assert_success
  1547. refute_output
  1548. }
  1549. @test "PGSQL: Unsuspend database" {
  1550. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1551. skip "PostGreSQL is not installed"
  1552. fi
  1553. run v-unsuspend-database $pguser $pgdatabase
  1554. assert_success
  1555. refute_output
  1556. }
  1557. @test "PGSQL: Change database user" {
  1558. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1559. skip "PostGreSQL is not installed"
  1560. fi
  1561. skip
  1562. run v-change-database-user $pguser $pgdatabase database
  1563. assert_success
  1564. refute_output
  1565. validate_database pgsql $pgdatabase $pgdatabase 123456
  1566. }
  1567. @test "PGSQL: Delete database" {
  1568. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1569. skip "PostGreSQL is not installed"
  1570. fi
  1571. run v-delete-database $pguser $pgdatabase
  1572. assert_success
  1573. refute_output
  1574. }
  1575. @test "PGSQL: Delete missing database" {
  1576. if [ -z "$(echo $DB_SYSTEM | grep -w "pgsql")" ]; then
  1577. skip "PostGreSQL is not installed"
  1578. fi
  1579. run v-delete-database $pguser $pgdatabase
  1580. assert_failure $E_NOTEXIST
  1581. run v-delete-user $pguser
  1582. }
  1583. #----------------------------------------------------------#
  1584. # System #
  1585. #----------------------------------------------------------#
  1586. @test "System: Set/Enable SMTP account for internal mail" {
  1587. run v-add-sys-smtp $domain 587 STARTTLS info@$domain 1234-test noreply@$domain
  1588. assert_success
  1589. refute_output
  1590. }
  1591. @test "System: Disable SMTP account for internal mail" {
  1592. run v-delete-sys-smtp
  1593. assert_success
  1594. refute_output
  1595. }
  1596. @test "System: Set/Enable SMTP relay" {
  1597. run v-add-sys-smtp-relay $domain info@$domain 1234-test 587
  1598. assert_success
  1599. refute_output
  1600. assert_file_exist /etc/exim4/smtp_relay.conf
  1601. }
  1602. @test "System: Delete SMTP relay" {
  1603. run v-delete-sys-smtp-relay
  1604. assert_success
  1605. refute_output
  1606. assert_file_not_exist /etc/exim4/smtp_relay.conf
  1607. }
  1608. #----------------------------------------------------------#
  1609. # Firewall #
  1610. #----------------------------------------------------------#
  1611. @test "Firewall: Add ip to banlist" {
  1612. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1613. assert_success
  1614. refute_output
  1615. check_ip_banned '1.2.3.4' 'HESTIA'
  1616. }
  1617. @test "Firewall: Delete ip to banlist" {
  1618. run v-delete-firewall-ban '1.2.3.4' 'HESTIA'
  1619. assert_success
  1620. refute_output
  1621. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1622. }
  1623. @test "Firewall: Add ip to banlist for ALL" {
  1624. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1625. assert_success
  1626. refute_output
  1627. run v-add-firewall-ban '1.2.3.4' 'MAIL'
  1628. assert_success
  1629. refute_output
  1630. check_ip_banned '1.2.3.4' 'HESTIA'
  1631. }
  1632. @test "Firewall: Delete ip to banlist CHAIN = ALL" {
  1633. run v-delete-firewall-ban '1.2.3.4' 'ALL'
  1634. assert_success
  1635. refute_output
  1636. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1637. }
  1638. @test "Test Whitelist Fail2ban" {
  1639. echo "1.2.3.4" >> $HESTIA/data/firewall/excludes.conf
  1640. run v-add-firewall-ban '1.2.3.4' 'HESTIA'
  1641. rm $HESTIA/data/firewall/excludes.conf
  1642. check_ip_not_banned '1.2.3.4' 'HESTIA'
  1643. }
  1644. @test "Test create ipset" {
  1645. run v-add-firewall-ipset "country-nl" "https://raw.githubusercontent.com/ipverse/rir-ip/master/country/nl/ipv4-aggregated.txt" v4 yes
  1646. assert_success
  1647. refute_output
  1648. }
  1649. @test "Create firewall with Ipset" {
  1650. run v-add-firewall-rule 'DROP' 'ipset:country-nl' '8083,22' 'TCP' 'Test'
  1651. assert_success
  1652. refute_output
  1653. }
  1654. @test "List firewall rules" {
  1655. run v-list-firewall csv
  1656. assert_success
  1657. assert_line --partial '11,DROP,TCP,8083,22,ipset:country-nl'
  1658. }
  1659. @test "Delete firewall with Ipset" {
  1660. run v-delete-firewall-rule '11'
  1661. assert_success
  1662. refute_output
  1663. }
  1664. @test "Test delete ipset" {
  1665. run v-delete-firewall-ipset "country-nl"
  1666. assert_success
  1667. refute_output
  1668. }
  1669. #----------------------------------------------------------#
  1670. # PACKAGE #
  1671. #----------------------------------------------------------#
  1672. @test "Package: Create new Package" {
  1673. cp $HESTIA/data/packages/default.pkg /tmp/package
  1674. run v-add-user-package /tmp/package hestiatest
  1675. assert_success
  1676. refute_output
  1677. }
  1678. @test "Package: Assign user to new Package" {
  1679. run v-change-user-package $user hestiatest
  1680. assert_success
  1681. refute_output
  1682. }
  1683. @test "Package: Create new package (Duplicate)" {
  1684. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1685. run v-add-user-package /tmp/package hestiatest
  1686. assert_failure $E_EXISTS
  1687. }
  1688. @test "Package: Update new Package" {
  1689. sed -i "s/BANDWIDTH='unlimited'/BANDWIDTH='100'/g" /tmp/package
  1690. run v-add-user-package /tmp/package hestiatest yes
  1691. assert_success
  1692. refute_output
  1693. }
  1694. @test "Package: Update package of user" {
  1695. run v-change-user-package $user hestiatest
  1696. assert_success
  1697. refute_output
  1698. run grep "BANDWIDTH='100'" $HESTIA/data/users/$user/user.conf
  1699. assert_success
  1700. assert_output --partial "100"
  1701. }
  1702. @test "Package: Copy package Not Exists" {
  1703. run v-copy-user-package hestiadoesnotexists hestiatest2
  1704. assert_failure $E_NOTEXIST
  1705. }
  1706. @test "Package: Copy package" {
  1707. run v-copy-user-package hestiatest hestiatest2
  1708. assert_success
  1709. refute_output
  1710. }
  1711. @test "Package: Copy package Exists" {
  1712. run v-copy-user-package hestiatest hestiatest2
  1713. assert_failure $E_EXISTS
  1714. }
  1715. @test "Package: Delete package" {
  1716. run v-delete-user-package hestiatest
  1717. run v-delete-user-package hestiatest2
  1718. rm /tmp/package
  1719. assert_success
  1720. refute_output
  1721. run grep "BANDWIDTH='unlimited'" $HESTIA/data/users/$user/user.conf
  1722. assert_success
  1723. assert_output --partial "unlimited"
  1724. }
  1725. #----------------------------------------------------------#
  1726. # Backup user #
  1727. #----------------------------------------------------------#
  1728. @test "Backup: Backup user" {
  1729. run v-backup-user $user
  1730. assert_success
  1731. }
  1732. @test "Backup: List Backups" {
  1733. run v-list-user-backups $user plain
  1734. assert_success
  1735. assert_output --partial "$user"
  1736. }
  1737. @test "Backup: Delete backups" {
  1738. run v-delete-user-backup $user $(v-list-user-backups $user plain | cut -f1)
  1739. assert_success
  1740. run rm /backup/$user.log
  1741. }
  1742. #----------------------------------------------------------#
  1743. # Change owner scripts #
  1744. #----------------------------------------------------------#
  1745. @test "Change: Change domain owner" {
  1746. run v-change-domain-owner $domain $user2
  1747. assert_success
  1748. run v-restart-web
  1749. run v-restart-proxy
  1750. }
  1751. @test "Change: Add database" {
  1752. run v-add-database $user database dbuser 1234 mysql
  1753. assert_success
  1754. refute_output
  1755. # validate_database mysql database_name database_user password
  1756. validate_database mysql $database $dbuser 1234
  1757. }
  1758. @test "Change: Change database owner" {
  1759. run v-change-database-owner $database $user2
  1760. assert_success
  1761. validate_database mysql test-5286_database test-5286_dbuser 1234
  1762. }
  1763. @test "Change: Delete database" {
  1764. run v-delete-database $user2 test-5286_database
  1765. assert_success
  1766. refute_output
  1767. }
  1768. #----------------------------------------------------------#
  1769. # CLEANUP #
  1770. #----------------------------------------------------------#
  1771. @test "Mail: Delete domain" {
  1772. run v-delete-mail-domain $user2 $domain
  1773. assert_success
  1774. refute_output
  1775. }
  1776. @test "DNS: Delete domain" {
  1777. run v-delete-dns-domain $user2 $domain
  1778. assert_success
  1779. refute_output
  1780. }
  1781. @test "WEB: Delete domain" {
  1782. run v-delete-web-domain $user2 $domain
  1783. assert_success
  1784. refute_output
  1785. }
  1786. @test "Delete user" {
  1787. run v-delete-user $user
  1788. assert_success
  1789. refute_output
  1790. }
  1791. @test "Delete user2" {
  1792. run v-delete-user $user2
  1793. assert_success
  1794. refute_output
  1795. }
  1796. @test "Ip: Delete the test IP" {
  1797. run v-delete-sys-ip 198.18.0.125
  1798. assert_success
  1799. refute_output
  1800. }
  1801. @test 'assert()' {
  1802. touch '/var/log/test.log'
  1803. assert [ -e '/var/log/test.log' ]
  1804. }