Skip to content

Commit

Permalink
[tests] move checker functions to separate file
Browse files Browse the repository at this point in the history
also clean up minor typos etc
  • Loading branch information
MalinAhlberg committed Dec 20, 2024
1 parent 8675a14 commit 50bdc3b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 57 deletions.
28 changes: 28 additions & 0 deletions .github/integration/scripts/checkers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -e

# Function checking that file(s) were encrypted
function check_encrypted_file {
for k do
echo "working with $k"
output=$(head -c 8 "$k")

if [[ "$output" == "crypt4gh" ]]; then
echo "Encrypted data file: $k"
else
echo "Failed to encrypt file: $k"
exit 1
fi
done
}


# Function checking that a file was uploaded to the S3 backend
function check_uploaded_file {
if s3cmd -c testing/directS3 ls s3://"$1" | grep -q "$2"; then
echo "Uploaded encrypted file to s3 backend"
else
echo "Failed to upload file to s3 backend"
exit 1
fi
}
34 changes: 8 additions & 26 deletions .github/integration/tests/10_encrypt_decrypt.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
#!/bin/bash
set -e

# Function checking that a file was encrypted
function check_encypted_file() {

for k in $1
do
output=$(head -c 8 "$k")

if [[ "$output" = "crypt4gh" ]]; then
echo "Encrypted data file"
else
echo "Failed to encrypt file"
exit 1
fi
done
}

# inferred from access_key in testing/s3cmd.conf
user=test_dummy.org
test_dir=$(dirname "$0")
source "$test_dir/../scripts/checkers.sh"

# Create random file
dd if=/dev/urandom of=data_file count=1 bs=1M
Expand All @@ -34,16 +17,15 @@ fi
# Encrypt a file
./sda-cli encrypt -key sda_key.pub.pem data_file

files="data_file.c4gh"
check_encypted_file $files
check_encrypted_file data_file.c4gh


# Create folder and encrypt files in it
cp data_file data_file1
mkdir data_files_enc
./sda-cli encrypt -key sda_key.pub.pem -outdir data_files_enc data_file data_file1

check_encypted_file "data_files_enc/data_file.c4gh data_files_enc/data_file1.c4gh"
check_encrypted_file data_files_enc/data_file.c4gh data_files_enc/data_file1.c4gh

# Test multiple pub key encryption

Expand All @@ -55,7 +37,7 @@ do
else
echo "Failed to create key pair for encryption"
exit 1
fi
fi
done

# Create file with concatenated pub keys
Expand All @@ -67,7 +49,7 @@ cp data_file data_file_keys

# Encrypt with multiple key flag calls
./sda-cli encrypt -key sda_key.pub.pem -key sda_key2.pub.pem data_file_keys
check_encypted_file "data_file_keys.c4gh"
check_encrypted_file data_file_keys.c4gh
# Decrypt file with both keys, one at the time
for key in sda_key sda_key2
do
Expand All @@ -86,7 +68,7 @@ rm data_file_keys.c4gh

# Encrypt with a single key and with a concatenated key file
./sda-cli encrypt -key sda_key.pub.pem -key sda_keys data_file_keys
check_encypted_file "data_file_keys.c4gh"
check_encrypted_file data_file_keys.c4gh

# Decrypt file with all three keys
for key in sda_key sda_key1 sda_key2
Expand All @@ -105,7 +87,7 @@ rm data_file_keys.c4gh

# Encrypt with concatenated key file
./sda-cli encrypt -key sda_keys data_file_keys
check_encypted_file "data_file_keys.c4gh"
check_encrypted_file data_file_keys.c4gh

# Decrypt file with all keys
for key in sda_key1 sda_key2
Expand Down
36 changes: 5 additions & 31 deletions .github/integration/tests/20_upload.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
#!/bin/bash
set -e
test_dir=$(dirname "$0")
source "$test_dir/../scripts/checkers.sh"

# inferred from access_key in testing/s3cmd.conf
user=test_dummy.org


# Function checking that a file was encrypted
function check_encypted_file() {

for k in $1
do
output=$(head -c 8 "$k")

if [[ "$output" = "crypt4gh" ]]; then
echo "Encrypted data file"
else
echo "Failed to encrypt file"
exit 1
fi
done
}

# Function checking that a file was uploaded to the S3 backend
function check_uploaded_file() {
# TODO if emtpy, this will fail silently
output=$(s3cmd -c testing/directS3 ls s3://"$1" | grep -q "$2")
if $output ; then
echo "Uploaded encrypted file to s3 backend"
else
echo "Failed to upload file to s3 backend"
exit 1
fi
}


# Create folder with subfolder structure and add some encrypted files
mkdir data_files_enc/dir1 data_files_enc/dir1/dir2
cp data_files_enc/data_file.c4gh data_files_enc/data_file3.c4gh
Expand All @@ -47,7 +21,7 @@ check_uploaded_file "test/$user/data_file.c4gh" data_file.c4gh


# Try to upload a file twice with the --force-overwrite flag
output=$(./sda-cli -config testing/s3cmd.conf upload --force-overwrite data_file.c4gh)
./sda-cli -config testing/s3cmd.conf upload --force-overwrite data_file.c4gh


# Test upload all files from a folder, one by one
Expand Down Expand Up @@ -105,7 +79,7 @@ cp data_file data_files_unenc/. && cp data_file data_files_unenc/dir1/data_file1
uploadDir="testEncryptUpload"
./sda-cli -config testing/s3cmd.conf upload -encrypt-with-key sda_key.pub.pem -r data_files_unenc -targetDir "$uploadDir"

check_encypted_file "data_files_unenc/data_file.c4gh" "data_files_unenc/dir1/data_file1.c4gh"
check_encrypted_file data_files_unenc/data_file.c4gh data_files_unenc/dir1/data_file1.c4gh

for k in data_files_unenc/data_file.c4gh data_files_unenc/dir1/data_file1.c4gh
do
Expand Down

0 comments on commit 50bdc3b

Please sign in to comment.