Skip to content

Commit d4db3c9

Browse files
authored
Improve general tests + Add support for PostgreSQL testing (hestiacp#2006)
* Split up restore test and General test * Add multiple tests + add support for PostgreSQL tests * Fix 2 minor bugs * Use .pgpass instead source
1 parent 0e7cb01 commit d4db3c9

File tree

6 files changed

+761
-489
lines changed

6 files changed

+761
-489
lines changed

.drone.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ platform:
1919
arch: amd64
2020

2121
steps:
22-
- name: Down submodules
22+
- name: Download submodules
2323
image: alpine/git
2424
commands:
2525
- git submodule update --init --recursive
26-
- name: build-install
26+
- name: Build Hestia package and install
2727
commands:
2828
- ./src/hst_autocompile.sh --hestia --install '~localsrc'
2929
- name: Run Bats
3030
commands:
3131
- bats ./test/test.bats
32+
- bats ./test/restore.bats
3233
- name: Run Check PHP
3334
commands:
3435
- ./test/check_php.sh
@@ -57,16 +58,17 @@ platform:
5758
arch: amd64
5859

5960
steps:
60-
- name: Down submodules
61+
- name: Download submodules
6162
image: alpine/git
6263
commands:
6364
- git submodule update --init --recursive
64-
- name: build-install
65+
- name: Build Hestia package install
6566
commands:
6667
- ./src/hst_autocompile.sh --hestia --install '~localsrc'
6768
- name: Run Bats
6869
commands:
6970
- bats ./test/test.bats
71+
- bats ./test/restore.bats
7072
- name: Run Check PHP
7173
commands:
7274
- ./test/check_php.sh
@@ -76,4 +78,4 @@ trigger:
7678

7779
---
7880
kind: signature
79-
hmac: 206d86147c4ee57339c4af654f073c0d2f136f591c890eb4244ccaef087c433f
81+
hmac: f3763c63fcebe50a2ad24dc3fb2ab3191cba15750e4dd80be82cea87466d96bc

bin/v-add-database

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ is_object_unsuspended "../../../conf/$type" 'DBHOST' "$host"
5858
#is_charset_valid
5959
is_package_full 'DATABASES'
6060
is_password_valid
61+
62+
if [ "$type" = "pgsql" ]; then
63+
exclude="-"
64+
if [[ "$dbuser" =~ $exclude ]]; then
65+
check_result $E_INVALID "invalid database user format"
66+
fi
67+
if [[ "$database" =~ $exclude ]]; then
68+
check_result $E_INVALID "invalid database format"
69+
fi
70+
fi
71+
6172
dbpass="$password"
6273

6374
# Perform verification if read-only mode is enabled

bin/v-change-database-user

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ get_database_values
6565

6666
#Fix issue #1084 with "Upper case not allowed with PGSQL"
6767
if [ "$TYPE" = "pgsql" ]; then
68-
dbuser=$(echo $dbuser | tr '[:upper:]' '[:lower:]');
68+
dbuser=$(echo $dbuser | tr '[:upper:]' '[:lower:]');
69+
exclude="-"
70+
if [[ "$dbuser" =~ $exclude ]]; then
71+
check_result $E_INVALID "invalid database user format"
72+
fi
6973
fi
7074

7175
# Rebuild database

func/db.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ add_pgsql_database() {
284284
query="GRANT CONNECT ON DATABASE template1 to $dbuser"
285285
psql_query "$query" > /dev/null
286286

287-
query="SELECT rolpassword FROM pg_authid WHERE rolname='$dbuser';"
287+
query="SELECT rolpassword FROM pg_authid WHERE rolname='$dbuser'"
288288
md5=$(psql_query "$query" | grep md5 | cut -f 2 -d \ )
289289
}
290290

@@ -350,7 +350,7 @@ change_pgsql_password() {
350350
query="ALTER ROLE $DBUSER WITH LOGIN PASSWORD '$dbpass'"
351351
psql_query "$query" > /dev/null
352352

353-
query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER';"
353+
query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER'"
354354
md5=$(psql_query "$query" | grep md5 |cut -f 2 -d \ )
355355
}
356356

@@ -387,9 +387,9 @@ delete_pgsql_database() {
387387
psql_query "$query" > /dev/null
388388

389389
if [ "$(grep "DBUSER='$DBUSER'" $USER_DATA/db.conf |wc -l)" -lt 2 ]; then
390-
query="REVOKE CONNECT ON DATABASE template1 FROM $db_user"
390+
query="REVOKE CONNECT ON DATABASE template1 FROM $DBUSER"
391391
psql_query "$query" > /dev/null
392-
query="DROP ROLE $db_user"
392+
query="DROP ROLE $DBUSER"
393393
psql_query "$query" > /dev/null
394394
fi
395395
}
@@ -413,9 +413,9 @@ dump_pgsql_database() {
413413

414414
psql_dump $dump $database
415415

416-
query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER';"
416+
query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER'"
417417
md5=$(psql_query "$query" | head -n1 | cut -f 2 -d \ )
418-
pw_str="UPDATE pg_authid SET rolpassword='$md5' WHERE rolname='$DBUSER';"
418+
pw_str="UPDATE pg_authid SET rolpassword='$md5' WHERE rolname='$DBUSER'"
419419
gr_str="GRANT ALL PRIVILEGES ON DATABASE $database to '$DBUSER'"
420420
echo -e "$pw_str\n$gr_str" >> $grants
421421
}

0 commit comments

Comments
 (0)