Skip to content

Commit

Permalink
Add large-file test to unit-test.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
JElchison committed Apr 1, 2018
1 parent 3afcf14 commit 53709d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ tags
##########

*.key
large.bin
21 changes: 20 additions & 1 deletion unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LOCKBOX_PATH=/tmp/lockbox
TOTAL_NUMBER_FILES=100
TEST_FILE_NUMBER=10
ROOT_FILE_NUMBER=42
LARGE_FILE_NAME=large.bin

# setup contents of lockbox
rm -rf "$LOCKBOX_PATH" || true
Expand All @@ -18,6 +19,12 @@ for I in $(seq $TOTAL_NUMBER_FILES); do
done
sudo chown root:root "$LOCKBOX_PATH/$ROOT_FILE_NUMBER"

# setup large file contents.
# must be larger than 8KiB (larger than block size in OpenSSL's enc).
head -c 10000 /dev/urandom > "$LARGE_FILE_NAME"
cp -v "$LARGE_FILE_NAME" "$LOCKBOX_PATH/$LARGE_FILE_NAME"
# leave original copy in CWD for final comparison.

# print summary info about lockbox
ls -li "$LOCKBOX_PATH"
xxd -g4 "$LOCKBOX_PATH/$TEST_FILE_NUMBER"
Expand All @@ -26,10 +33,12 @@ xxd -g4 "$LOCKBOX_PATH/$ROOT_FILE_NUMBER"
# record inode and size info
ORIG_INODE=$(ls -i "$LOCKBOX_PATH/$TEST_FILE_NUMBER" | cut -d ' ' -f 1)
ORIG_SIZE=$(stat -c %s "$LOCKBOX_PATH/$TEST_FILE_NUMBER")
ORIG_LARGE_INODE=$(ls -i "$LOCKBOX_PATH/$LARGE_FILE_NAME" | cut -d ' ' -f 1)
ORIG_LARGE_SIZE=$(stat -c %s "$LOCKBOX_PATH/$LARGE_FILE_NAME")

# generate key to be used for encryption
./gen_key.sh "$KEY_FILE_PATH"
# encrypt lockbox
# encrypt lockbox. intentionally omitting '-e' here to test default mode.
./lockbox.sh "$LOCKBOX_PATH" "$(xxd -p "$KEY_FILE_PATH" | tr -d '\n')"

# print summary info about lockbox
Expand All @@ -42,12 +51,17 @@ NEW_INODE=$(ls -i "$LOCKBOX_PATH/$TEST_FILE_NUMBER" | cut -d ' ' -f 1)
test "$NEW_INODE" -eq "$ORIG_INODE"
NEW_SIZE=$(stat -c %s "$LOCKBOX_PATH/$TEST_FILE_NUMBER")
test "$NEW_SIZE" -eq "$ORIG_SIZE"
NEW_LARGE_INODE=$(ls -i "$LOCKBOX_PATH/$LARGE_FILE_NAME" | cut -d ' ' -f 1)
test "$NEW_LARGE_INODE" -eq "$ORIG_LARGE_INODE"
NEW_LARGE_SIZE=$(stat -c %s "$LOCKBOX_PATH/$LARGE_FILE_NAME")
test "$NEW_LARGE_SIZE" -eq "$ORIG_LARGE_SIZE"

# verify that file owned by root has not been modified
diff -q "$LOCKBOX_PATH/$ROOT_FILE_NUMBER" <(echo "Test $ROOT_FILE_NUMBER")

# verify that file contents have been changed
if diff -q "$LOCKBOX_PATH/$TEST_FILE_NUMBER" <(echo "Test $TEST_FILE_NUMBER"); then false; fi
if diff -q "$LOCKBOX_PATH/$LARGE_FILE_NAME" "$LARGE_FILE_NAME"; then false; fi

# decrypt lockbox
./lockbox.sh -d "$LOCKBOX_PATH" "$(xxd -p "$KEY_FILE_PATH" | tr -d '\n')"
Expand All @@ -62,11 +76,16 @@ NEW_INODE=$(ls -i "$LOCKBOX_PATH/$TEST_FILE_NUMBER" | cut -d ' ' -f 1)
test "$NEW_INODE" -eq "$ORIG_INODE"
NEW_SIZE=$(stat -c %s "$LOCKBOX_PATH/$TEST_FILE_NUMBER")
test "$NEW_SIZE" -eq "$ORIG_SIZE"
NEW_LARGE_INODE=$(ls -i "$LOCKBOX_PATH/$LARGE_FILE_NAME" | cut -d ' ' -f 1)
test "$NEW_LARGE_INODE" -eq "$ORIG_LARGE_INODE"
NEW_LARGE_SIZE=$(stat -c %s "$LOCKBOX_PATH/$LARGE_FILE_NAME")
test "$NEW_LARGE_SIZE" -eq "$ORIG_LARGE_SIZE"

# verify that all files are back to original contents
for I in $(seq $TOTAL_NUMBER_FILES); do
diff -q "$LOCKBOX_PATH/$I" <(echo "Test $I")
done
diff -q "$LARGE_FILE_NAME" "$LOCKBOX_PATH/$LARGE_FILE_NAME"

# print success
echo "Test succeeded"

0 comments on commit 53709d9

Please sign in to comment.