1
0
mirror of https://github.com/deajan/obackup.git synced 2024-12-26 15:33:41 +01:00

Added encryption unit tests

This commit is contained in:
deajan 2016-09-02 13:13:53 +02:00
parent 694b73983a
commit f28b884c01
2 changed files with 664 additions and 78 deletions

View File

@ -1,11 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## obackup basic tests suite 2016083004 ## obackup basic tests suite 2016090101
#TODO: Must recreate files before each test set
OBACKUP_DIR="$(pwd)" OBACKUP_DIR="$(pwd)"
OBACKUP_DIR=${OBACKUP_DIR%%/dev*} OBACKUP_DIR=${OBACKUP_DIR%%/dev*}
DEV_DIR="$OBACKUP_DIR/dev" DEV_DIR="$OBACKUP_DIR/dev"
TESTS_DIR="$DEV_DIR/tests" TESTS_DIR="$DEV_DIR/tests"
CONF_DIR="$TESTS_DIR/conf"
LOCAL_CONF="local.conf"
PULL_CONF="pull.conf"
PUSH_CONF="push.conf"
OBACKUP_EXECUTABLE=obackup.sh OBACKUP_EXECUTABLE=obackup.sh
@ -21,6 +28,9 @@ TARGET_DIR_FILE_PULL="$TARGET_DIR/files-pull"
TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push" TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push"
TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push" TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push"
TARGET_DIR_SQL_CRYPT="$TARGET_DIR/sql-crypt"
TARGET_DIR_FILE_CRYPT="$TARGET_DIR/files-crypt"
SIMPLE_DIR="testData" SIMPLE_DIR="testData"
RECURSIVE_DIR="testDataRecursive" RECURSIVE_DIR="testDataRecursive"
@ -34,6 +44,7 @@ S_FILE_1="some file"
R_FILE_1="file_1" R_FILE_1="file_1"
R_FILE_2="file 2" R_FILE_2="file 2"
R_FILE_3="file 3" R_FILE_3="file 3"
N_FILE_1="non recurse file"
EXCLUDED_FILE="exclu.ded" EXCLUDED_FILE="exclu.ded"
@ -41,8 +52,88 @@ DATABASE_1="mysql.sql.xz"
DATABASE_2="performance_schema.sql.xz" DATABASE_2="performance_schema.sql.xz"
DATABASE_EXCLUDED="information_schema.sql.xz" DATABASE_EXCLUDED="information_schema.sql.xz"
CRYPT_EXTENSION=".obackup.gpg"
ROTATE_1_EXTENSION=".obackup.1"
PASSFILE="passfile"
function SetStableToYes () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i.tmp 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to yes" "0" $?
fi
}
function SetStableToOrigin () {
if [ "$IS_STABLE" == "no" ]; then
sed -i.tmp 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to origin value" "0" $?
fi
}
function SetEncryption () {
local confFile="${1}"
local value="${2}"
if [ $value == true ]; then
sed -i 's/^ENCRYPTION=no/ENCRYPTION=yes/' "$confFile"
assertEquals "Enable encryption in $file" "0" $?
else
sed -i 's/^ENCRYPTION=yes/ENCRYPTION=no/' "$confFile"
assertEquals "Disable encryption in $file" "0" $?
fi
}
function SetupGPG {
if ! gpg2 --list-keys | grep "John Doe" ; then
cat >gpgcommand <<EOF
%echo Generating a GPG Key
Key-Type: RSA
Key-Length: 4096
Name-Real: John Doe
Name-Comment: obackup-test-key
Name-Email: john@example.com
Expire-Date: 0
Passphrase: PassPhrase123
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
# Setup fast entropy
if type rndg > /dev/null 2>&1; then
rndg -r /dev/urandom
fi
gpg2 --batch --gen-key gpgcommand
echo $(gpg2 --list-keys)
rm -f gpgcommand
fi
echo "PassPhrase123" > "$TESTS_DIR/$PASSFILE"
}
function SetupSSH {
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
cat "${HOME}/.ssh/id_rsa_local.pub" >> "${HOME}/.ssh/authorized_keys"
chmod 600 "${HOME}/.ssh/authorized_keys"
ls ${HOME}/.ssh -lah
}
function oneTimeSetUp () { function oneTimeSetUp () {
source "$DEV_DIR/ofunctions.sh" source "$DEV_DIR/ofunctions.sh"
SetupGPG
SetupSSH
}
function SetUp () {
rm -rf "$SOURCE_DIR"
rm -rf "$TARGET_DIR"
mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1" mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR" mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR"
@ -52,6 +143,7 @@ function oneTimeSetUp () {
touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1" touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE" touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1" touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2" touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2 dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2
@ -59,6 +151,7 @@ function oneTimeSetUp () {
FilePresence=( FilePresence=(
"$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1" "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3"
@ -81,38 +174,23 @@ function oneTimeSetUp () {
DirectoriesExcluded=( DirectoriesExcluded=(
"$RECURSIVE_DIR/$R_EXCLUDED_DIR" "$RECURSIVE_DIR/$R_EXCLUDED_DIR"
) )
} }
function oneTimeTearDown () { function oneTimeTearDown () {
if [ "$IS_STABLE" == "no" ]; then SetStableToOrigin
sed -i 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
fi
#rm -rf $SOURCE_DIR
#rm -rf $TARGET_DIR
} }
function test_Merge () { function test_Merge () {
cd "$DEV_DIR" cd "$DEV_DIR"
./merge.sh ./merge.sh
assertEquals "Merging code" "0" $? assertEquals "Merging code" "0" $?
SetStableToYes
} }
function test_SetStable () { function test_LocalRun () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set as stable" "0" $?
fi
}
function test_FirstLocalRun () {
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/local.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do for file in "${FilePresence[@]}"; do
@ -139,27 +217,26 @@ function test_FirstLocalRun () {
[ -d "$TARGET_DIR_FILE_LOCAL/$directory" ] [ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $? assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
done done
}
function test_SecondLocalRun () { # Tests presence of rotated files
# Only tests presence of rotated files
cd "$OBACKUP_DIR" ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
./$OBACKUP_EXECUTABLE dev/tests/conf/local.conf
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file.obackup.1" ] [ -f "$TARGET_DIR_SQL_LOCAL/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $? assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done done
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1" ] [ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1]" "0" $? assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
} }
function test_FirstPullRun () { function test_PullRun () {
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/pull.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do for file in "${FilePresence[@]}"; do
@ -186,27 +263,27 @@ function test_FirstPullRun () {
[ -d "$TARGET_DIR_FILE_PULL/$directory" ] [ -d "$TARGET_DIR_FILE_PULL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $? assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
done done
}
function test_SecondPullRun () { # Tests presence of rotated files
# Only tests presence of rotated files
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/pull.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file.obackup.1" ] [ -f "$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $? assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done done
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR).obackup.1" ] [ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence" "0" $? assertEquals "File rotated Presence" "0" $?
} }
function test_FirstPushRun () { function test_PushRun () {
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/push.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do for file in "${FilePresence[@]}"; do
@ -233,21 +310,190 @@ function test_FirstPushRun () {
[ -d "$TARGET_DIR_FILE_PUSH/$directory" ] [ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $? assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
done done
}
function test_SecondPushRun () { # Tests presence of rotated files
# Only tests presence of rotated files
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/push.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file.obackup.1" ] [ -f "$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $? assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR).obackup.1" ] [ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence" "0" $? assertEquals "File rotated Presence" "0" $?
}
function test_EncryptLocalRun () {
SetEncryption "$CONF_DIR/$LOCAL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# TODO: Exclusion lists don't work with encrypted files yet
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
}
function test_EncryptPullRun () {
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PULL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PULL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$PULL_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
}
function test_EncryptPushRun () {
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PUSH_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$PUSH_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
} }
function test_WaitForTaskCompletion () { function test_WaitForTaskCompletion () {
@ -301,15 +547,15 @@ function test_WaitForTaskCompletion () {
function test_ParallelExec () { function test_ParallelExec () {
# Test if parallelExec works correctly # Test if parallelExec works correctly
cmd="sleep 10;sleep 10;sleep 10;sleep 10" cmd="sleep 2;sleep 2;sleep 2;sleep 2"
ParallelExec 4 "$cmd" ParallelExec 4 "$cmd"
assertEquals "ParallelExec test 1" "0" $? assertEquals "ParallelExec test 1" "0" $?
cmd="sleep 10;du /none;sleep 5" cmd="sleep 2;du /none;sleep 2"
ParallelExec 2 "$cmd" ParallelExec 2 "$cmd"
assertEquals "ParallelExec test 2" "1" $? assertEquals "ParallelExec test 2" "1" $?
cmd="sleep 19;du /none;sleep 10;du /none;sleep 4" cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
ParallelExec 3 "$cmd" ParallelExec 3 "$cmd"
assertEquals "ParallelExec test 3" "2" $? assertEquals "ParallelExec test 3" "2" $?
} }

View File

@ -1,11 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## obackup basic tests suite 2016083004 ## obackup basic tests suite 2016090101
#TODO: Must recreate files before each test set
OBACKUP_DIR="$(pwd)" OBACKUP_DIR="$(pwd)"
OBACKUP_DIR=${OBACKUP_DIR%%/dev*} OBACKUP_DIR=${OBACKUP_DIR%%/dev*}
DEV_DIR="$OBACKUP_DIR/dev" DEV_DIR="$OBACKUP_DIR/dev"
TESTS_DIR="$DEV_DIR/tests" TESTS_DIR="$DEV_DIR/tests"
CONF_DIR="$TESTS_DIR/conf"
LOCAL_CONF="local.conf"
PULL_CONF="pull.conf"
PUSH_CONF="push.conf"
OBACKUP_EXECUTABLE=obackup.sh OBACKUP_EXECUTABLE=obackup.sh
@ -21,6 +28,9 @@ TARGET_DIR_FILE_PULL="$TARGET_DIR/files-pull"
TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push" TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push"
TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push" TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push"
TARGET_DIR_SQL_CRYPT="$TARGET_DIR/sql-crypt"
TARGET_DIR_FILE_CRYPT="$TARGET_DIR/files-crypt"
SIMPLE_DIR="testData" SIMPLE_DIR="testData"
RECURSIVE_DIR="testDataRecursive" RECURSIVE_DIR="testDataRecursive"
@ -34,6 +44,7 @@ S_FILE_1="some file"
R_FILE_1="file_1" R_FILE_1="file_1"
R_FILE_2="file 2" R_FILE_2="file 2"
R_FILE_3="file 3" R_FILE_3="file 3"
N_FILE_1="non recurse file"
EXCLUDED_FILE="exclu.ded" EXCLUDED_FILE="exclu.ded"
@ -41,8 +52,88 @@ DATABASE_1="mysql.sql.xz"
DATABASE_2="performance_schema.sql.xz" DATABASE_2="performance_schema.sql.xz"
DATABASE_EXCLUDED="information_schema.sql.xz" DATABASE_EXCLUDED="information_schema.sql.xz"
CRYPT_EXTENSION=".obackup.gpg"
ROTATE_1_EXTENSION=".obackup.1"
PASSFILE="passfile"
function SetStableToYes () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i.tmp 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to yes" "0" $?
fi
}
function SetStableToOrigin () {
if [ "$IS_STABLE" == "no" ]; then
sed -i.tmp 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to origin value" "0" $?
fi
}
function SetEncryption () {
local confFile="${1}"
local value="${2}"
if [ $value == true ]; then
sed -i 's/^ENCRYPTION=no/ENCRYPTION=yes/' "$confFile"
assertEquals "Enable encryption in $file" "0" $?
else
sed -i 's/^ENCRYPTION=yes/ENCRYPTION=no/' "$confFile"
assertEquals "Disable encryption in $file" "0" $?
fi
}
function SetupGPG {
if ! gpg2 --list-keys | grep "John Doe" ; then
cat >gpgcommand <<EOF
%echo Generating a GPG Key
Key-Type: RSA
Key-Length: 4096
Name-Real: John Doe
Name-Comment: obackup-test-key
Name-Email: john@example.com
Expire-Date: 0
Passphrase: PassPhrase123
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
# Setup fast entropy
if type rndg > /dev/null 2>&1; then
rndg -r /dev/urandom
fi
gpg2 --batch --gen-key gpgcommand
echo $(gpg2 --list-keys)
rm -f gpgcommand
fi
echo "PassPhrase123" > "$TESTS_DIR/$PASSFILE"
}
function SetupSSH {
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
cat "${HOME}/.ssh/id_rsa_local.pub" >> "${HOME}/.ssh/authorized_keys"
chmod 600 "${HOME}/.ssh/authorized_keys"
ls ${HOME}/.ssh -lah
}
function oneTimeSetUp () { function oneTimeSetUp () {
source "$DEV_DIR/ofunctions.sh" source "$DEV_DIR/ofunctions.sh"
SetupGPG
SetupSSH
}
function SetUp () {
rm -rf "$SOURCE_DIR"
rm -rf "$TARGET_DIR"
mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1" mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR" mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR"
@ -52,6 +143,7 @@ function oneTimeSetUp () {
touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1" touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE" touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1" touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2" touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2 dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2
@ -59,6 +151,7 @@ function oneTimeSetUp () {
FilePresence=( FilePresence=(
"$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1" "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3"
@ -81,38 +174,23 @@ function oneTimeSetUp () {
DirectoriesExcluded=( DirectoriesExcluded=(
"$RECURSIVE_DIR/$R_EXCLUDED_DIR" "$RECURSIVE_DIR/$R_EXCLUDED_DIR"
) )
} }
function oneTimeTearDown () { function oneTimeTearDown () {
if [ "$IS_STABLE" == "no" ]; then SetStableToOrigin
sed -i 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
fi
#rm -rf $SOURCE_DIR
#rm -rf $TARGET_DIR
} }
function test_Merge () { function test_Merge () {
cd "$DEV_DIR" cd "$DEV_DIR"
./merge.sh ./merge.sh
assertEquals "Merging code" "0" $? assertEquals "Merging code" "0" $?
SetStableToYes
} }
function test_SetStable () { function test_LocalRun () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set as stable" "0" $?
fi
}
function test_FirstLocalRun () {
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR" cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE dev/tests/conf/local.conf ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do for file in "${FilePresence[@]}"; do
@ -139,21 +217,283 @@ function test_FirstLocalRun () {
[ -d "$TARGET_DIR_FILE_LOCAL/$directory" ] [ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $? assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
done done
}
function test_SecondLocalRun () { # Tests presence of rotated files
# Only tests presence of rotated files
cd "$OBACKUP_DIR" ./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
./$OBACKUP_EXECUTABLE dev/tests/conf/local.conf
assertEquals "Return code" "0" $? assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file.obackup.1" ] [ -f "$TARGET_DIR_SQL_LOCAL/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $? assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done done
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1" ] [ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1]" "0" $? assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
}
function test_PullRun () {
# Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PULL/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PULL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence" "0" $?
}
function test_PushRun () {
# Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence" "0" $?
}
function test_EncryptLocalRun () {
SetEncryption "$CONF_DIR/$LOCAL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# TODO: Exclusion lists don't work with encrypted files yet
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
}
function test_EncryptPullRun () {
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PULL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PULL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$PULL_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
}
function test_EncryptPushRun () {
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PUSH_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
SetEncryption "$CONF_DIR/$PUSH_CONF" false
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt sql storage" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage" "0" $?
} }
function test_WaitForTaskCompletion () { function test_WaitForTaskCompletion () {
@ -207,15 +547,15 @@ function test_WaitForTaskCompletion () {
function test_ParallelExec () { function test_ParallelExec () {
# Test if parallelExec works correctly # Test if parallelExec works correctly
cmd="sleep 10;sleep 10;sleep 10;sleep 10" cmd="sleep 2;sleep 2;sleep 2;sleep 2"
ParallelExec 4 "$cmd" ParallelExec 4 "$cmd"
assertEquals "ParallelExec test 1" "0" $? assertEquals "ParallelExec test 1" "0" $?
cmd="sleep 10;du /none;sleep 5" cmd="sleep 2;du /none;sleep 2"
ParallelExec 2 "$cmd" ParallelExec 2 "$cmd"
assertEquals "ParallelExec test 2" "1" $? assertEquals "ParallelExec test 2" "1" $?
cmd="sleep 19;du /none;sleep 10;du /none;sleep 4" cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
ParallelExec 3 "$cmd" ParallelExec 3 "$cmd"
assertEquals "ParallelExec test 3" "2" $? assertEquals "ParallelExec test 3" "2" $?
} }