-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_encrypt_decrypt.sh
executable file
·65 lines (60 loc) · 1.99 KB
/
test_encrypt_decrypt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -e
# Test valid encryption of a file
echo "1. Test valid encryption of a file"
touch test_file.txt
./encrypt_decrypt.sh -m enc -s test_file.txt <<< "password"
if [ ! -f "test_file.txt.enc" ]; then
echo "Test failed: File not encrypted"
exit 1
else
echo "Success: 1. Test valid encryption of a file"
fi
rm test_file.txt test_file.txt.enc
# Test valid encryption of a folder
echo "2. Test valid encryption of a folder"
mkdir test_folder
touch test_folder/test_file1.txt test_folder/test_file2.txt
./encrypt_decrypt.sh -m enc -s test_folder <<< "password"
if [ ! -f "test_folder.enc" ]; then
echo "Test failed: Folder not encrypted"
exit 1
else
echo "Success: 2. Test valid encryption of a folder"
fi
rm -rf test_folder test_folder.enc
# Test valid decryption of a file
echo "3. Test valid decryption of a file"
touch test_file.txt
./encrypt_decrypt.sh -m enc -s test_file.txt <<< "password"
./encrypt_decrypt.sh -m dec -s test_file.txt.enc <<< "password"
if [ ! -f "test_file.txt" ]; then
echo "Test failed: File not decrypted"
exit 1
else
echo "Success: 3. Test valid decryption of a file"
fi
rm test_file.txt test_file.txt.enc
# Test valid decryption of a folder
echo "4. Test valid decryption of a folder"
mkdir test_folder
touch test_folder/test_file1.txt test_folder/test_file2.txt
./encrypt_decrypt.sh -m enc -s test_folder <<< "password"
./encrypt_decrypt.sh -m dec -s test_folder.enc <<< "password"
if [ ! -d "test_folder" ]; then
echo "Test failed: Folder not decrypted"
exit 1
else
echo "Success: 4. Test valid decryption of a folder"
fi
rm -rf test_folder test_folder.enc
# Test valid encryption and decryption of a string
echo "5. Test valid encryption of a string"
result=$(./encrypt_decrypt.sh -m enc -s "test_folder" <<< "password")
result_dec=$(./encrypt_decrypt.sh -m dec -s $result <<< "password")
if [ $result_dec != "test_folder" ]; then
echo "Test failed: String not encrypted correctly"
exit 1
else
echo "Success: 5. Test valid encryption of a string"
fi