@@ -18,6 +18,8 @@ function setup() {
1818 echo ' userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
1919 echo ' HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
2020 echo ' domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
21+ echo ' database=test-5285_database' >> /tmp/hestia-test-env.sh
22+ echo ' dbuser=test-5285_dbuser' >> /tmp/hestia-test-env.sh
2123 fi
2224
2325 source /tmp/hestia-test-env.sh
@@ -133,6 +135,40 @@ function validate_webmail_domain() {
133135 fi
134136}
135137
138+ function validate_database(){
139+ local database=$1
140+ local dbuser=$2
141+ local password=$3
142+
143+ host_str=$( grep " HOST='localhost'" $HESTIA /conf/mysql.conf)
144+ parse_object_kv_list " $host_str "
145+ if [ -z $PORT ]; then PORT=3306; fi
146+ if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ]; then
147+ echo " Error: mysql config parsing failed"
148+ log_event " $E_PARSING " " $ARGUMENTS "
149+ exit $E_PARSING
150+ fi
151+
152+ # Create an connection to verify correct username / password has been set correctly
153+ tmpfile=$( mktemp /tmp/mysql.XXXXXX)
154+ echo " [client]" > $tmpfile
155+ echo " host='$HOST '" >> $tmpfile
156+ echo " user='$dbuser '" >> $tmpfile
157+ echo " password='$password '" >> $tmpfile
158+ echo " port='$PORT '" >> $tmpfile
159+ chmod 600 $tmpfile
160+
161+ sql_tmp=$( mktemp /tmp/query.XXXXXX)
162+ echo " show databases;" > $sql_tmp
163+ run mysql --defaults-file=$tmpfile < " $sql_tmp "
164+
165+ assert_success
166+ assert_output --partial " $database "
167+
168+ rm -f " $sql_tmp "
169+ rm -f " $tmpfile "
170+ }
171+
136172# ----------------------------------------------------------#
137173# MAIN #
138174# ----------------------------------------------------------#
@@ -149,7 +185,6 @@ function validate_webmail_domain() {
149185# ----------------------------------------------------------#
150186
151187@test " Check reverse Dns validation" {
152-
153188 # 1. PTR record for a IP should return a hostname(reverse) which in turn must resolve to the same IP addr(forward). (Full circle)
154189 # `-> not implemented in `is_ip_rdns_valid` yet and also not tested here
155190 # 2. Reject rPTR records that match generic dynamic IP pool patterns
@@ -616,6 +651,61 @@ function validate_webmail_domain() {
616651# DB #
617652# ----------------------------------------------------------#
618653
654+ @test " DB: Add database (mysql)" {
655+ run v-add-database $user database dbuser 1234 mysql
656+ assert_success
657+ refute_output
658+ # validate_database database_name database_user password
659+ validate_database $database $dbuser 1234
660+ }
661+ @test " DB: Add Database (mysql) (Duplicate)" {
662+ run v-add-database $user database dbuser 1234 mysql
663+ assert_failure $E_EXISTS
664+ }
665+
666+ @test " DB: Rebuild Database (mysql)" {
667+ run v-rebuild-database $user $database
668+ assert_success
669+ refute_output
670+ }
671+
672+ @test " DB: Change database user password (mysql)" {
673+ run v-change-database-password $user $database 123456
674+ assert_success
675+ refute_output
676+
677+ validate_database $database $dbuser 123456
678+ }
679+
680+ @test " DB: Change database user (mysql)" {
681+ run v-change-database-user $user $database database
682+ assert_success
683+ refute_output
684+ validate_database $database $database 123456
685+ }
686+
687+ @test " DB: Suspend database" {
688+ run v-suspend-database $user $database
689+ assert_success
690+ refute_output
691+ }
692+
693+ @test " DB: Unsuspend database" {
694+ run v-unsuspend-database $user $database
695+ assert_success
696+ refute_output
697+ }
698+
699+ @test " DB: Delete database" {
700+ run v-delete-database $user $database
701+ assert_success
702+ refute_output
703+ }
704+
705+ @test " DB: Delete missing database" {
706+ run v-delete-database $user $database
707+ assert_failure $E_NOTEXIST
708+ }
619709
620710# ----------------------------------------------------------#
621711# Backup / Restore #
@@ -636,7 +726,20 @@ function validate_webmail_domain() {
636726# - hestia111_db
637727# cron:
638728# - 1: /bin/true
639- #
729+ # Hestia 1.3.1 archive contains (As zstd format)
730+ # user: hestia111
731+ # web:
732+ # - test.hestia.com (+SSL self-signed)
733+ # dns:
734+ # - test.hestia.com
735+ # mail:
736+ # - test.hestia.com
737+ # mail acc:
738+ # - testaccount@test.hestia.com
739+ # db:
740+ # - hestia111_db
741+ # cron:
742+ # - 1: /bin/true
640743# Vesta 0.9.8-23 archive contains:
641744# user: vesta09823
642745# web:
@@ -788,6 +891,139 @@ function validate_webmail_domain() {
788891 refute_output
789892}
790893
894+ @test " Restore[3]: Hestia (zstd) archive for a non-existing user" {
895+ if [ -d " $HOMEDIR /$userbk " ]; then
896+ run v-delete-user $userbk
897+ assert_success
898+ refute_output
899+ fi
900+
901+ mkdir -p /backup
902+
903+ local archive_name=" hestia111.zstd"
904+ run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache " https://hestiacp.com/testing/data/${archive_name} .tar" -O " /backup/${archive_name} .tar"
905+ assert_success
906+
907+ run v-restore-user $userbk " ${archive_name} .tar"
908+ assert_success
909+
910+ rm " /backup/${archive_name} .tar"
911+ }
912+
913+ @test " Restore[3]: From Hestia [WEB]" {
914+ local domain=" test.hestia.com"
915+ validate_web_domain $userbk $domain ' Hello Hestia'
916+ }
917+
918+ @test " Restore[3]: From Hestia [DNS]" {
919+ local domain=" test.hestia.com"
920+
921+ run v-list-dns-domain $userbk $domain
922+ assert_success
923+
924+ run nslookup $domain 127.0.0.1
925+ assert_success
926+ }
927+
928+ @test " Restore[3]: From Hestia [MAIL]" {
929+ local domain=" test.hestia.com"
930+
931+ run v-list-mail-domain $userbk $domain
932+ assert_success
933+ }
934+
935+ @test " Restore[3]: From Hestia [MAIL-Account]" {
936+ local domain=" test.hestia.com"
937+
938+ run v-list-mail-account $userbk $domain testaccount
939+ assert_success
940+ }
941+
942+ @test " Restore[3]: From Hestia [DB]" {
943+ run v-list-database $userbk " ${userbk} _db"
944+ assert_success
945+ }
946+
947+ @test " Restore[3]: From Hestia [CRON]" {
948+ run v-list-cron-job $userbk 1
949+ assert_success
950+ }
951+
952+ @test " Restore[3]: From Hestia Cleanup" {
953+ run v-delete-user $userbk
954+ assert_success
955+ refute_output
956+ }
957+
958+ @test " Restore[4]: Hestia (zstd) archive for a existing user" {
959+ if [ -d " $HOMEDIR /$userbk " ]; then
960+ run v-delete-user $userbk
961+ assert_success
962+ refute_output
963+ fi
964+
965+ if [ ! -d " $HOMEDIR /$userbk " ]; then
966+ run v-add-user $userbk $userbk test@hestia.com
967+ assert_success
968+ fi
969+
970+ mkdir -p /backup
971+
972+ local archive_name=" hestia111.zstd"
973+ run wget --quiet --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache " https://hestiacp.com/testing/data/${archive_name} .tar" -O " /backup/${archive_name} .tar"
974+ assert_success
975+
976+ run v-restore-user $userbk " ${archive_name} .tar"
977+ assert_success
978+
979+ rm " /backup/${archive_name} .tar"
980+ }
981+
982+ @test " Restore[4]: From Hestia [WEB]" {
983+ local domain=" test.hestia.com"
984+ validate_web_domain $userbk $domain ' Hello Hestia'
985+ }
986+
987+ @test " Restore[4]: From Hestia [DNS]" {
988+ local domain=" test.hestia.com"
989+
990+ run v-list-dns-domain $userbk $domain
991+ assert_success
992+
993+ run nslookup $domain 127.0.0.1
994+ assert_success
995+ }
996+
997+ @test " Restore[4]: From Hestia [MAIL]" {
998+ local domain=" test.hestia.com"
999+
1000+ run v-list-mail-domain $userbk $domain
1001+ assert_success
1002+ }
1003+
1004+ @test " Restore[4]: From Hestia [MAIL-Account]" {
1005+ local domain=" test.hestia.com"
1006+
1007+ run v-list-mail-account $userbk $domain testaccount
1008+ assert_success
1009+ }
1010+
1011+ @test " Restore[4]: From Hestia [DB]" {
1012+ run v-list-database $userbk " ${userbk} _db"
1013+ assert_success
1014+ }
1015+
1016+ @test " Restore[4]: From Hestia [CRON]" {
1017+ run v-list-cron-job $userbk 1
1018+ assert_success
1019+ }
1020+
1021+ @test " Restore[4]: From Hestia Cleanup" {
1022+ run v-delete-user $userbk
1023+ assert_success
1024+ refute_output
1025+ }
1026+
7911027
7921028# Testing Vesta Backups
7931029@test " Restore[1]: Vesta archive for a non-existing user" {
0 commit comments