test.bats 65 KB

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