test.bats 52 KB

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