-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_get_key.sh
executable file
·90 lines (71 loc) · 1.88 KB
/
test_get_key.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -e
set -o pipefail
# Use aa list instead of full decryption
FAST=1
FAILED=0
fail() {
echo "$1"
echo ""
if [ "$CI" = "true" ]; then
FAILED=1
else
exit 1
fi
}
rm -rf tmp
mkdir tmp
for i in tests/*; do
i=$(basename "$i")
TEST_DIR="tests/$i"
TMP_DIR="tmp/$i"
echo "Testing $i"
if [ -e "$TEST_DIR/skip_get_key" ]; then
echo "Skipping $i"
echo ""
continue
fi
if [ -e "$TEST_DIR/fast_unsupported" ]; then
FAST=0
fi
mkdir -p "$TMP_DIR"
ret=0
# Ensure expected key is valid first
if [ "$FAST" -eq 1 ]; then
aa list -i "$TEST_DIR/encrypted.aea" -key-value "base64:$(cat tests/"$i"/expected.txt)" || ret=$?
else
aea decrypt -i "$TEST_DIR/encrypted.aea" -o "/dev/null" -key-value "base64:$(cat tests/"$i"/expected.txt)" || ret=$?
fi
if [ $ret -ne 0 ]; then
fail "Failed to decrypt with expected key"
continue
fi
# Get the key
python3 get_key.py "$TEST_DIR/encrypted.aea" | tr -d '\n' >"$TMP_DIR/actual.txt" || ret=$?
if [ $ret -ne 0 ]; then
fail "Failed to get key"
continue
fi
# Ensure the key is correct
if [ "$FAST" -eq 1 ]; then
aa list -i "$TEST_DIR/encrypted.aea" -key-value "base64:$(cat tmp/"$i"/actual.txt)" || ret=$?
else
aea decrypt -i "$TEST_DIR/encrypted.aea" -o "/dev/null" -key-value "base64:$(cat tmp/"$i"/actual.txt)" || ret=$?
fi
if [ $ret -ne 0 ]; then
fail "Failed to decrypt with actual key"
continue
fi
diff "$TMP_DIR/actual.txt" "$TEST_DIR/expected.txt" || ret=$?
if [ $ret -ne 0 ]; then
echo "Warning: key does not match expected key, but decryption was successful"
fi
echo "Test $i passed"
echo ""
done
rm -rf tmp
echo Done
if [ $FAILED -ne 0 ]; then
echo "Some tests failed"
exit 1
fi